Comments: MPR121 Hookup Guide
Looking for answers to technical questions?
We welcome your comments and suggestions below. However, if you are looking for solutions to technical questions please see our Technical Assistance page.
If you've found an issue with this tutorial content, please send us your feedback!
Hello,
May I ask you how to end loop when I press hash? I tried to extend while condition for
When I tried to put condition on the end of cycle (before i ++) condition cycle is ended succesfully
Why first condition does not work?
Thank you very much for your advice.
Hi guys,
Does someone know how to solve that error : C:\Program Files (x86)\Arduino\libraries\MPR121\main.c:69:2: error: 'for' loop initial declarations are only allowed in C99 mode for (int i = 0; i < 5; i++) ^ C:\Program Files (x86)\Arduino\libraries\MPR121\main.c:69:2: note: use option -std=c99 or -std=gnu99 to compile your code Error compiling.
Scratch my question - Thanks Mike!
I receive a the following error code when I verify the sketch provided in the hookup guide under the zip file 52a0dbb8757b7f21158b4567.zip The error message is:
Arduino: 1.6.5 (Windows 7), Board: "Arduino Uno"
C:\Users\ATS\Documents\Arduino\libraries\MPR121Q\main.c: In function 'main': C:\Users\ATS\Documents\Arduino\libraries\MPR121Q\main.c:69:2: error: 'for' loop initial declarations are only allowed in C99 mode for (int i = 0; i < 5; i++) ^ C:\Users\ATS\Documents\Arduino\libraries\MPR121Q\main.c:69:2: note: use option -std=c99 or -std=gnu99 to compile your code Error compiling.
Does anyone have ideas on what I should do to eliminate this error? Thank you! Mike
I have the same problem and don't know how to fix it. How did you solve it please ?
thanks
FX
I can do use more than one MPR121 in arduino?
This is a little vague. Can you use more than one breakout board with an Arduino? Yes, but you'll need to open the address jumper on one of them. Using two shields on the same Arduino would be rather pointless, as one shield would be covered up by the other, limiting access to the touch pads.
Naive question: the MPR121 functions as an I2C slave device, and the interrupt triggers the master device (in this case, an Arduino) to either receive data from the MPR121 (e.g. capsense) or write data to (e.g. LED controller), correct?
Depending on how you have the Arduino programmed, yes.
When wiring the mpr121 to the electric imp the response time was a little two slow for my application, it need it to read the touch inputs in real time so I have switched to a different wireless solution. My question is I want to send the touch data to Xively to keep track of the touch states, I understand that the data has to be turned into a string to be read by the API, there plenty of tutorials using temp sensors, etc, how does one transfer touch states into a json data string to be read by Xively? Any help would be grateful.
The code scans through each electrode that is initialized and reads the touch state. Then each electrode is assigned a value of either 0 or 1, representing the electrode being touched or not. You would simply need to pull out these values of 0 or 1 corresponding to each electrode and print that to your API to then be transmitted.
Ok I've tried a couple different ways to extract the data, I think I get caught up in all the code for the mpr, so this is where I am at, I am trying to send data to Xively, I have done all that, and wifi shield cooperates. I am struggling with creating the appropriate sensor instance, after which I understand I must convert these instances into integers that Xively can read, through JSON, my problem is defining that instance, and relating that to the integers of 1 and 0, would I refer it touchStates [i] and does it matter that I have each sensor printing out different information…. Or do I define an instance for each sensor, and transfer that data into a JSON string? (that would be a lot of data) Thanks, I will send you a case a beer……. :)
I'm a tad confused. Are you having trouble with the sensor instance in JSON, or just getting the code off of the MPR121 through the Electric Imp?
Ok, so I am using the CC3300, and my difficulty is getting the data from MPR121 loop to feed into the Xively, I have broken up each of the sensors into Case instances, similar to the Bildr tutorial, I am posting the code below. (if that helps) much appreciated.
/*Copyright (c) 2010 bildr community
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ //
include <Adafruit_CC3000.h>
include <ccspi.h>
include <SPI.h>
include <string.h>
include "utility/debug.h"
include <stdlib.h>
include "mpr121.h"
include <Wire.h>
define ADAFRUIT_CC3000_IRQ 3
define ADAFRUIT_CC3000_VBAT 5
define ADAFRUIT_CC3000_CS 10
Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT, SPI_CLOCK_DIV2);
define WLAN_SSID "" // cannot be longer than 32 characters!
define WLAN_PASS ""
// Security can be WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2
define WLAN_SECURITY WLAN_SEC_WPA2
define WEBSITE "api.xively.com"
define API_key ""
define feedID ""
//Somewhere in here I need to create an instance to register the mpr121? //possibly could be in the wrong order //have not been able to get the mpr121 to register to the internet yet, I have tried a couple different formats //I have both the Imp April and CC3300 break out //
Serial.println(F("\nInitializing...")); if (!cc3000.begin()) { Serial.println(F("Couldn't begin()! Check your wiring?")); while(1); } int irqpin = 2; // Digital 2 boolean touchStates[12]; //to keep track of the previous touch states
void setup(){ pinMode(irqpin, INPUT); digitalWrite(irqpin, HIGH); //enable pullup resistor
Serial.begin(115200); Wire.begin();
mpr121_setup(); }
void loop(){ readTouchInputs(); }
void readTouchInputs(){ if(!checkInterrupt()){
} }
void mpr121_setup(void){
set_register(0x5A, ELE_CFG, 0x00);
Looking at using the WiFly or something similar. Like the CC3300. Either way I am stuck on register a touch being pushed to Xively and shield picking up the touches, not the mpr121 yet the wifi module itself. If that clarifies. Thanks again….
Both actually. Looking over my previous reply that is a little confusing.
Awesome thanks!
Curious on how to serial print info for different sensors using the breakout, I followed the example, and have my breakout functioning fine. At first the sensor 11 acted up, yet after I disconnected the USB and re-plugged it works fine. I have been able to get the proximity settings to work as well. I basically want different information to be displayed based on the sensor pressed. Is that just building on the serial print function? In reviewing the data sheet I understand a person could make the senors less or more sensitive, trying to figure out exactly the numbers to put in to make it go up in sensitivity and down in sensitivity. I'm using the Bare Conductive Paint, as my electrodes, and it works great. I eventually want to connect this project to the electric imp.... Any step in the right direction would be awesome. A nudge in the right direction is what I'm looking for, the way to learn is by doing.
Peace..
M.
You've got it. You would simply set up a basic if statement in your code, saying
if sensorA is pressed, Serial.print(info you want displayed)
. If you need more of a nudge than that, let us know :)Thanks!
Any idea about connecting an imp to one of these. More concerned about the pin layout to create a connection. Thanks for the prompt response.
M.
The Imp has I2C connections available, so it would be just like hooking this up to an Arduino's I2C connections. Check out our tutorial on the Imp for more info on that here.