0

Capacitive Touch on CPX 'Floats' on touch
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Capacitive Touch on CPX 'Floats' on touch

by notaquestion on Wed Feb 03, 2021 2:23 am

Hi Folks,

I've recently purchased some Circuit Playground Expresses to use with a project I wrote on a CPB. I'm working in Arduino.

I've noticed the Capacitive Touch isn't working the same way? The reading oscillates from 0 to 1000 rapidly when I touch an alligator clip connected to a pad, and osilates a little just from having the clip connected. This seems to happen on every pad.

CircuitPlaygroundExpressCapTouchData.png
CircuitPlaygroundExpressCapTouchData.png (181.69 KiB) Viewed 253 times


I found a way to turn the oscillation into a signal, but this isn't something I had to do on the CPB.

Fun bonus fact, if I touch the Ground pads, everything works like normal, i.e. like it did on the CPB, if with a smaller numerical range.

Any idea what could be different/what I'm doing wrong?

notaquestion
 
Posts: 5
Joined: Tue Nov 07, 2017 8:50 pm

Re: Capacitive Touch on CPX 'Floats' on touch

by adavid7 on Wed Feb 03, 2021 11:57 am

Have you issued a calibrate command for the touch pad you are using in your setup() method?

I haven't used the CPX touch pads with the Arduino, only MakeCode, but I imagine that exists in the Arduino library also. You have to calibrate whenever you change what you have connected to the touch pad.

adavid7
 
Posts: 68
Joined: Fri Jul 04, 2014 7:32 pm

Re: Capacitive Touch on CPX 'Floats' on touch

by notaquestion on Thu Feb 04, 2021 2:29 am

I've read through Adafruit_Circuit_Playground.h and .cpp, but I wasn't able to find any calibrate command. I have reset the device several times since clipping on the aligator clip, and the problem happens independently of the alligator clip, so I don't think calibration is the source of the issue.


While looking for a calibrate function though, I did notice that the CPX uses Adafruit_CPlay_FreeTouch while the CPB used CPlay_CapacitiveSensor, so maybe the difference is related to that?

The Freetouch stuff is a bit over my head however... I'm still stuck unsure why things are different.

notaquestion
 
Posts: 5
Joined: Tue Nov 07, 2017 8:50 pm

Re: Capacitive Touch on CPX 'Floats' on touch

by adavid7 on Thu Feb 04, 2021 11:33 pm

I don't know how the libraries are structured and haven't explored them, but in both the JavaScript and Python libraries in MakeCode, I see a method called "input.touch_a1.calibrate()".

Surely that "input" class must also exist in the Arduino library?

adavid7
 
Posts: 68
Joined: Fri Jul 04, 2014 7:32 pm

Re: Capacitive Touch on CPX 'Floats' on touch

by notaquestion on Thu Feb 11, 2021 1:28 am

I really don't think there is a calibrate function.

Also, I'm not using a function to get touches, I'm using it to get a raw capacitive reading. I can check to see if that goes over the threshold myself, but the Raw readings themselves seem wacky.

Here's the public functions from Adafruit_CircuitPlayground.h

Code: Select all | TOGGLE FULL SIZE
bool begin(uint8_t brightness = 20);

  Adafruit_CPlay_NeoPixel strip;  ///< the neopixel strip object
  Adafruit_CPlay_LIS3DH lis;      ///< the accelerometer object
  Adafruit_CPlay_Mic mic;         ///< the microphone object
  Adafruit_CPlay_Speaker speaker; ///< the speaker object

#if defined(__AVR__) ||                                                        \
    defined(ARDUINO_NRF52840_CIRCUITPLAY) // Circuit Playground 'classic' or
                                          // bluefruit
  CPlay_CapacitiveSensor cap[8]; ///< the array of capacitive touch sensors
#else
  Adafruit_CPlay_FreeTouch cap[7]; ///< the array of capacitive touch sensors
  IRrecvPCI irReceiver;            ///< the IR receiver object
  IRdecode irDecoder;              ///< the IR decoder object
  IRsend irSend;                   ///< the IR send object
#endif

  bool slideSwitch(void);
  void redLED(bool v);
  void playTone(uint16_t freq, uint16_t time, bool wait = true);
  bool leftButton(void);
  bool rightButton(void);
  uint16_t lightSensor(void);
  int16_t soundSensor(void);
  float temperature(void);
  float temperatureF(void);

  uint16_t readCap(uint8_t p, uint8_t samples = 10);

  // Accelerometer
  float motionX(void);
  float motionY(void);
  float motionZ(void);

  void setAccelRange(lis3dh_range_t range)

  void setAccelTap(uint8_t c, uint8_t clickthresh)

  uint8_t getAccelTap(void)

  void clearPixels(void)

  void setPixelColor(uint8_t p, uint32_t c)
  void setPixelColor(uint8_t p, uint8_t r, uint8_t g, uint8_t b)
  void setBrightness(uint16_t b)

  uint8_t sine8(uint8_t x)

  uint8_t gamma8(uint8_t x)

  uint32_t colorWheel(uint8_t x);

  void senseColor(uint8_t &red, uint8_t &green, uint8_t &blue);

  uint32_t senseColor()

  bool isExpress(void);

And here are the public functions from Adafruit_CPlay_FreeTouch.h
Code: Select all | TOGGLE FULL SIZE
public:
  Adafruit_CPlay_FreeTouch(int p = 0, oversample_t f = OVERSAMPLE_4, series_resistor_t r = RESISTOR_0, freq_mode_t fh = FREQ_MODE_NONE);
  bool begin(void);

  uint16_t measure(void);
  uint16_t measureRaw(void);


