SKU:RB-02S104 IIC觸摸傳感器

來自ALSROBOT WiKi
跳轉至: 導航搜索
02S10401.png

目錄

產品概述

IIC觸摸傳感器是 12 路電容式觸摸傳感器,基于接近電容式觸摸傳感器控制器的飛思卡爾- mpr121 芯片。它檢測到人類手指的觸摸或接近??梢耘c Arduino 簡單連接,創(chuàng)作你的互動項目。電容式觸摸傳感器可通過檢測當一個人(或動物)接觸到的傳感器電極之一輸出不同的信號給控制器。IIC觸摸傳感器可能應用于之前我們用過的使用觸碰感知的設備上,如觸摸式平板電腦和手機,以及觸控面板的電器。該IIC觸摸傳感器允許您用在可以對人體的接觸作出反應的電子產品中,并且支持最多 12 個獨立的觸摸通道。觸摸電極有時也能感知到手指的非直接接觸,那就是說,你不需要用你的手指觸摸的觸角上。

產品參數

  1. 工作電壓 :3.3V-5.5V
  2. 待機電流: 2uA
  3. 觸摸通道:12個
  4. 接口類型:IIC
  5. IIC地址:0x5A - 0x5D
  6. 尺寸大小: 80mm x 50mm
  7. 重量大?。?g
  8. 固定孔:4 * M3
  • 產品尺寸圖:
Size027.jpg

使用方法

基本應用

  • 實驗環(huán)境

1、硬件環(huán)境:

2、軟件環(huán)境:

  • 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     //對比度調節(jié)             
#define  AllPoint 0xA4           //非全屏顯示
#define  ADCset   0xA1            //負向,131-4
#define  COMset   0xc0            //com0-com63
#define  ELECTVO  0x81     //亮度調節(jié)         調節(jié)顏色         不同的模塊需要不同的  ELECTSET
#define  ELECTSET 0x2a           //亮度數值         調節(jié)顏色         不同的模塊需要不同的        數值
#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++)             //循環(huán)8次,每次發(fā)送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);      //一位數據發(fā)送完畢,時鐘拉高
    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 的串口監(jiān)視器,我們可以看到當手指觸碰到某個感應區(qū)域時,串口監(jiān)視器會輸出相應的觸碰點信息

02S10402.png

資料下載

Erweima.png
  • 產品資料

下載鏈接:https://pan.baidu.com/s/1gmo0VCtKwJEoKha6cG96Cw 提取碼:wv0w