模块说明
PAJ7620传感器是原相科技(Pixart)的一款内部集成光学阵列式传感器,以使复杂的手势和光标模式输出,内部集成了九种手势的识别:上、下、左、右、向前、向后、顺时针、逆时针以及挥动的手势动作识别、模块以i2c通信,传感器功能很强大,更详细模块说明的可参考数据手册。
硬件连接
- VCC -> Pin1
- GND -> Pin6
- SDA -> Pin3
- SCL -> Pin5
- INT -> 目前使用查询方式,可不接。
软件实现
#!/usr/bin/env python
#
# GrovePi Library for using the Grove - Gesture Sensor v1.0(http://www.seeedstudio.com/depot/Grove-Gesture-p-2463.html)
#
# The GrovePi connects the Raspberry Pi and Grove sensors. You can learn more about GrovePi here: http://www.dexterindustries.com/GrovePi
#
# Have a question about this library? Ask on the forums here: http://forum.dexterindustries.com/c/grovepi
#
# History
# ------------------------------------------------
# Author Date Comments
# Karan 31 Dec 15 Initial Authoring
# Lambor 11 July 18 Use smbus2
#
# Code derived from the basic Arduino library for the Gesture Sensor by Seeed: https://github.com/Seeed-Studio/Gesture_PAJ7620
'''
## License
The MIT License (MIT)
GrovePi for the Raspberry Pi: an open source platform for connecting Grove Sensors to the Raspberry Pi.
Copyright (C) 2017 Dexter Industries
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
'''
import time,sys
import RPi.GPIO as GPIO
#from grove.i2c import Bus
from smbus import SMBus
# use the bus that matches your raspi version
rev = GPIO.RPI_REVISION
if rev == 2 or rev == 3:
bus = SMBus(1)
# bus = Bus(1)
else:
bus = SMBus(0)
# bus = Bus(0)
class gesture:
#Registers and variables for the gesture sensor
GES_REACTION_TIME =.500 # You can adjust the reaction time according to the actual circumstance.
GES_ENTRY_TIME =.800 # When you want to recognize the Forward/Backward gestures, your gestures'