MPR121 SENSOR

The MPR121 is the second generation capacitive touch sensor controller after the initial release of the MPR03x series devices. The MPR121 features increased internal intelligence, some of the major additions include an increased electrode count, a hardware configurable I2C address, an expanded filtering system with debounce, and completely independent electrodes with auto-configuration built in. The device also features a 13th simulated sensing channel dedicated for near proximity detection using the multiplexed sensing inputs.

Working Principle

The output capacitance will increase if a conductive object touches or approaches the sensor electrode. The measurement circuit will detect the change in the capacitance and converts it into a trigger signal.

 

Features:

  • 1.71V to 3.6V operation
  • 29 μA typical run current at 16 ms sampling interval
  • 3 μA in scan stop mode current
  • 12 electrodes/capacitance sensing inputs in which 8 are multifunctional for LED driving and GPIO
  • Integrated independent autocalibration for each electrode input
  • Autoconfiguration of charge current and charge time for each electrode input • Separate touch and release trip thresholds for each electrode, providing hysteresis and electrode independence
  • I2C interface, with IRQ Interrupt output to advise electrode status changes • 3 mm x 3 mm x 0.65 mm 20 lead QFN package
  • -40°C to +85°C operating temperature range

 

Specifications

Supply Voltage                                 -0.3 to +3.6 V

Supply Voltage                                -0.3 to +2.75 V

 Input Voltage (SCL, SDA, IRQ)        VSS – 0.3 to VDD + 0.3 V

 Operating Temperature Range      -40 to +85 °C

GPIO Source Current per Pin           12 mA

 GPIO Sink Current per Pin              1.2 mA

Storage Temperature Range                    -40 to +125 °C

 

Link to data sheet:

  1. http://dl.btc.pl/kamami_wa/mpr121.pdf

2.https://media.digikey.com/pdf/Data%20Sheets/Sparkfun%20PDFs/MPR121_HookupGuide.pdf

  1. https://cdn-learn.adafruit.com/downloads/pdf/adafruit-mpr121-12-key-capacitive-touch-sensor-breakout-tutorial.pdf

 

 

Do’s and dont’s:

  1. Do check the connections before powering it up.
  2. Do hold the sensor from sides only.
  3. Do read the specifications before using the sensor.
  4. Do not touch circuit elements from finger tips, the static energy from your fingers can damage the sensor.
  5. Do not short the pins while soldering.

 

 

Storing Instructions:

Store in a closed container and cover it with a poly bag.

 

Advantages:

  1. Binary – interfaces easily with all microcontrollers
  2. Low cost
  3. Simple to construct and to connect
  4. Simple to operate – either the switch is active.

Disadvantages:

  1. Tactile – object must be “touched” to know it exists
  2. Low range
  1. Less accurate for acquiring range data – you only know that there is an object there within the motion range of the switch – not exactly how far it is, or exactly where the sensed object’s XY position is relative to the robots position

 

Schematics

Interfacing with Arduino 

 

Arduino Code:

    #include “mpr121.h”

    #include <Wire.h>

    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(9600);

        Wire.begin();

        mpr121_setup();

    }

    void loop(){

        readTouchInputs();

    }

void readTouchInputs(){

  if(!checkInterrupt()){

    //read the touch state from the MPR121

    Wire.requestFrom(0x5A,2);

    byte LSB = Wire.read();

    byte MSB = Wire.read();

    uint16_t touched = ((MSB << 8) | LSB); //16bits that make up the touch states

    for (int i=0; i < 12; i++){  // Check what electrodes were pressed

      if(touched & (1<<i)){

        if(touchStates[i] == 0){

          //pin i was just touched

          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);

          Serial.println(” is no longer being touched”);

          //pin i is no longer being touched

       }

        touchStates[i] = 0;

    }

    }

  }

}

