Silicon ChipCJMCU-7620 Gesture Recognition Module - June 2023 SILICON CHIP
  1. Outer Front Cover
  2. Contents
  3. Subscriptions: PE Subscription
  4. Subscriptions
  5. Back Issues: Hare & Forbes Machineryhouse
  6. Publisher's Letter: Powerful projects
  7. Feature: Technology comes in different shapes and sizes by Max the Magnificent
  8. Feature: Net Work by Alan Winstanley
  9. Project: Arduino Programmable Load by Tim Blythman
  10. Project: 500 WATTS POWER AMPLIFIER by JOHN CLARKE
  11. Project: High-Power Buck-Boost LED Driver by Tim Blythmhman
  12. Feature: CJMCU-7620 Gesture Recognition Module by Jim Rowe
  13. Feature: Max’s Cool Beans by Max the Magnificent
  14. Feature: Circuit Surgery by Ian Bell
  15. Feature: Make it with Micromite by Phil Boyce
  16. Feature: AUDIO OUT by Jake Rothman
  17. Feature: PE hands-on product review by Julian Edgar
  18. PCB Order Form
  19. Advertising Index

This is only a preview of the June 2023 issue of Practical Electronics.

You can view 0 of the 72 pages in the full issue.

Articles in this series:
  • (November 2020)
  • Techno Talk (December 2020)
  • Techno Talk (January 2021)
  • Techno Talk (February 2021)
  • Techno Talk (March 2021)
  • Techno Talk (April 2021)
  • Techno Talk (May 2021)
  • Techno Talk (June 2021)
  • Techno Talk (July 2021)
  • Techno Talk (August 2021)
  • Techno Talk (September 2021)
  • Techno Talk (October 2021)
  • Techno Talk (November 2021)
  • Techno Talk (December 2021)
  • Communing with nature (January 2022)
  • Should we be worried? (February 2022)
  • How resilient is your lifeline? (March 2022)
  • Go eco, get ethical! (April 2022)
  • From nano to bio (May 2022)
  • Positivity follows the gloom (June 2022)
  • Mixed menu (July 2022)
  • Time for a total rethink? (August 2022)
  • What’s in a name? (September 2022)
  • Forget leaves on the line! (October 2022)
  • Giant Boost for Batteries (December 2022)
  • Raudive Voices Revisited (January 2023)
  • A thousand words (February 2023)
  • It’s handover time (March 2023)
  • AI, Robots, Horticulture and Agriculture (April 2023)
  • Prophecy can be perplexing (May 2023)
  • Technology comes in different shapes and sizes (June 2023)
  • AI and robots – what could possibly go wrong? (July 2023)
  • How long until we’re all out of work? (August 2023)
  • We both have truths, are mine the same as yours? (September 2023)
  • Holy Spheres, Batman! (October 2023)
  • Where’s my pneumatic car? (November 2023)
  • Good grief! (December 2023)
  • Cheeky chiplets (January 2024)
  • Cheeky chiplets (February 2024)
  • The Wibbly-Wobbly World of Quantum (March 2024)
  • Techno Talk - Wait! What? Really? (April 2024)
  • Techno Talk - One step closer to a dystopian abyss? (May 2024)
  • Techno Talk - Program that! (June 2024)
  • Techno Talk (July 2024)
  • Techno Talk - That makes so much sense! (August 2024)
  • Techno Talk - I don’t want to be a Norbert... (September 2024)
  • Techno Talk - Sticking the landing (October 2024)
  • Techno Talk (November 2024)
  • Techno Talk (December 2024)
  • Techno Talk (January 2025)
  • Techno Talk (February 2025)
  • Techno Talk (March 2025)
  • Techno Talk (April 2025)
  • Techno Talk (May 2025)
  • Techno Talk (June 2025)
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. 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 £5-10 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 my modules from Banggood (China), it is often well worth shopping around (eBay/Amazon) to see if you can order locally for much speedier but probably pricier delivery. When my modules arrived, I found they were based on an SMD ‘micromodule’ called the PAJ7620U2, which is 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. 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 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 IC1 (REG1) and the IR LED (REG2). Then there are three 2.2kΩ 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 Fig.1: the block diagram for the PAJ7620 gesture recognition sensor IC. The module’s 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: https://bit.ly/pe-jun23-paj 40 Practical Electronics | June | 2023 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. 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, which contains 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 Seeed Studio, 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: https://bit.ly/pe-jun23-seeed https://bit.ly/pe-jun23-reveng These GitHub links are probably the most helpful because they provide quite a bit of documentation. Both libraries also come with example sketches to get you up and running. 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. 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. Practical Electronics | June | 2023 41 Board: “Arduino Uno” Port: “COM4 (Arduino Uno)” Fig.3: when running our sample Arduino sketch, follow this wiring diagram to connect the sensor module to an Arduino or equivalent device. Fig.4: similar to Fig.3, this is the wiring diagram when connecting the sensor module to a Micromite LCD BackPack. 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 42 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 should find your Arduino and its port, shown something like this: 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 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 oriented 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 orient 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, we found the module gave 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! Practical Electronics | June | 2023 www.poscope.com/epe Seeed Studios sells an alternative, slightly larger sensor module that can be purchased from: https://bit.ly/pe-jun23-grove – both the original (lower right) and alternative (top) are shown above at actual size. 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 seemed only to recognise one gesture (like ‘Right’ or ‘Down’) or else become totally ‘blind’ and be unable to recognise any gestures at all. Some sample output from the Arduino running our test program. Practical Electronics | June | 2023 Tim Blythman helped me track this down to the power supply connections; after changing to using the +3.3V 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 June 2023 page of the PE website at: https://bit.ly/pe-downloads. 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://bit.ly/pe-jun23-seeed2 They also have a library and example Arduino code for their module at: https://bit.ly/pe-jun23-seeed Reproduced by arrangement with SILICON CHIP magazine 2023. www.siliconchip.com.au - USB - Ethernet - Web server - Modbus - CNC (Mach3/4) - IO - PWM - Encoders - LCD - Analog inputs - Compact PLC - up to 256 - up to 32 microsteps microsteps - 50 V / 6 A - 30 V / 2.5 A - USB configuration - Isolated PoScope Mega1+ PoScope Mega50 - up to 50MS/s - resolution up to 12bit - Lowest power consumption - Smallest and lightest - 7 in 1: Oscilloscope, FFT, X/Y, Recorder, Logic Analyzer, Protocol decoder, Signal generator 43