Arduino with mpr121 and openlog

Hi,

maybe someone can help me with this.

I have a code for an mpr121 generating sounds from 8 sensor pads connected with an Arduino and a loudspeaker.

I bought an openlog and want to change this code now, so the signal of the sensors pad of the mpr121 will directly write on the sd card of the openlog.

I probably need to change the PWM value for generating the sound and simply write the message then by logging with serial.print() connecting openlog to an arduino pro mini interface. But i am not clear how to do this practically. Maybe someone can give me help with this. Enclosed below please find the code.

/*
 MPR121 capacitive keyboard

 Based on http://www.prizepony.us/2010/10/using-a-mpr121-with-arduino/
 Tested on an Arduino Mega
 */

#include <Wire.h>     // Wiring two-wire library for I2C
#include "mpr121.h"   // register definitions

int notes[]={239,213,190,179,159,142,127,119};
char touch_previous;

void setup()
{
  
  Serial.begin(9600);
  
  // PWM SETUP
  //http://www.arcfn.com/2009/07/secrets-of-arduino-pwm.html
  //Varying the timer top limit: phase-correct PWM 
  pinMode(9,OUTPUT);
  pinMode(10,OUTPUT);
  TCCR2A = _BV(COM2A0) | _BV(COM2B1) | _BV(WGM20);
  TCCR2B = _BV(WGM22) | _BV(CS22);
  OCR2B = 10;

  // MPR121 CONFIG
  Wire.begin();
  mpr121QuickConfig();
  
  touch_previous=0;
}

void loop()
{
  char buffer[32];
  int i=0;
  int note=0;
  
  Wire.beginTransmission(0x5A);
  Wire.send(0);

  Wire.requestFrom(0x5A, 18);
  
  while(Wire.available())
  { 
    buffer[i] = Wire.receive();
    i++;
  }
  Wire.endTransmission();

  if (buffer[0] != touch_previous){
    touch_previous=buffer[0];
    Serial.print("TOUCH STATUS ");
    Serial.println(buffer[0], DEC);
    
    note=0;
    for(i=0;i<8;i++){
      if ((buffer[0]>>i)&1){
        note=i;
      }
    }
    if (buffer[0]){
      OCR2A = notes[note];
    }else{
      OCR2A = 0;
    }
  }
  
}

char mpr121Read(unsigned char address)
{
  char data;

  Wire.beginTransmission(0x5A);  // begin communication with the MPR121 on I2C address 0x5A
  Wire.send(address);            // sets the register pointer
  Wire.requestFrom(0x5A, 1);     // request for the MPR121 to send you a single byte

  // check to see if we've received the byte over I2C
  if(1 <= Wire.available())
  {
    data = Wire.receive();
  }

  Wire.endTransmission();        // ends communication

  return data;  // return the received data
}

void mpr121Write(unsigned char address, unsigned char data)
{
  Wire.beginTransmission(0x5A);  // begin communication with the MPR121 on I2C address 0x5A 
  Wire.send(address);            // sets the register pointer
  Wire.send(data);               // sends data to be stored
  Wire.endTransmission();        // ends communication
}

// MPR121 Quick Config
// This will configure all registers as described in AN3944
// Input: none
// Output: none

void mpr121QuickConfig(void)
{
  // Section A
  // This group controls filtering when data is > baseline.
  mpr121Write(MHD_R, 0x01);
  mpr121Write(NHD_R, 0x01);
  mpr121Write(NCL_R, 0x00);
  mpr121Write(FDL_R, 0x00);

  // Section B
  // This group controls filtering when data is < baseline.
  mpr121Write(MHD_F, 0x01);
  mpr121Write(NHD_F, 0x01);
  mpr121Write(NCL_F, 0xFF);
  mpr121Write(FDL_F, 0x02);

  // Section C
  // This group sets touch and release thresholds for each electrode
  mpr121Write(ELE0_T, TOU_THRESH);
  mpr121Write(ELE0_R, REL_THRESH);
  mpr121Write(ELE1_T, TOU_THRESH);
  mpr121Write(ELE1_R, REL_THRESH);
  mpr121Write(ELE2_T, TOU_THRESH);
  mpr121Write(ELE2_R, REL_THRESH);
  mpr121Write(ELE3_T, TOU_THRESH);
  mpr121Write(ELE3_R, REL_THRESH);
  mpr121Write(ELE4_T, TOU_THRESH);
  mpr121Write(ELE4_R, REL_THRESH);
  mpr121Write(ELE5_T, TOU_THRESH);
  mpr121Write(ELE5_R, REL_THRESH);

  mpr121Write(ELE6_T, TOU_THRESH);
  mpr121Write(ELE6_R, REL_THRESH);
  mpr121Write(ELE7_T, TOU_THRESH);
  mpr121Write(ELE7_R, REL_THRESH);
  mpr121Write(ELE8_T, TOU_THRESH);
  mpr121Write(ELE8_R, REL_THRESH);
  mpr121Write(ELE9_T, TOU_THRESH);
  mpr121Write(ELE9_R, REL_THRESH);
  mpr121Write(ELE10_T, TOU_THRESH);
  mpr121Write(ELE10_R, REL_THRESH);
  mpr121Write(ELE11_T, TOU_THRESH);
  mpr121Write(ELE11_R, REL_THRESH);

  // Section D
  // Set the Filter Configuration
  // Set ESI2
  //mpr121Write(FIL_CFG, 0x04);
  mpr121Write(FIL_CFG, 0x00);

  // Section E
  // Electrode Configuration
  // Enable 6 Electrodes and set to run mode
  // Set ELE_CFG to 0x00 to return to standby mode
  mpr121Write(ELE_CFG, 0x0C);	// Enables all 12 Electrodes
  //mpr121Write(ELE_CFG, 0x06);		// Enable first 6 electrodes

  // Section F
  // Enable Auto Config and auto Reconfig
  mpr121Write(ATO_CFG0, 0x0B);
   	mpr121Write(ATO_CFGU, 0xC9);	// USL = (Vdd-0.7)/vdd*256 = 0xC9 @3.3V
   	mpr121Write(ATO_CFGL, 0x82);	// LSL = 0.65*USL = 0x82 @3.3V
   	mpr121Write(ATO_CFGT, 0xB5);  // Target = 0.9*USL = 0xB5 @3.3V

}
/*
    MPR121.h
	
*/

// MPR121 Register Defines
#define MHD_R	0x2B
#define NHD_R	0x2C
#define	NCL_R 	0x2D
#define	FDL_R	0x2E
#define	MHD_F	0x2F
#define	NHD_F	0x30
#define	NCL_F	0x31
#define	FDL_F	0x32
#define	ELE0_T	0x41
#define	ELE0_R	0x42
#define	ELE1_T	0x43
#define	ELE1_R	0x44
#define	ELE2_T	0x45
#define	ELE2_R	0x46
#define	ELE3_T	0x47
#define	ELE3_R	0x48
#define	ELE4_T	0x49
#define	ELE4_R	0x4A
#define	ELE5_T	0x4B
#define	ELE5_R	0x4C
#define	ELE6_T	0x4D
#define	ELE6_R	0x4E
#define	ELE7_T	0x4F
#define	ELE7_R	0x50
#define	ELE8_T	0x51
#define	ELE8_R	0x52
#define	ELE9_T	0x53
#define	ELE9_R	0x54
#define	ELE10_T	0x55
#define	ELE10_R	0x56
#define	ELE11_T	0x57
#define	ELE11_R	0x58
#define	FIL_CFG	0x5D
#define	ELE_CFG	0x5E
#define GPIO_CTRL0	0x73
#define	GPIO_CTRL1	0x74
#define GPIO_DATA	0x75
#define	GPIO_DIR	0x76
#define	GPIO_EN		0x77
#define	GPIO_SET	0x78
#define	GPIO_CLEAR	0x79
#define	GPIO_TOGGLE	0x7A
#define	ATO_CFG0	0x7B
#define	ATO_CFGU	0x7D
#define	ATO_CFGL	0x7E
#define	ATO_CFGT	0x7F


// Global Constants
#define TOU_THRESH	0x05
#define	REL_THRESH	0x02

jumbo9001:
… and simply write the message then by logging with serial.print() connecting openlog to an arduino pro mini interface.

I think you've answered your own question ... maybe. If you want to log all the serial messages sent by the Arduino to the serial monitor (and also to the Openlog) then simply connect the Openlog to the Arduino's TX-O ouput. The use the Serial.print() (and/or Serial.println()) command to log whatever it is you want logged. As is you have the port setup to the correct 9600 baud and if connected as above then you should log the key detected each time it's pressed via the existing code snippet below.
    Serial.print("TOUCH STATUS ");
    Serial.println(buffer[0], DEC);

