Silicon ChipMake it with Micromite - July 2021 SILICON CHIP
  1. Outer Front Cover
  2. Contents
  3. Subscriptions: PE Subscription
  4. Subscriptions: PicoLog Cloud
  5. Back Issues: PICOLOG
  6. Publisher's Letter
  7. Feature: The Fox Report by Barry Fox
  8. Feature: Techno Talk by Mark Nelson
  9. Feature: Net Work by Alan Winstanley
  10. Project: ATtiny816 Breakout and Development Board with Capacitive Touch by Tim Blythman
  11. Project: Infrared Remote Control Assistant by John Clarke
  12. Project: Touchscreen Wide-range RCL Box by Tim Blythman
  13. Feature: Practically Speaking
  14. Feature: PIC n’Mix by Mike Hibbett
  15. Feature: AUDIO OUT by Jake Rothman
  16. Feature: Make it with Micromite by Phil Boyce
  17. Back Issues: Circuit Surgery by Jake Rothman
  18. Feature: Circuit Surgery by Ian Bell
  19. Feature: Max’s Cool Beans by Max the Magnificent
  20. Feature: Max’s Cool Beans cunning coding tips and tricks
  21. PCB Order Form
  22. Advertising Index

This is only a preview of the July 2021 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 30: WeatherDemo explanation, and a PCB for the MKC I n this article we will conclude with any parameters (ie, location and WeatherDemo API key) being part of the request (here, t h e t o p i c o f Wi - F i i n t e r n e t Now, back to explaining how last month’s ?q=London,uk and &APPID=XXXXXX). connectivity for the Micromite by WeatherDemo program works. Fully Once this request has been processed by briefly explaining how last month’s appreciating that you are reading an their server, a response is sent back to your WeatherDemo program works. This electronics magazine rather than a coding browser. Their response is in the JavaScript really amounts to a discussion about two magazine, we will once again limit this to Object Notation (more commonly known things: first, how to send a GET request to discussing the building block steps used as a JSON response) and your browser is openweather.org (containing the location rather than going into the full details behind able to display the returned data in the that you input when the program is run); each and every command and line of code format shown in Fig.1. and second, how the serial data is then used. Remember that the Micromite User Note that the above method uses a extracted from the ESP32 module, which Manual can be referred to for an explanation computer’s browser, but of course we’re ultimately contains the weather data for of any MMBASIC command used in the using an ESP32 module and a Micromite the requested location. program. Likewise, the use, and structure, instead. So ideally we need a simple We then proceed with a new idea that of each AT Command used is detailed on Micromite way to somehow send the above has come about following feedback from the ESP manufacturer’s website (http:// request. Without going into too much detail, several PE readers. The underlying concept bit.ly/pe-may21-exp). In addition, there your browser is actually sending a GET of the Micromite Keyring Computer (MKC) is more information about any request request to openweathermap.org and this was always for it to be an easy DIY project parameter options on the openweathermap. is something the ESP32 can easily handle. that utilises just a handful of low-cost org website (API documentation). To be more specific, a TCP connection through-hole components; with these is first made by the ESP32 module to the components simply being soldered onto a Sending a GET request openweathermap.org server, and once readily available piece of stripboard. This Last month, we discussed how to sign up a connection is made, an HTTP GET concept was also applied to subsequent for an openweathermap.org account in request is then sent. The ESP32 then hardware add-ons, such as the Development order to get an API key. We also showed receives an HTTP response from the Module (DM), for example. you how to test your unique API key by openweathermap.org servers (in JSON However, even though the topics typing the following request into a webformat), and finally the TCP connection and projects covered in this series have browser (replacing the XXXXXX with your is closed. been very well received, some readers API key): have highlighted that it is rather a timeconsuming process to prepare the required api.openweathermap.org/data/2.5/ AT+CIPSTART stripboard (ie, having to cut out the correct weather?q=London,uk&APPID=XXXXXX Fortunately, the ESP32 has an AT size and shape, then making the trackcommand that makes it easy to establish cuts in all the correct positions, and then This effectively sends a request to the required TCP connection. The having to solder any required wire-links openweathermap.org for some data, command’s format is: into place). The best way to remove the need for preparing a piece of stripboard is to simply offer an alternative construction route with a PCB. So, this month we introduce the MKC PCB, the first in a planned set for the Make it with Fig.1. You can use a web browser and your API key to get the weather data for any location (see text). Shown here Micromite series. is weather data for London. 54 Practical Electronics | July | 2021 AT+CIPSTART="TCP","host",port_number where host needs to be set in our example to openweathermap. org (or the equivalent IP address), and port_number needs to be set to 80. We are sending this AT command with the SendAT subroutine discussed last month, so we will need to load it into AT_CMD$ as a string. However, MMBASIC needs to send each double quote character within a string as CHR$(34), and hence AT_CMD$ needs to be set as follows: AT_CMD$="AT+CIPSTART="+Chr$(34)+"TCP"+Chr$(34)+"," +Chr$(34)+"api.openweathermap.org"+Chr$(34)+",80" This may seem a little confusing at first glance, but just remember that an MMBASIC string needs to be surrounded by double quotes, and multiple strings can be joined together with the + character. When the AT_CIPSTART command is sent to the ESP32 module (by calling the SendAT subroutine), an attempt to establish a TCP connection is made. Assuming the ESP32 module is connected to a Wi-Fi network with Internet access, and also assuming the remote server at openweathermap.org exists (and is up and running), then a TCP connection will be established. This will result in the ESP32 sending back a "CONNECT" and an "OK" to the Micromite. You can refer to the ESP user manual for more details on this command. AT+CIPSEND Once a TCP connection is established with a remote server, the command AT+CIPSEND needs to be sent. This will cause the ESP32 to respond with an "OK" and ">" (or with "ERROR" should anything be wrong). This command puts the ESP32 module into what is called data sending mode, which means that any characters now sent to the ESP32 (from the Micromite) will be sent to the remote server that the ESP32 is currently connected to. Thus, we can now send our GET request (see next section). Note that to terminate the data sending mode, three consecutive + characters need to be sent. On sending "+++", and providing the data was successfully sent to the server, the ESP32 will respond with "SEND OK". The GET request In our WeatherDemo program code, we simply load the required GET request into the string WWcmd$, and then use PRINT #1 to send it to the ESP32 module. Let’s take a closer look at the exact format of the GET request. Above, we gave an example of what needs to be typed into a browser; repeating it here, the format of the request is: api.openweathermap.org/data/2.5/weather ?q=London,uk&APPID=XXXXXX This can be viewed as comprising two parts: api.openweathermap.org and /data/2.5/weather?q=London,uk&APPID=XXXXXX What we do with the ESP32, however, is slightly different, bearing in mind that we already have a connection to the api.openweathermap.org server (ie, the first part of the request above) which was established by using the command AT+CIPSTART… So, we just need to send the second part – but this needs to be formatted correctly into the following three lines: line 1 GET followed by the second part above (carriage-return / line-feed) line 2 HTTP/1.0 (carriage-return / line-feed) line 3 (carriage-return / line-feed) Practical Electronics | July | 2021 If you refer to the program code, you should now understand how the above is being stored into the string WWcmd$ with: WWcmd$="GET /data/2.5/weather?q="+Place$+ "&units=metric&appid="+APIKEY$ WWcmd$=WWcmd$+Chr$(13)+Chr$(10)+"HTTP/1.0"+ Chr$(13)+Chr$(10)+Chr$(13)+Chr$(10) There are three things to point out here: 1. The location of London (in the browser example) is replaced with the string Place$. This string contains whatever location you type in when the program is run, making it much more flexible. 2. There is a units parameter that has been set to metric. This simply returns any temperature values in centigrade. If you would like to experiment further with other parameters, you should refer to the API documentation available on the openweathermap.org website. This provides full detail of all the available parameters and their permitted values. Just add them into the WWcmd$ string, each one starting with an & symbol as shown above. 3. Chr$(13)+Chr$(10) is the equivalent of a carriage return / line feed (often shortened to CrLf or CR/LF) Referring to the program code, after the correctly formatted GET request has been sent (with PRINT #1,WWcmd$), you can see that the code calls the GetData subroutine which waits for any response back from the remote server. It will wait up to a maximum of 1.8 seconds (ie, 1800ms) which is set by loading the value 1800 into variable AT_TimeOut. Extracting the data The GetData subroutine is called so that our program code can wait for any data received from the remote server. What should be received is effectively what you see in Fig.1. In other words, lots of data separated by colons, commas, and various brackets. As mentioned last month, if you look at the data closely, you will see that it generally follows the format: "parameter name":"parameter value". The GetData subroutine simply breaks all this data down into individual lines for displaying on the screen. It also checks to see if it receives either "cod":"200" (success) or "cod":"400" (error). If so, it means that there is no more data to be received, so it simply exits the GetData subroutine. At this point, the code can send "+++" to exit the data sending mode, and then it can close the TCP connection to the remote server by sending the command AT+CIPCLOSE. The program then loops back to request a new location input, and once entered, the whole process is repeated; ie, establish a TCP connection to the remote server, send a GET request, wait a brief while for the server response, display any response, and finally close the connection to the remote server. Fancy a challenge? This example has provided you with enough detail for you to experiment with connecting to other services that are available via the Internet. As always, the best way to learn is to simply experiment by yourself (and use Google if you need to – there is so much online information available). Remember that all we have used for this Wi-Fi topic is just a single low-cost ESP32 module, and four jumper wires (0V, 3.3V, Tx, and Rx) to connect the ESP32 to the Micromite. Everything else is then determined by software. So why not challenge yourself to try to connect your Micromite to some other servers. Perhaps see if you can get a listing of what is on television; or maybe try and get the prices of goods from an online retailer. For the really adventurous, try using POST (instead of GET) to send data to a remote server! 55 The MKC PCB Computer (MKC); and in Part 2, we worked through the MKC hardware assembly. The circuit diagram of the MKC is repeated below in Fig.2, and Back in the February 2019 issue we began the Make it with Micromite series, introducing the Micromite Keyring 0 V 0 V 5 V J1 0 V J2 ID 18 17 16 15 26 25 24 23 22 21 D + D – + 5 V R 2 5 V C 3 10 0 nF + 28 27 26 25 24 23 22 21 20 19 18 17 16 15 IC 1 M C P 170 0 3 V 3 D 1 3 mm 0 V + G nd C 1 10 µ F T ant V o u t + C 2 10 µ F T ant 3 .3 V R 3 1 2 3 4 5 6 7 8 9 10 11 12 13 14 J4 2 3 4 5 6 7 9 10 0 V R x I P o w er V in R ST R 1 PCB assembly IC 2 P I C 3 2 M X 170 F 2 5 6B -5 0 I / SP T x O U SB B r eak- o u t bo ar d J3 C 4 10 µ F T ant the assembled stripboard is shown in Fig.3. Following some useful reader feedback, we decided to create a PCB for this circuit, which is shown in Fig.4. The MKC PCB is the same size and shape as the original stripboard design; and all the connectors have been placed in identical positions. Naturally, the electronics remains the same as before. Hence, this PCB is a nice alternative to using the stripboard. Assembly is very straightforward, but there are a few things we wish to point out. 14 3 .3 V Fig.2. Circuit diagram for the Micromite Keyring Computer (MKC). Fig.3. The assembled MKC stripboard in the bottom part of the recommended enclosure. Fig.4. Rendered views of the MKC PCB: (left) component side, (right) underside. The silkscreen on the PCB follows the component labelling shown in the circuit diagram in Fig.2 (apart from IC1 and IC2 which are labelled ‘U1’ and ‘U2’). Note that the positions of some components have been slightly changed to improve the overall assembly process. For example, R1 has been moved from under the USB Break-out-Board (BoB), and the voltage regulator and LED no longer require their leads to be bent in an odd way; minor but worthwhile improvements. The three 10µF tantalum capacitors are polarised, as is the LED, so care needs to be taken with these to ensure they are installed the correct way round. The PCB has ‘+’ markings on the silkscreen to assist with this. Otherwise, everything is as before. We still solder the 28-pin Micromite chip directly into place (ie, no DIL socket), as this allows the enclosure’s top to be fitted correctly. If you are not going to mount the MKC in the recommended enclosure, then we suggest using a DIL socket. Once the PCB is assembled and mounted in the bottom part of the enclosure, it should look like Fig.5. When the top of the enclosure has been attached, your MKC is ready for use in exactly the same way as the original version. Do look out for upcoming articles for the other PCBs from the Make it with Micromite series. We will be creating one for the Development Module (DM) very soon. Simply contact micromite. org if you would like an MKC PCB, or a PCB version of the MKC kit. Next month Inspired by the IoT Cricket module that was introduced in last month’s Practical Electronics, in the next Make it with Micromite we will show you just how easy it is to connect a Micromite to a Cricket so that MMBASIC can trigger data to be sent to the internet. Until then, have FUN! Fig.5. The assembled MKC PCB mounted in the bottom part of the keyring enclosure. Note that the MKC PCB shown here is an early prototype. 56 Questions? Please email Phil at: contactus<at>micromite.org Practical Electronics | July | 2021