Silicon ChipMake it with Micromite - May 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: Spring is here at last
  7. Feature: Prophecy can be perplexing by Max the Magnificent
  8. Feature: The Fox Report by Barry Fox
  9. Feature: Net Work by Alan Winstanley
  10. Project: 500 WATTS POWER AMPLIFIER PART 2 by JOHN CLARKE
  11. Project: Precision AM-FM DDS Signal Generator by Charles Kosina
  12. Project: IMPROVED SMDTest Tweezers by Tim Blythman
  13. Feature: Make it with Micromite by Phil Boyce
  14. Feature: Max’s Cool Beans by Max the Magnificent
  15. Feature: Circuit Surgery by Ian Bell
  16. Feature: AUDIO OUT by Jake Rothman
  17. Feature: Electronic Building Blocks by Julian Edgar
  18. PCB Order Form
  19. Advertising Index

This is only a preview of the May 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)
Make it with Micromite Phil Boyce – hands on with the mighty PIC-powered, BASIC microcontroller Part 46: A PicoMite Smart-light Controller – Part 1 T here are numerous smart- home devices available today, from lighting, security cameras and alarm systems to speakers, TVs, personal gadgets and even kitchen appliances. Typically, smart technology devices are controlled from a smartphone (or tablet) via an installed app. In the early days of smart tech, each manufacturer had its own eco-system, meaning that you could end up with several different apps, each of which controlled only certain devices, and they couldn’t talk to each other. As smart devices matured, their manufacturers incorporated compatibility with another branch of smart technology, voice control. Today, virtually all smart-home devices can be set up to be controlled with your voice using (at least) one of the three main systems: Google Home, Amazon Alexa and Apple Siri. Voice control effectively results in one common interface for all smart devices in a home, irrespective of the manufacturer. It is worth noting here that some devices also include a touchscreen for user control. However, these tend to be limited to the more expensive kitchen appliances and smart speakers. Now the dilemma – you may not always have your smartphone at hand to control, for example, a smart light. Likewise, it may not be suitable to use voice control (perhaps late at night) to instruct your smart speaker to switch off a smart light, and you certainly don’t want the smart speaker confirming it has understood your command… or not! (This is even worse when the confirmation is spoken loudly.) Granted, there are portable smartbutton light switches available, but when you have numerous smart lights in the home these buttons can quickly become muddled up, especially when children like to play jokes with each other and swap them all around. This led to an idea for a project; a lowcost PicoMite-based smart light controller. 46 The concept was simple; incorporate a touchscreen so that the user can select a single smart light from a list of all the available lights and turn the light on or off, or even alter the brightness. How hard can that be? Philips Hue There are a lot of choices when it comes to smart lighting. My preference is the Philips Hue range. Yes, it’s at the more expensive end of the price scale, however, their technology always works, and there are other benefits, as we shall see as we work through this project. I have found that a lot of other smart lighting that is available varies considerably in quality, often resulting in having to buy replacements earlier than expected. Just recently I had two LED strip-lights fail from a no-brand manufacturer. These were used as bedside lights, so they have now been replaced with Philips Hue striplights, meaning that the whole house (and garden) incorporates 100% Hue lighting. Without going into too much detail here, the Philips Hue smart lights can be controlled either by BlueTooth, or by Wi-Fi (Zigbee). Bluetooth control is very limited, and hence won’t provide the functionality that we’re trying to achieve. On the other hand, Wi-Fi provides full control of the smart lights, but the version of Zigbee Philips adopted is overly complex to implement. However, Wi-Fi control is made much easier when a centralised low-cost Philips Hue Hub is built into the setup; something that Philips have documented reasonably well. So, rather than communicating directly with the smart lights via a version of the Zigbee protocol, the Hue Hub makes it possible for developers to use a standard Wi-Fi protocol (non-Zigbee) to control every aspect of the setup simply by communicating directly with the centralised Hub. Hence, by incorporating a Wi-Fi module into our project (such as Fig.1. The surface-mount version of the ESP32-WROOM module. the readily available ESP32), we should be able to achieve our goal of a PicoMite Smart-light Controller. The ESP32 module There are many variations of the ESP32, both in terms of hardware and firmware. If you search online for ‘ESP32 WROOM’, you will see that there are two main variations available – a smaller surface-mount module (see Fig.1), and a slightly larger throughhole version (which is essentially an ESP32 surface-mount module mounted on a daughterboard that in turn provides header connections – see Fig.2). We recommend Fig.2. Through-hole version of the module is an SMD ESP32 mounted on a daughterboard with header connectors. Practical Electronics | May | 2023 slightly less if you’re able to solder the SMD module onto a daughterboard yourself. Turning to the ESP32’s firmware, one version is available that incorporates an extensive set of AT commands. A good set of AT commands means that it is possible to gain access to the many features that are built into the ESP32. Furthermore, communicating via AT commands from MMBASIC is straightforward, which in turn means the program code will be much easier to follow. The specific AT firmware file we require is available for free download from the ESP32 Fig.3. The MikroElektronika ESP32-WROOM module (MIKROE-3542) used in the development of the PicoMite manufacturer (Espressif). It will be used to overwrite Smart-light Controller. whatever firmware comes preloaded in your ESP32 WROOM hardware. that you go for the through-hole version Updating the ESP32 firmware can be of the ESP32 so that you can then easily challenging, so in Part 1 of this project connect it to the PicoMite using DuPont we will guide you through the process leads. At the time of development, I had a step-by-step. It is important to note that quantity of ESP32 WROOM Click modules updating the ESP32 WROOM with the (see Fig.3), so I used one of those for this relevant AT firmware is essential as it project. As a guide, expect to pay around will guarantee that all the AT commands £10-£15 for an ESP32 WROOM module; used in the project’s program code will be recognised by the ESP32, enabling successful Wi-Fi communication with the Philips Hue hub. Other versions of the ESP firmware will probably have some commands missing and may not work. Let’s get started. Updating the ESP32 firmware The five steps to update the ESP32 module with the AT firmware are as follows: 1. Download ESP32 Flash tool from Espressif 2. Download AT firmware file from Espressif 3. Connect ESP32 WROOM module to PC 4. Run Flash tool to upload the AT firmware 5. Test the firmware loaded successfully. To perform the above steps you will need the following items: • Windows PC (connected to the Internet) • USB-to-Serial module • Jumper leads (DuPont) • A mini breadboard. Note that the ESP32 is a 3.3V device which pulls more than 200mA at peak current (although it does operate lower than this most of the time). To handle these peak currents, you may require a beefier 3.3V supply than a USB-to-Serial module can cope with. Our recommendation is to use the Raspberry Pi Pico’s main 3.3V output (on pin 36) as it is capable of safely supplying 300mA. We will now work through the five firmware update steps. Step 1: Download ESP Flash Tool Fig.4. The ESP Flash Tool can be downloaded from Espressif’s website. It makes upgrading the ESP32 firmware a much easier task. The ESP32 Flash Tool is available for free download from the manufacturer’s website. However, it currently only supports the Windows platform. So, from a Windows computer, visit https://bit.ly/pe-may23-esp and click on the link to download the Flash Download Tools (see Fig.4). This will download a zipped folder (about 16MB), and at the time of writing, the version number was V3.9.4. Once downloaded, extract the files and you will then see the main program that we will be using: flash_download_tool_3.9.4.exe Step 2: Download AT Firmware file The required AT Firmware file can also be downloaded from the Espressif website. Visit: https://bit.ly/pe-may23-at and click the link at the top of the list to download a zipped folder (about 22MB). At the time of writing, this was: v2.4.0.0 ESP32-WROOM-32_AT_Bin_V2.4.0.0.zip (Recommended) – see Fig.5. Extract the files and make a note of where the extracted folder is (probably in your Downloads). Step 3: Connecting the ESP32 Fig.5. The latest version of the required firmware file (zipped folder) is shown at the top of the list. Here, it is version v2.4.0.0 ESP32-WROOM-32_AT_Bin_V2.4.0.0.zip (Recommended) Practical Electronics | May | 2023 The ESP32 module has three serial ports (UART0, UART1 and UART2) – we will 47 NC NC RST NC CS TX NC RX NC NC NC NC 3V3 NC GND GND to connect three GPIO pins as follows; along with 3.3V power (ideally 300mA capable) and the Enable pin: ESP GPIO0 GPIO1(TX) GPIO3(Rx) EN 0V 3.3V Wifi BLE click USB 0V Rx Tx 3.3V 0V 3.3V (ideally 300mA) Note: when GPIO0 is low (0V), the ESP32 enters ‘Bootloader’ mode, and this is exactly what we need to be able to load the new ESP32 AT firmware. However, when GPIO0 is high (3.3V), the ESP32 will be in normal execution mode. GPIO0 has an internal pullup resistor, so when this pin is unconnected, the ESP32 is in Normal mode. Now that the ESP32 is connected to the computer, we can load the new AT firmware. 3.3V USB-to-serial module EN D36 D39 D34 D35 D32 D33 D25 D26 D27 D14 D12 D13 GND VIN D23 D22 D1 D3 D21 D19 D18 D5 D17 D16 D4 D2 D15 GND 3V3 EN TX RX IO0 EN GND ESP32 EN GPIO36 GPIO39 GPIO34 GPIO35 GPIO32 GPIO33 GPIO25 GPIO26 GPIO27 GPIO14 GPIO12 GPIO13 GND VIN 0V TX RX Step 4: Upload Firmware Before running the ESP Flash Tool, make sure that you close any open terminal app program. This ensures that Windows frees up any COM port that would otherwise be assigned to to the USB-toSerial module. To launch the ESP Flash Tool, go to the folder unzipped in Step 1 Fig.6. The six connections shown here connect the USB-to-Serial module to the MIKROE ESP32 module and put it into Bootloader mode. It connects to UART0 on the ESP32. GPIO23 GPIO22 GPIO1 GPIO3 GPIO21 GPIO19 GPIO18 GPIO05 GPIO17 GPIO16 GPIO4 GPIO2 GPIO5 GND 3V3 UART 0 TX UART 0 RX UART 2 TX UART 2 RX BOOT Fig.7. (Right) Pin labelling on a typical ESP32 throughhole module. Positions of pins may vary between different manufacturers. that contains the executable file: flash_download_tool_3.9.4.exe Launch it, and the initial screen will be as shown in Fig.8a. The top option (Chip Type) will be set to ‘ESP8266’, and this will need changing. Click on the drop-down arrow (Fig.8b) and select ‘ESP32’ so that the screen now looks like Fig.8c. The other two options should be left set to ‘Develop’ and ‘UART’. On clicking the ‘OK’ button, you will see a screen like that shown in Fig.9. At the bottom, you should select the appropriate COM port (the one Windows assigns to the USB-to-Serial module) and the correct baud rate (115200). Next, in the top empty line near the top of the screen, select the three dots to open a file browser and select the extracted file factory_WROOM-32.bin from the firmware folder from Step 2 in your Downloads folder: Downloads\ ESP32-WROOM-32_AT_Bin_V2.4.0.0\ ESP32-WROOM-32-V2.4.0.0\factory In the smaller empty box on the right, enter the value 0x00. Now check all the other settings so they match that shown in Fig.10 (in particular, ensure ‘DoNotChgBin’ is ticked). With the settings configured, press the ‘START’ button. This will start the uploading process with a green progress bar at the bottom of the screen (Fig.11). Note that the ‘DetectedInfo’ box (left of screencentre) will also show some information, along with some other data shown in the box below that is not relevant, but confirms things are happening as expected. use two of them. To flash the firmware file into the ESP32 we have to connect our USB-to-Serial module to UART0. On the MIKROE ESP32 module, UART0 is accessed via a dedicated row of pins (along with the other pins we need to connect for flashing the firmware). Fig.6 shows how to connect the MIKROE ESP32 module to the USB-to-Serial module. If your module does not have a dedicated set of pins for flashing the firmware, then all the relevant pins on the module will be labelled with GPIO numbers (plus power and others for basic control, such as ‘Enable’) – Fig.7 Fig.8. On launching the ESP Flash Tool (left to right): a) change from the default ESP8266 option; shows an example. You will need b) use the drop-down; and c) select the ESP32 option. 48 Practical Electronics | May | 2023 Fig.9. (Left-top) The main screen of the ESP Flash Tool program. The COM port and BAUD rate need to be set so it connects to the USB-to-Serial module correctly. Fig.10. (Left-middle) The ESP Flash Tool program needs to be loaded with the AT Firmware File. The three dots highlighted will open a file browser from where you point to the location of the firmware .BIN file downloaded as part of Step 2. Fig.11. (Left-bottom) The upload process is triggered by pressing the ‘START’ button. Progress is indicated by the green progress bar at the bottom of the screen. After a short while, the upload process will finish, indicated by a full green progress bar, and a light-blue button in lower left corner stating ‘FINISH’. If you look at the ‘black screen’ behind the main window, you will also see some text, and the last line also confirms the process is finished (see Fig.12). The ESP Flash Tool program can now be closed, ready for the next step. Step 5: Testing To test that the ESP32 firmware upload has been successful, we need to alter the way that the ESP32 module is connected. We now need to connect our USB-to-Serial module to UART2 on the ESP32, and also ensure that we don’t put the ESP32 into Bootloader mode by removing the connection to GPIO0 (the internal pull-up resistor on this pin will ensure that the ESP32 is in Normal mode). Now make the four connections shown in Fig.13 and then launch your terminal app to communicate directly with the ESP32 and begin sending AT commands to it. For the following demonstration, we will be using TeraTerm as our terminal app. Begin by connecting TeraTerm to the COM port that Windows assigns to the USB-to-Serial module. Note that there are two settings within TeraTerm that you may need to alter: 1. In the ‘Setup-Terminal…’ menu, ensure ‘Receive’ is set to ‘CR’, ‘Transmit’ is set to ‘CR+LF’, and ‘Echo’ is unticked (see Fig.14). 2. In the ‘Setup-Serial port…’ menu, ensure that ‘Speed:’ is set to 115200, and the other settings on this page match those shown in Fig.15. With the settings configured correctly, simply type AT and then press enter. The ESP32 should respond with OK. If so, then all is good. However, if you don’t see the OK response then first check the four connections (Fig.13), and then re-check the terminal app settings (Fig.14 and Fig.15). Fig.12. When the upload is complete, the screen will display a blue FINISH message in the lower-left corner. Practical Electronics | May | 2023 49 Fig.15. (Right) TeraTerm’s Serial port settings need to match those shown here (speed: 115200 baud). TX RX EN IO0 GND ESP32 NC NC RST NC CS TX NC RX NC NC NC NC 3V3 NC GND GND Wifi BLE click 3.3V USB-to-serial module 0V TX RX Two common mistakes are an incorrect baudrate (speed) setting (115200), and also the Tx and Rx connections swapped over. Remember, Tx on the USB-toSerial module goes to Rx on the ESP32 (GPIO16), and Rx on the USB-to-Serial module goes to ESP32 Tx which is GPIO17. If it still doesn’t work, then it is likely to be a power issue. As explained, a 3.3V power supply is required; ideally, capable of supplying a minimum of 250mA. So, if connections and settings are correct but you are still not seeing the OK response, then power the ESP32 module from the 3.3V output from the PicoMite (Pin 36). When you’ve achieved an OK response after sending the AT command, you can proceed to check that the version of the ESP32 firmware is correct (ie, the firmware update has worked). To do this, type the command AT+GMR and it will respond with the version number of the installed firmware (see Fig.16). If all has worked, then you will see something similar to: AT version:2.4.0.0(4c6eb5e - ESP32 - May 20 2022 03:11:58) SDK version:qa-test-v4.3.3-20220423 compile time(5641e0a):May 20 2022 11:12:05 Bin version:2.4.0(WROOM-32) OK Fig.13. The four connections above put the ESP32 into Normal mode, allowing it to receive AT commands directly from a terminal app such as TeraTerm. If you don’t see the updated firmware version number, then repeat the upload process. However, if you have followed the above process step-by-step then this is unlikely to be incorrect. Congratulations, you have successfully updated the ESP32 with the required firmware version in preparation for Part 2 next month. Next time Next month, we’ll configure the Philips Hue Hub and assemble a test circuit – based on a PicoMite and ESP32 – to check we can communicate with the Hue Hub via Wi-Fi. Until then, stay safe, and have FUN! Fig.16. To test if the ESP32 firmware upload was successful, use the AT+GMR command, and check the version number – here, 2.4.0.0. Fig.14. Ensure that the settings in TeraTerm’s Terminal settings page match those shown here. 50 Questions? Please email Phil at: contactus<at>micromite.org Practical Electronics | May | 2023