If you want to be able to send to the PC, and log, differing messages then you can use the SoftwareSerial library and assign a new output pin for the logger. The “print” to the software port those messages you want logged.

http://arduino.cc/en/Reference/SoftwareSerial

I don’t understand why you think you have to change PWM frequencies or what that would have to do with logging data. :?: What is it that you wish to log exactly ? And that makes me wonder …

Alternately when you said …

I bought an openlog and want to change this code now,…

By "this" do you mean you wish to change the code of the Openlog to incorporate your existing code on the Arduino with that of the Openlog so as to eliminate the Arduino in between the 2 ? That is your system would be just the Openlog and the MPR121 (and the speaker) ? This is a bit trickier but should be do-able.

Interestingly (to me anyway) the Openlog’s 328 runs on 3.3v and at 16 MHz. If your existing Arduino is a basic Uno, you shouldn’t have to change the PWM settings as the clocks are the same. The MPR121 also runs at 3.3v so you shouldn’t have any problems with interfacing the two. The MPR121 would normally be wired to the SDA and SCL lines (A4 and A5 on an Uno) and the corresponding pins are unused on the Openlog’s 328. The MPR121 would also use the external interrupt on an Uno’s D2 and that’s free on the Openlog also. The tricky part is that those pins on the Openlog 328, because they’re unused, aren’t brought out to any connector. You’ll have to directly tack wires onto the pins to connect to the MPR121. And add the pull-up resistors of course. I don’t know what pin you’re presently using to drive the speaker (piezo ?) but again there are free pins to do that and you’ll need to tack on another wire.

You would need a USB-TTLserial converter board as described here to load the new code.

https://github.com/sparkfun/OpenLog/wik … g-Firmware

Then it’s just a question of combining the 2 code packages and hoping they’ll fit. It might be just as easy as inserting your code into that of the Openlog (in the proper places of course). I don’t see any inherent conflicts btw the 2 software packages but timing might be one possible gotcha.

Of course the Openlog won’t be logging messages received via it’s UART in your case, but it should be “easy” to store the ASCII you want logged in the appropriate array so it gets sent to the SD card. Now I suppose you could use the SoftwareSerial library to “print” the text you want logged, out on a spare digital pin (tack on yet another wire) and then wire that pin to the RX-I of the Openlog and so not have to do that new code. :idea: You’d then log the data as done normally.

Ok i just connected alltogether, the arduino, i use an arduino nano here, the mpr121 and the openlog.

I connected the RXI pin of the openlog with the RXO pin of the Arduino. Due to this the line

  pinMode(10, OUTPUT);

in the void setup i would need to change to

  pinMode(RXI, OUTPUT);

?

Enclosed the code, which i changed in the void setup section and added the serial print touch status, but it does not want to compile.

/*
 MPR121 capacitive keyboard
 http://youtu.be/Cksx3Cq4EBI
 
 November 2011
 by Xulio Coira <xulioc@gmail.com>
 
 Based on http://www.prizepony.us/2010/10/using-a-mpr121-with-arduino/
 Tested on an Arduino Mega
 */

#include <Wire.h>     // Wiring two-wire library for I2C
#include "mpr121.h"   // register definitions

int notes[]={239,213,190,179,159,142,127,119};
char touch_previous;

void setup()
{
  
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. 
  }
  
  
  Serial.print("TOUCH STATUS ");
    Serial.println(buffer[0], DEC);
  
  pinMode(10, OUTPUT);
  
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    return;
  }
  Serial.println("card initialized.");

  

  // MPR121 CONFIG
  Wire.begin();
  mpr121QuickConfig();
  
  touch_previous=0;
}

void loop()
{
  char buffer[32];
  int i=0;
  int note=0;
  
  Wire.beginTransmission(0x5A);
  Wire.send(0);

  Wire.requestFrom(0x5A, 18);
  
  while(Wire.available())
  { 
    buffer[i] = Wire.receive();
    i++;
  }
  Wire.endTransmission();

  if (buffer[0] != touch_previous){
    touch_previous=buffer[0];
    Serial.print("TOUCH STATUS ");
    Serial.println(buffer[0], DEC);
    
    note=0;
    for(i=0;i<8;i++){
      if ((buffer[0]>>i)&1){
        note=i;
      }
    }
    if (buffer[0]){
      OCR2A = notes[note];
    }else{
      OCR2A = 0;
    }
  }
  
}

