-->
Page 1 of 1

MPR121 touch sensor

PostPosted: Fri Mar 11, 2016 1:56 pm
by jmccoy555
Hello all,

I'm trying to use the MPR121 touch sensor with Sming but am getting no where...... other than more confused :roll:

Would any of you good people be able to provide an example to get me going?

Thanks!

Re: MPR121 touch sensor

PostPosted: Mon Mar 14, 2016 5:00 pm
by jmccoy555
So, it turns out to be quite easy once you know how!!!

1. Download, extract and put the Adafruit library in the Sming/Libraries folder
2. I had to change line 87 from __attribute__((deprecated)) void setThreshholds(uint8_t touch, uint8_t release); to void setThreshholds(uint8_t touch, uint8_t release);
3. Remake sming (wasn't an obvious step to me until I though about it, make clean - make - make spiffy
4 Cobble together some code based on the Arduino example (not sure if its 100% accurate and correct but it works!);

#include <user_config.h>
#include <SmingCore/SmingCore.h>
#include <Libraries/Adafruit_MPR121/Adafruit_MPR121.h>

Adafruit_MPR121 cap = Adafruit_MPR121();

// Keeps track of the last pins touched
// so we know when buttons are 'released'
uint16_t lasttouched = 0;
uint16_t currtouched = 0;

Timer procTouchTimer;

void touch()
{

// Get the currently touched pads
currtouched = cap.touched();

for (uint8_t i=0; i<12; i++) {
// it if *is* touched and *wasnt* touched before, alert!
if ((currtouched & _BV(i)) && !(lasttouched & _BV(i)) ) {
Serial.print(i); Serial.println(" touched");
}
// if it *was* touched and now *isnt*, alert!
if (!(currtouched & _BV(i)) && (lasttouched & _BV(i)) ) {
Serial.print(i); Serial.println(" released");
}
}

// reset our state
lasttouched = currtouched;

// comment out this line for detailed data from the sensor!
return;

// debugging info, what
Serial.print("\t\t\t\t\t\t\t\t\t\t\t\t\t 0x"); Serial.println(cap.touched(), HEX);
Serial.print("Filt: ");
for (uint8_t i=0; i<12; i++) {
Serial.print(cap.filteredData(i)); Serial.print("\t");
}
Serial.println();
Serial.print("Base: ");
for (uint8_t i=0; i<12; i++) {
Serial.print(cap.baselineData(i)); Serial.print("\t");
}
Serial.println();


}


void init()
{
Serial.begin(SERIAL_BAUD_RATE); // 115200 by default
Serial.systemDebugOutput(true); // Debug output to serial



cap.begin(0x5A);
procTouchTimer.initializeMs(1 * 500, touch).start(); // check every 500ms

}



Hope that helps someone out! I guess it would be similar for other libraries too.

Re: MPR121 touch sensor

PostPosted: Tue Jun 13, 2017 8:50 am
by zhinc
jmccoy555 wrote:So, it turns out to be quite easy once you know how!!!

1. Download, extract and put the Adafruit library in the Sming/Libraries folder
2. I had to change line 87 from __attribute__((deprecated)) void setThreshholds(uint8_t touch, uint8_t release); to void setThreshholds(uint8_t touch, uint8_t release);
3. Remake sming (wasn't an obvious step to me until I though about it, make clean - make - make spiffy
4 Cobble together some code based on the Arduino example (not sure if its 100% accurate and correct but it works!);

Hope that helps someone out! I guess it would be similar for other libraries too.

Hello,
I'm sorry.. I'm very new to the NodeMCU and MPR121
What does remake sming mean?
Where should I change the line of code(line 87)?

Any help would be great

Thanks,
Zhinc