This is only a preview of the March 2022 issue of Silicon Chip. You can view 37 of the 112 pages in the full issue, including the advertisments. For full access, purchase the issue for $10.00 or subscribe for access to the latest issues. Articles in this series:
Items relevant to "Capacitor Discharge Welder, part one":
Items relevant to "Raspberry Pi Pico BackPack":
Articles in this series:
Items relevant to "Amplifier Clipping Indicator":
Items relevant to "Dual Hybrid Power Supply, part two":
Items relevant to "A Gesture Recognition Module":
Articles in this series:
Purchase a printed copy of this issue for $11.50. |
Using Cheap Asian Electronic Modules
By Jim Rowe
CJMCU-7620 Gesture
Recognition Module
With this module, you can experiment with sensing and recognising
gestures made with your hands (or others’). It is very small, relatively
low in cost and can easily be hooked up to an Arduino or a Micromite.
There are some tricks to make it work, detailed in this article.
W
hen I first saw this little module advertised, I confess I was a
bit dubious. How could a 16 x 20mm
module selling for as little as $13.50 be
capable of sensing and recognising a
range of hand gestures? I was intrigued
enough to order a couple, to see if the
claims were justified.
Gestures it is said to recognise
include moving a hand left, right, up,
down, forward or back, clockwise or
anti-clockwise, and waving.
While I ordered mine from Banggood, I later discovered that Jaycar sells a very similar module (Cat
XC3742) for $19.95, with the significant benefit that you don’t have to wait
for it to arrive from overseas.
When my modules arrived, I
found they were based on an SMD
‘micromodule’ called the PAJ7620U2,
made by PixArt Imaging Inc based in
Hsinchu, Taiwan (www.pixart.com).
The PAJ7620U2 itself measures only
5.2 x 3 x 1.88mm but is surprisingly
complex, as seen from the internal
block diagram, Fig.1.
The sensing is done using pulses
of infrared (940nm) light from the IR
LED shown at upper left, with reflected
light detected by a 30 x 30 pixel IR sensor array shown at centre left. The gesture sensing range of the PAJ7620U2 is
specified as being 100-200mm within
a 60° cone.
The rest of the circuitry is involved
in timing the LED pulses and the sensor array scanning, extracting information from the sensor array, recognising
any detected gesture and saving the
data in a memory register bank.
There are also two serial interfaces:
an I2C interface used mainly for interfacing the PAJ7620U2 with a microcontroller unit (MCU) for gesture recognition, and an SPI interface primarily intended for the PAJ7620U2’s other
mode of operation, ‘cursor’ mode.
Cursor mode provides real-time data
output describing the position, size
and brightness of an object within the
range of its IR sensor array.
Fig.2 shows the small number
of extra components around the
PAJ7620U2 in the CJMCU-7620 module. Apart from the PAJ7620U2 (IC1),
it has just two tiny 3.3V low-dropout
(LDO) voltage regulators, REG1 and
REG2, with their associated capacitors, used to supply the logic part of
Fig.1: the block diagram for the PAJ7620 gesture recognition sensor IC. The detection range for gestures using this IC is
5 to 15cm, with it typically processing an image size of 30x30 pixels. The datasheet can be found at siliconchip.com.au/
link/abc5
96
Silicon Chip
Australia's electronics magazine
siliconchip.com.au
An enlarged shot of the PAJ7620 IC,
which the CJMCU-7620 module in
the lead photo is based on. The nine
basic gestures that can be detected
are: right, left, up, down, forward,
backward, clockwise, anti-clockwise
and waving.
IC1 (REG1) and the IR LED (REG2).
Then there are three 2.2kW resistors to pull up the SDA, SCL and INT
outputs of IC1 to the positive supply
rail. That’s it!
The CJMCU7620 module does not
provide connections to the SPI interface of IC1, only to the I2C interface,
meaning it probably isn’t suitable for
use in cursor mode.
All the I2C interface connections
are brought out to the 5-pin header at
lower left in Fig.2.
Figuring out how to use it
Before trying it out, I looked around
on the internet to see if I could find a
data sheet or application information
on the PAJ7620U2. Although I did
manage to find a data sheet (actually,
two different data sheets, one of which
was more complete than the other),
I couldn’t find much in the way of
application information. And neither
version of the data sheet was all that
helpful either.
One of them, titled “PAJ7620U2
General data sheet”, gives you a fair
bit of information including the pin
configuration, main electrical specifications and a set of tables showing
the two banks of 256 memory registers.
But these tables contain only brief and
somewhat cryptic descriptions of the
function of most of the registers.
There was no information in
that data sheet about the PAJ7620’s
serial interfaces. For that, you must
refer to the second data sheet titled
“PAJ7620U2 Product data sheet”, containing details of the device’s I2C and
SPI interface protocols and timing
parameters.
Neither data sheet gives much information on things like what data needs
to be written to which registers to initialise the PAJ7620U2 for gesture recognition, the exact order in which the
data should be written, or the correct
timing for this writing.
There is also no real information on
decoding the recognised gesture data,
apart from a table showing which of
the eight bits in register 0x43 of Bank0
indicates the gesture recognised.
So instead, I started looking for code
to interface the PAJ7620U2 with an
Arduino MCU, which proved much
more successful. Several people had
already solved most of the problems
regarding communicating with the
PAJ7620U2, so I was able to download
a couple of Arduino sketches for communicating with the device, including
two different Arduino libraries.
Analysing the libraries and sketches
provided much more insight into how
to initialise the PAJ7620U2 and then
use it for gesture recognition. But I still
ran into significant problems when I
tried writing a Micromite program to
initialise the PAJ7620U2 and decode
its gestures. But more about that later;
let’s start by looking at the situation
with an Arduino.
Using it with an Arduino
Hooking the module up to an Arduino is very straightforward, as you can
see from Fig.3. The module’s Vcc pin
connects to the Arduino’s +5V pin,
its GND to one of the Arduino’s GND
pins, its SDA pin to the Arduino’s A4
pin and its SCL pin to the Arduino’s
A5 pin. The module’s INT pin is left
unconnected as it is not required.
As for the software, first, you need
to download one of the Arduino
PAJ7620U2 libraries. You’ll find two
of these on the main Arduino website
at www.arduino.cc/en/libraries/
One is written by SeeedStudios,
called “Gesture-paj7620”, and the
other is written by multiple authors
and is called “RevEng-PAJ7620”. Both
of them can also be found on GitHub:
Fig.2: the circuit diagram for the CJMCU-7620 module, which incorporates the PAJ7620 gesture recognition IC. Data is
read via an I2C bus; while the chip has an SPI interface, these pins are not connected on this module.
siliconchip.com.au
Australia's electronics magazine
March 2022 97
Fig.3: when running our sample Arduino sketch, follow this wiring diagram to
connect the sensor module to an Arduino or equivalent device.
https://github.com/Seeed-Studio/
Gesture_PAJ7620
https://github.com/acrandal/
RevEng_PAJ7620
These GitHub links are probably the
most helpful as they provide quite a
bit of documentation. Both libraries
also come with example sketches to
get you going.
When you have downloaded one or
the other of these libraries (they both
come as a ZIP file), save it in a convenient folder and then start up your
Arduino IDE (integrated development
environment). If you haven’t installed
the IDE yet, you can always download
the latest version from www.arduino.
cc/en/software
Now you can install the downloaded
library in the IDE by clicking on the
top drop-down “Sketch” menu button, clicking on “Include Library” and
then “Add .ZIP Library”. You can then
direct the IDE to the library ZIP file
you saved earlier, and it will install
the library (and its example sketches)
without further ado.
Next, click on the top drop-down
“File” menu, go down to “Examples”,
select “Examples from Custom Libraries” and then choose the library you’ve
just installed (Gesture PAJ7620 or
RevEng PAJ7620). You can then select
one of the example sketches that came
with it. It will then open up that sketch
in the IDE window for you to look over
and upload.
Before you can run the sketch, you
will need to connect the CJMCU-7620
module to an Arduino, as shown in
Fig.3, then plug the Arduino into one
of your computer’s USB ports.
Then you should check in the Windows Control Panel or Settings dialog
box to make sure that the Arduino has
connected properly, and find the virtual serial port it has been allocated.
In most cases, this will be something
like “Arduino Uno (COM4)”.
Next, click on the Arduino IDE Tools
menu and you find your Arduino and
its port, shown something like this:
Board: “Arduino Uno”
Port: “COM4 (Arduino Uno)”
Fig.4: similar to Fig.3, this is the wiring diagram when connecting the sensor
module to a Micromite LCD BackPack.
If all seems well, go to Tools → Serial
Monitor. This will display a second
window so that you can monitor messages sent back from the Arduino. Set
the Serial Monitor for 9600 baud since
most Arduino sketches use that speed.
Then, assuming you have already
loaded the example sketch, it’s simply
Australia's electronics magazine
siliconchip.com.au
98
Silicon Chip
a matter of clicking on Sketch → Verify/Compile. If no problems arise, use
Sketch → Upload to direct the IDE
to send the compiled sketch to your
Arduino. Once that finishes, moving
your hand in front of the CJMCU-7620
module should result in messages
appearing in the Serial Monitor.
Note that the CJMCU-7620 module
should be orientated so that its five
header pins are at the bottom, as shown
in Fig.3. This will have the PAJ7620U2
device with its IR LED to the left and
the lens in front of its IR sensor array
to the right. That is the device orientation assumed by the sketches; other
orientations will tend to give recognition errors, like “Up” or “Down”
instead of “Right” or “Left”.
If you want to orientate the module differently later, the sketch or its
libraries can be revised to suit the new
orientation.
So hooking up the CJMCU-7620
module up to an Arduino and using
that combination is pretty straightforward. Now let us look at what’s
involved in using it with a Micromite.
Using it with a Micromite
First, the easy part: connecting the
module to a Micromite. As shown in
Fig.4, this is much the same as with
an Arduino, with one small difference. The SDA and SCL lines connect
to pin 18 (SDA) and pin 17 (SCL) of
the Micromite and the GND line to the
Micromite’s GND pin as you’d expect,
but the module’s Vcc pin connects to
the Micromite’s +3.3V pin, not the
+5V pin.
This looks wrong, considering that
the module’s circuit in Fig.2 shows
that it has its own pair of LDO voltage regulators onboard to provide the
PAJ7620U2 with two regulated +3.3V
supplies. So connecting the module
to a +3.3V supply would seem both
unnecessary and likely to prevent
the onboard regulators from doing
their job.
But the fact is that we found the
module to give much more reliable
and consistent results when it was
powered from the Micromite’s +3.3V
line, not the +5V line. It’s not easy to
explain or understand, but it did seem
to work better that way.
The next difficulty is the software. I
couldn’t find any pre-existing MMBasic code for the PAJ7620U2, so I had
to write it myself. Since the PixArt
data sheets were so unhelpful, I had
to spend quite a bit of time studying
the Arduino libraries and sketches to
see how they worked.
It doesn’t seem too difficult. First,
you check for the presence of a
PAJ7620 and confirm that it is functional, then send over 200 bytes of
initialising data to specific memory
registers to set it up correctly in gesture recognition mode. Finally, you
keep polling one of its memory registers (Bank0, address 0x43) to read its
gesture recognition codes.
Taking this approach ended up with
a program that seemed to work pretty
well, at least from time to time. When
I made various gestures in front of the
PAJ7620U2 device, the Micromite
would correctly identify the gesture
on its LCD screen and send the same
information back to the MMEdit Chat
window.
But this would only happen some
of the time. At other times, the setup
would seem only to recognise one gesture (like “Right” or “Down”) or else
become totally ‘blind’ and be unable
to recognise any gestures at all.
Tim Blythman helped me track this
down to the power supply connections; after changing to using the +3.3V
Seeed Studios sells an alternative, slightly larger sensor module that can be
purchased from www.seeedstudio.com/Grove-Gesture-PAJ7620U2.html Both the
original (lower right) and alternative (top) are shown above at actual size.
siliconchip.com.au
Australia's electronics magazine
Micromite supply rail as described
above, it started working much more
reliably.
He also pointed out that I should add
an extra write to a register (Bank1, register 0x65, data byte 0x12) at the end
of the initialisation sequence which
made another improvement.
So we ended up with a Micromite
program that is at least as accurate
and reliable as either of the Arduino sketches. The program is called
“PAJ7620 Gesture Rec.bas” and you
can download it from the Silicon Chip
website.
While functional, this program
could probably use some tweaking,
so if you feel you have improved it,
please send us your version so we can
share it with other readers.
Final comments
While writing this article, I learned
that Seeed Studio offers a PAJ7620based Hand Gesture module in their
“Grove” series of modules. This module is slightly larger (at 20 x 20mm)
than the CJMCU and similar modules.
It appears to have additional circuitry,
including a pair of small P-channel
Mosfets to perform level translation on
the SDA and SCL output lines.
It’s possible that this module would
give more reliable gesture recognition
when used with our program running
on a Micromite, even when running
from the Micromite’s +5V supply line,
but we haven’t had a chance to get one
and try it out yet.
You can find documentation for
this module on Seed Studio’s website at https://wiki.seeedstudio.com/
Grove-Gesture_v1.0/#resources
They also have a library and example Arduino code for their module
at: https://github.com/Seeed-Studio/
SC
Gesture_PAJ7620
Some sample output from
the Arduino running our
test program.
March 2022 99
|