Adafruit MPR121 12-Key Capacitive Touch Sensor Breakout Tutorial Created by lady ada Last updated on 2017-11-29 12:46:45 AM UTC
Guide Contents Guide Contents Overview Pinouts Power Pins I2C Pins IRQ and ADDR Pins Assembly Prepare the header strip: Add the breakout board: And Solder! Wiring Download Adafruit_MPR121 Load Demo Library Reference Touch detection Raw Data 7 8 9 10 10 11 14 14 14 CircuitPython Wiring Parts Wiring CircuitPython Software Adafruit CircuitPython Module Install Example Usage Electrodes Downloads Datasheets & Files Breakout Board Schematic Fabrication Print © Adafruit Industries 2 3 5 5 5 5 7 https://lear
Overview Add lots of touch sensors to your next microcontroller project with this easy-to-use 12-channel capacitive touch sensor breakout board, starring the MPR121. This chip can handle up to 12 individual touch pads. © Adafruit Industries https://learn.adafruit.
The MPR121 has support for only I2C, which can be implemented with nearly any microcontroller. You can select one of 4 addresses with the ADDR pin, for a total of 48 capacitive touch pads on one I2C 2-wire bus. Using this chip is a lot easier than doing the capacitive sensing with analog inputs: it handles all the filtering for you and can be configured for more/less sensitivity. This sensor comes as a tiny hard-to-solder chip so we put it onto a breakout board for you.
Pinouts The little chip in the middle of the PCB is the actual MPR121 sensor that does all the capacitive sensing and filtering. We add all the extra components you need to get started, and 'break out' all the other pins you may want to connect to onto the PCB. For more details you can check out the schematics in the Downloads page. Power Pins The sensor on the breakout requires 3V power. Since many customers have 5V microcontrollers like Arduino, we tossed a 3.3V regulator on the board.
© Adafruit Industries https://learn.adafruit.
Assembly Prepare the header strip: Cut the strip to length if necessary. It will be easier to solder if you insert it into a breadboard - long pins down © Adafruit Industries https://learn.adafruit.
Add the breakout board: Place the breakout board over the pins so that the short pins poke through the breakout pads © Adafruit Industries https://learn.adafruit.
And Solder! Be sure to solder all pins for reliable electrical contact. (For tips on soldering, be sure to check out our Guide to Excellent Soldering (https://adafru.it/aTk)). You're done! Check your solder joints visually and continue onto the next steps © Adafruit Industries https://learn.adafruit.
Wiring You can easily wire this breakout to any microcontroller, we'll be using an Arduino. For another kind of microcontroller, just make sure it has I2C, then port the code - its pretty simple stuff! Connect Vin to the power supply, 3-5V is fine. Use the same voltage that the microcontroller logic is based off of. For most Arduinos, that is 5V Connect GND to common power/data ground Connect the SCL pin to the I2C clock SCL pin on your Arduino.
https://adafru.it/dKF Rename the uncompressed folder Adafruit_MPR121 and check that the Adafruit_MPR121 folder contains Adafruit_MPR121.cpp and Adafruit_MPR121.h Place the Adafruit_MPR121 library folder your arduinosketchfolder/libraries/ folder. You may need to create the libraries subfolder if its your first library. Restart the IDE. We also have a great tutorial on Arduino library installation at: http://learn.adafruit.
Make sure you see the "MPR121 found!" text which lets you know that the sensor is wired correctly. Now touch the 12 pads with your fingertip to activate the touch-detection © Adafruit Industries https://learn.adafruit.
For most people, that's all you'll need! Our code keeps track of the 12 'bits' for each touch and has logic to let you know when a contect is touched or released. If you're feeling more advanced, you can see the 'raw' data from the chip. Basically, what it does it keep track of the capacitance it sees with "counts". There's some baseline count number that depends on the temperature, humidity, PCB, wire length etc.
Most people don't need raw data too much, but it can be handy if doing intense debugging. It can be helpful if you are tweaking your sensors to get good responsivity. Library Reference Since the sensors use I2C, there's no pins to be defined during instantiation. You can just use: Adafruit_MPR121 cap = Adafruit_MPR121(); When you initialize the sensor, pass in the I2C address. It can range from 0x5A (default) to 0x5D cap.
filteredData(sensornumber); baselineData(sensornumber); It returns a 16-bit number which is the number of counts, there's no unit like "mg" or "capacitance". The baseline is initialized to the current ambient readings when the sensor begin() is called - you can always reinitialize by re-calling begin()! The baseline will drift a bit, that's normal! It is trying to compensate for humidity and other environmental changes.
CircuitPython Wiring Parts You'll need the following hardware to follow this guide: Board running CircuitPython. Currently ESP8266 or SAMD21-based boards are supported by CircuitPython. The Feather HUZZAH ESP8266 or Feather M0 boards are great options that can easily be connected to an accelerometer. See the guide on loading MicroPython & CircuitPython firmware on a board for details on loading CircuitPython. MPR121 capacitive touch breakout board or MPR121 capacitive touch Arduino shield.
MPR121 SDA to board SDA (I2C data) - yellow wire. Continue on to learn how to install a CircuitPython module to control the MPR121 board. © Adafruit Industries https://learn.adafruit.
CircuitPython Software Adafruit CircuitPython Module Install To use the MPR121 with your Adafruit CircuitPython board you'll need to install the Adafruit_CircuitPython_MPR121 module on your board. First make sure you are running the latest version of Adafruit CircuitPython for your board. Next you'll need to install the necessary libraries to use the hardware--carefully follow the steps to find and install these libraries from Adafruit's CircuitPython library bundle.
# Simple test of the MPR121 capacitive touch sensor library. # Will print out a message when any of the 12 capacitive touch inputs of the # board are touched. Open the serial REPL after running to see the output. # Author: Tony DiCola import time # Import MPR121 module. import adafruit_mpr121 import busio # Create I2C bus. import board i2c = busio.I2C(board.SCL, board.SDA) # Create MPR121 class. mpr121 = adafruit_mpr121.
# Import MPR121 module. import adafruit_mpr121 This code initializes the I2C bus: # Create I2C bus. import board import busio i2c = busio.I2C(board.SCL, board.SDA) Remember for boards without hardware I2C like the ESP8266 you might need to use the bitbangio module to create the I2C bus: # Create I2C bus for software I2C boards (ESP8266) import board import bitbangio i2c = bitbangio.I2C(board.SCL, board.
# Call touched to get a 12-bit value with the state of each MPR121 input. touch = mpr121.touched() # Test if exactly bit 0 and 11 are set to 1, i.e. input 0 and 11 are touched. if touch == 0b100000000001: print('Input 0 and 11 touched!') # Or test if either bit 0 or 11 are set to 1, i.e.
Electrodes Once you have the MPR121 breakout working you'll want to construct electrodes. These are large conductive piece of copper, foil, paint, etc that will act as the "thing you touch" Remember that electrodes must be electrically conductive! We suggest copper foil tape, conductive fabrics, ITO, pyralux flex PCB, etc. We have tons of great conductive materials in our Materials category. Some can be soldered to, others can be clipped to with alligator chips.
Downloads Datasheets & Files MPR121 Datasheet EagleCAD PCB files on GitHub Fritzing object in Adafruit Fritzing library Breakout Board Schematic Fabrication Print Dimensions in Inches © Adafruit Industries https://learn.adafruit.
© Adafruit Industries Last Updated: 2017-11-29 12:46:44 AM UTC Page 24 of 24