SKU:RB-02S102 Gesture Sensor
來自ALSROBOT WiKi
目錄 |
產(chǎn)品概述
Gesture Sensor模塊是基于APDS-9960傳感器的一款能夠識(shí)別手勢(shì)移動(dòng)方向(上下左右)的傳感器模塊。APDS-9960芯片集成了RGB、環(huán)境光、接近和手勢(shì)檢測(cè)功能。模塊使用I2C接口,使用相應(yīng)arduino庫函數(shù)即可對(duì)編程控制,傳感器返回的信號(hào)可用于作為機(jī)器人接收的控制信號(hào),從而實(shí)現(xiàn)對(duì)機(jī)器人的控制。內(nèi)置的識(shí)別算法相當(dāng)智能,能夠把雙手從生硬的按鍵中解放出來。
產(chǎn)品參數(shù)
- 輸入電壓:3.3V - 5V
- 引腳接口:IIC接口* 1、中斷引腳 * 1
- 接口類型:直插、KF2510
- 輸出信號(hào):數(shù)字
- 產(chǎn)品尺寸:30 mm * 25 mm
- 定位孔:4 * M3,間距 23mm x 18mm
- 檢測(cè)距離:10 cm
- 重量大?。?g
- 產(chǎn)品尺寸圖:
使用方法_1(Arduino 控制器)
使用硬件
- 1 * Arduino UNO 控制器
- 杜邦線若干
- USB 數(shù)據(jù)線
硬件連接
Arduino_code_1
#include <Wire.h> #include <ALS_APDS9960.h> ALS_APDS9960 apds = ALS_APDS9960(); int isr_flag = 0; void setup() { Serial.begin(9600); Serial.println(); Serial.println(F("--------------------------------")); Serial.println(F("SparkFun APDS-9960 - GestureTest")); Serial.println(F("--------------------------------")); if ( apds.init() ) { Serial.println(F("APDS-9960 initialization complete")); } else { Serial.println(F("Something went wrong during APDS-9960 init!")); } // Start running the APDS-9960 gesture sensor engine if ( apds.enableGestureSensor(true) ) { Serial.println(F("Gesture sensor is now running")); } else { Serial.println(F("Something went wrong during gesture sensor init!")); } } void loop() { handleGesture(); delay(50); } void handleGesture() { if ( apds.isGestureAvailable() ) { switch ( apds.readGesture() ) { case DIR_UP: Serial.println("UP"); break; case DIR_DOWN: Serial.println("DOWN"); break; case DIR_LEFT: Serial.println("LEFT"); break; case DIR_RIGHT: Serial.println("RIGHT"); break; case DIR_NEAR: Serial.println("NEAR"); break; case DIR_FAR: Serial.println("FAR"); break; default: Serial.println("NONE"); } } }
程序效果
手在上下左右遠(yuǎn)近滑過經(jīng)過傳感器時(shí),串口會(huì)打印如圖所示的數(shù)據(jù)
使用方法_2(Arduino 控制器)
使用硬件
- 1 * LED 發(fā)光模塊
- 1 * Arduino 控制器
- 1 * 傳感器擴(kuò)展板 V5.0
- 1 * 手勢(shì)傳感器
- 1 * USB 數(shù)據(jù)線
- 1 * 4P 傳感器連接線
- 杜邦線若干
硬件連接
Arduino_code_2
#include <Wire.h> #include <ALS_APDS9960.h> #define led 4 #define APDS9960_INT 2 ALS_APDS9960 apds = ALS_APDS9960(); int temp = 0; int isr_flag = 0; void setup() { pinMode(led,OUTPUT); pinMode(APDS9960_INT, INPUT); Serial.begin(9600); Serial.println(); Serial.println(F("--------------------------------")); Serial.println(F("ALS_APDS-9960 - GestureTest")); Serial.println(F("--------------------------------")); attachInterrupt(0, interruptRoutine, FALLING); if ( apds.init() ) { Serial.println(F("APDS-9960 initialization complete")); } else { Serial.println(F("Something went wrong during APDS-9960 init!")); } if ( apds.enableGestureSensor(true) ) { Serial.println(F("Gesture sensor is now running")); } else { Serial.println(F("Something went wrong during gesture sensor init!")); } } void loop() { if( isr_flag == 1 ) { detachInterrupt(0); handleGesture(); isr_flag = 0; attachInterrupt(0, interruptRoutine, FALLING); } } void interruptRoutine() { isr_flag = 1; switch(temp){ case 1: digitalWrite(led,HIGH); break; case 2: digitalWrite(led,LOW); break; } } void handleGesture() { if ( apds.isGestureAvailable() ) { switch ( apds.readGesture() ) { case DIR_UP: Serial.println("UP"); temp = 1; break; case DIR_DOWN: Serial.println("DOWN"); temp = 2; break; case DIR_LEFT: Serial.println("LEFT"); break; case DIR_RIGHT: Serial.println("RIGHT"); break; case DIR_NEAR: Serial.println("NEAR"); break; case DIR_FAR: Serial.println("FAR"); break; default: Serial.println("NONE"); temp = 0; } } }
程序效果
- 向上滑動(dòng)時(shí),通過串口打印‘UP’,同時(shí) LED 亮起
- 向下滑動(dòng)時(shí),通過串口打印‘DOWM’,同時(shí) LED 熄滅
應(yīng)用案例
1、測(cè)試環(huán)境
- 硬件環(huán)境:Starduino UNO R3 、傳感器V5.0擴(kuò)展板、紅外手勢(shì)傳感器、8*8點(diǎn)陣
- 軟件環(huán)境:Arduino IDE 1.7.7
2、引腳定義
- -:電源地
- +:電源正極
- SDA:數(shù)據(jù)引腳
- SCL:時(shí)引腳
3、硬件連接
4、例子程序
#include <Wire.h> #include <ALSROBOT_APDS9960.h> const int DINPin = 4; //數(shù)據(jù)引腳 連接到數(shù)字P4口 const int CLKPin = 5; //時(shí)鐘引腳 連接到數(shù)字P5口 const int LTHPin = 6; //鎖存引腳 連接到數(shù)字P6口 byte LieScan[16] = { //列掃描,點(diǎn)陣只點(diǎn)亮一列 0xFE,0xFD,0xFB,0xF7,0xEF,0xDF,0xBF,0x7F }; byte HanZi_1[] = { 0x1c,0x7c,0x7e,0x3f,0x3f,0x7e,0x7c,0x1c //顯示心形圖案 }; char Left[]={0x00,0x18,0x3c,0x7e,0x18,0x18,0x18,0x00}; char Down[]={0x00,0x10,0x30,0x7e,0x7e,0x30,0x10,0x00}; char Up[]={0x00,0x08,0x0c,0x7e,0x7e,0x0c,0x08,0x00}; char Right[]={0x00,0x18,0x18,0x18,0x7e,0x3c,0x18,0x00}; char Far[]={0xff,0xff,0xc3,0xc3,0xc3,0xc3,0xff,0xff}; char Near[]={0x00,0x00,0x3c,0x3c,0x3c,0x3c,0x00,0x00}; char Moren[]={0x18,0x3c,0x5a,0xff,0xff,0x5a,0x3c,0x18}; ALSROBOT_APDS9960 apds = ALSROBOT_APDS9960(); int isr_flag = 0; int temp=0; void setup() { pinMode(DINPin,OUTPUT); //設(shè)置數(shù)據(jù)引腳為輸出 pinMode(CLKPin,OUTPUT); //設(shè)置鎖存引腳為輸出 pinMode(LTHPin,OUTPUT); //設(shè)置時(shí)鐘引腳為輸出 // Initialize Serial port Serial.begin(9600); Serial.println(); Serial.println(F("--------------------------------")); Serial.println(F("ALSROBOT APDS-9960 - GestureTest")); Serial.println(F("--------------------------------")); if ( apds.init() ) { Serial.println(F("APDS-9960 initialization complete")); } else { Serial.println(F("Something went wrong during APDS-9960 init!")); } // Start running the APDS-9960 gesture sensor engine if ( apds.enableGestureSensor(true) ) { Serial.println(F("Gesture sensor is now running")); } else { Serial.println(F("Something went wrong during gesture sensor init!")); } } void left(){ for(unsigned char times_1 = 0;times_1 <250;times_1++) { //持續(xù)刷新250次 for(char x = 0;x <8;x++) { shiftOut(DINPin, CLKPin, MSBFIRST, LieScan[x]); //先選擇列 shiftOut(DINPin, CLKPin, MSBFIRST, Left[x]); //再送行數(shù)據(jù) digitalWrite(LTHPin, LOW); //刷新顯示 digitalWrite(LTHPin, HIGH); } } } void down() { for(unsigned char times_1 = 0;times_1 <250;times_1++) { //持續(xù)刷新250次 for(char x = 0;x <8;x++) { shiftOut(DINPin, CLKPin, MSBFIRST, LieScan[x]); //先選擇列 shiftOut(DINPin, CLKPin, MSBFIRST, Down[x]); //再送行數(shù)據(jù) digitalWrite(LTHPin, LOW); //刷新顯示 digitalWrite(LTHPin, HIGH); } } } void up() { for(unsigned char times_1 = 0;times_1 <250;times_1++) { //持續(xù)刷新250次 for(char x = 0;x <8;x++) { shiftOut(DINPin, CLKPin, MSBFIRST, LieScan[x]); //先選擇列 shiftOut(DINPin, CLKPin, MSBFIRST, Up[x]); //再送行數(shù)據(jù) digitalWrite(LTHPin, LOW); //刷新顯示 digitalWrite(LTHPin, HIGH); } } } void right() { for(unsigned char times_1 = 0;times_1 <250;times_1++) { //持續(xù)刷新250次 for(char x = 0;x <8;x++) { shiftOut(DINPin, CLKPin, MSBFIRST, LieScan[x]); //先選擇列 shiftOut(DINPin, CLKPin, MSBFIRST, Right[x]); //再送行數(shù)據(jù) digitalWrite(LTHPin, LOW); //刷新顯示 digitalWrite(LTHPin, HIGH); } } } void far() { for(unsigned char times_1 = 0;times_1 <250;times_1++) { //持續(xù)刷新250次 for(char x = 0;x <8;x++) { shiftOut(DINPin, CLKPin, MSBFIRST, LieScan[x]); //先選擇列 shiftOut(DINPin, CLKPin, MSBFIRST, Far[x]); //再送行數(shù)據(jù) digitalWrite(LTHPin, LOW); //刷新顯示 digitalWrite(LTHPin, HIGH); } } } void near() { for(unsigned char times_1 = 0;times_1 <250;times_1++) { //持續(xù)刷新250次 for(char x = 0;x <8;x++) { shiftOut(DINPin, CLKPin, MSBFIRST, LieScan[x]); //先選擇列 shiftOut(DINPin, CLKPin, MSBFIRST, Near[x]); //再送行數(shù)據(jù) digitalWrite(LTHPin, LOW); //刷新顯示 digitalWrite(LTHPin, HIGH); } } } void moren() { for(unsigned char times_1 = 0;times_1 <250;times_1++) { //持續(xù)刷新250次 for(char x = 0;x <8;x++) { shiftOut(DINPin, CLKPin, MSBFIRST, LieScan[x]); //先選擇列 shiftOut(DINPin, CLKPin, MSBFIRST, 0x00); //再送行數(shù)據(jù) digitalWrite(LTHPin, LOW); //刷新顯示 digitalWrite(LTHPin, HIGH); } } } void loop() { switch(temp) { case 1:up();break; case 2:down();break; case 3:left();break; case 4:right();break; case 5:near();break; case 6:far();break; default :moren();break; } handleGesture(); } void handleGesture() { if ( apds.isGestureAvailable() ) { switch ( apds.readGesture() ) { case DIR_UP: temp=1; Serial.println("UP"); break; case DIR_DOWN: temp=2; Serial.println("DOWN"); break; case DIR_LEFT: temp=3; Serial.println("LEFT"); break; case DIR_RIGHT: temp=4; Serial.println("RIGHT"); break; case DIR_NEAR: temp=5; Serial.println("NEAR"); break; case DIR_FAR: temp=6; Serial.println("FAR"); break; default:temp=7; Serial.println("NONE"); } } }
5、程序效果 如圖所示,當(dāng)手滑動(dòng)時(shí),點(diǎn)陣顯示相應(yīng)的滑動(dòng)方向
產(chǎn)品相關(guān)推薦
資料下載
- Arduino 庫文件加載方法
- 例程及芯片手冊(cè)下載鏈接: https://pan.baidu.com/s/1UWH-DQiHI-AbRQPh_9PI6Q 提取碼:qip3