void mpr121_setup(void){

  set_register(0x5A, ELE_CFG, 0x00);

  // Section A – Controls filtering when data is > baseline.

  set_register(0x5A, MHD_R, 0x01);

  set_register(0x5A, NHD_R, 0x01);

  set_register(0x5A, NCL_R, 0x00);

  set_register(0x5A, FDL_R, 0x00);

  // Section B – Controls filtering when data is < baseline.

  set_register(0x5A, MHD_F, 0x01);

  set_register(0x5A, NHD_F, 0x01);

  set_register(0x5A, NCL_F, 0xFF);

  set_register(0x5A, FDL_F, 0x02);

  // Section C – Sets touch and release thresholds for each electrode

  set_register(0x5A, ELE0_T, TOU_THRESH);

  set_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, TOU_THRESH);

  set_register(0x5A, ELE3_R, REL_THRESH);

  set_register(0x5A, ELE4_T, TOU_THRESH);

  set_register(0x5A, ELE4_R, REL_THRESH);

  set_register(0x5A, ELE5_T, TOU_THRESH);

  set_register(0x5A, ELE5_R, REL_THRESH);

  set_register(0x5A, ELE6_T, TOU_THRESH);

  set_register(0x5A, ELE6_R, REL_THRESH);

  set_register(0x5A, ELE7_T, TOU_THRESH);

  set_register(0x5A, ELE7_R, REL_THRESH);

  set_register(0x5A, ELE8_T, TOU_THRESH);

  set_register(0x5A, ELE8_R, REL_THRESH);

  set_register(0x5A, ELE9_T, TOU_THRESH);

  set_register(0x5A, ELE9_R, REL_THRESH);

  set_register(0x5A, ELE10_T, TOU_THRESH);

  set_register(0x5A, ELE10_R, REL_THRESH);

  set_register(0x5A, ELE11_T, TOU_THRESH);

  set_register(0x5A, ELE11_R, REL_THRESH);

  // Section D

  // Set the Filter Configuration

  // Set ESI2

  set_register(0x5A, FIL_CFG, 0x04);

  // Section E

  // Electrode Configuration

  // Set ELE_CFG to 0x00 to return to standby mode

  set_register(0x5A, ELE_CFG, 0x0C);  // Enables all 12 Electrodes  // Section F

  // Enable Auto Config and auto Reconfig

  /*set_register(0x5A, ATO_CFG0, 0x0B);

  set_register(0x5A, ATO_CFGU, 0xC9);  // USL = (Vdd-0.7)/vdd*256 = 0xC9 @3.3V   set_register(0x5A, ATO_CFGL, 0x82);  // LSL = 0.65*USL = 0x82 @3.3V

  set_register(0x5A, ATO_CFGT, 0xB5);*/  // Target = 0.9*USL = 0xB5 @3.3V

  set_register(0x5A, ELE_CFG, 0x0C);

}

boolean checkInterrupt(void){

  return digitalRead(irqpin);

}

void set_register(int address, unsigned char r, unsigned char v){

    Wire.beginTransmission(address);

    Wire.write(r);

    Wire.write(v);

    Wire.endTransmission();

}

Applications:

  • PC Peripherals
  • MP3 Players
  • Remote Controls
  • Mobile Phones
  • Lighting Controls

  

FAQ’s:

Q1. Could this be used stand alone (no rasp pi)? for example, could this be a momentary i/o switch when only connecting a 5v usb ps, and trigger object?

Ans. No, you have to use a brain like arduino.

 

Q2. Can I connect these to the metal handles on a cabinet drawer so that touching the handle toggles an interior light?

Ans. Yes. You definitely should be able to. This particular one has 12 sensors, so I guess you hook up 12 different things to it. You will still need a separate board for “the brain”.

 

Referral Links:

  1. https://www.adafruit.com/product/1982
  2. https://www.mouser.in/new/nxp-semiconductors/freescalempr121/
  3. https://www.adafruit.com/product/2024

 

Documentation links :

  1. https://learn.sparkfun.com/tutorials/mpr121-hookup-guide

2. https://www.sparkfun.com/datasheets/Components/MPR121.pdf

WhatsApp us whatsapp