SKU:RB-02S104 IIC觸摸傳感器
來自ALSROBOT WiKi
目錄 |
產(chǎn)品概述
IIC觸摸傳感器是 12 路電容式觸摸傳感器,基于接近電容式觸摸傳感器控制器的飛思卡爾- mpr121 芯片。它檢測到人類手指的觸摸或接近。可以與 Arduino 簡單連接,創(chuàng)作你的互動項目。電容式觸摸傳感器可通過檢測當(dāng)一個人(或動物)接觸到的傳感器電極之一輸出不同的信號給控制器。IIC觸摸傳感器可能應(yīng)用于之前我們用過的使用觸碰感知的設(shè)備上,如觸摸式平板電腦和手機,以及觸控面板的電器。該IIC觸摸傳感器允許您用在可以對人體的接觸作出反應(yīng)的電子產(chǎn)品中,并且支持最多 12 個獨立的觸摸通道。觸摸電極有時也能感知到手指的非直接接觸,那就是說,你不需要用你的手指觸摸的觸角上。
產(chǎn)品參數(shù)
- 工作電壓 :3.3V-5.5V
- 待機電流: 2uA
- 觸摸通道:12個
- 接口類型:IIC
- IIC地址:0x5A - 0x5D
- 尺寸大?。?80mm x 50mm
- 重量大?。?g
- 固定孔:4 * M3
- 產(chǎn)品尺寸圖:
使用方法
基本應(yīng)用
- 實驗環(huán)境
1、硬件環(huán)境:
- Starduino UNO R3 控制器 * 1個
- IIC 觸摸傳感器 * 1個
- 4P 傳感器連接線 * 1條
- USB 數(shù)據(jù)線 * 1條
- LCD12864 液晶擴展板 * 1個
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:數(shù)據(jù)寄存器 0:指令寄存器 #define sck_mini12864 5 //時鐘 #define sda_mini12864 6 //數(shù)據(jù) //上面的腳可以自己修改 #define Display 0xAF //顯示開啟 #define Power 0x2F //電源全開 #define VO 0x24 //對比度調(diào)節(jié) #define AllPoint 0xA4 //非全屏顯示 #define ADCset 0xA1 //負(fù)向,131-4 #define COMset 0xc0 //com0-com63 #define ELECTVO 0x81 //亮度調(diào)節(jié) 調(diào)節(jié)顏色 不同的模塊需要不同的 ELECTSET #define ELECTSET 0x2a //亮度數(shù)值 調(diào)節(jié)顏色 不同的模塊需要不同的 數(shù)值 #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位數(shù)據(jù),高位先傳 { for (int i = 0; i < 8; i++) //循環(huán)8次,每次發(fā)送1個最高位 { digitalWrite(sck_mini12864, 0); //時鐘拉低,一位數(shù)據(jù)開始 if (d & 0x80) //與上10000000,最高位如果是1,就數(shù)據(jù)位就高 digitalWrite(sda_mini12864, 1); else //與上10000000,最高位如果是0,就數(shù)據(jù)位就低 digitalWrite(sda_mini12864, 0); digitalWrite(sck_mini12864, 1); //一位數(shù)據(jù)發(fā)送完畢,時鐘拉高 d <<= 1; // d|ddddddd0 拋掉最高位,其余數(shù)據(jù)左移一位,最低位填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) //寫數(shù)據(jù) { digitalWrite(cs_mini12864, 0); //片選拉低,選中芯片 digitalWrite(rs_mini12864, 1); //rs為高,寫入數(shù)據(jù) send_8bit_mini12864(dat); //寫入8位數(shù)據(jù) } 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); //設(shè)置各個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); //以下為初始設(shè)置,具體請參考數(shù)據(jù)手冊 write_cmd_mini12864(0x24);//對比度 write_cmd_mini12864(0x81);//SET ELECTRONIC VOLUME write_cmd_mini12864(0x20);//set pm: 通過改變這里的數(shù)值來改變電壓 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); /*寫數(shù)據(jù)到LCD,每寫完一個8 位的數(shù)據(jù)后列地址自動加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)視器,我們可以看到當(dāng)手指觸碰到某個感應(yīng)區(qū)域時,串口監(jiān)視器會輸出相應(yīng)的觸碰點信息
資料下載
- 產(chǎn)品資料
下載鏈接:https://pan.baidu.com/s/1gmo0VCtKwJEoKha6cG96Cw 提取碼:wv0w
- 產(chǎn)品購買鏈接:http://lifestyle201.com/goods-774.html
- 奧松機器人技術(shù)論壇:http://www.makerspace.cn