SKU:RB-02S104 IIC触摸传感器

来自ALSROBOT WiKi
跳转至: 导航搜索
02S10401.png

目录

产品概述

IIC触摸传感器是 12 路电容式触摸传感器,基于接近电容式触摸传感器控制器的飞思卡尔- mpr121 芯片。它检测到人类手指的触摸或接近。可以与 Arduino 简单连接,创作你的互动项目。电容式触摸传感器可通过检测当一个人(或动物)接触到的传感器电极之一输出不同的信号给控制器。IIC触摸传感器可能应用于之前我们用过的使用触碰感知的设备上,如触摸式平板电脑和手机,以及触控面板的电器。该IIC触摸传感器允许您用在可以对人体的接触作出反应的电子产品中,并且支持最多 12 个独立的触摸通道。触摸电极有时也能感知到手指的非直接接触,那就是说,你不需要用你的手指触摸的触角上。

产品参数

  1. 工作电压 :3.3V-5.5V
  2. 待机电流: 2uA
  3. 触摸通道:12个
  4. 接口类型:IIC
  5. IIC地址:0x5A - 0x5D
  6. 尺寸大小: 80mm x 50mm
  7. 重量大小:6g
  8. 固定孔:4 * M3
  • 产品尺寸图:
Size027.jpg

使用方法

库文件下载

基本应用

  • 实验环境

1、硬件环境:

2、软件环境:

  • Arduino IDE 1.7.10
  • 例子程序
#include <Wire.h>
#include "ALSROBOT_MPR121.h"

#define cs_mini12864 2   //片选 低电平片选
#define rst_mini12864 3 //物理重置.低电平有效
#define rs_mini12864 4   //寄存器选择 1:数据寄存器 0:指令寄存器
#define sck_mini12864 5 //时钟
#define sda_mini12864 6 //数据
//上面的脚可以自己修改
#define  Display  0xAF     //显示开启
#define  Power    0x2F           //电源全开
#define  VO       0x24     //对比度调节             
#define  AllPoint 0xA4           //非全屏显示
#define  ADCset   0xA1            //负向,131-4
#define  COMset   0xc0            //com0-com63
#define  ELECTVO  0x81     //亮度调节         调节颜色         不同的模块需要不同的  ELECTSET
#define  ELECTSET 0x2a           //亮度数值         调节颜色         不同的模块需要不同的        数值
#define  BIASSET  0xA2    //占空比1/9

// You can have up to 4 on one i2c bus but one is enough for testing!
ALSROBOT_MPR121 cap = ALSROBOT_MPR121();

// Keeps track of the last pins touched
// so we know when buttons are 'released'
uint16_t lasttouched = 0;
uint16_t currtouched = 0;