char mpr121Read(unsigned char address)
{
  char data;

  Wire.beginTransmission(0x5A);  // begin communication with the MPR121 on I2C address 0x5A
  Wire.send(address);            // sets the register pointer
  Wire.requestFrom(0x5A, 1);     // request for the MPR121 to send you a single byte

  // check to see if we've received the byte over I2C
  if(1 <= Wire.available())
  {
    data = Wire.receive();
  }

  Wire.endTransmission();        // ends communication

  return data;  // return the received data
}

void mpr121Write(unsigned char address, unsigned char data)
{
  Wire.beginTransmission(0x5A);  // begin communication with the MPR121 on I2C address 0x5A 
  Wire.send(address);            // sets the register pointer
  Wire.send(data);               // sends data to be stored
  Wire.endTransmission();        // ends communication
}

// MPR121 Quick Config
// This will configure all registers as described in AN3944
// Input: none
// Output: none

void mpr121QuickConfig(void)
{
  // Section A
  // This group controls filtering when data is > baseline.
  mpr121Write(MHD_R, 0x01);
  mpr121Write(NHD_R, 0x01);
  mpr121Write(NCL_R, 0x00);
  mpr121Write(FDL_R, 0x00);

  // Section B
  // This group controls filtering when data is < baseline.
  mpr121Write(MHD_F, 0x01);
  mpr121Write(NHD_F, 0x01);
  mpr121Write(NCL_F, 0xFF);
  mpr121Write(FDL_F, 0x02);

  // Section C
  // This group sets touch and release thresholds for each electrode
  mpr121Write(ELE0_T, TOU_THRESH);
  mpr121Write(ELE0_R, REL_THRESH);
  mpr121Write(ELE1_T, TOU_THRESH);
  mpr121Write(ELE1_R, REL_THRESH);
  mpr121Write(ELE2_T, TOU_THRESH);
  mpr121Write(ELE2_R, REL_THRESH);
  mpr121Write(ELE3_T, TOU_THRESH);
  mpr121Write(ELE3_R, REL_THRESH);
  mpr121Write(ELE4_T, TOU_THRESH);
  mpr121Write(ELE4_R, REL_THRESH);
  mpr121Write(ELE5_T, TOU_THRESH);
  mpr121Write(ELE5_R, REL_THRESH);

  mpr121Write(ELE6_T, TOU_THRESH);
  mpr121Write(ELE6_R, REL_THRESH);
  mpr121Write(ELE7_T, TOU_THRESH);
  mpr121Write(ELE7_R, REL_THRESH);
  mpr121Write(ELE8_T, TOU_THRESH);
  mpr121Write(ELE8_R, REL_THRESH);
  mpr121Write(ELE9_T, TOU_THRESH);
  mpr121Write(ELE9_R, REL_THRESH);
  mpr121Write(ELE10_T, TOU_THRESH);
  mpr121Write(ELE10_R, REL_THRESH);
  mpr121Write(ELE11_T, TOU_THRESH);
  mpr121Write(ELE11_R, REL_THRESH);

  // Section D
  // Set the Filter Configuration
  // Set ESI2
  //mpr121Write(FIL_CFG, 0x04);
  mpr121Write(FIL_CFG, 0x00);

  // Section E
  // Electrode Configuration
  // Enable 6 Electrodes and set to run mode
  // Set ELE_CFG to 0x00 to return to standby mode
  mpr121Write(ELE_CFG, 0x0C);	// Enables all 12 Electrodes
  //mpr121Write(ELE_CFG, 0x06);		// Enable first 6 electrodes

  // Section F
  // Enable Auto Config and auto Reconfig
  mpr121Write(ATO_CFG0, 0x0B);
   	mpr121Write(ATO_CFGU, 0xC9);	// USL = (Vdd-0.7)/vdd*256 = 0xC9 @3.3V
   	mpr121Write(ATO_CFGL, 0x82);	// LSL = 0.65*USL = 0x82 @3.3V
   	mpr121Write(ATO_CFGT, 0xB5);  // Target = 0.9*USL = 0xB5 @3.3V

}
[/*
    MPR121.h
	April 8, 2010
	by: Jim Lindblom
*/

// MPR121 Register Defines
#define MHD_R	0x2B
#define NHD_R	0x2C
#define	NCL_R 	0x2D
#define	FDL_R	0x2E
#define	MHD_F	0x2F
#define	NHD_F	0x30
#define	NCL_F	0x31
#define	FDL_F	0x32
#define	ELE0_T	0x41
#define	ELE0_R	0x42
#define	ELE1_T	0x43
#define	ELE1_R	0x44
#define	ELE2_T	0x45
#define	ELE2_R	0x46
#define	ELE3_T	0x47
#define	ELE3_R	0x48
#define	ELE4_T	0x49
#define	ELE4_R	0x4A
#define	ELE5_T	0x4B
#define	ELE5_R	0x4C
#define	ELE6_T	0x4D
#define	ELE6_R	0x4E
#define	ELE7_T	0x4F
#define	ELE7_R	0x50
#define	ELE8_T	0x51
#define	ELE8_R	0x52
#define	ELE9_T	0x53
#define	ELE9_R	0x54
#define	ELE10_T	0x55
#define	ELE10_R	0x56
#define	ELE11_T	0x57
#define	ELE11_R	0x58
#define	FIL_CFG	0x5D
#define	ELE_CFG	0x5E
#define GPIO_CTRL0	0x73
#define	GPIO_CTRL1	0x74
#define GPIO_DATA	0x75
#define	GPIO_DIR	0x76
#define	GPIO_EN		0x77
#define	GPIO_SET	0x78
#define	GPIO_CLEAR	0x79
#define	GPIO_TOGGLE	0x7A
#define	ATO_CFG0	0x7B
#define	ATO_CFGU	0x7D
#define	ATO_CFGL	0x7E
#define	ATO_CFGT	0x7F


// Global Constants
#define TOU_THRESH	0x05
#define	REL_THRESH	0x02

jumbo9001:
Ok i just connected alltogether, the arduino, i use an arduino nano here, the mpr121 and the openlog.

I connected the RXI pin of the openlog with the RXO pin of the Arduino.

Why ? What you've done is connect the output of the USB->serial IC to your Openlog.

Due to this the line

  pinMode(10, OUTPUT);

in the void setup i would need to change to

  pinMode(RXI, OUTPUT);

?

Why ? What is pin 10 supposed to do ? What did you define RXI as ? I didn’t see it in the code below ? Nor did I see the above line.

Enclosed the code, which i changed in the void setup section and added the serial print touch status, but it does not want to compile.

I got an error message that *buffer* wasn't defined and a bunch of other errors because I don't have the proper libraries installed. Why don't you copy and paste the error messages you got. In the Arduino IDE under File, Preferences, be sure to check the "show verbose output during compilation".

BTW a Nano is generally a 5V device and the MPR121 a 3.3V device. You need to be careful about how you interconnect them.

I cleaned up the obvious errors. See if this compiles.

/*
     MPR121 capacitive keyboard
 http://youtu.be/Cksx3Cq4EBI
 
 November 2011
 by Xulio Coira <xulioc@gmail.com>
 
 Based on http://www.prizepony.us/2010/10/using-a-mpr121-with-arduino/
 Tested on an Arduino Mega
 */

#include <Wire.h>     // Wiring two-wire library for I2C
#include "mpr121.h"   // register definitions

int notes[]={
  239,213,190,179,159,142,127,119};
char touch_previous;
char buffer[32];
int i=0;
int note=0;

void setup()
{
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect.
  }

  Serial.print("TOUCH STATUS ");
  Serial.println(buffer[0], DEC);

  pinMode(10, OUTPUT);  //What is this for ????????????

  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    return;
  }
  Serial.println("card initialized.");

  // MPR121 CONFIG
  Wire.begin();
  mpr121QuickConfig();

  touch_previous=0;
}