Let me know if I'm missing a calibrate in there? Maybe it's named something I'm not familiar with?

notaquestion
 
Posts: 5
Joined: Tue Nov 07, 2017 8:50 pm

Re: Capacitive Touch on CPX 'Floats' on touch

by adavid7 on Thu Feb 11, 2021 1:44 am

I'm not sure. I've not used those libraries. In MakeCode there is this calibrate method. I just assumed something similar would be in the C++ version, but I don't know much about it.

calibrate.png
calibrate.png (86.5 KiB) Viewed 200 times

adavid7
 
Posts: 68
Joined: Fri Jul 04, 2014 7:32 pm

Re: Capacitive Touch on CPX 'Floats' on touch

by adafruit_support_carter on Thu Feb 11, 2021 4:26 pm

The raw readings can vary from board to board given the different nature of the cap touch hardware.

Are you using the readCap() function?
http://adafruit.github.io/Adafruit_Circ ... e65bd1e923
It has a parameter that let's you adjust the number of samples used to compute an averaged value.

adafruit_support_carter
 
Posts: 20627
Joined: Tue Nov 29, 2016 2:45 pm

Re: Capacitive Touch on CPX 'Floats' on touch

by notaquestion on Sat Feb 13, 2021 7:02 pm

Hi Carter,

Thank you for replying!

I tried adjusting the samples, but it seems like they're not hooked up to anything in Adafruit_CircuitPlayground.cpp if you're using the express.

Code: Select all | TOGGLE FULL SIZE
  uint16_t Adafruit_CircuitPlayground::readCap(uint8_t p, uint8_t samples) {
#if defined(__AVR__) ||                                                        \
    defined(ARDUINO_NRF52840_CIRCUITPLAY) // Circuit Playground Classic or
                                          // bluefruit
  switch (p) {
  case 0:
    return cap[0].capacitiveSensor(samples);
    ...
  }
#elif defined(__SAMD21G18A__) // Circuit Playground Express
  // analog pins r ez!
  if ((p >= A1) && (p <= A7)) {
    return cap[p - A1].measure();
  }
  // oof digital pins
  switch (p) {
  case 0:
    return cap[A6 - A1].measure();
  case 1:
    ...
  }
#endif
}


The measure function it is using Adafruit_CPlay_FreeTouch, declared here.

Code: Select all | TOGGLE FULL SIZE
for (int i = 0; i < 7; i++) {
    cap[i] = Adafruit_CPlay_FreeTouch(A1 + i, OVERSAMPLE_4, RESISTOR_50K,
                                      FREQ_MODE_NONE);
    if (!cap[i].begin())
      return false;
  }


And that takes no paramaters...

Code: Select all | TOGGLE FULL SIZE
uint16_t Adafruit_CPlay_FreeTouch::measure(void) {
  uint16_t m;

  m = measureRaw();
  if (m == -1) return -1;

  // normalize the signal
  switch (oversample) {
    case OVERSAMPLE_1:   return m;
    case OVERSAMPLE_2:   return m/2;
    case OVERSAMPLE_4:   return m/4;
    case OVERSAMPLE_8:   return m/8;
    case OVERSAMPLE_16:  return m/16;
    case OVERSAMPLE_32:  return m/32;
    case OVERSAMPLE_64:  return m/64;
  }

  return -1; // shouldn't reach here but fail if we do!
}


Maybe the answer is in one of these? Nothings commented though so I'm not sure what they actually do.
Code: Select all | TOGGLE FULL SIZE
// set up sense resistor
  setSeriesResistor(seriesres);
  // set up prescalar
  setOversampling(oversample);
  // set up freq hopping
  setFreqHopping(freqhop, hops);
  // set up compensation cap + int (?) cap
  setCompCap(compcap);
  setIntCap(intcap);

notaquestion
 
Posts: 5
Joined: Tue Nov 07, 2017 8:50 pm

Re: Capacitive Touch on CPX 'Floats' on touch

by adafruit_support_carter on Mon Feb 15, 2021 12:44 pm

Seems like maybe it should? Opened an issue for this here:
https://github.com/adafruit/Adafruit_Ci ... /issues/61

adafruit_support_carter
 
Posts: 20627
Joined: Tue Nov 29, 2016 2:45 pm

Re: Capacitive Touch on CPX 'Floats' on touch

by notaquestion on Mon Feb 22, 2021 12:54 am

Any sense of when we may get a reply to the github issue?

I've ordered some of the CPBluefruit versions because I know they don't have this issue, but now I have a couple of CPX I don't currently have a use for.

notaquestion
 
Posts: 5
Joined: Tue Nov 07, 2017 8:50 pm

Re: Capacitive Touch on CPX 'Floats' on touch

by flyingcheesehead on Fri Feb 26, 2021 11:27 pm

notaquestion wrote:I've noticed the Capacitive Touch isn't working the same way? The reading oscillates from 0 to 1000 rapidly when I touch an alligator clip connected to a pad, and osilates a little just from having the clip connected. This seems to happen on every pad.

CircuitPlaygroundExpressCapTouchData.png



I'm getting something similar! viewtopic.php?f=58&t=175832&p=857516#p857516

I don't have a solution, unfortunately, but you're not alone. Really hope this gets resolved soon as it's no fun to have gadgets that don't work right.

flyingcheesehead
 
Posts: 13
Joined: Wed Jan 13, 2021 5:39 pm

Please be positive and constructive with your questions and comments.