Silicon ChipPi Pico-based Thermal Camera - July 2024 SILICON CHIP
  1. Contents
  2. Subscriptions
  3. Back Issues
  4. Publisher's Letter: We’ve come a long way
  5. Feature: Techno Talk by Max the Magnificent
  6. Feature: The Fox Report by Barry Fox
  7. Feature: Net Work by Alan Winstanley
  8. Project: Pi Pico-based Thermal Camera by Kenneth Horton
  9. Project: Dynamic NFC Tag by Tim Blythman
  10. Project: Reciprocal Frequency Counter by Charles Kosina
  11. Feature: Circuit Surgery by Ian Bell
  12. Feature: Audio Out by Jake Rothman
  13. Feature: Max’s Cool Beans by Max the Magnificent
  14. Feature: Teach-In 2024 – Learn electronics with the ESP32 by Mike Tooley
  15. PartShop
  16. Market Centre
  17. Back Issues

This is only a preview of the July 2024 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)
Articles in this series:
  • The Fox Report (July 2024)
  • The Fox Report (September 2024)
  • The Fox Report (October 2024)
  • The Fox Report (November 2024)
  • The Fox Report (December 2024)
  • The Fox Report (January 2025)
  • The Fox Report (February 2025)
  • The Fox Report (March 2025)
  • The Fox Report (April 2025)
  • The Fox Report (May 2025)
Articles in this series:
  • Win a Microchip Explorer 8 Development Kit (April 2024)
  • Net Work (May 2024)
  • Net Work (June 2024)
  • Net Work (July 2024)
  • Net Work (August 2024)
  • Net Work (September 2024)
  • Net Work (October 2024)
  • Net Work (November 2024)
  • Net Work (December 2024)
  • Net Work (January 2025)
  • Net Work (February 2025)
  • Net Work (March 2025)
  • Net Work (April 2025)
Articles in this series:
  • Circuit Surgery (April 2024)
  • STEWART OF READING (April 2024)
  • Circuit Surgery (May 2024)
  • Circuit Surgery (June 2024)
  • Circuit Surgery (July 2024)
  • Circuit Surgery (August 2024)
  • Circuit Surgery (September 2024)
  • Circuit Surgery (October 2024)
  • Circuit Surgery (November 2024)
  • Circuit Surgery (December 2024)
  • Circuit Surgery (January 2025)
  • Circuit Surgery (February 2025)
  • Circuit Surgery (March 2025)
  • Circuit Surgery (April 2025)
  • Circuit Surgery (May 2025)
  • Circuit Surgery (June 2025)
Articles in this series:
  • Audio Out (January 2024)
  • Audio Out (February 2024)
  • AUDIO OUT (April 2024)
  • Audio Out (May 2024)
  • Audio Out (June 2024)
  • Audio Out (July 2024)
  • Audio Out (August 2024)
  • Audio Out (September 2024)
  • Audio Out (October 2024)
  • Audio Out (March 2025)
  • Audio Out (April 2025)
  • Audio Out (May 2025)
  • Audio Out (June 2025)
Articles in this series:
  • Max’s Cool Beans (April 2024)
  • Max’s Cool Beans (May 2024)
  • Max’s Cool Beans (June 2024)
  • Max’s Cool Beans (July 2024)
  • Max’s Cool Beans (August 2024)
  • Max’s Cool Beans (September 2024)
  • Max’s Cool Beans (October 2024)
  • Max’s Cool Beans (November 2024)
  • Max’s Cool Beans (December 2024)
Articles in this series:
  • Teach-In 2024 (April 2024)
  • Teach-In 2024 (May 2024)
  • Teach-In 2024 – Learn electronics with the ESP32 (June 2024)
  • Teach-In 2024 – Learn electronics with the ESP32 (July 2024)
  • Teach-In 2024 – Learn electronics with the ESP32 (August 2024)
  • Teach-In 2024 – Learn electronics with the ESP32 (September 2024)
  • Teach-In 2024 – Learn electronics with the ESP32 (October 2024)
  • Teach-In 2024 – Learn electronics with the ESP32 (November 2024)