void loop()
{
  Wire.beginTransmission(0x5A);
  Wire.write(0);

  Wire.requestFrom(0x5A, 18);

  while(Wire.available())
  {
    buffer[i] = Wire.read();
    i++;
  }
  Wire.endTransmission();

  if (buffer[0] != touch_previous){
    touch_previous=buffer[0];
    Serial.print("TOUCH STATUS ");
    Serial.println(buffer[0], DEC);

    note=0;
    for(i=0; i<8; i++){
      if ((buffer[0]>>i)&1){
        note=i;
      }
    }
    if (buffer[0]){
      OCR2A = notes[note];
    }
    else{
      OCR2A = 0;
    }
  }
}

char mpr121Read(unsigned char address)
{
  char data;

  Wire.beginTransmission(0x5A);  // begin communication with the MPR121 on I2C address 0x5A
  Wire.write(address);            // sets the register pointer
  Wire.requestFrom(0x5A, 1);     // request for the MPR121 to send you a single byte

  // check to see if we've received the byte over I2C
  if(1 <= Wire.available())
  {
    data = Wire.read();
  }

  Wire.endTransmission();        // ends communication

    return data;  // return the received data
}

void mpr121Write(unsigned char address, unsigned char data)
{
  Wire.beginTransmission(0x5A);  // begin communication with the MPR121 on I2C address 0x5A
  Wire.write(address);            // sets the register pointer
  Wire.write(data);               // sends data to be stored
  Wire.endTransmission();        // ends communication
}

