Introduction
This GR10-30 gesture sensor is capable of recognizing 12 hand gestures: move up, down, left, right, forward & backward, rotate clockwise & counterclockwise, rotate clockwise & counterclockwise continuously, hover, and wave. And users can set parameters such as the gesture trigger distance, the hand rotation angle and hovering time that can be recognized, and the size of recognition window to get more accurate results. The GR10-30 features stable performance and high accuracy within sensing distance of up to 30cm.
The sensor is well suited to non-contact operation applications like gesture remote controllers, robot interaction, human-machine interface control, lighting control, and gesture game machine.
Features
- Maximum Recognition distance of 30cm
- Capable of recognizing 12 gestures
- Configurable recognition threshold & other parameters
- Support UART & I2C communication
Application
- Gesture Remote Controller
- Robot Interaction
- Human-machine Interface Control
Specification
- Supply Voltage: 3.3V to 5V
- Operating Current: <10mA
- I2C Address: 0x73
- Baud Rate: 9600
- Maximum Recognition Distance: 30cm
- Operating Temperature: 0℃ to 70℃
- Operating Humidity: 5%RH to 85%RH
- Dimension: 22×30mm/0.87×1.18”
Board Overview
Num | Label | Description |
---|---|---|
1 | + | Power + |
2 | - | Power - |
3 | C/R | I2C clock line/Serial receive |
4 | D/T | I2C data line/Serial transmit |
LED: Light up when there is an object moving in the detection range, and black out if there is no object and when the object is stationary or the detection area is completely blocked for over 3s.
Tutorial for Arduino
Requirements
- Hardware
- DFRduino UNO R3 (or similar) x 1
- Gravity: GR10-30 Gesture Sensor x 1
- DuPont Wires
- Software
- Arduino IDE
- RTU Library (Install RTU library when using serial for communication)
- Download and install the GR10-30 library & sample codes (About how to install the library?)
Connection Diagram
Sample Code 1 - Read gesture by polling
Read gesture by polling
Parameter Explanation
- gr10_30.setLeftRange(5);
When the detected hand moves five units to the left, it will be determined as "move left" gesture- Moving distance (cm)=(hand distance from sensor * Set parameter) / 25
- gr10_30.setUdlrWin(18, 11);
Set recognition area as 18*11 units - gr10_30.setCwsAngle(4);
Rotating by 90° will be determined as "rotate" gesture- The recognition distance for rotation gestures is about half of the maximum recognition distance.
/*!
* @file getGestures.ino
* @brief Run the routine to read gesture type
* @n
* @n connected table
* ---------------------------------------------------------------------------------------------------------------
* board | MCU | Leonardo/Mega2560/M0 | UNO | ESP8266 | ESP32 | microbit |
* VCC | 3.3V/5V | VCC | VCC | VCC | VCC | X |
* GND | GND | GND | GND | GND | GND | X |
* RX | TX | Serial1 TX1 | 5 | 5/D6 | D2 | X |
* TX | RX | Serial1 RX1 | 4 | 4/D7 | D3 | X |
* ---------------------------------------------------------------------------------------------------------------
*
* @copyright Copyright (c) 2021 DFRobot Co.Ltd (http://www.dfrobot.com)
* @license The MIT License (MIT)
* @author [zhixinliu](zhixinliu@dfrobot.com)
* @version V0.1
* @date 2022-07-25
* @url https://github.com/DFRobor/DFRobot_GR10_30
*/
#include "DFRobot_GR10_30.h"
#if defined(ARDUINO_AVR_UNO)||defined(ESP8266)
#include <SoftwareSerial.h>
#endif
//#define UARTMODE // Serial mode
#define I2CMODE // I2C mode
#if defined UARTMODE
#if defined(ARDUINO_AVR_UNO)||defined(ESP8266)
SoftwareSerial mySerial(/*rx =*/4, /*tx =*/5);
DFRobot_GR10_30 gr10_30(/*addr =*/GR10_30_DEVICE_ADDR, /*s =*/&mySerial);
#else
DFRobot_GR10_30 gr10_30(/*addr =*/GR10_30_DEVICE_ADDR, /*s =*/&Serial1);
#endif
#endif
#if defined I2CMODE
DFRobot_GR10_30 gr10_30(/*addr = */GR10_30_DEVICE_ADDR, /*pWire = */&Wire);
#endif
void setup()
{
#if defined UARTMODE
//Init MCU communication serial port
#if defined(ARDUINO_AVR_UNO)||defined(ESP8266)
mySerial.begin(9600);
#elif defined(ESP32)
Serial1.begin(9600, SERIAL_8N1, /*rx =*/D3, /*tx =*/D2);
#else
Serial1.begin(9600);
#endif
#endif
Serial.begin(115200);
while(gr10_30.begin() != 0){
Serial.println(" Sensor initialize failed!!");
delay(1000);
}
Serial.println(" Sensor initialize success!!");
/** Set the gesture to be enabled
* GESTURE_UP
* GESTURE_DOWN
* GESTURE_LEFT
* GESTURE_RIGHT
* GESTURE_FORWARD
* GESTURE_BACKWARD
* GESTURE_CLOCKWISE
* GESTURE_COUNTERCLOCKWISE
* GESTURE_WAVE It is not suggested to enable rotation gesture (CW/CCW) and wave gesture at the same time.
* GESTURE_HOVER Disable other gestures when hover gesture enables.
* GESTURE_UNKNOWN
* GESTURE_CLOCKWISE_C
* GESTURE_COUNTERCLOCKWISE_C
*/
gr10_30.enGestures(GESTURE_UP|GESTURE_DOWN|GESTURE_LEFT|GESTURE_RIGHT|GESTURE_FORWARD|GESTURE_BACKWARD|GESTURE_CLOCKWISE|GESTURE_COUNTERCLOCKWISE|GESTURE_CLOCKWISE_C|GESTURE_COUNTERCLOCKWISE_C);
// Use detailed config if enabled; use the default config if not enabled
/**
* Set the detection window you want, only data collected in the range are valid
* The largest window is 31, the configured number represents distance from the center to the top, bottom, left and right
* For example, if the configured distance from top to bottom is 30, then the distance from center to top is 15, and distance from center to bottom is also 15
* udSize Range of distance from top to bottom 0-31
* lrSize Range of distance from left to right 0-31
*/
// gr10_30.setUdlrWin(30, 30);
// gr10_30.setHovrWin(20, 20);
/**
* Set moving distance that can be recognized as a gesture
* Distance range 5-25, must be less than distances of the detection window
*/
// gr10_30.setLeftRange(10);
// gr10_30.setRightRange(10);
// gr10_30.setUpRange(10);
// gr10_30.setDownRange(10);
// gr10_30.setForwardRange(10);
// gr10_30.setBackwardRange(10);
/**
* Set distance of moving forward and backward that can be recognized as a gesture
* Distance range 1-15
*/
// gr10_30.setForwardRange(10);
// gr10_30.setBackwardRange(10);
/**
* Set wave number that can be recognized
* Number range 1-15
*/
// gr10_30.setWaveNumber(2);
/**
* Set hover time that can trigger the gesture
* 1-200 10ms-2s Default is 60 600ms
*/
// gr10_30.setHovrTimer(60);
/**
* Set rotation angle that can trigger the gesture
* count Default is 16 range 0-31
* count Rotation angle is 22.5 * count
* count = 16 22.5*count = 360 Rotate 360° to trigger the gesture
*/
// gr10_30.setCwsAngle(/*count*/16);
// gr10_30.setCcwAngle(/*count*/16);
/**
* Set degrees of continuous rotation that can trigger the gesture
* count Default is 4 range 0-31
* count The degrees of continuous rotation is 22.5 * count
* For example: count = 4 22.5*count = 90
* Trigger the clockwise/counterclockwise rotation gesture first, if keep rotating, then the continuous rotation gesture will be triggered once every 90 degrees
*/
// gr10_30.setCwsAngleCount(/*count*/8);
// gr10_30.setCcwAngleCount(/*count*/8);
}
void loop()
{
if(gr10_30.getDataReady()){
uint16_t gestures = gr10_30.getGesturesState();
if(gestures&GESTURE_UP){
Serial.println("Up");
}
if(gestures&GESTURE_DOWN){
Serial.println("Down");
}
if(gestures&GESTURE_LEFT){
Serial.println("Left");
}
if(gestures&GESTURE_RIGHT){
Serial.println("Right");
}
if(gestures&GESTURE_FORWARD){
Serial.println("Forward");
}
if(gestures&GESTURE_BACKWARD){
Serial.println("Backward");
}
if(gestures&GESTURE_CLOCKWISE){
Serial.println("Clockwise");
}
if(gestures&GESTURE_COUNTERCLOCKWISE){
Serial.println("Contrarotate");
}
if(gestures&GESTURE_WAVE){
Serial.println("Wave");
}
if(gestures&GESTURE_HOVER){
Serial.println("Hover");
}
if(gestures&GESTURE_CLOCKWISE_C){
Serial.println("Continuous clockwise");
}
if(gestures&GESTURE_COUNTERCLOCKWISE_C){
Serial.println("Continuous counterclockwise");
}
}
delay(1);
}
Result
Main API Functions
/**
* @fn enGestures
* @brief Enable gesture
* @param gestures
* GESTURE_UP
* GESTURE_DOWN
* GESTURE_LEFT
* GESTURE_RIGHT
* GESTURE_FORWARD
* GESTURE_BACKWARD
* GESTURE_CLOCKWISE
* GESTURE_COUNTERCLOCKWISE
* GESTURE_WAVE It is not suggested to enable rotation gesture (CW/CCW) and wave gesture at the same time.
* GESTURE_HOVER Disable other gestures when hover gesture enables.
* GESTURE_UNKNOWN
* GESTURE_CLOCKWISE_C
* GESTURE_COUNTERCLOCKWISE_C
* @return NONE
*/
void enGestures(uint16_t gestures);
/**
* @fn getExist
* @brief Get whether the object is in the detection range of sensor
* @return Is the object in the detection range of sensor
* @retval 1 Yes
* @retval 0 No
*/
uint16_t getExist(void);
/**
* @fn getDataReady
* @brief Get if a gesture is detected
* @return Is the gesture detected
* @retval 1 Detected
* @retval 0 Not detected
*/
uint16_t getDataReady(void);
/**
* @fn getGesturesState
* @brief Get gesture type
* @return Gesture type
* @retval GESTURE_UP
* @retval GESTURE_DOWN
* @retval GESTURE_DOWN
* @retval GESTURE_LEFT
* @retval GESTURE_RIGHT
* @retval GESTURE_FORWARD
* @retval GESTURE_BACKWARD
* @retval GESTURE_CLOCKWISE
* @retval GESTURE_COUNTERCLOCKWISE
* @retval GESTURE_WAVE
* @retval GESTURE_HOVER
* @retval GESTURE_UNKNOWN
* @retval GESTURE_CLOCKWISE_C
* @retval GESTURE_COUNTERCLOCKWISE_C
*/
uint16_t getGesturesState(void);
/**
* @fn setUdlrWin
* @brief Set the detection window you want
* @param udSize Distance from top to bottom distance range 0-31
* @param lrSize Distance from left to right distance range 0-31
* @return NONE
*/
void setUdlrWin(uint8_t udSize, uint8_t lrSize);
/**
* @fn setLeftRange
* @brief Set distance of moving to left that can be recognized
* @param range
* @n Distance range 0-31, must be less than distance from left to right of the detection window
* @return NONE
*/
void setLeftRange(uint8_t range);
/**
* @fn setRightRange
* @brief Set distance of moving to right that can be recognized
* @param range
* @n Distance range 0-31, must be less than distance from left to right of the detection window
* @return NONE
*/
void setRightRange(uint8_t range);
/**
* @fn setUpRange
* @brief Set distance of moving up that can be recognized
* @param range
* @n Distance range 0-31, must be less than distance from top to bottom of the detection window
* @return NONE
*/
void setUpRange(uint8_t range);
/**
* @fn setDownRange
* @brief Set distance of moving down that can be recognized
* @param range
* @n Distance range 0-31, must be less than distance from top to bottom of the detection window
* @return NONE
*/
void setDownRange(uint8_t range);
/**
* @fn setForwardRange
* @brief Set distance of moving forward that can be recognized
* @param range
* @n Distance range 0-31
* @return NONE
*/
void setForwardRange(uint8_t range);
/**
* @fn setBackwardRange
* @brief Set distance of moving backward that can be recognized
* @param range
* @n Distance range 0-31
* @return NONE
*/
void setBackwardRange(uint8_t range);
/**
* @fn setWaveNumber
* @brief Set wave number that can be recognized
* @param number
* @n Number range 0-15
* @return NONE
*/
void setWaveNumber(uint8_t number);
/**
* @fn setHovrWin
* @brief Set hover detection window
* @param udSize Distance from top to bottom distance range 0-31
* @param lrSize Distance from left to right distance range 0-31
* @return NONE
*/
void setHovrWin(uint8_t udSize, uint8_t lrSize);
/**
* @fn setHovrTimer
* @brief Set hover time that can trigger the gesture
* @param timer
* @n timer 1-0x3ff 10ms-10s default is 0X3c 600ms
* @return NONE
*/
void setHovrTimer(uint16_t timer);
/**
* @fn setCwsAngle
* @brief Set clockwise rotation angle that can trigger the gesture
* @param count Default is 16 range 1-31
* @n count Rotation angle is 22.5 * count
* @n For example: count = 16 22.5*count = 360 Rotate 360° to trigger the gesture
* @return NONE
*/
void setCwsAngle(uint8_t count);
/**
* @fn setCcwAngle
* @brief Set counterclockwise rotation angle that can trigger the gesture
* @param count Default is 16 range 1-31
* @n count Rotation angle is 22.5 * count
* @n For example: count = 16 22.5*count = 360 Rotate 360° to trigger the gesture
* @return NONE
*/
void setCcwAngle(uint8_t count);
/**
* @fn setCwsAngleCount
* @brief Set clockwise rotation angle that can trigger the gesture
* @param count Default is 4 range 1-31
* @n count The degree of continuous rotation is 22.5 * count
* @n For example: count = 4 22.5*count = 90
* @n Trigger the clockwise/counterclockwise rotation gesture first, if keep rotating, then the continuous rotation gesture will be triggered once every 90 degrees
* @return NONE
*/
void setCwsAngleCount(uint8_t count);
/**
* @fn setCcwAngleCount
* @brief Set counterclockwise rotation angle that can trigger the gesture
* @param count Default is 4 range 1-31
* @n count The degree of continuous rotation is 22.5 * count
* @n For example: count = 4 22.5*count = 90
* @n Trigger the clockwise/counterclockwise rotation gesture first, if keep rotating, then the continuous rotation gesture will be triggered once every 90 degrees
* @return NONE
*/
void setCcwAngleCount(uint8_t count);
Tutorial for Raspberry Pi
Requirements
- Hardware
- Raspberry Pi 4 Model B (or similar) × 1
- Gravity: GR10-30 Gesture Sensor × 1
- DuPont Wires × 1
- Software
Connection Diagram
Connect the module to the Raspberry Pi according to the connection diagram.
Driver Installation
Enable I2C of Raspberry Pi. Skip this step if it is already enabled. Open terminal and input the following command and press Enter:
pi@raspberrypi:~ $ sudo raspi-config
Then use the UP/Down keys to select "5 Interfacing Options", press Enter, select "P5 I2C" and press Enter to comfirm "Yes". Reboot the Raspberry Pi board.To install Python dependency library and git, the Raspberry Pi needs to be connected to the Internet. Skip this step if they're already installed. In the terminal, input the following command and press Enter:
pi@raspberrypi:~ $ sudo apt-get update
pi@raspberrypi:~ $ sudo apt-get install build-essential python-dev python-smbus git
Download DFRobot_GR10_30 driver library. In the terminal, input the following command and press Enter:
pi@raspberrypi:~ $ cd Desktop/
pi@raspberrypi:~/Desktop $ git clone https://github.com/DFRobot/DFRobot_GR10_30
Sample Code
Sample Code 1 - Get gesture by polling(get_getures.py)
- In the terminal, input the following command and press Enter to run the sample code:
pi@raspberrypi:~/Desktop $ cd DFRobot_GR10_30/python/raspberry/example/
pi@raspberrypi:~/Desktop/DFRobot_GR10_30/python/raspberry/example/ $ python get_getures.py
Modbus RTU Protocols
Note: The communication interface uses UART
GR10-30 Register Table (V1.0).xlsx
FAQ
For any questions, advice or cool ideas to share, please visit the DFRobot Forum.