unsigned char  shuzi16X32[10][64] = {
{0x00,0x00,0x00,0x00,0x00,0x80,0xC0,0xC0,0x40,0x40,0xC0,0x80,0x00,0x00,0x00,0x00,
0x00,0x00,0xF0,0xFE,0xFF,0x0F,0x01,0x00,0x00,0x00,0x01,0x07,0xFF,0xFE,0xF0,0x00,
0x00,0x00,0x3F,0xFF,0xFF,0xC0,0x00,0x00,0x00,0x00,0x00,0x80,0xFF,0xFF,0x3F,0x00,
0x00,0x00,0x00,0x01,0x03,0x07,0x0E,0x0C,0x08,0x08,0x0E,0x07,0x03,0x01,0x00,0x00},/*"0",0*/

{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x01,0x01,0x01,0x01,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x08,0x08,0x08,0x0C,0x0F,0x0F,0x0F,0x0C,0x08,0x08,0x08,0x00,0x00},/*"1",0*/

{0x00,0x00,0x00,0x00,0x80,0xC0,0x40,0x40,0x40,0x40,0xC0,0xC0,0x80,0x80,0x00,0x00,
0x00,0x00,0x1E,0x1F,0x19,0x00,0x00,0x00,0x00,0x00,0x00,0xC1,0xFF,0xFF,0x3E,0x00,
0x00,0x00,0x00,0x00,0x80,0xC0,0x70,0x38,0x1C,0x0E,0x07,0x03,0x01,0xC0,0xC0,0x00,
0x00,0x00,0x0E,0x0F,0x0D,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0E,0x0F,0x03,0x00},/*"2",0*/

{0x00,0x00,0x00,0x80,0x80,0xC0,0x40,0x40,0x40,0xC0,0xC0,0x80,0x00,0x00,0x00,0x00,
0x00,0x00,0x0F,0x0F,0x0F,0x00,0x00,0x00,0x00,0x80,0xC1,0xFF,0x7F,0x3E,0x00,0x00,
0x00,0x00,0xC0,0xC0,0xC0,0x00,0x01,0x01,0x01,0x03,0x03,0x06,0xFE,0xFC,0xF0,0x00,
0x00,0x00,0x03,0x07,0x07,0x0C,0x08,0x08,0x08,0x08,0x0C,0x06,0x07,0x03,0x00,0x00},/*"3",0*/

{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0xC0,0xC0,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x80,0xE0,0x70,0x1C,0x0F,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,
0x00,0x30,0x3C,0x2E,0x27,0x21,0x20,0x20,0x20,0xFF,0xFF,0xFF,0x20,0x20,0x20,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x08,0x08,0x0F,0x0F,0x0F,0x08,0x08,0x08,0x00},/*"4",0*/

{0x00,0x00,0x00,0x00,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0x00,
0x00,0x00,0x00,0xFF,0xFF,0x80,0xC0,0x40,0x40,0x40,0xC0,0xC0,0x80,0x00,0x00,0x00,
0x00,0x00,0xC0,0xC3,0xC3,0x01,0x00,0x00,0x00,0x00,0x00,0x01,0xFF,0xFF,0xFC,0x00,
0x00,0x00,0x03,0x07,0x04,0x0C,0x08,0x08,0x08,0x08,0x0C,0x07,0x07,0x03,0x00,0x00},/*"5",0*/

{0x00,0x00,0x00,0x00,0x00,0x80,0x80,0xC0,0x40,0x40,0x40,0xC0,0x80,0x80,0x00,0x00,
0x00,0x00,0xE0,0xFC,0xFF,0x87,0xC1,0xC0,0x40,0x40,0xC0,0xC3,0x83,0x03,0x00,0x00,
0x00,0x00,0x7F,0xFF,0xFF,0x83,0x00,0x00,0x00,0x00,0x00,0x01,0xFF,0xFF,0xFC,0x00,
0x00,0x00,0x00,0x01,0x07,0x07,0x0E,0x0C,0x08,0x08,0x0C,0x0E,0x07,0x03,0x00,0x00},/*"6",0*/

{0x00,0x00,0x00,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0x00,
0x00,0x00,0x0E,0x0F,0x03,0x00,0x00,0x00,0x00,0xE0,0xF8,0x1E,0x07,0x01,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0xFC,0xFF,0x03,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x0F,0x0F,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"7",0*/

{0x00,0x00,0x00,0x00,0x80,0xC0,0xC0,0x40,0x40,0x40,0xC0,0xC0,0x80,0x00,0x00,0x00,
0x00,0x00,0x3E,0x7F,0xFF,0xF1,0xC0,0xC0,0x80,0x00,0x80,0xC1,0x7F,0x7F,0x1E,0x00,
0x00,0xF0,0xFC,0xFE,0x0E,0x03,0x01,0x01,0x03,0x07,0x0F,0x1E,0xFE,0xFC,0xF0,0x00,
0x00,0x01,0x03,0x07,0x06,0x0C,0x08,0x08,0x08,0x08,0x0C,0x06,0x07,0x03,0x01,0x00},/*"8",0*/

{0x00,0x00,0x00,0x80,0x80,0xC0,0x40,0x40,0x40,0x40,0xC0,0x80,0x00,0x00,0x00,0x00,
0x00,0xFC,0xFF,0xFF,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xFF,0xFE,0xF8,0x00,
0x00,0x01,0x03,0x07,0x0F,0x0C,0x08,0x08,0x08,0x0C,0x06,0xE7,0xFF,0x7F,0x1F,0x00,
0x00,0x00,0x07,0x07,0x0F,0x08,0x08,0x08,0x0C,0x0E,0x07,0x03,0x01,0x00,0x00,0x00}/*"9",0*/

};/*"0",0*/

void send_8bit_mini12864(unsigned char d)  //传8位数据,高位先传
{
  for (int i = 0; i < 8; i++)             //循环8次,每次发送1个最高位
  {
    digitalWrite(sck_mini12864, 0);      //时钟拉低,一位数据开始
    if (d & 0x80)                       //与上10000000,最高位如果是1,就数据位就高
      digitalWrite(sda_mini12864, 1);
    else                                //与上10000000,最高位如果是0,就数据位就低
      digitalWrite(sda_mini12864, 0);
    digitalWrite(sck_mini12864, 1);      //一位数据发送完毕,时钟拉高
    d <<= 1;                            // d|ddddddd0    抛掉最高位,其余数据左移一位,最低位填0
  }
}

void write_cmd_mini12864(unsigned char cmd)  //写命令
{
  digitalWrite(cs_mini12864, 0); //片选拉低,选中芯片
  digitalWrite(rs_mini12864, 0); //rs为低,写入命令
  send_8bit_mini12864(cmd);     //写入8位命令
}

void write_dat_mini12864(unsigned char dat)  //写数据
{
  digitalWrite(cs_mini12864, 0); //片选拉低,选中芯片
  digitalWrite(rs_mini12864, 1); //rs为高,写入数据
  send_8bit_mini12864(dat);          //写入8位数据
}

void mini12864_cl()         //清屏,其实就是把所有的地址全部填成0
{
  unsigned char x, y;
  for (y = 0; y < 8; y++)
  {
    write_cmd_mini12864(0xb0 + y);
    write_cmd_mini12864(0x10);
    write_cmd_mini12864(0x00);
    for (x = 0; x < 132; x++)  write_dat_mini12864(0);
  }
}

void mini12864_Init()   //初始化
{
  pinMode(cs_mini12864, OUTPUT);  //设置各个I/O为输出
  pinMode(rst_mini12864, OUTPUT);
  pinMode(rs_mini12864, OUTPUT);
  pinMode(sck_mini12864, OUTPUT);
  pinMode(sda_mini12864, OUTPUT);
  digitalWrite(cs_mini12864, LOW);
  digitalWrite(rst_mini12864, LOW);         //物理重置
  delay(200);
  digitalWrite(rst_mini12864, HIGH);
  delay(1000);
  write_cmd_mini12864(0xe2);                //软件重置
  delay(200);
  //以下为初始设置,具体请参考数据手册
  write_cmd_mini12864(0x24);//对比度
  write_cmd_mini12864(0x81);//SET ELECTRONIC VOLUME
  write_cmd_mini12864(0x20);//set pm: 通过改变这里的数值来改变电压
  write_cmd_mini12864(0x2f);//set power control
  write_cmd_mini12864(0xa2);//BR=1/9
  write_cmd_mini12864(0xa0);//set seg direction
  write_cmd_mini12864(0xc8);//set com direction
  write_cmd_mini12864(0x40);//set scroll line
  write_cmd_mini12864(0xaf);//开显示
  mini12864_cl();  //清屏
}

void mini12864_address(unsigned char page, unsigned char column)
{
  digitalWrite(cs_mini12864, 0); //片选拉低,选中芯片
  column = column - 1;
  page = page - 1;
  write_cmd_mini12864(0xb0 + page);
  write_cmd_mini12864(((column >> 4) & 0x0f) + 0x10);
  write_cmd_mini12864(column & 0x0f);
}

void full_dispaly()
{
  int i, j;
  for (i = 0; i < 8; i++)
  {
    digitalWrite(cs_mini12864, 0); //片选拉低,选中芯片
    mini12864_address(i + 1, 0);
    for (j = 0; j < 128; j++)
    {
      write_dat_mini12864(0xff);
    }
  }
}

void display_graphic_16x32(unsigned char page, unsigned char column, unsigned char *dp)
{
  unsigned char i, j;
  digitalWrite(cs_mini12864, 0); //片选拉低,选中芯片
  for (j = 0; j < 4; j++)
  {
    mini12864_address(page + j, column);
    for (i = 0; i < 16; i++)
    {
      write_dat_mini12864(*dp); /*写数据到LCD,每写完一个8 位的数据后列地址自动加1*/
      dp++;
    }
  }
  digitalWrite(cs_mini12864, 1); //片选拉低,选中芯片
}

void setup() {
  while (!Serial);        // needed to keep leonardo/micro from starting too fast!

  Serial.begin(9600);
  Serial.println("ALSROBOT MPR121 Capacitive Touch sensor test"); 
  
  // Default address is 0x5A, if tied to 3.3V its 0x5B
  // If tied to SDA its 0x5C and if SCL then 0x5D
  if (!cap.begin(0x5A)) {
    Serial.println("MPR121 not found, check wiring?");
    while (1);
  }
  Serial.println("MPR121 found!");
  mini12864_Init();   //初始化液晶
  mini12864_cl();  //清屏
}

void loop() {
  // Get the currently touched pads
  currtouched = cap.touched();
  for (uint8_t i=0; i<12; i++) {
    // it if *is* touched and *wasnt* touched before, alert!
    if ((currtouched & _BV(i)) && !(lasttouched & _BV(i)) ) {
      display_graphic_16x32(3, (0+48), shuzi16X32[i/10]);
      display_graphic_16x32(3, (0+64), shuzi16X32[i%10]);
      Serial.print(i); Serial.println(" touched");
    }
  }
  lasttouched = currtouched;
}
  • 程序效果

通过 Arduino IDE 的串口监视器,我们可以看到当手指触碰到某个感应区域时,串口监视器会输出相应的触碰点信息

02S10402.png

产品相关推荐

Erweima.png

例子程序下载

产品购买地址

相关资料