SKU:RB-02S102 Gesture Sensor
来自ALSROBOT WiKi
目录 |
产品概述
Gesture Sensor模块是基于APDS-9960传感器的一款能够识别手势移动方向(上下左右)的传感器模块。APDS-9960芯片集成了RGB、环境光、接近和手势检测功能。模块使用I2C接口,使用相应arduino库函数即可对编程控制,传感器返回的信号可用于作为机器人接收的控制信号,从而实现对机器人的控制。内置的识别算法相当智能,能够把双手从生硬的按键中解放出来。
产品参数
- 输入电压:3.3V - 5V
- 引脚接口:IIC接口* 1、中断引脚 * 1
- 接口类型:直插、KF2510
- 输出信号:数字
- 产品尺寸:30 mm * 25 mm
- 定位孔:4 * M3,间距 23mm x 18mm
- 检测距离:10 cm
- 重量大小:3g
- 产品尺寸图:
使用方法_1(Arduino 控制器)
使用硬件
- 1 * Arduino UNO 控制器
- 杜邦线若干
- USB 数据线
硬件连接
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"); } } }
程序效果
手在上下左右远近滑过经过传感器时,串口会打印如图所示的数据
使用方法_2(Arduino 控制器)
使用硬件
- 1 * LED 发光模块
- 1 * Arduino 控制器
- 1 * 传感器扩展板 V5.0
- 1 * 手势传感器
- 1 * USB 数据线
- 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; } } }
程序效果
- 向上滑动时,通过串口打印‘UP’,同时 LED 亮起
- 向下滑动时,通过串口打印‘DOWM’,同时 LED 熄灭
应用案例
1、测试环境
- 硬件环境:Starduino UNO R3 、传感器V5.0扩展板、红外手势传感器、8*8点阵
- 软件环境:Arduino IDE 1.7.7
2、引脚定义
- -:电源地
- +:电源正极
- SDA:数据引脚
- SCL:时引脚
3、硬件连接
4、例子程序
#include <Wire.h> #include <ALSROBOT_APDS9960.h> const int DINPin = 4; //数据引脚 连接到数字P4口 const int CLKPin = 5; //时钟引脚 连接到数字P5口 const int LTHPin = 6; //锁存引脚 连接到数字P6口 byte LieScan[16] = { //列扫描,点阵只点亮一列 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); //设置数据引脚为输出 pinMode(CLKPin,OUTPUT); //设置锁存引脚为输出 pinMode(LTHPin,OUTPUT); //设置时钟引脚为输出 // 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++) { //持续刷新250次 for(char x = 0;x <8;x++) { shiftOut(DINPin, CLKPin, MSBFIRST, LieScan[x]); //先选择列 shiftOut(DINPin, CLKPin, MSBFIRST, Left[x]); //再送行数据 digitalWrite(LTHPin, LOW); //刷新显示 digitalWrite(LTHPin, HIGH); } } } void down() { for(unsigned char times_1 = 0;times_1 <250;times_1++) { //持续刷新250次 for(char x = 0;x <8;x++) { shiftOut(DINPin, CLKPin, MSBFIRST, LieScan[x]); //先选择列 shiftOut(DINPin, CLKPin, MSBFIRST, Down[x]); //再送行数据 digitalWrite(LTHPin, LOW); //刷新显示 digitalWrite(LTHPin, HIGH); } } } void up() { for(unsigned char times_1 = 0;times_1 <250;times_1++) { //持续刷新250次 for(char x = 0;x <8;x++) { shiftOut(DINPin, CLKPin, MSBFIRST, LieScan[x]); //先选择列 shiftOut(DINPin, CLKPin, MSBFIRST, Up[x]); //再送行数据 digitalWrite(LTHPin, LOW); //刷新显示 digitalWrite(LTHPin, HIGH); } } } void right() { for(unsigned char times_1 = 0;times_1 <250;times_1++) { //持续刷新250次 for(char x = 0;x <8;x++) { shiftOut(DINPin, CLKPin, MSBFIRST, LieScan[x]); //先选择列 shiftOut(DINPin, CLKPin, MSBFIRST, Right[x]); //再送行数据 digitalWrite(LTHPin, LOW); //刷新显示 digitalWrite(LTHPin, HIGH); } } } void far() { for(unsigned char times_1 = 0;times_1 <250;times_1++) { //持续刷新250次 for(char x = 0;x <8;x++) { shiftOut(DINPin, CLKPin, MSBFIRST, LieScan[x]); //先选择列 shiftOut(DINPin, CLKPin, MSBFIRST, Far[x]); //再送行数据 digitalWrite(LTHPin, LOW); //刷新显示 digitalWrite(LTHPin, HIGH); } } } void near() { for(unsigned char times_1 = 0;times_1 <250;times_1++) { //持续刷新250次 for(char x = 0;x <8;x++) { shiftOut(DINPin, CLKPin, MSBFIRST, LieScan[x]); //先选择列 shiftOut(DINPin, CLKPin, MSBFIRST, Near[x]); //再送行数据 digitalWrite(LTHPin, LOW); //刷新显示 digitalWrite(LTHPin, HIGH); } } } void moren() { for(unsigned char times_1 = 0;times_1 <250;times_1++) { //持续刷新250次 for(char x = 0;x <8;x++) { shiftOut(DINPin, CLKPin, MSBFIRST, LieScan[x]); //先选择列 shiftOut(DINPin, CLKPin, MSBFIRST, 0x00); //再送行数据 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、程序效果 如图所示,当手滑动时,点阵显示相应的滑动方向
产品相关推荐
例子程序下载
- 产品例子程序及库文件下载链接:http://pan.baidu.com/s/1i5eIqlZ 密码:q24j
- Arduino 库文件加载方法:http://www.makerspace.cn/forum.php?mod=viewthread&tid=6647&fromuid=10780