I need to use as many inputs as possible with one Arduino. So I need to use multiple CapSens boars with different addresses.
I need some kind of guidance how to wire these up to Arduino - I think I need set of 2 analog–1 dig pin for each board. Or just separate IRQ reading is needed? Also I don't see the reading these analog pins (A4 A5) anywhere in the example code so I have no idea where to do the changes.
If you know this guidance or tutorial exist, pleas point me to it or try to help otherwise.
Capacitive Sensor MPR121 multiple board setup guide
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
-
- Posts: 19
- Joined: Sat Jun 12, 2010 10:47 am
- adafruit_support_carter
- Posts: 29150
- Joined: Tue Nov 29, 2016 2:45 pm
Re: Capacitive Sensor MPR121 multiple board setup guide
From here:ADDR is the I2C address select pin. By default this is pulled down to ground with a 100K resistor, for an I2C address of 0x5A. You can also connect it to the 3Vo pin for an address of 0x5B, the SDA pin for 0x5C or SCL for address 0x5D
https://learn.adafruit.com/adafruit-mpr ... -addr-pins
-
- Posts: 19
- Joined: Sat Jun 12, 2010 10:47 am
Re: Capacitive Sensor MPR121 multiple board setup guide
Thank you.
I had this info already. However do I need to use 100K resistor to connect ADD to other pins? Do I need to unsolder 100K resistor from ADD to GRD?
How about the other questions regarding connecting additional MPR121 to Arduino?
I had this info already. However do I need to use 100K resistor to connect ADD to other pins? Do I need to unsolder 100K resistor from ADD to GRD?
How about the other questions regarding connecting additional MPR121 to Arduino?
- adafruit_support_carter
- Posts: 29150
- Joined: Tue Nov 29, 2016 2:45 pm
Re: Capacitive Sensor MPR121 multiple board setup guide
No. Just straight wire as described above.However do I need to use 100K resistor to connect ADD to other pins?
No.Do I need to unsolder 100K resistor from ADD to GRD?
Once you've assigned each a unique address (via above method), just wire them all on the same I2C bus. You can assign four addresses so are limited to a max of four MPR121s on a given bus.How about the other questions regarding connecting additional MPR121 to Arduino?
-
- Posts: 19
- Joined: Sat Jun 12, 2010 10:47 am
Re: Capacitive Sensor MPR121 multiple board setup guide
I have run into problem that I do not know if it is really a problem.
I have 4 board setup and all is well as long all 4 boards are connected/present. However if even one is missing nothing(the remaining boards) works. Is this how it supposed to be or not?
I have 4 board setup and all is well as long all 4 boards are connected/present. However if even one is missing nothing(the remaining boards) works. Is this how it supposed to be or not?
- adafruit_support_carter
- Posts: 29150
- Joined: Tue Nov 29, 2016 2:45 pm
Re: Capacitive Sensor MPR121 multiple board setup guide
Post a photo showing your setup with all wiring connections.
-
- Posts: 19
- Joined: Sat Jun 12, 2010 10:47 am
Re: Capacitive Sensor MPR121 multiple board setup guide
You will not see much on the photo. But I assure you this a has assembled as on the scetch. Sparkfun or genric(clone) MPR121 boards have connection ADD to GND cut and ADD is wired to Arduino pins accordingly for board addresses.
Or maybe there is something in the code that causes it?
BTW it does not make any difference if the MPR121 checking routine is edited out.
Or maybe there is something in the code that causes it?
BTW it does not make any difference if the MPR121 checking routine is edited out.
Code: Select all
#include <MIDI.h>
MIDI_CREATE_DEFAULT_INSTANCE();
#include <Wire.h>
#include "Adafruit_MPR121.h"
Adafruit_MPR121 cap = Adafruit_MPR121();
Adafruit_MPR121 cap2 = Adafruit_MPR121();
Adafruit_MPR121 cap3 = Adafruit_MPR121();
Adafruit_MPR121 cap4 = Adafruit_MPR121();
// Keeps track of the last pins touched
uint16_t lasttouched = 0;
uint16_t currtouched = 0;
uint16_t lasttouched2 = 0;
uint16_t currtouched2 = 0;
uint16_t lasttouched3 = 0;
uint16_t currtouched3 = 0;
uint16_t lasttouched4 = 0;
uint16_t currtouched4 = 0;
////////////////////////////////////MIDI notes to play
//KORG SYMPHONY sensor 1-2 Timber1(CHORUS); sensor 3 Timber2(Organ1);
//sensor 4 Timber3(DRUM notes 84-95))
int seqOne[] = {48, 52, 53, 55, 57, 59, 60, 64, 65, 67, 69, 71};
int seqTwo[] = {50, 53, 55, 57, 59, 60, 62, 65, 67, 69, 71, 72};
int seqThree[] = {48, 52, 53, 55, 57, 59, 60, 64, 65, 67, 69, 71};
int seqFour[] = {84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95};
////////////////////////////////////
void setup() {
Serial.begin(9600);//test routine for MPR121 boards
Serial.println("Adafruit MPR121 Capacitive Touch sensor test");
// Default address is 0x5A, if tied to 3.3V its 0x5B
// If tied to SDA its 0x5C and if SCL then 0x5D
if (!cap.begin(0x5A)) {
Serial.println("MPR121 not found, check wiring?");
while (1);
}
Serial.println("MPR121 a found!");
if (!cap2.begin(0x5B)) {
Serial.println("MPR121 not found, check wiring?");
while (1);
}
Serial.println("MPR121 b found!");
if (!cap3.begin(0x5C)) {
Serial.println("MPR121 not found, check wiring?");
while (1);
}
Serial.println("MPR121 c found!");
if (!cap4.begin(0x5D)) {
Serial.println("MPR121 not found, check wiring?");
while (1);
}
Serial.println("MPR121 d found!");
delay(1000);
MIDI.begin();
}
void loop() {
// Get the currently touched pads
currtouched = cap.touched();
currtouched2 = cap2.touched();
currtouched3 = cap3.touched();
currtouched4 = cap4.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)) ) {
MIDI.sendNoteOn(seqOne[i], 127, 1); //send note 44+i
}
// if it *was* touched and now *isnt*, alert!
if (!(currtouched & _BV(i)) && (lasttouched & _BV(i)) ) {
MIDI.sendNoteOff(seqOne[i], 0, 1);
}
//2///////////////////////////////////////////////////
if ((currtouched2 & _BV(i)) && !(lasttouched2 & _BV(i)) ) {
MIDI.sendNoteOn(seqTwo[i], 127, 1); //send note 44+i
}
// if it *was* touched and now *isnt*, alert!
if (!(currtouched2 & _BV(i)) && (lasttouched2 & _BV(i)) ) {
MIDI.sendNoteOff(seqTwo[i], 0, 1);
}
//3///////////////////////////////////////////////////
if ((currtouched3 & _BV(i)) && !(lasttouched3 & _BV(i)) ) {
MIDI.sendNoteOn(seqThree[i], 127, 2); //send note 44+i
}
// if it *was* touched and now *isnt*, alert!
if (!(currtouched3 & _BV(i)) && (lasttouched3 & _BV(i)) ) {
MIDI.sendNoteOff(seqThree[i], 0, 2);
}
//4///////////////////////////////////////////////////
if ((currtouched4 & _BV(i)) && !(lasttouched4 & _BV(i)) ) {
MIDI.sendNoteOn(seqFour[i], 127, 3); //send note 44+i
}
// if it *was* touched and now *isnt*, alert!
if (!(currtouched4 & _BV(i)) && (lasttouched4 & _BV(i)) ) {
MIDI.sendNoteOff(seqFour[i], 0, 3);
}
}
// reset our state
lasttouched = currtouched;
lasttouched2 = currtouched2;
lasttouched3 = currtouched3;
lasttouched4 = currtouched4;
return;
}
- adafruit_support_carter
- Posts: 29150
- Joined: Tue Nov 29, 2016 2:45 pm
Re: Capacitive Sensor MPR121 multiple board setup guide
Would really need to see the actual hardware setup to provide any meaningful guidance. Your code does go into infinite loops if any of the boards do not initialize though. Maybe it's that?
-
- Posts: 19
- Joined: Sat Jun 12, 2010 10:47 am
Re: Capacitive Sensor MPR121 multiple board setup guide
How to correct this in the code? Would be worth of try.
Here are the pix with two boards(sparkfun on this) that behaves the same. 4 board setup is built-in already - taking pictures not possible.
Here are the pix with two boards(sparkfun on this) that behaves the same. 4 board setup is built-in already - taking pictures not possible.
- adafruit_support_carter
- Posts: 29150
- Joined: Tue Nov 29, 2016 2:45 pm
Re: Capacitive Sensor MPR121 multiple board setup guide
For each MPR121, you have this:However if even one is missing nothing(the remaining boards) works.
Code: Select all
if (!cap.begin(0x5A)) {
Serial.println("MPR121 not found, check wiring?");
while (1);
}
It is up to you what behaviour you want if an MPR121 does not initialize properly. But if you want the rest of the code to continue, you can simply comment out the while(1); However, you'll then run in to issues later in code when you try to use the removed sensor.
-
- Posts: 19
- Joined: Sat Jun 12, 2010 10:47 am
Re: Capacitive Sensor MPR121 multiple board setup guide
Yeeea, I had all checking routine edited out and behaviour persisted.
Code: Select all
#include <MIDI.h>
MIDI_CREATE_DEFAULT_INSTANCE();
#include <Wire.h>
#include "Adafruit_MPR121.h"
Adafruit_MPR121 cap = Adafruit_MPR121();
Adafruit_MPR121 cap2 = Adafruit_MPR121();
Adafruit_MPR121 cap3 = Adafruit_MPR121();
Adafruit_MPR121 cap4 = Adafruit_MPR121();
// Keeps track of the last pins touched
// so we know when buttons are 'released'
uint16_t lasttouched = 0;
uint16_t currtouched = 0;
uint16_t lasttouched2 = 0;
uint16_t currtouched2 = 0;
uint16_t lasttouched3 = 0;
uint16_t currtouched3 = 0;
uint16_t lasttouched4 = 0;
uint16_t currtouched4 = 0;
////////////////////////////////////
//KORG SYMPHONY sensor 1-2 Timber1(CHORUS); sensor 3 Timber2(Organ1);
//sensor 4 Timber3(DRUM notes 84-95))
int seqOne[] = {48, 52, 53, 55, 57, 59, 60, 64, 65, 67, 69, 71};
int seqTwo[] = {50, 53, 55, 57, 59, 60, 62, 65, 67, 69, 71, 72};
int seqThree[] = {48, 52, 53, 55, 57, 59, 60, 64, 65, 67, 69, 71};
int seqFour[] = {84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95};
////////////////////////////////////
void setup() {
MIDI.begin();
cap.begin(0x5A); //Pin ADD to GRND 0x5A
cap2.begin(0x5B); //Pin ADD to 3.3V 0x5B
cap3.begin(0x5C); //Pin ADD to SDA 0x5C
cap4.begin(0x5D); //Pin ADD to SCL 0x5D
}
void loop() {
// Get the currently touched pads
currtouched = cap.touched();
currtouched2 = cap2.touched();
currtouched3 = cap3.touched();
currtouched4 = cap4.touched();
//1////////////////////////////////////////////////////
for (uint8_t i=0; i<12; i++) {
// it if *is* touched and *wasnt* touched before, alert!
if ((currtouched & _BV(i)) && !(lasttouched & _BV(i)) ) {
MIDI.sendNoteOn(seqOne[i], 127, 1); //send note 44+i
}
// if it *was* touched and now *isnt*, alert!
if (!(currtouched & _BV(i)) && (lasttouched & _BV(i)) ) {
MIDI.sendNoteOff(seqOne[i], 0, 1);
}
//2///////////////////////////////////////////////////
if ((currtouched2 & _BV(i)) && !(lasttouched2 & _BV(i)) ) {
MIDI.sendNoteOn(seqTwo[i], 127, 1); //send note 44+i
}
// if it *was* touched and now *isnt*, alert!
if (!(currtouched2 & _BV(i)) && (lasttouched2 & _BV(i)) ) {
MIDI.sendNoteOff(seqTwo[i], 0, 1);
}
//3///////////////////////////////////////////////////
if ((currtouched3 & _BV(i)) && !(lasttouched3 & _BV(i)) ) {
MIDI.sendNoteOn(seqThree[i], 127, 2); //send note 44+i
}
// if it *was* touched and now *isnt*, alert!
if (!(currtouched3 & _BV(i)) && (lasttouched3 & _BV(i)) ) {
MIDI.sendNoteOff(seqThree[i], 0, 2);
}
//4///////////////////////////////////////////////////
if ((currtouched4 & _BV(i)) && !(lasttouched4 & _BV(i)) ) {
MIDI.sendNoteOn(seqFour[i], 127, 3); //send note 44+i
}
// if it *was* touched and now *isnt*, alert!
if (!(currtouched4 & _BV(i)) && (lasttouched4 & _BV(i)) ) {
MIDI.sendNoteOff(seqFour[i], 0, 3);
}
}
// reset our state
lasttouched = currtouched;
lasttouched2 = currtouched2;
lasttouched3 = currtouched3;
lasttouched4 = currtouched4;
return;
}
-
- Posts: 19
- Joined: Sat Jun 12, 2010 10:47 am
Re: Capacitive Sensor MPR121 multiple board setup guide
I got this suggestion from a member pylon at https://forum.arduino.cc
Is this part of Adafruit_MPR121.h or Wire.h
Is this part of Adafruit_MPR121.h or Wire.h
The library you are using isn't written to handle non-working boards:
Code: [Select]
while (Wire.requestFrom(_i2caddr, 2) != 2);
If there is no chip answering under the given I2C address this while loop is waiting forever -> freeze!
Fix the library or ensure all board are always connected.
- adafruit_support_carter
- Posts: 29150
- Joined: Tue Nov 29, 2016 2:45 pm
Re: Capacitive Sensor MPR121 multiple board setup guide
It's in the MPR121 library:
https://github.com/adafruit/Adafruit_MP ... 1.cpp#L108
https://github.com/adafruit/Adafruit_MP ... 1.cpp#L116
What they've suggested is valid.
https://github.com/adafruit/Adafruit_MP ... 1.cpp#L108
https://github.com/adafruit/Adafruit_MP ... 1.cpp#L116
What they've suggested is valid.
-
- Posts: 19
- Joined: Sat Jun 12, 2010 10:47 am
Re: Capacitive Sensor MPR121 multiple board setup guide
I see it.
Could this be changed so the Wire.requestFrom() will be stopped after number of requests?
If you do not want to change this on public library, could you provide me a special one.
I have a setup of different objects, one has an Arduino and one or two MPR121 boards inside, the others have just MPR121 boards. Every object is visually unique with different sensor tabs. So my plan was to change these object around as needed. The best would have been to do it hot(just plugging 6 wire cable on and off). But I can live with restarting the system after every modification.
BTW
I looked into Wire.h library as well. I wonder if this use the same procedure?
Could this be changed so the Wire.requestFrom() will be stopped after number of requests?
If you do not want to change this on public library, could you provide me a special one.
I have a setup of different objects, one has an Arduino and one or two MPR121 boards inside, the others have just MPR121 boards. Every object is visually unique with different sensor tabs. So my plan was to change these object around as needed. The best would have been to do it hot(just plugging 6 wire cable on and off). But I can live with restarting the system after every modification.
BTW
I looked into Wire.h library as well. I wonder if this use the same procedure?
If true, requestFrom() sends a stop message after the request, releasing the I2C bus.
If false, requestFrom() sends a restart message after the request. The bus will not be released, which prevents another master device from requesting between messages. This allows one master device to send multiple requests while in control.
The default value is true.
- adafruit_support_carter
- Posts: 29150
- Joined: Tue Nov 29, 2016 2:45 pm
Re: Capacitive Sensor MPR121 multiple board setup guide
It's probably worth submitting an issue in the git repo against this. But if you don't want to wait around for it to get changed/fixed (no guarantee when it would get done) you would need to fork it and make your own changes.
Please be positive and constructive with your questions and comments.