A thermal infrared camera measures hot or cold spots compared to the surrounding area. This is extremely useful in diagnosing hot spots in electronic circuits, which may indicate a failing component or the need for a heatsink. They can be pricey, but not this one, a DIY version that’s easy to build. Pi Pico-based Thermal Camera I R thermal cameras have many uses beyond those listed above, such as checking for overheating mechanical bearings or identifying areas of heat loss in a building. Panasonic produces the AMG8833 Infrared Array Sensor (‘Grid-EYE’) that detects IR emissions on a 64-pixel 8 × 8 array. It uses the I2C serial protocol, so it can easily interface with a Raspberry Pi Pico running the Pico­Mite operating system. Objects emit infrared energy in proportion to their temperature; the higher the temperature, the more IR energy is emitted and the higher its frequency. For really hot objects, the frequency extends into the visible wavelengths, which is why hot objects are seen to glow. By measuring this energy, we can get a pretty good idea of the temperature. However, there are some pitfalls, which we will mention later. With the Grid-EYE sensor, each pixel has a viewing angle of approximately 7.5°, so the overall sensor has a viewing angle of 60° (7.5° × 8). Each pixel has a tolerance of ±2.5°C when operated within specification. We can minimise this error by calibrating the sensor, as described below. Also, there can be random operating ‘noise’ of up to ±2.5°C per pixel. To reduce this, the sensor is used in moving-­average mode, which averages two readings when the sensor is set up for a 10Hz frame rate or 20 readings when for a 1Hz frame rate. Practical Electronics | July | 2024 If the raw output of the Array Sensor is displayed directly on an LCD screen, it appears very ‘blocky’. Still, it can easily be upscaled using a technique called bilinear interpolation to give the appearance of many more data points. The PicoMite Thermal Camera can upscale by factors of two, four or nine. These factors were chosen as they make the best use of the screen width. Below the thermal image display is a text read-out showing the maximum, minimum and average temperatures and the current operating mode. As mentioned above, the Array Sensor can sample at 10 FPS (frames per second) or 1 FPS. The former is most suited to fast-changing subjects, while the latter better smooths out random noise in the sensor, giving a more stable and accurate output. Bilinear interpolation This involves drawing an imaginary straight line between two data points, then generating new data points in between that lie on that line. It’s a simple technique that produces a much smoother-looking result than the more basic ‘nearest neighbour’ technique that gives a blocky image. More complicated interpolation schemes like trilinear, bicubic, Lanczos or anisotropic interpolation involve considerably more processing (arithmetic) than bilinear. In by Kenneth Horton this case, their advantages are minor; bilinear gets us most of the improvement compared to no filtering with very little processing. Object emissivity The ‘fly in the ointment’ for a thermal camera is that objects vary in emissivity. An ideal IR emitter is called a ‘black body’ with 100% electromagnetic emission/absorption. Shiny objects like mirrors have an emissivity closer to 0%. If you point an IR thermometer or camera at them, you will measure the temperature of an object that the mirror is reflecting, not the mirror itself. Luckily for us, many electronic components are dark colours and will have an emissivity of at least 90%, so a thermal camera will measure their temperature accurately. Human skin has an emissivity of 97-99.9%, so IR thermometers also work well for measuring our temperature. This isn’t a fatal flaw but be aware that the temperature measurements of metallic objects using this IR camera could be inaccurate. It isn’t just well-polished metal surfaces either; even rough, oxidised aluminium only has an emissivity of about 20%, with polished metal surfaces usually below 5%. A known work-around to measuring the temperature of shiny surfaces (eg stainless steel pipes) is to apply some matte painters tape, which has 17 Raspberry Pi-based Thermal Camera Fig.1: the Thermal Camera circuit is straightforward, with the IR sensor array (MOD1) communicating with the Raspberry Pi Pico over an I2C bus (SDA/SCL) and the LCD screen being driven over an SPI bus (CS, SCK and MOSI). The only other components are the pushbutton for changing modes (S1) and a 39W resistor to set the LCD backlight current. a better emissivity. For more information, see: https://w.wiki/6R6E Circuit details Refer now to Fig.1, which shows that the hardware for the project is relatively straightforward. It consists of just three modules: the Infrared Array Sensor, a Raspberry Pi Pico running the PicoMite operating system (MMBasic) and a 1.8-inch SPI TFT LCD screen with a display resolution of 128 × 160 pixels and an ST7735 controller. The sensor array is connected to the Pico via an I2C interface, while communications with the LCD screen are over an SPI interface. The only passive components are a pushbutton to change modes and a 39W resistor to set the current at which the display backlight operates. The following Pico GPIO pins are used: GP08 LCD data/control (D/C) GP09 LCD chip select (CS) GP10 LCD SPI clock (SCK) GP11 LCD SPI data (MOSI) GP15 LCD reset (RST) GP18 pushbutton sensing GP20 AMG8833 I2C data (SDA) GP21 AMG8833 I2C clock (SCL) find the display on the same sites. There are some suggested links in the parts list. The prototype was powered via the USB port on the Pi Pico, but there are also pads on the PCB for an external 5V power supply. This way, the Thermal Camera can be powered by a battery. The pushbutton is connected so that it pulls the GP18 pin to GND when it is pressed. The Pico has an internal pull-up current enabled on that pin, so its voltage is high when the button is not pressed and goes low when it’s pressed, allowing the digital input to sense the change. Software operation The basic flow of the program is: 1 Initialise the PicoMite, LCD screen and IR sensor array 2 Restore the calibration data and last pushbutton settings 3 Load the colour spectrum from the table 4 Enter the main loop a. Read 64 pixels from the sensor and adjust with the calibration data b. Calculate the maximum, minimum and average temperatures c. Convert the absolute temperatures to points on the colour spectrum d. Interpolate the intermediate colour values for each row using bilinear interpolation e. Interpolate the intermediate colour values for each column using bilinear interpolation f. Update the display g. Check the pushbutton state h. Delay if necessary Repeat items a-h above indefinitely The rear of the enclosure (86 × 33.4 × 57.3mm) has a cutout for the AMG8833 IR sensor; you can also see a small cutout for the Pi Pico’s USB connector on the lip. The double-sided PCB is a carrier for the three modules, the pushbutton and the resistor. The display runs from a 5V DC supply from the Pico. On the Pico board, this is stepped down by a regulator to 3.3V. That 3.3V runs the RP2040 microcontroller on the Pico and is also available off-board, where it is used to power the AMG8833 IR sensor array. The array sensor is available from the usual auction sites pre-mounted on a breakout board, and you can 18 Practical Electronics | July | 2024 while the Pi Pico and IR sensor are mounted on the top. For convenience, the three modules can be mounted via socket strips rather than soldering them directly to the PCB. You can cut the sockets from longer strips if you don’t have 6-pin and 8-pin sockets. The resistor can be mounted on either side of the board. The switch is a two-pin or three-pin SIL-type vertical pushbutton that solders directly to the PCB. Alternatively, there is a provision in the 3D-printed enclosure to mount other types of pushbutton below the LCD screen and wire them up to the pads on the board using short connecting wires. Once plugged into its socket, the IR sensor is secured to the board by two 20mm-long M2.5 machine screws and nuts with 3D-printed The Raspberry Pi is mounted on pin headers in sockets to make it easy to replace. spacers (Fig.4) between the PCB and sensor. One of the spacers for the IR LCD screen limitations Also, the display is extremely sensi- sensor has a cut-out to fit around an Although the LCD screen is, in tive to the viewing angle and must be SMD component next to the module's theory, a standard item, displays viewed head-on to get the full spec- mounting hole. With the IR sensor array and LCD from different suppliers have dif- trum of colours. Otherwise, adjacent attached to the PCB, now is also a good ferent characteristics. One display colours blend into each other. time to plug the Raspberry Pi Pico into tested had the red and blue colours its sockets. reversed, while another batch had Construction You can print the custom-made random pixels at the bottom and The Thermal Camera is built on a douright-hand side of the display. As a ble-sided PCB coded 04105231, measur- enclosure in two parts (body and lid), result, three constants are defined ing 60 × 52.5mm and available from the shown in Fig.5. The STL 3D printer to allow the program to be tailored PE PCB Service. The components are files are optimised for 0.2mm layer height, 0.4mm wall thickness and to the attached display: mounted as shown in Fig.2 and Fig.3. There are nine vias on this board. 100% fill; they can be downloaded ' Set to false for RGB displays If you are using a commercially-­ from the July 2024 page of the PE website: and true for BGR displays produced board (such as the one sold https://bit.ly/pe-downloads Const BGR_display = False Note that the first layer of the by Practical Electeonics), they will be ' Some ST7735 displays have a plated, and nothing else needs to be screw holes is filled as it gives a more pixel alignment problem! Try done. If you etch the board yourself, pleasing appearance to the front and = 2 those nine vias need to be drilled and back of the case – just drill them out Const HRES_offset = 0 short wire links soldered between the after printing. The holes in the lid ' Some ST7735 displays have a top and bottom layers in each location. are countersunk under the top layer pixel alignment problem! Try and are best cleared with an 8-10mm The LCD screen and switch = 1 mount on the underside of the PCB, drill by hand. Const VRES_offset = 0 Despite the display supposedly having 65,536 colours, they can’t actually show that many. First, RGB(247,251,247) is one step down from white but looks significantly dimmer. The difference between this and the next step down, RGB(239,247,239), is less noticeable, as is each subsequent step. For dimmer values, the less effect each step has. RGB(127,127,127) is very dim, and RGB(63,63,63) is almost black! Another, more technical way of saying this is that the display has a very high gamma value. As a result, it is difficult to get more than about 38 distinct colours across the spectrum (even with a good imagination), and the span from yellow through green to cyan seems particularly compressed! Practical Electronics | July | 2024 Fig.2 and Fig.3: components are mounted on both sides of the board. On one side are the Raspberry Pi Pico and IR sensor, both plugged in via header strips. The LCD screen, pushbutton and resistor are mounted on the other side, although the resistor can go on either side. 19 The PCB assembly is held in the case by four 25mm-long M3 machine screws and nuts, with 3D-printed spacers between the display and the PCB at the opposite end to the connector. It is necessary to insert the display into the case first, insert the machine screws from the front of the case, place the spacers over the screw shafts and then plug the PCB onto the display. Finally, secure it with the nuts. Loading the software Many readers will be familiar with loading PicoMite software, which was described in the article on the PicoMite in the July 2022 issue (Make it with Micromite – Part 37); briefly, an overview is: nD ownload the PicoMite operating system and unzip the file from: http://geoffg.net/picomite.html nT o load the operating system onto the PI Pico, plug the USB cable into a PC while holding down the white button. nT he Pi Pico will appear as a USB drive. To that drive, copy/drag the file PicoMitexx.xx.xx.uf2 nC onnect to the PicoMite’s USB serial port using your preferred serial terminal emulator (eg, TeraTerm or PuTTY). nO nce connected, enter each of these commands in turn, but note that many of them reset the Pi Pico, so the USB connection is lost and will need to be restored before entering the next: OPTION RESET OPTION CPUSPEED 252000 OPTION SYSTEM SPI GP10,GP11,GP12 OPTION LCDPANEL ST7735,RP,GP8,GP15,GP9 OPTION SYSTEM I2C GP20,GP21 The pushbutton is visible on the back of the PCB at upper left. A few different compatible types can be obtained. loading the BASIC code. The only difference between the two files is the expected LCD screen configuration, so if the displayed colours are wrong, load the other file. 1. Operation The pushbutton has the following functions: nS hort press (less than 1.5 seconds): cycles the display scaling factor through 1, 2, 4 and 9 nL ong press (more than 1.5 seconds): toggles between 1 FPS and 10 FPS nV ery long press (more than 10 seconds): enters calibration mode Note that the frame rates are sensor refresh times, not screen refresh times. At 10 frames per second, the screen update time is longer than 1/10th of a second for scale factors 4 and 9. At scale factor 4, the display will be updated approximately every 220ms and, at scale factor 9, every 700ms. This is because the bilinear calculations take some time to complete for higher scaling factors. In calibration mode, the sensor is set to 1 FPS, and 10 readings are taken over a 10-second period. These are then averaged, and the correction factors for each pixel are stored in Fig.4: 3D-printed spacers are used rather than off-the-shelf types since we can make them exactly the right dimensions, and you can print them at the same time as the case. Note the cut-out in one to clear an SMD component near the mounting hole on the IR sensor module. nT he following two commands are optional; the first shows you what you have configured, while the second lets you verify that the LCD screen is working: OPTION LIST GUI TEST LCDPANEL nF inally, load Thermal camera.bas into the PicoMite, again using your preferred serial terminal emulator or MMEdit. Use the ‘Autosave’ or ‘XMODEM receive’ commands, depending upon your preference. n I f you’d prefer to skip most of the above sequence, you can download the Thermal camera (RGB). uf2 or Thermal camera (BGR). uf2 file from the PE website and upload it in the third step above. That’s equivalent to running all the configuration commands and 20 Fig.5: the 3D printed enclosure base and lid. The holes do not go all the way through because it gives a neater result to drill the thin panels after printing the case than print the case with the holes. Practical Electronics | July | 2024 Parts List – Raspberry Pi Thermal Camera 1 double-sided PCB coded 04105231, 60 × 52.5mm from the PE PCB Service 1 Raspberry Pi Pico 1 3D-printed enclosure (body and lid) 4 3D-printed spacers 1 AMG8833 Grid-EYE IR sensor array breakout board module with pin order VIN, GND, SCL, SDA, INT and ADO [AliExpress www.aliexpress.com/item/33012193094.html] 1 1.8-inch 128×160 pixel SPI LCD TFT screen with ST7735 controller [Tempero Systems TS-S006; eBay; AliExpress www.aliexpress.com/ item/1005003797803015.html {1.8 inch option}] 1 SPDT momentary PCB-mounting subminiature pushbutton switch (S1) [Altronics S1493 or APEM TP32P0] 1 39W 5% ¼W axial resistor 2 20-pin headers, 2.54mm pitch 2 20-pin header sockets, 2.54mm pitch 1 8-pin header socket, 2.54mm pitch 1 6-pin header socket, 2.54mm pitch 2 M2.5 × 20mm panhead machine screws and hex nuts 4 M3 × 25mm panhead machine screws and hex nuts 4 No.2 × 6mm countersunk head self-tapping screws non-volatile memory. Good results are obtained by holding the sensor perfectly still 2-3cm from a white sheet of paper. If the button is pressed during calibration, calibration is abandoned, and the correction factors are cleared. We recommend letting the sensor stabilise for at least one minute with power on before performing calibration. It’s critical you purchase a module with the same output pin layout as the one shown above. Software tweaks In the software, the constant ‘Fahrenheit’ can be set to ‘true’ to display Order direct from Electron Publishing GET T LATES HE T CO OF OU PY R TEACH -IN SE RIES AVAILA BL NOW! E temperatures in Fahrenheit rather than centigrade/Celsius. The constant ‘Minimum_span’ sets the minimum temperature span for the display when there is little temperature variation across the whole display. This prevents wildly varying colours for minimal temperature changes. Lower values make the display more sensitive when there is an almost uniform temperature gradient. Speeding up the refresh rate The latest version of the Pico­Mite firmware PicoMiteV5.07.06.uf2) allows the CPU speed to be increased from the old maximum speed of 252000 to 378000 with the command: Option CPUspeed 378000 This means that, with a scale factor of 4, the display will be updated approximately every 165ms rather than 220ms and, at scale factor 9, every 520ms rather than 700ms. However, note that this is ‘overclocking’ the RP2040 processor and it’s possible that it won’t work on every board or under all conditions. Still, most Pico boards should be capable of running at this speed. Reproduced by arrangement with SILICON CHIP magazine 2024. www.siliconchip.com.au EE FR -ROM CD ELECTRONICS TEACH-IN 9 FROM THE PUBLISHERS OF GET TESTING! Electronic test equipment and measuring techniques, plus eight projects to build PRICE £8.99 (includes P&P to UK if ordered direct from us) £8.99 FREE CD-ROM TWO TEACH -INs FOR THE PRICE OF ONE • Multimeters and a multimeter checker • Oscilloscopes plus a scope calibrator • AC Millivoltmeters with a range extender • Digital measurements plus a logic probe • Frequency measurements and a signal generator • Component measurements plus a semiconductor junction tester PIC n’ Mix Including Practical Digital Signal Processing PLUS... Teach-In 9 – Get Testing! YOUR GUIDE TO THE BBC MICROBIT Teach-In 9 A LOW-COST ARM-BASED SINGLE-BOARD COMPUTER Get Testing This series of articles provides a broad-based introduction to choosing and using a wide range of test gear, how to get the best out of each item and the pitfalls to avoid. It provides hints and tips on using, and – just as importantly – interpreting the results that you get. The series deals with familiar test gear as well as equipment designed for more specialised applications. The articles have been designed to have the broadest possible appeal and are applicable to all branches of electronics. The series crosses the boundaries of analogue and digital electronics with applications that span the full range of electronics – from a single-stage transistor amplifier to the most sophisticated microcontroller system. There really is something for everyone! Each part includes a simple but useful practical test gear project that will build into a handy gadget that will either extend the features, ranges and usability of an existing item of test equipment or that will serve as a stand-alone instrument. We’ve kept the cost of these projects as low as possible, and most of them can be built for less than £10 (including components, enclosure and circuit board). Three Microchip PICkit 4 Debugger Guides Files for: PIC n’ Mix PLUS Teach-In 2 -Using PIC Microcontrollers. In PDF format © 2018 Wimborne Publishing Ltd. www.epemag.com Teach In 9 Cover.indd 1 01/08/2018 19:56 PLUS! You will receive the software for the PIC n’ Mix series of articles and the full Teach-In 2 book – Using PIC Microcontrollers – A practical introduction – in PDF format. Also included are Microchip’s MPLAB ICD 4 In-Circuit Debugger User’s Guide; MPLAB PICkit 4 In-Circuit Debugger Quick Start Guide; and MPLAB PICkit4 Debugger User’s Guide. ORDER YOUR COPY TODAY: www.electronpublishing.com Practical Electronics | July | 2024 21