// MPR121 Quick Config
// This will configure all registers as described in AN3944
// Input: none
// Output: none

void mpr121QuickConfig(void)
{
  // Section A
  // This group controls filtering when data is > baseline.
  mpr121Write(MHD_R, 0x01);
  mpr121Write(NHD_R, 0x01);
  mpr121Write(NCL_R, 0x00);
  mpr121Write(FDL_R, 0x00);

  // Section B
  // This group controls filtering when data is < baseline.
  mpr121Write(MHD_F, 0x01);
  mpr121Write(NHD_F, 0x01);
  mpr121Write(NCL_F, 0xFF);
  mpr121Write(FDL_F, 0x02);

  // Section C
  // This group sets touch and release thresholds for each electrode
  mpr121Write(ELE0_T, TOU_THRESH);
  mpr121Write(ELE0_R, REL_THRESH);
  mpr121Write(ELE1_T, TOU_THRESH);
  mpr121Write(ELE1_R, REL_THRESH);
  mpr121Write(ELE2_T, TOU_THRESH);
  mpr121Write(ELE2_R, REL_THRESH);
  mpr121Write(ELE3_T, TOU_THRESH);
  mpr121Write(ELE3_R, REL_THRESH);
  mpr121Write(ELE4_T, TOU_THRESH);
  mpr121Write(ELE4_R, REL_THRESH);
  mpr121Write(ELE5_T, TOU_THRESH);
  mpr121Write(ELE5_R, REL_THRESH);

  mpr121Write(ELE6_T, TOU_THRESH);
  mpr121Write(ELE6_R, REL_THRESH);
  mpr121Write(ELE7_T, TOU_THRESH);
  mpr121Write(ELE7_R, REL_THRESH);
  mpr121Write(ELE8_T, TOU_THRESH);
  mpr121Write(ELE8_R, REL_THRESH);
  mpr121Write(ELE9_T, TOU_THRESH);
  mpr121Write(ELE9_R, REL_THRESH);
  mpr121Write(ELE10_T, TOU_THRESH);
  mpr121Write(ELE10_R, REL_THRESH);
  mpr121Write(ELE11_T, TOU_THRESH);
  mpr121Write(ELE11_R, REL_THRESH);

  // Section D
  // Set the Filter Configuration
  // Set ESI2
  //mpr121Write(FIL_CFG, 0x04);
  mpr121Write(FIL_CFG, 0x00);

  // Section E
  // Electrode Configuration
  // Enable 6 Electrodes and set to run mode
  // Set ELE_CFG to 0x00 to return to standby mode
  mpr121Write(ELE_CFG, 0x0C);   // Enables all 12 Electrodes
  //mpr121Write(ELE_CFG, 0x06);      // Enable first 6 electrodes

  // Section F
  // Enable Auto Config and auto Reconfig
  mpr121Write(ATO_CFG0, 0x0B);
  mpr121Write(ATO_CFGU, 0xC9);   // USL = (Vdd-0.7)/vdd*256 = 0xC9 @3.3V
  mpr121Write(ATO_CFGL, 0x82);   // LSL = 0.65*USL = 0x82 @3.3V
  mpr121Write(ATO_CFGT, 0xB5);  // Target = 0.9*USL = 0xB5 @3.3V
}

I still have no idea what you’re trying to with pin 10.

Hi,

thanks now it compiles. The pin 10 thing was rest of a code i once used for sd breakout module.

openlog, mpr121 and arduino are now connected.

But after uploading the code, i open the serial monitor and i just get there

: TOUCH STATUS 0

It doesnt react when one of the sensors is being touched.

I connected here only the RXI of the openlog with the TXO pin of the arduino pro mini. Should that be enough or is that the reason why it doesnt run?

Below is the setup of my wiring and the code as well:

Mpr121 → Arduino Pro mini:

3.3v → VCC

