Silicon ChipTeach-In 2024 – Learn electronics with the ESP32 - August 2024 SILICON CHIP
  1. Contents
  2. Subscriptions
  3. Back Issues
  4. Publisher's Letter: Exciting News!
  5. Feature: Techno Talk - That makes so much sense! by Max the Magnificent
  6. Feature: Net Work by Alan Winstanley
  7. Project: LC and ESR Meter by Steve Matthysen
  8. Project: WebMite by Geoff Graham & Peter Mather
  9. Project: WebMite-based Watering System Controller by Geoff Graham
  10. Feature: Circuit Surgery by Ian Bell
  11. Feature: Audio Out by Jake Rothman
  12. Feature: Max’s Cool Beans by Max the Magnificent
  13. Feature: Teach-In 2024 – Learn electronics with the ESP32 by Mike Tooley
  14. Market Centre
  15. Advertising Index
  16. PartShop
  17. Back Issues

This is only a preview of the August 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:
  • 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)
Teach-In 2024 Learn electronics with the ESP32 by Mike Tooley Part 6 – The ESP32 as a Wi-Fi Access Point I n the previous part of our Teach-In series, we introduced the 1-wire and I2C bus interface standards and showed how you can easily add a low-cost LCD display to your ESP32 projects. Coding Workshop introduced maths operations and functions and our Teach-In Project featured the design, construction and coding of a simple environmental monitor displaying temperature, barometric pressure and humidity. This month, we begin to explore some of the ESP32’s inbuilt features that help make wireless communication a reality. We begin by introducing some of the basic concepts and terminology associated with Wi-Fi technology and how the ESP32 can scan for available networks to which it can connect. Our Practical Project shows how the ESP32 can be configured for use as a Wi-Fi Access Point, making environmental data from a low-cost sensor available for remote display on a smartphone, tablet, laptop or desktop PC. The learning objectives for the sixth part of our series are, know: n How to set up and use ESP32 Wi-Fi n  The difference between Station (STA) mode and Access Point (AP) mode n How to run a scan for nearby wireless networks n How to configure the ESP32 Wi-Fi in AP mode n  How to apply simple Arduino C++ string handling techniques n That HTML is used to display AP data in a web browser. Getting to grips with Wi-Fi Since this is the first time that we’ve used Wi-Fi in this TeachIn series it’s worth starting by explaining a few of the concepts that underpin the technology. By enabling connectivity without the need for cabling, Wi-Fi is now commonly used in modern homes and businesses. All ‘smart’ devices make use of Wi-Fi and even a humble item such as a doorbell now employs this technology. We will start by explaining some key terms before moving on to explain the two modes of connection that the ESP32 uses. Internet Protocol (IP) First proposed in 1974, Internet Protocol (IP) is simply a set of rules that facilitates the exchange of data between devices connected to a network. IP defines the structure of the packets that encapsulate the data to be delivered from a source to a host, and vice versa. Each packet consists of the data to be transmitted together with a header that incorporates an IP address. IP forms part of the layered protocol often referred to as ‘Internet protocol suite’, the different levels of which are categorised as Application, Transport, Internet and Link. 60 About Teach-In Our latest Teach-In series is about using the popular ESP32 module as a basis for learning electronics and coding. We will be making no assumptions about your coding ability or your previous experience of electronics. If you know one but not the other, you have come to the right place. On the other hand, if you happen to be a complete newbie there’s no need to worry because the series will take a progressive hands-on approach. There will be plenty of time to build up your knowledge and plenty of opportunity to test things out along the way. We’ve not included too much basic theory because this can be easily found elsewhere, including several of our previous Teach-In series, see: https://bit.ly/pe-ti https://bit.ly/pe-ti-bundle Earch month, there’ll be projects and challenges to help you check and develop your understanding of the topics covered. IP addresses For reasons that will be obvious, every device connected to a network needs to have its own unique address. This address is simply a 32-bit (IPv4) or 128-bit (IPv6) number. These are usually expressed as a sequence of bytes with the decimal values quoted for each. Here’s an example of a four-byte local IP address: 192.168.1.1. Note that devices connected to your own router are all members of the same network and can Fig.6.1. An ESP32 operating in Access Point (AP) mode. Practical Electronics | August | 2024 Fig.6.3. An ESP32 serving data to several ESP32 clients. versions of the ESP32 operate on the 2.4GHz band, but dualband versions (such as the ESP32-C5) have recently become available. The 5GHz band suffers from less congestion and can therefore be more reliable, but unfortunately it’s less robust and the range can be somewhat limited due to signal absorption and attenuation within buildings. For most purposes singleband operation at 2.4GHz is perfectly adequate for the ESP32. Fig.6.2. An ESP32 operating in Station (STA) mode. communicate using these local IP addresses without the need for an Internet connection. Service Set Identifier (SSID) An SSID is the name used to identify a Wi-Fi network and just comprises a sequence of alphanumeric characters. SSID is not case-sensitive and a default SSID is normally set by the equipment manufacturer and often appears printed on a label attached to the bottom or rear panel of a wireless router. The SSID can usually be changed easily if required. Dynamic Host Control Protocol (DHCP) IP addresses within the network are assigned by the router using Dynamic Host Control Protocol (DHCP). This process is automatic, and it occurs whenever a device first connects to the network. The router then updates its list of connected devices together with their allocated IP addresses. If you have the correct network privileges you can easily log into the router and view this list. Wi-Fi bands Wi-Fi communication operates in two discrete frequency bands. The original 2.4GHz band and the more recently available 5GHz band. Each of these bands is further subdivided into several channels, each with an allocated number. Most existing Fig.6.4. Typical output from Listing 6.1. Table 6.1 Summary of common Wi-Fi encryption methods Encryption Outline Wired Equivalent Privacy (WEP) Outdated but still widely used. Available in 64, 128 and 256-bit versions. Officially retired by the Wi-Fi Alliance in 2004. Wi-Fi Protected Access (WPA) Formally adopted in 2003, the most-common WPA configuration is WPA-PSK (Pre-Shared Key). The keys used by WPA are 256-bit, a significant increase over the 64-bit and 128-bit keys used in the WEP system. WPA originally employed Temporal Key Integrity Protocol (TKIP) but this was later superseded by the Advanced Encryption Standard (AES). Wi-Fi Protected Access II (WPA2) Officially superseded WPA in 2006. It uses AES algorithms and CCMP (Counter Cipher Mode with Block Chaining Message Authentication Code Protocol) as a replacement for TKIP which is still available in WPA2 (as a fallback) and to ensure interoperability with WPA. Wi-Fi Protected Access III (WPA3) First announced in 2018 and offering significant improvements over WPA2. It uses Protected Management Frames (PMF) to enable encryption of the data used for network management (in addition to that used for the data itself). Also incorporates other security enhancements and protection against brute force and offline attacks. WPA3 192-bit Enterprise Mode currently offers the most advanced Wi-Fi encryption. Practical Electronics | August | 2024 61 Listing 6.1 A simple ESP32 Wi-Fi scanner /* Simple Wi-Fi Network Scanner */ #include “WiFi.h” void setup() { Serial.begin(115200); // Initialise WiFi WiFi.mode(WIFI_STA); WiFi.disconnect(); delay(1000); // Short delay } void loop() { Serial.println(“Starting scan ...”); int n = WiFi.scanNetworks(); // n is number of networks discovered Serial.println(“Scan completed!”); if (n == 0) { Serial.println(“No networks discovered!”); // Alert if none found. } else { Serial.print(n); Serial.println(“ networks found”); Serial.println(“No.\tSSID\t\t\t\t\t\RSSI\tCH\tEncryption”); for (int i = 0; i < n; ++i) { // Print SSID and RSSI for each network found Serial.printf(“%2d”, i + 1); Serial.print(“\t”); Serial.printf(“%-32.32s”, WiFi.SSID(i).c_str()); Serial.print(“\t”); Serial.printf(“%4d”, WiFi.RSSI(i)); Serial.print(“\t”); Serial.printf(“%2d”, WiFi.channel(i)); Serial.print(“\t”); switch (WiFi.encryptionType(i)) { case WIFI_AUTH_OPEN: Serial.print(“open”); break; case WIFI_AUTH_WEP: Serial.print(“WEP”); break; case WIFI_AUTH_WPA_PSK: Serial.print(“WPA”); break; case WIFI_AUTH_WPA2_PSK: Serial.print(“WPA2”); break; case WIFI_AUTH_WPA_WPA2_PSK: Serial.print(“WPA+WPA2”); break; case WIFI_AUTH_WPA2_ENTERPRISE: Serial.print(“WPA2-EAP”); break; case WIFI_AUTH_WPA3_PSK: Serial.print(“WPA3”); break; case WIFI_AUTH_WPA2_WPA3_PSK: Serial.print(“WPA2+WPA3”); break; case WIFI_AUTH_WAPI_PSK: Serial.print(“WAPI”); break; default: Serial.print(“Not known”); } Serial.println(); delay(10); } } Serial.println(“”); WiFi.scanDelete(); // Tidy up delay(5000); // Delay before the next scan } 62 Gotcha! To avoid making your network vulnerable and prevent an ‘Evil Twin’ attack, it is considered good practice to change your router’s SSID. You will find further information in the documentation supplied with your router. Received Signal Strength Indicator RSSI provides you with an indication of the strength of a Wi-Fi signal. The greater the RSSI the better the signal quality with less susceptibility to errors. Strictly speaking, RSSI is a relative measurement whereas ‘dBm’ is an absolute measure of the power received from a Wi-Fi antenna. Despite this, RSSI is normally expressed in ‘dBm’ (decibels relative to 1mW) and a value of -70dBm (or greater) is often quoted as an indicator of good Wi-Fi performance. Note, however, that values in the range -70dBm to -90dBm can still prove satisfactory provided there is no co-channel contention. Security and encryption Since the introduction of Wi-Fi in the late 1990s, Wi-Fi has always had some form of security algorithm to provide for user authentication and communication encryption. Several different forms of data encryption help make networks more secure. Some that you are most likely to encounter are listed in Table 6.1. In order of effectiveness, Wi-Fi encryption methods are usually ranked in the following order: 1. WPA3 (currently the most effective security) 2. WPA2 plus AES 3. WPA plus AES 4. WPA plus AES with fallback to TKIP 5. WPA plus TKIP 6. WEP 7. Open network (no security at all). ESP32 connection modes The ESP32’s Wi-Fi API (Application Programming Interface) provides support for the industry standard IEEE 802.11b/g/n protocol driver. So, when connected to a network the ESP32 can be configured either in Access Point (AP) mode (Fig.6.1) or in Station (STA) mode (Fig.6.2). Gotcha! The negative values that are used when quoting RSSI simply indicate that the received signal power is below 1mW. Therefore, large negative values of RSSI correspond to weaker signals. You should also note that the decibel (dB) measure is logarithmic so that, for example, a power difference of 20dB actually corresponds to a ratio of 100:1. Practical Electronics | August | 2024 Gotcha! It’s easy to confuse different Wi-Fi configurations. In AP Mode the ESP32 provides its own Wi-Fi network to which other devices connect, but in STA Mode the ESP32 just connects to an AP provided by another device, usually a wireless router. In STA mode the ESP32 connects to another Wi-Fi network such as that provided by a nearby wireless router. In this mode the ESP32 effectively becomes a Wi-Fi client. Note that, whereas the AP to which the ESP32 connects is usually a router, an AP could also be provided by another ESP32 acting as a server. When operating in AP Mode, Wi-Fienabled devices (such as a smartphone, tablet or PC) can connect to the ESP32. In this situation, the ESP32 creates its own Wi-Fi network to which other WiFi devices can connect. In this mode, the ESP32 serves HTTP data that can be read and displayed using a Web browser running on a client device (Fig.6.3) Check it out! The time has come to make use of the ESP32’s Wi-Fi capability, so let’s get started by carrying out a scan to discover the available networks. Depending on where you live this can be as few as one (the Wi-Fi network provided by your own wireless router) to well over a dozen! Each network will display a different SSID and each will have a particular encryption method. We need to start by initialising the ESP32’s Wi-Fi in Station Mode (STA) using a line of the form: WiFi.mode(WIFI_STA); // Initialise in STA mode However, if by chance, the ESP32 has already been connected to an Access Point (AP) we first need to disconnect from it by using: WiFi.disconnect(); // Disconnect from an AP Then we need to scan the available networks, and determine the SSID and encryption method for each one. We will send the results using the ESP32’s serial print function so that they can be Listing 6.2 Code for this month’s Practical project /* Basic WiFi Access Point with an ESP32 sending temperature and humidity data obtained from a DHT22 sensor. Uses the DHT22 library file by dvarrel */ #include <WiFi.h> #include <WebServer.h> #include <DHT22.h> // Enter your chosen SSID and password here const char* ssid = “ESP32”; const char* password = “12345678”; // Create an instance of the DHT22 class and // set the digital I/O to pin-21 DHT22 dht22(21); // Configure the IP address IPAddress local_ip(192, 168, 1, 1); IPAddress gateway(192, 168, 1, 1); IPAddress subnet(255, 255, 255, 0); WebServer server(80); void setup() { // Use the serial monitor Serial.begin(115200); // Configure WiFi connection WiFi.softAP(ssid, password); WiFi.softAPConfig(local_ip, gateway, subnet); delay(100); // Enable the AP server server.on(“/”, handle_OnConnect); server.onNotFound(handle_NotFound); server.begin(); Serial.println(“HTTP AP started”); } void loop() { server.handleClient(); } void handle_OnConnect() { Serial.println(“Reading data...”); // Read the DHT22 sensor float humidity = dht22.getHumidity(); float temperature = dht22.getTemperature(); server.send(200, “text/html”, SendHTML(temperature, humidity)); } void handle_NotFound() { server.send(404, “text/plain”, “Not found”); } String SendHTML(float temperature, float humidity) { String ptr = “<!DOCTYPE html> <html>\n”; ptr += “<head><meta name=\”viewport\” content=\”width=device-width, initial-scale=1.0, user-scalable=no\”>\n”; ptr += “<title>ESP32 Access Point</title>\n”; ptr += “<style>html { font-family: Helvetica; display: inline-block; margin: 0px auto; text-align: center;}\n”; ptr += “body{margin-top: 50px;} h1 {color: #006600;margin: 50px auto 30px;} h2 {color: #660099;margin-bottom: 50px;}\n”; ptr += “</style>\n”; ptr += “</head>\n”; ptr += “<body>\n”; ptr += “<h1>ESP32 Access Point</h1>\n”; ptr += “<h2>Temperature: “ + String(temperature) + “&deg;C</h2>\n”; ptr += “<h2>Humidity: “ + String(humidity) + “%</h2>\n”; ptr += “</body>\n”; ptr += “</html>\n”; return ptr; } Fig.6.5. ESP32 and DHT22 interconnection. Practical Electronics | August | 2024 63 Gotcha! When exploring your network environment, it’s always worth scanning several times to see if anything has changed. Wi-Fi networks are dynamic, and you will find that some will appear and disappear sporadically from the network list. displayed using the IDEs and display them on our host PC. Since a further scan might reveal something different we will repeat this process every five seconds. Each time deleting the results of the previous scan in order to free memory. This is achieved using: Fig.6.6. Layout diagram for Fig.6.5. WiFi.scanDelete(); // Tidy up and free some memory The code for our simple Wi-Fi scanner is shown in Listing 6.1. Fig.6.4 shows typical output produced by Listing 6.1. It’s worth taking a close look at this. The Wi-Fi networks found are displayed in strict order of received RSSI (strongest at the top of the list). If you look at the RSSI column you will see that the best signal (at -54dBm) is received from one of the stations on the BTWholeHome network while the weakest (at -97dBm) is being received from the BT-PRFK5J network. You should also note that five of the networks are operating on Channel 11, three on Channel 1, and one on Channel 6. Note that BTWholeHome is a mesh network with three separate connecting points, one on each floor of the house. Fig.6.4 also reveals that the most common encryption method is WPA2, with one network using WPA+WPA2, and another is ‘open’ (with no encryption). Practical project We mentioned earlier that in AP mode the ESP32 can create its own Wi-Fi network to which other smart devices can be connected. This allows you to monitor and view data remotely without the need for a wireless router or host computer. To show how useful this is we’ve created an application based on the DHT22 temperature and humidity sensor that we met last. month. The complete code for our Practical Project is shown in Listing 6.2. Note that Gotcha! You might have noticed that we’ve used ‘\t’ in several of the Serial. println statements of Listing 6.1. The \t simply inserts a nonprinting tab character in the string to be printed and this can be used to ensure that the text is aligned neatly. 64 Fig.6.7. Serial monitor output from Listing 6.2. Fig.6.8. Typical Wi-Fi configuration screen on a desktop PC. we need to include three libraries at the beginning of the code. This is done with the following lines: #include <WiFi.h> ESP32 Wi-Fi // To use #include <WebServer.h> // To use the ESP32 as a web server #include <DHT22.h> the DHT22 sensor // To use It may not be necessary to download and install all of these library files as you might already have them. If not, just go to the IDE’s Library Manager (as described in earlier parts of this Teach-In series). In Listing 6.2 we have included several lines of code that are needed to configure the IP address used by the ESP32. Note that we’ve set the local IP address to 192.168.1.1. This is the address that you will need to enter into your browser’s address bar to access the hypertext transfer language (HTML) data served by the ESP32. Rather than just display plain text, we’ve included some HTML tags to improve the appearance of the data. Practical Electronics | August | 2024 Listing 6.3 Some examples of string handling /* Some simple examples of string handling */ #include <string> void setup() { Serial.begin(115200); } void loop() { Serial.println(“String handling examples ...”); char firstString[] = “Practical Electronics”; int n = strlen(firstString); Serial.print(“First string length = “); Serial.println(n); // Print the first string Serial.println(firstString); // Print the first character Serial.print(“First character = “); Serial.println(firstString[0]); // Print the last character Serial.print(“Last character = “); Serial.println(firstString[n - 1]); String secondString = “ ESP32 “; // Print the second string Serial.print(“Second string = “); Serial.println(secondString); // Trim leading and trailing spaces secondString.trim(); // Print the trimmed string Serial.print(“Trimmed string = “); Serial.println(secondString); // Shorten a string String thirdString = “OUTPUT DATA”; // Print the third string Serial.print(“Third string = “); Serial.println(thirdString); String subString = thirdString.substring(0, 3); Serial.print(“First three characters = “); Serial.println(subString); while (1) // Suspend execution ; } These appear between the <style> and </style> tags. Between the <body> and </body> tags you will find the three lines of text that will actually be displayed on the client device. This text inherits the properties (font, colour, margins and so on) that we’ve previously defined between the <style> and </style> tags. Fig.6.5 and 6.6 respectively show the circuit and wiring layouts for the Practical Project – the interconnection of the DHT22/ ESP32. You will find that these are identical to the diagrams that we used in our previous Teach-In (refer to this if you need further information on the DHT22 temperature and humidity sensor). To test the Practical Project you will need to enter or download the code from the PE website at: https://bit.ly/pe-downloads Open the file in the IDE and then compile and execute the code. If you’ve followed the series thus far this should be a breeze! You might then want to check that the AP is up and running. To do this, start the Serial Monitor and then press the ESP32’s reset button. You should be rewarded with a ‘power-on’ message like that shown in Fig.6.7. This confirms that the AP is operational. If you look at the code in Listing 6.2 you should find that we’ve allocated an SSID of ‘ESP32’ and used ‘12345678’ as the password. This isn’t particularly imaginative, and you are welcome to change both. However, at this stage we will assume that you’ve kept our default values. Fig.6.9. (Top right) Typical network selection screen on a smartphone showing the ESP32 as an available Access Point (AP). Fig.6.10. (Bottom right) Connecting to the ESP32 AP. Practical Electronics | August | 2024 65 Fig.6.12. Desktop PC browser showing data served by the ESP32 in AP mode (note the IP address in the browser’s address bar). Now select your client device. This can be a desktop, laptop, tablet or smartphone equipped with Wi-Fi and a web browser. For a typical Widows PC go to Network and Internet settings, select Wi-Fi, and then click on ‘Show available networks’ as shown in Fig.6.8. Examine the list of available networks and then select ‘ESP32’ Fig.6.11. Entering the ESP32’s network security key (the as shown in Fig.6.9. password). Click on ‘Connect’ (see Fig.6.10) and enter the password ‘12345678’ as shown in Fig.6.11. There’s one final step to complete the project. Having connected your device to the ESP32 AP you will need to open a browser and enter the IP address that we’ve assigned. This should be entered into the browser’s address bar as ‘192.168.1.1’. You will be rewarded with the page that your ESP32 is currently serving, and it should look like that shown in Fig.6.12 although the displayed data will, of course, be different. If you are using a tablet or smartphone the procedure will be similar. Fig.6.13 shows a typical list of Wi-Fi networks displayed using a smartphone while Fig.6.14 shows the page provided by the ESP32 after entering the same IP address and connecting to it. Coding Workshop As you begin to experiment with your own ESP32 applications you will sooner or later begin to feel the need for code that will allow you to manipulate strings of characters. This Coding Workshop Fig.6.13. (Left) Selecting the ESP32 AP using an Android smartphone. 66 Gotcha! Arrays in the C++ language are indexed from zero. This means that the first element stored in an array has an index of 0 and for a string comprising n characters the last element will have an index of (n-1) provides you with some pointers to help you along the way. Strings are just a series of alphanumeric characters stored in array. You have already met quite a few of them, for example: HTTP started … and text/ html in Listing 6.2. Each of these strings is enclosed in quotation marks but note that an opening quote must always have a matching closing quote! The characters in these strings are stored in a series of memory locations that we refer to as an ‘array’. Here’s an example of some alphanumeric text stored in an array. char titleString[] = “Practical Electronics”; The 21 characters of ‘Practical Electronics’ are stored in 21 consecutive memory locations and they are individually indexed (from 0 to 20) within the Gotcha! Once again, if you find that the Serial Monitor displays gobbledygook instead of a series of meaningful values, you should first check that you have set a baud rate that matches the speed that you’ve specified in your code. The examples in this instalment all configure the ESP32’s serial port for operation at 115200 baud. To work correctly this must match the value that you’ve set in the Serial Monitor. Practical Electronics | August | 2024 spending a little time experimenting with this code to get a feel for just how useful this can be. The output from Listing 6.3 is shown in Fig.6.15. Check Point Now that we’ve reached the half-way point in our Teach-In series Check Point replaces our usual Teach-In Challenge. This is a great opportunity to test your knowledge of the ESP32. Just select one answer to each of these questions. When you’ve finished you can check your answers at the bottom of page 16. Good luck! Fig.6.14. Smartphone showing data served by the ESP32 in AP mode (note the IP address in the browser’s address bar). 1. The maximum integer number that can be represented using unsigned eight bits is: (a) 7 (b) 15 (c) 255. 2. In-line comments are preceded by: (a) * (b) // (c) $. 3. In which band does ESP32 Wi-Fi normally operate? (a) 1.2GHz (b) 2.4GHz (c) 5GHz. 4. The expression delay(50); will suspend the execution of code for: (a) 5s (b) 50s (c) 0.050s. 5. Analogue output from an ESP32 is based on: (a) Amplitude modulation (AM) (b) Frequency modulation (FM) (c) Pulse-width modulation (PWM). 6. 16-bit numbers with no decimal points are referred to as: (a) Bytes (b) Integers (c) Floating point. Fig.6.15. Output from Listing 6.3. character array. For example, to extract and print the eleventh character we could use: Serial.println(titleString[10]); You’ve hopefully concluded that this would output ‘E’ (the eleventh item in the array) on the Serial Monitor. The sample code shown in Listing 6.3 shows ways in which strings can be accessed and also modified using the trim() function (to remove leading and trailing spaces) and the substring() function (to create a substring from consecutive characters within the original string). It’s worth Gotcha! When entering your code remember that character strings to be printed need to start and end with matching opening and closing quotation marks. An error will occur if you don’t do this and the compiler will reject your code. Practical Electronics | August | 2024 7. In the first byte of an I2C transfer, how many bits are used to convey the address? (a) Four bits (b) Seven bits (c) All eight bits. 8. When an LED is conducting, its: (a) Anode is positive with respect to its cathode (b) Cathode is positive with respect to its anode (c) Cathode is at the same potential as its anode. 9. To set the state of a digital I/O pin you would use: (a) outputSet(); (b) digitalWrite(); (c) outputWrite();. 10. The I2C interface standard allows for a maximum of: (a) 15 devices (b) 63 devices (c) 127 devices. 11. The speed at which serial data is transferred is often quoted in: (a) Baud (b) Hertz (c) Mbyte. 67 12. In an I2C bus: (a) Only slaves can be present (b) Only one bus master can be present (c) More than one bus master can be present. 13. The ESP32’s magnetic sensor is based on: (a) Hall effect (b) Ohm’s Law (c) Charge conservation. 14. Which one of the following gives the typical forward current for a small LED indicator? (a) 5mA (b) 50mA (c) 500mA 15. Internal pull-up and pull-down resistors are provided for use with: (a) All of the ESP32’s digital I/O pins (b) None of the ESP32’s digital I/O pins (c) Some of the ESP32’s digital I/O pins. 16. On an SPI bus the bus lines are: (a) Usually pulled high and driven low when data is present (b) Usually pulled low and driven high when data is present (c) Always left floating regardless of whether data is present. 17. When x = 2 and y = 3 the maths expression pow(x, y) will evaluate to: (a) 6 (b) 8 (c) 9. Your best bet since 18. The maximum HIGH state voltage that can appear on any of the ESP32’s GPIO pins is: (a) +2V (b) +3.3V (c) +5V. 19. Which one of the following lines of code will generate an error? (a) int a = 3.142; (b) delay(60000); (c) pinMode(19, OUTPUT); 20. Switch bounce results in: (a) A rapid and undesirable change in logic levels (b) The inability of a switch to remain in the currently selected state (c) Unwanted delay before the contacts of a switch open or close. Answers are at the bottom of page 16. How did you do? If you scored 18 or more, you’ve already become an ESP32 expert. If you scored between 15 and 18, you’re already well on the way. If you scored less than 15 it’s worth taking another look at the earlier parts of this Teach-In series. Next month In next month’s Teach-In we will be introducing Network Time Protocol (NTP). Our Practical Project will take the form of an accurate clock that displays network time on a 16 × 2 character LCD. Coding Workshop will look at arrays and array handling. MAPLIN Chock-a-Block with Stock Visit: www.cricklewoodelectronics.com Or phone our friendly knowledgeable staff on 020 8452 0161 Components • Audio • Video • Connectors • Cables Arduino • Test Equipment etc, etc JTAG Connector Plugs Directly into PCB!! No Header! No Brainer! Our patented range of Plug-of-Nails™ spring-pin cables plug directly into a tiny footprint of pads and locating holes in your PCB, eliminating the need for a mating header. Save Cost & Space on Every PCB!! Visit our Shop, Call or Buy online at: www.cricklewoodelectronics.com 020 8452 0161 68 Visit our shop at: 40-42 Cricklewood Broadway London NW2 3ET Solutions for: PIC . dsPIC . ARM . MSP430 . Atmel . Generic JTAG . Altera Xilinx . BDM . C2000 . SPY-BI-WIRE . SPI / IIC . Altium Mini-HDMI . & More www.PlugOfNails.com Tag-Connector footprints as small as 0.02 sq. inch (0.13 sq cm) Practical Electronics | August | 2024