This is only a preview of the April 2024 issue of Silicon Chip. You can view 39 of the 104 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. Items relevant to "Becoming a Radio Amateur":
Items relevant to "Pico Gamer":
Articles in this series:
Items relevant to "Skill Tester 9000, Pt1":
Items relevant to "ESP32-CAM BackPack":
Items relevant to "Reference MEMS Microphones":
Purchase a printed copy of this issue for $12.50. |
Project by Tim Blythman
ESP32-CAM
LCD BackPack
After we reviewed the Altronics Z6387
ESP32 WiFi camera module, we thought it
would be great with an LCD BackPack. The ESP32-CAM
LCD BackPack PCB connects the ESP32 WiFi camera module to a
3.5in LCD touch panel and makes it easy to reprogram the ESP32 module.
W
e were impressed by the ESP32
WiFi camera module when we
reviewed it in the February 2024
issue (siliconchip.au/Article/16129).
It is a compact module with a WiFi-
provisioned ESP32 microcontroller
and an OV2640 camera chip. It is also
called the ESP32-CAM (the name is
printed on its board).
The module is easy to use. While the
easiest way to retrieve camera images
was to use a separate microcontroller (such as a Pico W BackPack) with
WiFi, the onboard ESP32 is a capable
32-bit microcontroller. So it makes
sense to use it in a standalone fashion and remove the need for a second
microcontroller.
This straightforward LCD BackPack
for the ESP32-CAM module lets you do
that. The ESP32 microcontroller can
display camera images on the 3.5in
LCD touch panel, while other circuit
features simplify programming and
communication.
We’ve also written some sample
Arduino code that will provide a basic
demo of the BackPack and form a starting point for writing your own ESP32CAM LCD BackPack code.
To demonstrate the standalone
nature of the BackPack, the demo code
does not use the WiFi features of the
ESP32 processor (but you can if you
want to).
ESP32-CAM recap
The ESP32-CAM contains an ESP32
sub-module, which in turn contains
the ESP32 processor plus some passive components and a flash memory
chip, the latter storing the program that
runs on the processor. There is also a
72
Silicon Chip
PCB antenna for WiFi and Bluetooth.
The ESP32-CAM module adds a
camera chip that uses 1.2V and 2.8V
supply rails, provided by a pair of
onboard regulators. A serial PSRAM
(pseudo-static random access memory) chip provides working memory
for image processing.
There is a microSD card slot, a pair
of eight-way headers for external connections, one LED to perform the role
of a camera flash, plus the necessary
smattering of passive components. We
included a circuit for the module in
the review article.
The ESP32 sub-module has a socket
for an external WiFi antenna, which
can be used (instead of the PCB
antenna) by changing the position of
a single jumper resistor.
ESP32-CAM LCD BackPack Kit
SC6886 ($42.50 + postage):
comes with the PCB and all nonoptional onboard components
except the ESP32-CAM module. It
does include the touchscreen.
These lines are not connected to
anything unless a microSD card is
fitted in the socket, so the solution is
simply not to insert one.
While disabling the microSD card
slot is a hindrance, the ample flash
memory of the ESP32-CAM module
still allows data to be saved in non-
volatile storage. There are Arduino
libraries, such as LittleFS, that can
treat the flash memory as a file system
to read and write files.
Fig.1 shows the resulting circuit of
the ESP32-CAM LCD BackPack. As
you can see, it mainly provides connections between the headers for the
ESP32-CAM and the LCD touch panel
via CON3.
The six signals we freed up are the
minimum necessary to update the LCD
screen and sense touches on the panel.
Three lines are used for SPI communication: SCK (IO14), MOSI (IO2) and
MISO (IO4).
The LCD and touch panel controllers each have a CS (chip select) line,
for which we use IO12 and IO15,
respectively. The LCD controller also
has a D/C (data/command) line, which
we connect to IO13 on the ESP32
microcontroller.
The LCD controller’s RESET line
is tied to the ESP32’s E32_RST line,
so the LCD is reset whenever the processor is reset. In any case, a software
reset command can be sent to the LCD
controller over the SPI bus. The LCD
panel’s LED control line is tied high,
meaning there is no control of the LED
backlight; it is fully illuminated as long
as the BackPack is powered.
The biggest compromise we have
made is that one of the lines to the
Australia's electronics magazine
siliconchip.com.au
ESP32-CAM LCD BackPack
We noted in our review that practically all the ESP32’s I/O pins are used
up by features on the module. The
camera chip alone requires 15 lines.
To free up enough pins to control an
LCD touch panel, we need to lose some
functionality on the ESP32-CAM.
We have chosen to disable the
microSD card slot, as there is no other
way to free up six easily-accessible
pins. Fortunately, its control lines are
broken out to the module’s headers, so
we do not need to modify the module
to access them.
Fig.1: the ESP32CAM LCD
BackPack is a
little more than
a breakout board
that allows the ESP32-CAM
module to be connected to
a 3.5in LCD touch panel.
A header for a CP2102
USB-serial module and a
pair of tactile pushbuttons
allow communication and
programming of the ESP32
processor on the module.
LCD touch panel (IO4) is also used
to control the flash LED. However, it
was already shared with the microSD
card socket, so that brings no new
challenges.
We are using this line for MISO
(master in/slave out), which is only
used by the touch panel interface chip.
Since there is a pulldown resistor on
this pin, and it is only driven high
when the touch panel sends binary ‘1’
data bits, the flash remains off except
for brief moments when the touch
panel controller is communicating. It’s
low again so quickly that the resulting LED illumination is barely visible.
We have added extra rows of pads on
the PCB to allow the available pins to
be broken out. There likely isn’t much
that can be done with these, short of
sourcing 3.3V or 5V power for external circuitry. Still, there is plenty of
free space on the board, and no extra
cost to add those pads.
We have also added a CP2102
siliconchip.com.au
USB-serial module, attached to CON1.
It can be used to supply 5V power to
the ESP32-CAM’s onboard 3.3V regulator from a USB power source.
We could have taken 3.3V from the
CP2102 module. However, its regulator is integrated into the CP2102 chip
and would probably not be able to supply the current needed by the ESP32
processor and camera chip.
Naturally, the CP2102 module also
connects to the ESP32-CAM’s serial
communication lines, providing a
USB serial terminal to interact with
the BackPack.
Since there is spare space, we’ve
also added a mini-USB socket footprint, CON2, which can be used to
provide power to the BackPack if the
CP2102 module is not fitted.
Finally, two tactile pushbuttons, S1
and S2, are connected to the RESET
and IO0 pins, respectively, pulling
them to ground when pressed. These
can be used to reset the processor or to
Australia's electronics magazine
put it into bootloader mode for uploading new firmware.
So, even if you don’t need to connect an LCD panel to the ESP32-CAM,
the BackPack can make programming
and communicating with the module
easier. It is much tidier than using a
breadboard, which is what we used
when prototyping the software for
this design.
If you wish to experiment, you could
carefully follow the Fig.1 circuit diagram and wire it up on a breadboard.
Still, the ESP32-CAM LCD BackPack
is easy to build and inexpensive, so we
recommend doing that instead.
Construction
The ESP32-CAM BackPack is
built on a double-sided PCB coded
07102241 that measures 99 × 55mm.
During construction, refer to its overlay diagrams, Figs.2 & 3 that show
which parts go where.
The only somewhat tricky part of
April 2024 73
the assembly process is ensuring that
all the components are fitted to the
correct sides of the PCB, but the overlay diagrams and photos will help
with that. They are all through-hole
parts except for the optional mini-USB
socket, CON2.
CON2 should only be fitted if you
aren’t using a CP2102 module. Be
aware that you will need another way
to program the ESP32-CAM module
in that case.
If you are fitting CON2, do so first.
Apply flux to the pads and solder the
larger mechanical leads to the PCB
after checking that the locating pins
have aligned the socket correctly.
Then, clean your iron and carefully
solder the smaller pads.
Clean off any flux residue once you
have finished soldering CON2 using an
appropriate solvent (most pure alcohols will work). Allow the PCB to fully
dry before continuing.
Two eight-way female header strips
are used to mount the ESP32-CAM
module. Temporarily fit them to the
ESP32-CAM and slot those into the
pads on the PCB, making sure it is on
the side marked for the module. Solder
the headers in place, ensuring everything is neat and square, then detach
the ESP32-CAM module so it doesn’t
get damaged during subsequent steps.
Slot the two switches into place on
the other side of the PCB and solder
them to it, then fit the tapped spacers to
the outermost set of holes on the main
PCB, on the same side as the switches.
They should align with the holes for
the 3.5in LCD panel.
The innermost holes will align with
a 2.8in LCD panel, although our software will not work with the ILI9341
controller on those displays. Numerous libraries are designed for these
controllers, so if you want to utilise a
2.8in panel, you could develop your
own software to work with it. Most
constructors should stick with the
higher-resolution 3.5in panel as it
doesn’t cost much more.
Plug the 14-way header socket into
the header on the 3.5in LCD panel and
align the LCD panel to the main PCB
with the tapped spacers. This will
allow you to solder the header socket
squarely to the PCB. Note that you cannot have the four-way header (for the
SD card socket on the LCD panel) fitted to the LCD panel, as it would foul
the tactile switches.
Also, remember that the CP2102
module needs to fit under the LCD
panel. This module is usually supplied with right-angled headers, but
you must use straight headers to mount
it flat against the PCB.
Sandwich the straight header
between the PCB and the CP2102 module and ensure the CP2102 module is
pushed down against the header. Tack
one lead to the PCB and module, then
confirm that everything is square and
fits under the LCD panel before soldering the remaining pins.
You can then trim the excess pin
header length to keep the headers clear
of the LCD panel. Another option is to
use a matching set of male and female
headers to allow the CP2102 module to
be detached, although you may need
to be creative to ensure that this fits
under the LCD panel.
If you haven’t already done so, fit the
camera to the FFC (flexible flat cable)
socket on the ESP32-CAM module. A
pivoting black bar rotates upwards,
allowing the cable to be slotted in. The
black bar is pushed down to secure
the camera.
Then, use the attached tape to affix
the camera chip to the microSD card
holder on the module and plug the
ESP32-CAM module into the headers.
Fit the LCD panel and secure it with
the screws.
If you apply power now to the
CP2102 module, you should see the
LCD backlight illuminate, but not
much else will happen until the
ESP32-CAM is programmed to work
with the LCD panel.
Programming it
Figs.2 & 3: the PCB is not difficult to assemble, although there are components
on both sides. The eight-way male and female headers are fitted to the side
marked ESP32 CAMERA MODULE. The remaining parts go on the other side,
which faces the back of the LCD, allowing the camera to face outwards.
We are using the Arduino IDE
to program the ESP32 chip on the
ESP32-CAM. To add support for
ESP32 boards, go to the Board Manager section under the File → Preferences menu item and add “https://
dl.espressif.com/dl/package_esp32_
index.json” to the list of Board Manager URLs.
Next, open the Board Manager
itself and add the ESP32 board profile
(search for “esp32”). You should add
Australia's electronics magazine
siliconchip.com.au
74
Silicon Chip
Screen 1: the demo
sketch updates
the LCD panel
as quickly as
possible, showing
the image at native
resolution. At
96×96 pixels, it
refreshes at 25fps,
making it appear
smooth. The
camera orientation
means horizontal
and vertical flip
must be on so the
displayed image is
the right way up.
the version provided by Espressif Systems; there is also a version provided
by Arduino, but it does not support
the ESP32-CAM.
We used version 2.0.14, but later
versions should work equally well.
Choose the “AI Thinker ESP32-CAM”
board from the dropdown menu and
set the serial monitor baud rate to
115,200. That is the default rate used
by the ESP32, so it is handy for viewing boot and diagnostic data. Open the
serial monitor to the serial port of the
CP2102 module.
Now open the “ESP32CAM_BACKPACK_DEMO” sketch and put the
ESP32-CAM LCD BackPack into programming mode by pressing and holding S1 (RESET). While holding S1,
press and hold S2 (IO0), then release
S1, followed by S2.
S2 must be held down when S1 is
released to set the correct boot state.
Pressing S1 first ensures that IO0 is
not being driven by the ESP32 microcontroller when S2 is pressed. If IO0
is pulled low by S2 while being driven
high, that could damage the chip
(although it’s unlikely).
You should see a ‘waiting for download’ message in the serial terminal,
meaning that the ESP32 is in programming mode. If you see something different, try again.
Upload the sketch, and the LCD
should initialise and display an image.
If that doesn’t happen within a second
or two, briefly press the S1 (RESET)
button to reset the microcontroller.
If you still don’t see anything on
the LCD, check the serial monitor for
any error messages. That will include
information about whether the camera was correctly detected and which
model was found.
There will be a constant stream of
data as the sketch describes the images
it is processing, so you may have to
turn off auto-scrolling in the serial
monitor.
If the camera is not detected, power
off the ESP32-CAM LCD BackPack and
check the connection to the FFC connector on the ESP32-CAM module.
Screen 2: the
TEST button at
upper right turns
on the camera
chip’s colour bar
test. If you are not
making out a clear
image, the colour
bar test should
help identify
whether the
ESP32 is receiving
correct image data.
The colour bars’
appearance will
change at different
resolutions.
Screen 3: at higher
image capture
resolutions, the
demo sketch
crops out the
centre 240×240
pixels, which is
like performing
a digital zoom on
the central part of
the image. Here,
we have tweaked
the brightness and
contrast settings to
improve the image
quality.
Screen 4: the
EFFECT setting
activates image
processing on the
camera, providing
special effects
without extra
load on the ESP32
processor. The
EFFECT 2 setting
is monochrome
(compare this to
Screen 3). The
default effects set
also offers reverse
video and several
colour tints.
Demo sketch functions
Screens 1 to 4 show some views
of the LCD panel as it runs the demo
sketch. The camera was pointed at
a laptop screen showing the Silicon
Chip website. The camera image is
refreshed as quickly as possible and
displayed inside the white rectangle.
siliconchip.com.au
Australia's electronics magazine
April 2024 75
Parts List – ESP32-CAM BackPack
1 double-sided PCB coded 07102241, 99 × 55mm
1 UB3 Jiffy box (optional)
1 laser-cut Jiffy box replacement lid (optional) [SC5083 or SC5856]
1 ESP32-CAM module (MOD1) [Altronics Z6387]
1 3.5in LCD touchscreen (MOD2) [Silicon Chip SC5062]
1 CP2102 USB-serial module (MOD3) [SC3543]
1 6-way 2.54mm-pitch pin header (CON1; for CP2102 module)
1 SMD mini-USB socket (CON2; optional, instead of CON1)
1 14-way 2.54mm-pitch header socket (CON3; for LCD touchscreen)
2 8-way 2.54mm-pitch header sockets (CON4 & CON5)
2 8-way 2.54mm-pitch headers (CON6 & CON7; optional)
2 right-angled tactile switches (S1, S2)
4 12mm-long M3 tapped spacers
8 M3 × 5mm panhead machine screws
4 M3 × 8mm panhead machine screws
(optional, to mount to acrylic lid panel)
4 1mm-thick, 6mm outer diameter M3 Nylon washers
(optional, to mount to acrylic lid panel)
The calculated frame rate is shown
below the image. We found that the
ESP32-CAM could achieve about
25fps (frames per second) when running at 96×96 pixels. Most of the processing time involves transferring data
to the LCD controller.
Several touch panel buttons are
provided on the right. They are only
scanned once per display update, so
you may need to press longer when
higher resolutions are set. The flash
LED will flicker when the touch panel
is scanned.
The buttons provide access to a
useful subset of the settings available
on the camera chip. Later, in the Software section, we’ll note how you can
find the full range of settings that can
be changed from within an Arduino
sketch.
From the top, the TEST setting
enables a colour bars test pattern, as
seen in Screen 2. This can be used to
test whether any problems are due to
the camera chip itself, or if they are
due to communications or processing
faults elsewhere.
The SIZE parameter cycles through
several preset resolutions up to
640×480 pixels. Although the camera
chip supports images up to 1600×1200
pixels, processing images that size
would take too long and wouldn’t fit
on the LCD screen without substantial cropping.
Smaller images are displayed with a
grey border, while images larger than
the LCD resolution of 480×320 pixels are cropped, giving the effect of a
digital zoom.
76
Silicon Chip
The H-FLIP and V-FLIP settings
mirror the image horizontally or vertically. We found that they both had
to be turned on for the Altronics module to align the camera image with the
image displayed on the LCD panel.
The QUALITY setting changes the
JPEG compression level used by the
camera chip. Perhaps confusingly,
lower numbers correspond to better
image quality. This value can vary
from four to 63, although we didn’t see
much difference between the settings.
The BRIGHTNESS and CONTRAST
settings work as expected, although
they can only vary from -2 to +2.
Finally, the EFFECT setting provides some special effects performed
on the camera chip, so they do not
require any extra processing from the
ESP32. The available effects include
reverse video, black-and-white and
several colour tints that can be applied.
EFFECT 0 means that no special effect
is applied.
Software details
Much of the demo sketch is involved
in providing the user controls, allowing the settings to be tweaked. There
is not much code needed if you simply wish to display an image from the
camera on the LCD panel; the following is a guide to the minimum required
to do so.
The Arduino setup() function
should call displaySetup() to initialise the LCD panel and camInit()
to configure the camera chip. These
functions can be found in the sketch
folder, inside the files “LCD.h” and
“camera_pins.h”, respectively. If you
need to change the resolution, use the
set_framesize() function.
Like many other camera settings,
this and similar functions are found
in the “sensor.h” file, which is part of
the ESP32 board profile. If you can’t
find it on your computer, you can
view it at https://github.com/espressif/
esp32-camera/blob/master/driver/
include/sensor.h
To acquire an image, call the esp_
camera_fb_get() function. The frame
buffer contains JPG data and can be
converted to RGB bitmap data with
the frame2bmp() function.
Finally, the drawBitMap() function
can be used to draw the bitmap to the
LCD panel. This function definition
can be found at the bottom of the main
sketch. It takes care of cropping and
Here is the BackPack board without the touchscreen panel, so you can see the
positions of the USB-serial adaptor and right-angle tactile pushbuttons. The
ESP32-CAM module mounts on the opposite
side (it’s shown separately on
the right).
Australia's electronics magazine
siliconchip.com.au
ensuring that the RGB data triples are
output in the correct order.
You need to release the JPG buffer
with esp_camera_fb_return(), and the
bitmap buffer with free() once you
have finished processing the data and
before starting the next acquisition, or
the program will quickly terminate
due to memory exhaustion.
The “ESP32CAM_BACKPACK_
DEMO_minimum” sketch from the
software downloads is nearly the
minimum needed, apart from some
diagnostic error messages. It simply
displays a camera image in the centre
of the LCD.
We have also written a sketch named
“ESP32CAM_BACKPACK_FILE_
CAMERA”. This sketch programs the
ESP32-CAM LCD BackPack to behave
like a very basic digital camera, capturing and displaying images to and
from the internal flash-based LittleFS
file system.
It has a small viewfinder preview
that constantly updates and buttons to
allow digital zooming up to four times.
You can also scroll through the saved
images and format the file system to
delete all saved images.
Enclosure option
The stack of three PCBs, including
ESP32-CAM module, BackPack PCB
and LCD panel, stands roughly 40mm
deep when assembled. It will thus fit
neatly into a 44mm deep UB3 Jiffy box,
such as Altronics’ H0203.
The camera lens will sit a few millimetres inside the base of the box,
so you will need to drill a hole to
allow the camera lens to ‘peek out’.
Alternatively, longer spacers, like the
stackable headers used for Arduino
boards, could be used to position the
camera lens just outside the base of
the box through a hole.
You can use our SC5083 or SC5856
laser-cut acrylic lid panels to mount
the assembly. These are available from
the Silicon Chip Online Shop. You
might also need longer self-tapping
screws that can thread through the
extra depth of the acrylic. We have
noted these optional parts in the Parts
List.
Note that the lens is not centred on
the BackPack PCB due to the asymmetry of the ESP32-CAM module. The
LCD panel and thus the acrylic panels
are not symmetrical either.
Conclusion
A camera is a very useful sensor to
be able to connect to a microcontroller,
allowing images of the world to be captured and displayed. While the ESP32
is known for its WiFi capabilities, it is
also a capable 32-bit processor wellsuited to image processing.
The ESP32-CAM module is useful on its own, providing many of
the features of a basic WiFi camera.
The ESP32-CAM LCD BackPack adds
to this by processing and displaying
camera images on an LCD touch panel.
We think it will be of interest to
those looking to perform low-level
image capture and processing. While
adding the LCD panel to the ESP32CAM means that the onboard microSD
card slot is not usable, alternatives
such as the LittleFS flash file system
SC
exist.
Ideal Bridge Rectifiers
Choose from six Ideal Diode Bridge
Rectifier kits to build: siliconchip.
com.au/Shop/?article=16043
28mm spade (SC6850, $30)
Compatible with KBPC3504
10A continuous (20A peak),
72V
Connectors: 6.3mm spade
lugs, 18mm tall
IC1 package: MSOP-12
(SMD)
Mosfets: TK6R9P08QM,RQ (DPAK)
21mm square pin (SC6851, $30)
Compatible with PB1004
10A continuous (20A peak),
72V
Connectors: solder pins on
a 14mm grid (can be bent
to a 13mm grid)
IC1 package: MSOP-12
Mosfets: TK6R9P08QM,RQ
5mm pitch SIL (SC6852, $30)
Compatible with KBL604
10A continuous (20A peak), 72V
Connectors: solder pins at
5mm pitch
IC1 package: MSOP-12
Mosfets: TK6R9P08QM,RQ
mini SOT-23 (SC6853, $25)
Width of W02/W04
2A continuous, 40V
Connectors: solder
pins 5mm apart
at either end
IC1 package: MSOP-12
Mosfets: SI2318DS-GE3 (SOT-23)
D2PAK standalone (SC6854, $35)
20A continuous, 72V
Connectors: 5mm screw
terminals at each end
IC1 package:
MSOP-12
Mosfets:
IPB057N06NATMA1
(D2PAK)
TO-220 standalone (SC6855, $45)
40A continuous,
72V
Connectors:
6.3mm spade lugs,
18mm tall
IC1 package: DIP-8
Mosfets:
TK5R3E08QM,S1X
(TO-220)
This is how the ESP32-Cam
module mounts to the headers
marked CON4 & CON5. The pin descriptions are marked on the other side of
the PCB, as that is where we expect most readers will attach any accessories.
siliconchip.com.au
Australia's electronics magazine
See our article
in the December
2023 issue for more details:
siliconchip.au/Article/16043
April 2024 77
|