IRQ → D2

SCL → A5

SDA → A4

GND → GND

Sensor → Mpr121:

Sensor 1 –> Pin 0 mrp121

Sensor 2 → Pin 1 mpr121

Sensor 3 –> Pin 2 mpr121

Sensor 4 → Pin 3 mpr121

Sensor 5 → Pin 4 mpr121

Sensor 6 → Pin 5 mpr121

Sensor 7 → Pin 6 mpr121

Sensor 8 → Pin 7 mpr121

Openlog → Arduino Pro Mini:

RXI → TXO

VCC → Connected to 3.3V of the mpr121

GND → GND

TXO → RXI

FTDI Basic Breakout – 3.3V → Arduino Pro Mini:

BLK → BLK

CTS → GND

3.3V –> VCC

RXI → TXO

GRN → GRN

This is my code:

/*
     MPR121 capacitive keyboard
 
 */
#include <Wire.h>     // Wiring two-wire library for I2C
#include "mpr121.h"   // register definitions
int notes[]={
  239,213,190,179,159,142,127,119};
char touch_previous;
char buffer[32];
int i=0;
int note=0;
void setup()
{
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect.
  }
  Serial.print("TOUCH STATUS ");
  Serial.println(buffer[0], DEC);

  // MPR121 CONFIG
  Wire.begin();
  mpr121QuickConfig();
  touch_previous=0;
}
void loop()
{
  Wire.beginTransmission(0x5A);
  Wire.write(0);
  Wire.requestFrom(0x5A, 18);
  while(Wire.available())
  {
    buffer[i] = Wire.read();
    i++;
  }
  Wire.endTransmission();
  if (buffer[0] != touch_previous){
    touch_previous=buffer[0];
    Serial.print("TOUCH STATUS ");
    Serial.println(buffer[0], DEC);
    note=0;
    for(i=0; i<8; i++){
      if ((buffer[0]>>i)&1){
        note=i;
      }
    }
    if (buffer[0]){
      OCR2A = notes[note];
    }
    else{
      OCR2A = 0;
    }
  }
}
char mpr121Read(unsigned char address)
{
  char data;
  Wire.beginTransmission(0x5A);  // begin communication with the MPR121 on I2C address 0x5A
  Wire.write(address);            // sets the register pointer
  Wire.requestFrom(0x5A, 1);     // request for the MPR121 to send you a single byte
  // check to see if we've received the byte over I2C
  if(1 <= Wire.available())
  {
    data = Wire.read();
  }
  Wire.endTransmission();        // ends communication
    return data;  // return the received data
}
void mpr121Write(unsigned char address, unsigned char data)
{
  Wire.beginTransmission(0x5A);  // begin communication with the MPR121 on I2C address 0x5A
  Wire.write(address);            // sets the register pointer
  Wire.write(data);               // sends data to be stored
  Wire.endTransmission();        // ends communication
}
// MPR121 Quick Config
// This will configure all registers as described in AN3944
// Input: none
// Output: none
void mpr121QuickConfig(void)
{
  // Section A
  // This group controls filtering when data is > baseline.
  mpr121Write(MHD_R, 0x01);
  mpr121Write(NHD_R, 0x01);
  mpr121Write(NCL_R, 0x00);
  mpr121Write(FDL_R, 0x00);
  // Section B
  // This group controls filtering when data is < baseline.
  mpr121Write(MHD_F, 0x01);
  mpr121Write(NHD_F, 0x01);
  mpr121Write(NCL_F, 0xFF);
  mpr121Write(FDL_F, 0x02);
  // Section C
  // This group sets touch and release thresholds for each electrode
  mpr121Write(ELE0_T, TOU_THRESH);
  mpr121Write(ELE0_R, REL_THRESH);
  mpr121Write(ELE1_T, TOU_THRESH);
  mpr121Write(ELE1_R, REL_THRESH);
  mpr121Write(ELE2_T, TOU_THRESH);
  mpr121Write(ELE2_R, REL_THRESH);
  mpr121Write(ELE3_T, TOU_THRESH);
  mpr121Write(ELE3_R, REL_THRESH);
  mpr121Write(ELE4_T, TOU_THRESH);
  mpr121Write(ELE4_R, REL_THRESH);
  mpr121Write(ELE5_T, TOU_THRESH);
  mpr121Write(ELE5_R, REL_THRESH);
  mpr121Write(ELE6_T, TOU_THRESH);
  mpr121Write(ELE6_R, REL_THRESH);
  mpr121Write(ELE7_T, TOU_THRESH);
  mpr121Write(ELE7_R, REL_THRESH);
  mpr121Write(ELE8_T, TOU_THRESH);
  mpr121Write(ELE8_R, REL_THRESH);
  mpr121Write(ELE9_T, TOU_THRESH);
  mpr121Write(ELE9_R, REL_THRESH);
  mpr121Write(ELE10_T, TOU_THRESH);
  mpr121Write(ELE10_R, REL_THRESH);
  mpr121Write(ELE11_T, TOU_THRESH);
  mpr121Write(ELE11_R, REL_THRESH);
  // Section D
  // Set the Filter Configuration
  // Set ESI2
  //mpr121Write(FIL_CFG, 0x04);
  mpr121Write(FIL_CFG, 0x00);
  // Section E
  // Electrode Configuration
  // Enable 6 Electrodes and set to run mode
  // Set ELE_CFG to 0x00 to return to standby mode
  mpr121Write(ELE_CFG, 0x0C);   // Enables all 12 Electrodes
  //mpr121Write(ELE_CFG, 0x06);      // Enable first 6 electrodes
  // Section F
  // Enable Auto Config and auto Reconfig
  mpr121Write(ATO_CFG0, 0x0B);
  mpr121Write(ATO_CFGU, 0xC9);   // USL = (Vdd-0.7)/vdd*256 = 0xC9 @3.3V
  mpr121Write(ATO_CFGL, 0x82);   // LSL = 0.65*USL = 0x82 @3.3V
  mpr121Write(ATO_CFGT, 0xB5);  // Target = 0.9*USL = 0xB5 @3.3V
}
/*
    MPR121.h
	
*/

