This is only a preview of the February 2024 issue of Silicon Chip.
You can view 36 of the 112 pages in the full issue, including the advertisments.
Items relevant to "Microphone Preamplifier":
Items relevant to "Mains Power-Up Sequencer, Pt1":
Items relevant to "ESP32-CAM WiFi Camera Module":
Items relevant to "Raspberry Pi Clock Radio, Pt2":
Items relevant to "Model Railway Points Controller":
Purchase a printed copy of this issue for $12.50.
Review by Tim Blythman Altronics’ Z6387 ESP32 WiFi Camera Module It’s incredible what’s available to hobbyists these days. We have access to 32-bit microcontrollers that include features like WiFi and Bluetooth and are easy to program using the Arduino IDE. Altronics’ Z6387 is such a device but it also includes a two-megapixel digital camera. Here is what you can do with it. T his WiFi and Bluetooth capable camera development board, based on an Espressif Systems ESP32-S3 microcontroller, costs just $32.95. While the Altronics Z6387 “ESP32-CAM” can be programmed using the Arduino IDE, it can also be used out-of-the-box. The module has two 8-way pin headers and measures just 27 × 40 × 15mm. It could be reduced in thickness to 10mm if the headers were removed. The pin header rows are 0.9in (22.86mm) apart, so it will comfortably plug into most breadboards with some room to connect jumper wires. As well as looking at the camera module in detail, we have some Arduino code that can connect to its WiFi interface and fetch images. We also have some example code that can be programmed directly into the module. We’ll even show how the WebMite can pull images from the module and display them on a 3.5in LCD panel. The ESP32 The ESP32-S3 is a dual-core Tensilica Xtensa LX6 32-bit microcontroller from Espressif Systems that includes WiFi and Bluetooth radios. It is a successor to the ESP8266, which was a pioneer in low-cost WiFi microcontrollers. The dual-core processor allows the radio functions to run independently of the main application. The chip has a generous 512kB of RAM and 384kB of ROM. The ROM includes a bootloader and some low-level radio and library functions, allowing them to run more quickly than if they were loaded from external flash memory (while saving that flash space for other things). Like many ESP32 & ESP8266 based boards, the ESP32-S3 chip is fitted to 60 Silicon Chip a small surface-mounting module that includes a flash memory chip for firmware and a smattering of other parts hidden under a folded metal shield. The module also has a PCB trace antenna for the radio interface. The ESP32-S3 on the camera module appears to be identically pinned to the ESP-WROOM-32 module that is found on some other boards. The ESP32-S3 module on the Z6387 has a U.FL antenna socket, which can be used by attaching a suitable antenna and relocating the link resistor that usually feeds the PCB trace antenna. The processor module is only a small part of the WiFi camera module, so let’s look at how it works and what we can do with it. The WiFi camera module The circuit of the WiFi camera module is shown in Fig.1. It includes MOD1, the ESP32-S3 module mentioned earlier, with an onboard 32Mbit (4MB) flash memory chip. The WiFi camera module also has a serial 32Mbit (4MB) PSRAM chip that connects to MOD1 over its QSPI (quad SPI) bus. PSRAM is an abbreviation for pseudo- static RAM; it is actually a form of dynamic RAM (DRAM) with its own internal refresh circuitry. Since the quirks of the DRAM are handled internally, it can be treated as though it were SRAM. These are huge quantities for those used to dealing with microcontrollers that might have only kilobytes of flash memory and RAM. Of course, they are necessary for dealing with the complexities of WiFi and image processing. U2, an AMS1117 3.3V regulator in an SMD SOT-223 package, provides a 3.3V rail from a nominally 5V supply. Australia's electronics magazine The 5V supply feeds only the 3.3V regulator, so this could realistically be any voltage that the AMS1117 and its input capacitor can handle. P-channel Mosfet Q2 (controlled by one of MOD1’s digital outputs) switches power to two XC6206 voltage regulators (U3 and U1) that provide the 1.2V and 2.8V rails the camera chip needs. Naturally, the regulators are surrounded by numerous bypassing capacitors. A 24-pin FFC (flat flexible cable) socket connects to CAM1, a tiny camera module less than 1cm2 in size (apart from the cable). The camera is an Omnivision OV2640 CMOS camera chip with a resolution of 1632 × 1232 pixels or 2MP. This camera chip model is now nearly 20 years old and has long been marked as obsolete; it was one of the early camera chips used in mobile phones. It incorporates a compression engine that can directly output compressed JPEG (aka JPG) image data. The OV2640 can also perform subsampling and windowing, effectively allowing zooming and panning in software, although this naturally reduces the effective resolution. Because of its wide adoption and lengthy history, there is still stock of these parts, and clones have even appeared. Its specifications are pretty modest compared to modern equipment, but its capabilities are a good match for modern 32-bit microcontrollers. 15 digital lines go between MOD1 and CAM1. Two of these are an I2C pair carrying control and configuration commands, while the others include an 8-bit parallel bus used to transport image data, plus various clock signals. Another six digital pins on MOD1 siliconchip.com.au Fig.1: much of the circuitry connects the ESP32 module to the camera chip and other peripherals. Many components run from 3.3V, although the camera chip also needs 1.2V and 2.8V rails provided by U3 and U1, respectively. There are not many spare I/O pins; using any of them will probably require the microSD card socket to be unused. siliconchip.com.au Australia's electronics magazine February 2024 61 connect to a microSD card socket, allowing QSPI operation. One digital pin drives a small LED via a 1kW resistor to the 3.3V rail, and another pin (via another 1kW resistor) goes to the base of NPN transistor Q1 to drive a larger white LED. Notably, this LED does not have a current-limiting resistor and is only intended to be used for short periods, like a camera flash. The external connections are a pair of 8-way pin headers. CON1 has connections for 3.3V, ground, the UART pins, as well as the E32_RST and GPIO0 pins. These are all handy for communications or programming the flash memory on MOD1. Tactile pushbutton S1 can short the E32_RST line to ground to reset the processor, while the state of GPIO0 dictates whether or not the bootloader or flash memory application runs. Interestingly, the E32_RST pin on CON1 is marked GND/R. It appears that similar boards (from other suppliers) connect this pin to ground and don’t otherwise break out the E32_RST line. Since the tactile pushbutton is on the underside of the module when fitted to a breadboard, these variants appear to be difficult to program. Header CON2 breaks out 5V, ground and the six I/O lines that also go to the microSD card socket. These are about the only spare I/O pins if you want to interface other hardware to the ESP32 WiFi camera module. However, that would probably mean that the microSD socket could not be used simultaneously. The wide-angle camera lens on the Z6387 ESP32 WiFi camera module has an approximately 160° field of view. There are other versions of the camera with a more narrow field of view of around 60°. Like many such cameras, the focus is fixed by a threaded lens insert glued in place. As a point of reference, human binocular vision has a field of view of about 114°. Powering it The nominal dropout of the onboard AMS1117 regulator is 1V at 800mA, so we had no trouble operating the camera module with an input as low as 4.2V (using our Breadboard PSU from December 2022; siliconchip.au/ Series/401). So running from a battery of three series AA cells would be a viable option, but using 3.7V LiPo or similar batteries will require a boost circuit. The camera module’s current draw peaked near 500mA on startup and when there was activity, dropping to around 200mA at idle. With the supply at 7V, the regulator was noticeably warm but not worryingly so. So the camera module should also be fine if powered by a battery of four AA cells in series, which could reach 6.4V when new. Operation Fortunately, the Altronics Z6387 ESP32 WiFi camera module comes loaded with useful default firmware, so no programming is required. However, there are a few steps you need to take before it can be used. Firstly, the firmware requires a microSD card in the card socket. We tried 2GB and 8GB cards with FAT If the camera chip is not connected to the camera module, open the FFC connector by pivoting the black bar upwards, as seen here. Insert the cable and press the bar back down to lock the cable in place. Then use the attached tape to secure the camera to the microSD card socket. 62 Silicon Chip formatting without issue. We are unsure why the card is needed, as we couldn’t see any features in the firmware that would use it. Most likely, the firmware attempts to initialise it for some reason and fails to proceed if it is absent. Also, after taking delivery of the module, you might find that the camera is not in its FFC socket. In that case, carefully pivot up the black bar on the FFC socket. The camera’s FFC cable slots in with its exposed metal contacts at the bottom. The bar rotates down to lock the cable in place. The back of the camera is also fitted with a pad of double-sided tape, allowing it to be secured to the top of the microSD card socket. This also allows the socket’s metal shell to dissipate heat from the camera, so you should adhere the camera to the microSD card socket once you are sure the cable is correctly fitted. We recommend that you connect a USB-serial converter so that you can check the module’s debugging output, including its IP address. Fig.2 shows how to wire it up. You can initially ignore the wires going to the two pushbuttons; they are only needed for programming (which we will discuss later). The USB-serial converter needs to have 3.3V logic levels, matching the camera module’s I/O levels. Set the baud rate in your serial terminal to 115,200 baud. The module briefly turns on the flash LED while powering up, so don't look directly at it. Screen 1 shows the debugging output you should see at powerup. If the microSD card is missing, you will see a “Card mount failed” message. If you don’t have a USB-serial converter then connecting a 5V supply to the 5V and ground pins on the CON2 header should be sufficient to get it to work, although you won’t have access to any diagnostic data. Screen 1: once it has successfully connected to a WiFi network, the diagnostic data from the camera module will indicate if the microSD card has been successfully mounted and the module’s IP address. The top line indicates the normal boot process when a program is run from flash memory. Australia's electronics magazine siliconchip.com.au HTTP interface The ESP32 WiFi camera module expects to connect to a network named “TEST” with the password “88888888”. It then creates an HTTP web server that provides a web page you can use to view and interact with the camera. You could temporarily change your router’s credentials to the above, or use a mobile phone’s WiFi hotspot feature to create such a network. Then use a web browser and navigate to the IP address shown in the serial terminal; Screen 2 shows what the web page looks like. With the default firmware, it’s much like a very basic wireless IP camera. It has no security features, so anyone connected to the WiFi network can access and control it. As you can see from all the settings, the camera is quite configurable. We tried the Face Detection and Face Recognition features. The camera module can detect faces, marking them with a yellow rectangle, but we can’t see how that would be usable outside of the HTTP interface. Fig.2: connecting the camera module to a CP2102 (or similar) USB-serial converter allows diagnostic data to be viewed in a serial terminal. The two pushbuttons are needed to reprogram the ESP32 chip. Pico W BackPack software We have prepared a program for the Pico W BackPack (siliconchip. au/Article/15616) that creates a suitable access point and allows the camera module to connect. The sketch is named “PICOW_BACKPACK_FOR_ ESP32CAM_SD” and there is a corresponding precompiled UF2 file. This program allows you to interact with the ESP32 WiFi camera module, including capturing and displaying images with different settings and image sizes, as well as saving and loading them to and from a microSD card. The Pico W BackPack only needs to be built with a minimal configuration, as long as it includes the 3.5in touchscreen and backlight control components. You will also need the microSD card socket components fitted (and a suitably formatted card installed) to use the microSD card related features, although the other features will work without it. To install the firmware for this, put the Pico W in bootloader mode and copy the UF2 file to the RPI-RP2 drive that appears. You can control the Pico W BackPack sketch from either the touch panel or a serial terminal. We use TeraTerm on Windows and minicom on Linux. siliconchip.com.au Screen 2: you can use a web browser on a mobile phone, tablet or computer to interface with the camera module and explore its features once it has connected to a WiFi network. Screen 3 shows the BackPack’s LCD image after booting. Power on the ESP32 WiFi camera module and, if you have a serial terminal monitoring its activity, wait until you see it indicate that it has connected (as per the end of Screen 1). Press the “Scan” button (or type “s” on the serial terminal) to allow the BackPack to find the camera module. Then use the “Capt” button or “c” followed by “d” in the serial terminal to capture and display an image. Screen 4 shows a sample image captured by the camera. The “Scan” button detects the camera by looking for its HTTP server. Don’t let too many other devices connect to the TEST access point, or the camera module might not be detected correctly. Screen 5 shows the serial terminal output for the BackPack after following the above steps, which includes a list of the other serial terminal commands. The size, quality, brightness and contrast settings are changed by sending an HTTP request to the camera, effectively clicking buttons on the web page that the camera module serves. Lower values correspond to clearer images (and larger file sizes) for the quality parameter. Numerous other settings can be accessed from the “/control” endpoint of the HTTP server on the camera module using a URL like this: http://192.168.42.16/ control?var=framesize&val=2 The “Expt” button or “e” on the serial terminal will export (save) the currently displayed image to the microSD card (if fitted and initialised). “Next” or “n” on the serial terminal will attempt to display the next file found on the microSD card. This can be used to display JPG images captured with the camera or created on a computer and copied to the card. The sketch is intended mainly to test and demonstrate the features of the camera module. Still, it would be a good starting point if you wanted to create an M2M (machine to machine) application where a microcontroller uses the camera module to capture images for processing. You could change the sketch to periodically log photos to the microSD card, or continuously display the camera’s view as a basic remote monitor. Screen 3: the LCD screen of the Pico W BackPack after being loaded with the PICOW_ BACKPACK_ FOR_ ESP32CAM_SD firmware. It creates an access point for the camera module to connect to. Screen 4: pressing “Scan” will find the camera module on the access point’s WiFi network. Then press “Capt” to take a photo and display it on the LCD’s screen. The other large buttons save and load images to and from the microSD card. 64 Silicon Chip Australia's electronics magazine Adding a PIR motion sensor could turn it into a simple but functional security camera. Programming the camera module The Pico W BackPack makes it very easy to interface with the camera module, but you could do something more than simply displaying and saving images. Using the Arduino IDE and the ESP32 board profile, it’s possible to upload custom code to the camera module. The arrangement for programming the module is shown in Fig.2. The two momentary switches are needed to reset the processor and put it into programming download mode. If you have access to the RST button on the module, it will function the same as the RESET button in Fig.2. However, it will probably be inaccessible if the module is fitted to a breadboard. If you don’t have switches, you can use jumper wires that can temporarily be shorted to ground. You might notice that the ESP32 chips use much the same system as ESP8266 chips, and the circuit is almost the same as used for the ESP-01 modules in the WiFi Relay article from the January 2024 issue (siliconchip.au/ Article/16088). You’ll also need to install the ESP32 board profile for the Arduino IDE. You can do that by adding https:// dl.espressif.com/dl/package_esp32_ index.json to the Board Manager URLs in Preferences. The ESP32 profile should then be available to install from the Boards Manager menu. We used the AI Thinker ESP32-CAM board setting under the Tools menu. The ESP32’s diagnostic and boot data serial rate is 115,200 baud, so set your Arduino serial monitor to that rate. The ESP32CAM_ WEBSERVER sketch The firmware loaded onto the Altronics Z6387 ESP32 WiFi camera module appears to be nearly identical to the CameraWebServer example sketch included with the ESP32 board profile. The difference is that the CameraWebServer sketch does not attempt to initialise the microSD card. We created a copy of this sketch and changed the settings to match the Altronics camera module. This is the “ESP32CAM_WEBSERVER” sketch in our software download package. siliconchip.com.au When we loaded the camera module with that sketch, it behaved almost exactly the same as when it was new. To put the processor into programming mode and allow it to download the sketch, press and hold the switch labelled RESET, then press and hold the IO0 switch. Release the RESET switch, then the IO0 switch. You should see (among other text) something like: rst:0x1 (POWERON_RESET), boot:0x3 (DOWNLOAD_BOOT) waiting for download If you instead see: rst:0x1 (POWERON_RESET), boot:0x13 (SPI_FAST_FLASH_BOOT) That means the sequencing was incorrect, and you should try again. Pressing and releasing RESET resets the microcontroller and gives the second message. You can try that if your sketch doesn’t appear to start correctly after uploading. Once it’s in the correct mode, upload the Arduino sketch using the Upload button or pressing Ctrl-U on your keyboard. You should then see output on the serial terminal like in Screen 1. If you wish to use this software with an existing WiFi network, change the SSID and password in the “Enter your WiFi credentials” section of the sketch. Then, upload the sketch with the new credentials. Screen 5: the Pico W BackPack sketch also provides a serial terminal interface and can be controlled by the commands shown here. Here, the “s”, “c” and “d” commands have been used after the menu was displayed. The ESP32CAM_PROBE_SD sketch The ESP32CAM_PROBE_SD sketch intends to show what can be achieved by code running on the ESP32 processor without WiFi. The options are similar to the Pico W sketch, although there is no LCD panel to display the images. To upload this sketch, open it in the Arduino IDE, select the AI Thinker ESP32-CAM board profile and the correct serial port at 115,200 baud. Then use the above switch sequence to select programming download mode and pick the Upload menu option from the Arduino IDE. When it runs, the sketch will show something like Screen 6 in the serial monitor. We used the “s” menu option to capture an image and save it to the microSD card, followed by the “a” option, which takes a photo and renders it as ASCII art in the terminal. The image is of a hand in front of a sheet of paper. siliconchip.com.au Screen 6: the ESP32CAM_PROBE_SD sketch shows what can be done with the camera module without requiring a WiFi interface; it can save photos to a microSD card. The ASCII art shown here is a photo of a hand above a piece of white paper. It’s intended as a way to check that the camera is working. Australia's electronics magazine February 2024 65 If you don’t have a Pico W BackPack, this is about the quickest way to see the camera generating images successfully. If you power off the camera module and put the microSD card in a card reader in a computer, you should see the photos that have been saved to the microSD card. This sketch is broken up into functions to allow you to easily modify the sketch in case you want to run custom code on the camera module. In that case, look at the files noted near the top of the sketch. They contain definitions of some other useful functions and constants (provided as part of the ESP32 board profile) that interface with the camera: sensor.h esp_camera.h img_converters.h Most of the top of the camera module is taken up by the camera chip and its FFC (flat flexible cable) connector. The chip sits on the microSD card socket and uses it as a heatsink. The LED at lower right is labelled FLASH LED in Fig.1. Both photos are shown enlarged for clarity. On our system (for the 2.0.13 version we are using), these are in “(board manager package location)\esp32\ hardware\esp32\2.0.13\tools\sdk\ esp32\include\esp32-camera”. There aren’t many spare pins available on the camera module. Most of the pins on the CON1 header are for power and serial data, while those on CON2 are shared with those used for the microSD card socket. So it is tricky to add much extra hardware to the camera module. Keep in mind that the ESP32 processors support Bluetooth as well as WiFi, so you might think of other ways to interface with it. BIN compiled binary files are also included in the software downloads. You can upload them to the ESP32 board using the ESP download tool, at address 0x000000. We won’t go into detail on how to do that as documentation is available online. WebMite software The underside carries the ESP32 module, PSRAM chip and 3.3V regulator U2. The RST button at top right is inaccessible when the module is plugged into a breadboard. The U.FL socket at lower left is for an external antenna, but the adjacent jumper resistor must be moved if using it. 66 Silicon Chip The WebMite MMBasic firmware (which also runs on a Pico W microcontroller) can interface with the camera module. We have produced software to demonstrate this, although it has few features since the WebMite cannot do everything that can be done with the Arduino IDE. The WebMite firmware is intended to be used with the Pico W BackPack hardware; it only needs the 3.5in LCD touchscreen and backlight components fitted. The program is named “WebMite ESP32-CAM.bas”. Australia's electronics magazine The easiest way to install the software is to put the Pico W in bootloader mode and copy the “WebMite ESP32CAM.UF2” file to the RPI-RP2 drive. Otherwise, the necessary OPTIONs are listed at the start of the BASIC file, if you wish to set it up yourself. If you have configured the ESP32CAM_WEBSERVER sketch to use a custom WiFi network, change the OPTION WIFI settings to match. Note that you need a WiFi router or similar to create the TEST access point, because the WebMite cannot act as an access point like the Pico W can when programmed with the Arduino IDE. You also need to manually determine the IP address of the camera module, such as by monitoring its serial output. Screen 7 shows the serial terminal output of the WebMite. Once it connects to WiFi, use the “V” option to enter the last octet of the camera module’s IP address. For example, if the camera module’s IP address is 192.168.42.16, type “16” followed by Enter. This assumes that the network uses a 255.255.255.0 subnet mask, which is typical for many home WiFi networks. If that is not the case, you can manually edit the “CAMIP” string. Screen 7 shows the output of the “G” command, which performs a GET HTTP request on the camera module and, if successful, saves the resulting JPG file to the internal A: drive of the WebMite. Finally, the “D” command displays the captured image file from the A: drive on the LCD panel. That is done by just a single line of BASIC code. The most recent captured image file remains on the WebMite’s A: drive and can be seen by using the FILES command at the MMBasic prompt. Comments Note that the camera module’s settings are shared by multiple devices trying to access it. For example, if one device changes the image size, that will be the setting used by all devices that try to capture an image with that camera module. We have also published some quite specialised Circuit Notebook items that use devices similar to the ESP32 WiFi camera module. We have not tested them with the Altronics Z6387 ESP32 WiFi camera module, but we suspect that some would work with it: • The Motion Triggered WiFi siliconchip.com.au camera from May 2022 (siliconchip. au/Article/15317) appears to use a board similar to the camera module, but has the alternative ground wiring to CON1. • The ESP32 camera sentry (November 2022; siliconchip.au/ Article/15541) and Object Recognition with Arduino and ESP32-CAM (July 2023; siliconchip.au/Article/15864) also use the alternate wiring noted above, and both require quite a bit of software set up on a second device to work. • The Automatic AI Doorman (October 2023 issue; siliconchip.au/ Article/15992) uses a different board that also includes a separate processor for AI classification of the camera images. Still, these Circuit Notebook items might inspire those looking to see what might be possible with the camera module. Conclusion The ESP32 WiFi camera module is a great entry point for those looking to incorporate a camera into a microcontroller project. Although quite an old model, the camera is configurable Screen 7: we’ve also created a simple WebMite BASIC program that can connect to the camera module over WiFi. You will need a separate WiFi access point to try this program, as the WebMite cannot create a WiFi access point. If you have a 3.5-inch LCD panel attached to your WebMite, it can also display captured photos. and handily produces compressed JPG data. Our example code means it should be straightforward to write your own software to interface with the camera module. The inbuilt WiFi interface means that just about any WiFi-capable 500 microcontroller can use the camera by connecting to the HTTP server. Alternatively, the ESP32 processor can be directly programmed with the Arduino IDE for standalone applications. The ESP32 WiFi camera module is available from Altronics (Catalog code Z6387): siliconchip.au/link/abrd SC POWER WATTS AMPLIFIER Produce big, clear sound with low noise and distortion with our massive 500W Amplifier. It's robust, includes load line protection and if you use two of them together, you can deliver 1000W into a single 8Ω loudspeaker! PARTS FOR BUILDING: 500W Amplifier PCB Set of hard-to-get parts SC6367 SC6019 $25 + postage $180 + postage SC6019 is a set of the critical parts needed to build one 500W Amplifier module (PCB sold separately; SC6367); see the parts list on the website for what’s included. Most other parts can be purchased from Jaycar or Altronics. Read the articles in the April – May 2022 issues of Silicon Chip: siliconchip.com.au/Series/380 siliconchip.com.au Australia's electronics magazine February 2024 67