|
RevEng_PAJ7620
1.5.0
|
The library here is for the PAJ7620 sensor with an I2C interface. The device also has several variants such as the PAJ7620U2 and PAJ7620F2. The device provides simple motion-based gesture recognition, object tracking (cursor mode), and other (unimplemented so far) modes.
In gesture mode it can recognize 9 hand moving gestures including:
The device also counts the quantity of hand waves, which is now available via an API call in version 1.2.
The sensor's datasheet is available here.
The PAJ7620U2 is available from various vendors such as Seeed Studio on a breakout board. For more information about their product, please visit the wiki. Breakout boards are also sold under the part number GY-PAJ7620 by various unnamed manufacturers.
Via ArduinoIDE/CLI
This library is available in the Arduino extended library collection. To install:
Selecting a release from GitHub
On the GitHub page (https://github.com/acrandal/RevEng_PAJ7620), there is a "releases" section in the right sidebar. You can click on the release version you would like to use, or just "Releases" for the latest one. On that page you'll find a "source code" link in various archive formats like tar.gz or zip. Download that and follow the directions in the next section here.
Manual install from the Git repository
To download from the repo, choose the branch you want, click the DOWNLOAD ZIP button, rename the uncompressed folder to RevEng_PAJ7620. Check that the RevEng_PAJ7620 folder contains a src directory with RevEng_PAJ7620.cpp and RevEng_PAJ7620.h
Place the RevEng_PAJ7620 library folder into your <arduinoSketchFolder>/libraries/ folder. You may need to create the libraries subfolder if its your first library. Restart the IDE.
There's a great tutorial on Arduino library installation at: http://learn.adafruit.com/adafruit-all-about-arduino-libraries-install-use
Installing using arduino-cli
The arduino-cli (command line interface) tool keeps and maintains the same libraries as your ArduinoIDE environment. This library can be installed on the terminal with these commands:
This package comes with several example scripts to get you rolling quickly. In all cases, you need to connect the sensor to Vcc and Ground, plus the I2C lines: SDA & SDL. For the interrupt driven sketch, you also need to connect the sensor's INT pin to pin 2 of your device.
That should work for most arduino platforms (Uno, Mega). See the Arduino attachInterrupt documentation for the full list of boards and their interrupt capable pins.
Sketches provided:
Major releases of this library have doxygen pages hosted on GitHub pages here. The rest of this section gives a summary and notes of how the library's major features are designed.
To use this library, include the libary's header:
Create the driver object for the sensor:
In setup(), initialize and configure the driver:
To read any gestures detected, use the readGesture() interface:
The RevEng_PAJ7620.h header defines an enumerated type called Gesture for the gesture results. This enum provides a value for all 9 built in gestures and a "no gesture" result GES_NONE. The types it returns are: GES_NONE, GES_UP, GES_DOWN, GES_LEFT, GES_RIGHT, GES_FORWARD, GES_BACKWARD, GES_CLOCKWISE, GES_ANTICLOCKWISE, GES_WAVE
(GES stands for gesture)
Reading a gesture has timing issues, notably the time it takes for the person to position their hand before starting a gesture and the time to remove their hand after finishing the gesture. These values are most important for the forward and backward gestures. To provide the ability to tune these timing values, two interfaces are provided to set their values in milliseconds:
These values are defaulted to Entry Time: 0ms and Exit Time: 200ms. You might need to play with these values for your given application and expected use behaviors. The entry time is most important to reduce false positive errors when trying for the backwards gesture. The exit time is most important for preventing double gesture detection, especially for the forward and backward gestures.
The PAJ7620 sensor counts waves (rapid back and forth passes of an object) using a 4 bit register, so it holds values in the range 0..15. Once the waving stops is when it raises the wave interrupt. The quantity of waves is available for reading and is exposed using this interface:
The PAJ7620 can be enabled and disabled during runtime. After the call to begin(), the device is already enabled and running. This library provides an interface to disable the devices and enable it as needed via these calls:
When disabled, the sensor will not raise any interrupts, either on the interrupt pin or when calling readGesture();
NOTE: There is a more complete disabling that turns of all I2C messages, but that is not implemented fully here.
To use other I2C busses than the default Wire, use the begin() initializer by passing a pointer to the bus you want. The library will store the bus of choice and use it from there on out. For example:
You can use multiple PAJ7620 devices on an Arduino, with one per I2C bus if your device has multiple busses available. This would look like:
The PAJ7620 sensor is capable of a 'cursor' mode. This is essentially a finger/object tracking capability where the center of the closest object in view is reported using (x,y) coordinates. This mode would be used for higher fidelity applications. The instantiation of the class is the same, and once it's initialized you can change to cursor mode and start tracking a target.
The program can return to gesture mode with the setGestureMode call:
The PixArt datasheets refer prominently to "game mode" with the sensor. The documentation talks about game mode providing 240fps instead of normal mode's 120fps. After working with PixArt to get the correct values in place, these modes are set with the driver API's:
The biggest side effect of using game speed is that if you're polling the sensor for events, especially cursor location updates, you can receive data results at around twice the rate with the game speed set.
NOTE: if you change modes (gesture to cursor or cursor to gesture) the speed shall return to normal speed until you call setGameSpeed() again.
In Gesture mode, there are metrics about the visible object available. Notably, you can pull the "brightness" (IR reflected light) and size (pixels) of any object in view.
Brightness is measured on a scale of 0..255 with no units. Size is 0..900 where the value is how many pixels of the 30x30 IR camera are picking up an object.
In Gesture mode, you can get some stats on object visibility and motion.
NoObjectCount reports the number of ticks since an object left the view. It reports a value between 0..255. Each increment represents about 7.2ms in normal mode and 4.1ms in game mode.
Similarly, NoMotionCount is ticks since there was motion (even if there is still an object in view, but it's holding still). For some reason it only counts 0..12.
getObjectCenterX and getObjectCenterY return an int with a coordinate for any object in view. They both return 0 if there's no object. The results are in 0..3712. NOTE: The X coordinate is reversed in gesture mode by default so 0 is on the right. This can be flipped with the invertXAxis() interface, but will also reverse the gestures (GES_LEFT becomes GES_RIGHT, Clockwise becomes Anti-Clockwise).
getObjectVelocityX and getObjectVelocityY poll for a velocity of any object crossing the sensor's view. They return 0 if no object is in view or if the object isn't moving. They return an int from -63 to 63. Negative and positive refer to the direction of travel.
isObjectInView returns true if there's an object in view.
The Corner interface returns which quadrant an object is currently in. This is called in Gesture Mode, but it works in cursor mode which has the quadrants are flipped.
NW | NE
–MID–
SW | SE
getCorner() returns a Corner enum. This enum has six values (and synonyms):
Note: Width of middle is set by CORNERS_BUFFER_WIDTH_PCT from .h file
Version 1.5.0
Version 1.4.1
Version 1.4.0
Version 1.3.0
Version 1.2.0
Version 1.1.0
Version 1.0.0
Contributors
License
MIT - see LICENSE file
Version
1.5.0