sparkfun MPR121 Скачать руководство пользователя страница 1

MPR121 Hookup Guide 

CONTR IBUTORS: 

TONI_K

MPR121 Overview

If you are interested in adding the ‘magic’ of touch to control your 
electronics project, a capacitive touch sensor might be the way to go. This 
hookup guide will show you how to use the MPR121QR2 sensor.

The MPR121QR2 is a capacitive touch sensor controller that makes it very 
easy to integrate capacitive touch sensing into your project. It 
communicates via I C, and works by measuring the capacitance of twelve 
electrode points. When an object comes close to the electrode connector, 
the measured capacitance changes. This signals the MPR121 that 
something has touched a ‘button’. The IC is also capable of driving LEDs or 
basic GPIO functionality on electrode pins 4 through 11, giving you a lot of 
freedom for setting up your project. The sensor works from 1.6V to 3.3V. 
The sensor isn’t very current-hungry, drawing only around 29 µA when 
sampling every 16 milliseconds.

Materials

To work through this tutorial, you are going to need one of the three 
versions of the MPR121 sensor:

• MPR121 Capacitive Touch Sensor Breakout Board
• Touch Shield
• MPR121 Capacitive Touch Keypad

You will also want a soldering iron, some hookup wires and a 
microcontroller capable of I C communication. For our examples, we will be 
using an Arduino Uno. You will also need some kind of material to act as a 
capacitive sensing surface (also known as an electrode, which is not to be 
confused with the character Electrode). Generally, aluminum foil works well. 
However, you could also use coins, conductive paint, or copper tape.

2

2

Page 1 of 24

Содержание MPR121

Страница 1: ...GPIO functionality on electrode pins 4 through 11 giving you a lot of freedom for setting up your project The sensor works from 1 6V to 3 3V The sensor isn t very current hungry drawing only around 2...

Страница 2: ...he most versatile option of the three MPR121 products You can wire it up to any kind of electrode you want and as it is a simple breakout board does not have a particular microcontroller footprint it...

Страница 3: ...ind the most up to date firmware for working with the breakout board available on GitHub Let s take a look and see exactly what the code is doing include mpr121 h include Wire h int irqpin 2 Digital 2...

Страница 4: ...of the code is incredibly simple as it only calls a single function void loop readTouchInputs The function is actually described in the next section of the code The Arduino requests the electrode stat...

Страница 5: ...uched Serial print pin Serial print i Serial println was just touched else if touchStates i 1 pin i is still being touched touchStates i 1 else if touchStates i 1 Serial print pin Serial print i Seria...

Страница 6: ...or section of the code defines the threshold values for each electrode Each electrode must have a touch threshold and a release threshold for the Arduino to compare the current state of the electrode...

Страница 7: ...register 0x5A ELE0_R REL_THRESH set_register 0x5A ELE1_T TOU_THRESH set_register 0x5A ELE1_R REL_THRESH set_register 0x5A ELE2_T TOU_THRESH set_register 0x5A ELE2_R REL_THRESH set_register 0x5A ELE3_T...

Страница 8: ...0x0B set_register 0x5A ATO_CFGU 0xC9 USL Vdd 0 7 vdd 256 0xC9 3 3V set_register 0x5A ATO_CFGL 0x82 LS L 0 65 USL 0x82 3 3V set_register 0x5A ATO_CFGT 0xB5 Target 0 9 USL 0xB5 3 3V set_register 0x5A EL...

Страница 9: ...ilities for your project using the MPR121 IC The shield itself has 9 touch pads on it conveniently numbered 1 9 in a 3x3 grid and has headers for 3 additional electrode connections The shield connects...

Страница 10: ...eld However you don t have to do this to get the shield to function It s up to you Check out the Fritzing diagram below to see how your shield should look if you have added buttons on to your shield o...

Страница 11: ...definitions This is laying out the keypad functionality ONE TWO etc and defining which electrode pin corresponds to each number As the comment states electrode pins 9 10 and 11 are not currently conne...

Страница 12: ...de initializes the I C communication lines without using the Wiring library The MPR121 chip is then configured with the proper sensitivity settings on the electrodes The final step in the setup loop c...

Страница 13: ...sed if touchstatus 1 j touchNumber if touchNumber 1 if touchstatus 1 SEVEN digits 7 else if touchstatus 1 FOUR digits 4 else if touchstatus 1 ONE digits 1 else if touchstatus 1 EIGHT digits 8 else if...

Страница 14: ...s int touch touch mpr121Read 0x01 8 touch mpr121Read 0x00 return touch Now that you have basic communication up and running with your shield you can start integrating this into projects If you haven t...

Страница 15: ...is very similar to the MPR121 breakout board but instead of having to attach your own electrodes this board comes with a 12 pin keypad built in The keypad has 5 lines that need to be connected to you...

Страница 16: ...er to communicate with your keypad you ll want to download the example sketch available here Alternatively you can check for the most up to date firmware available in the GitHub repository This sketch...

Страница 17: ...define POUND 8 define NINE 9 define SIX 10 define THREE 11 int irqpin 2 D2 uint16_t touchstatus char phoneNumber PHONE_DIGITS The second section of the code is the basic initialization of the serial...

Страница 18: ...r Serial print nDialing for int i 0 i PHONE_DIGITS i Serial print phoneNumber i while 1 As you can see in the function loop for getPhoneNumber the Arduino checks the touchstatus register for each elec...

Страница 19: ...if touchstatus 1 STAR phoneNumber i else if touchstatus 1 SEVEN phoneNumber i 7 else if touchstatus 1 FOUR phoneNumber i 4 else if touchstatus 1 ONE phoneNumber i 1 else if touchstatus 1 ZERO phoneNu...

Страница 20: ...cSendByte MPR121_W write 0xB4 i2cWaitForComplete i2cSendByte address write register address i2cWaitForComplete i2cSendStart i2cSendByte MPR121_R write 0xB5 i2cWaitForComplete i2cReceiveByte TRUE i2cWa...

Страница 21: ...e i2cSendByte address write register address i2cWaitForComplete i2cSendByte data i2cWaitForComplete i2cSendStop The mpr121QuickConfig function is then defined In this function all 12 of the electrodes...

Страница 22: ...e 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...

Страница 23: ...Q pin for an indication that an electrode has been pressed It then returns either a 1 or 0 as the value for checkInterrupt variable byte checkInterrupt void if digitalRead irqpin return 1 return 0 Now...

Страница 24: ...tutorials have I C communication They can also both be used in conjunction with this sensor to act as a display for the button triggers or to monitor the temperature as well OpenSegment Hook Up Guide...

Отзывы: