Datasheet

This code initializes the I2C bus:
Remember for boards without hardware I2C like the ESP8266 you might need to use the bitbangio module to create
the I2C bus:
Once the I2C bus is intialized the MPR121 class can be created by passing it an instance of the I2C bus:
Notice the MPR121 class initializer takes an optional address parameter if you changed the board's I2C address.
Now you're ready to start checking if inputs are touched. Notice the main loop for the example calls the MPR121 class
is_touched function for every input:
Just pass a value 0 to 11 to the is_touched function and it will return a boolean True or False value depending on if the
input is currently being touched or not. In the example it prints a small message when an input is touched.
The example doesn't show its usage but if you want to check all of the inputs at once you can call the touched
function. This function returns a 12-bit value where each bit represents the touch state of an input. So bit 0 is input 0
and will be 1 if it's touched and 0 if it's not touched, bit 1 would be input 1, etc. For example to test if input 0 and 11 are
being touched with one call you could run code like:
# Import MPR121 module.
import adafruit_mpr121
# Create I2C bus.
import board
import busio
i2c = busio.I2C(board.SCL, board.SDA)
# Create I2C bus for software I2C boards (ESP8266)
import board
import bitbangio
i2c = bitbangio.I2C(board.SCL, board.SDA)
# Create MPR121 class.
mpr121 = adafruit_mpr121.MPR121(i2c)
# Note you can optionally change the address of the device:
#mpr121 = adafruit_mpr121.MPR121(i2c, address=0x91)
# Loop forever testing each input and printing when they're touched.
while True:
# Loop through all 12 inputs (0-11).
for i in range(12):
# Call is_touched and pass it then number of the input. If it's touched
# it will return True, otherwise it will return False.
if mpr121.is_touched(i):
print('Input {} touched!'.format(i))
time.sleep(0.25) # Small delay to keep from spamming output messages.
© Adafruit Industries
https://learn.adafruit.com/adafruit-mpr121-12-key-capacitive-touch-sensor-breakout-
tutorial
Page 20 of 24