// MPR121 Register Defines
#define MHD_R	0x2B
#define NHD_R	0x2C
#define	NCL_R 	0x2D
#define	FDL_R	0x2E
#define	MHD_F	0x2F
#define	NHD_F	0x30
#define	NCL_F	0x31
#define	FDL_F	0x32
#define	ELE0_T	0x41
#define	ELE0_R	0x42
#define	ELE1_T	0x43
#define	ELE1_R	0x44
#define	ELE2_T	0x45
#define	ELE2_R	0x46
#define	ELE3_T	0x47
#define	ELE3_R	0x48
#define	ELE4_T	0x49
#define	ELE4_R	0x4A
#define	ELE5_T	0x4B
#define	ELE5_R	0x4C
#define	ELE6_T	0x4D
#define	ELE6_R	0x4E
#define	ELE7_T	0x4F
#define	ELE7_R	0x50
#define	ELE8_T	0x51
#define	ELE8_R	0x52
#define	ELE9_T	0x53
#define	ELE9_R	0x54
#define	ELE10_T	0x55
#define	ELE10_R	0x56
#define	ELE11_T	0x57
#define	ELE11_R	0x58
#define	FIL_CFG	0x5D
#define	ELE_CFG	0x5E
#define GPIO_CTRL0	0x73
#define	GPIO_CTRL1	0x74
#define GPIO_DATA	0x75
#define	GPIO_DIR	0x76
#define	GPIO_EN		0x77
#define	GPIO_SET	0x78
#define	GPIO_CLEAR	0x79
#define	GPIO_TOGGLE	0x7A
#define	ATO_CFG0	0x7B
#define	ATO_CFGU	0x7D
#define	ATO_CFGL	0x7E
#define	ATO_CFGT	0x7F


// Global Constants
#define TOU_THRESH	0x05
#define	REL_THRESH	0x02

I was under the impression that you had the MPR121 working with an Arduino prior adding the Openlog ? Ideally the Openlog comes ready to log, just add power, gnd and the input data and it’s supposed to log. The connections you describe above for it look good. If you can upload code to the Arduino Pro, then the FTDI board connections are good. If the MPR121 isn’t working now, let me suggest you concentrate on just that to start with … disconnect the Openlog. Start simple, get it working and then add in more “stuff”.

Right now it seems you can upload code. If you’re unsure that’s working, upload a simple blinking LED sketch and verify it works. So far as I can tell your MPR121 connections look good, perhaps it’s time to verify there really are what you think they are. If the wires are all good … and if you didn’t have the MPR121 working beforehand … then it’s time to read the manual and see if there’s any configuration of it that needs doing. I’ve not worked with it before so I’m starting where you are re: the MPR121.