Silicon ChipIO Cricket - June 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: Touchscreen Wide-range RCL Box by Tim Blythman
  11. Project: Roadies’ Test Signal Generator by John Clarke
  12. Project: CONCRETO Speaker System by Allan Linton-Smith
  13. Feature: KickStart by Mike Tooley
  14. Feature: IO Cricket by Khairul Alam
  15. Feature: AUDIO OUT by Jake Rothman
  16. Feature: Make it with Micromite by Phil Boyce
  17. Feature: Circuit Surgery by Ian Bell
  18. Feature: Max’s Cool Beans by Max the Magnificent
  19. Feature: Max’s Cool Beans cunning coding tips and tricks by Max the Magnificent
  20. PCB Order Form
  21. Advertising Index

This is only a preview of the June 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)
IoT Cricket Khairul Alam – making the Internet of Things accessible for everyone Part 1: IoT made easy for everyone T he IoT (Internet of Things) connects our physical and digital worlds together. It transforms our lives as we adapt and become more efficient by using data collected from our environment. For example, as we analyse temperature, light and sunshine over time, we may be able to work out how to reduce energy usage. This is just one example of how IoT is playing an important role in transforming our lives. IoT connects various types of devices to the Internet and allows them to interact with each other. The ‘Thing’ in the IoT can be any device with any kind of built-insensor that has the ability to collect and transfer data over a network without any human interaction. Common sensor types measure temperature and humidity, light, pressure, proximity, linear and angular position (accelerometers and gyroscopes), noise and air quality; RFID (radio-frequency identification) devices can also be. How IoT works An IoT system normally comprises the following four fundamental components. (Fig.1 shows the IoT components and the interconnection among them.) 1. Device In an IoT system, a ‘device’ is an end node. A system developer will probably spend a big portion of their time creating this stage. A typical IoT device contains one or more sensors and a processing unit. Usually, microcontrollers are used for collecting and processing sensor data and sending it to the Cloud. Up to now, to make a such device you might have required specialised programming and electronics knowledge. However, this is changing rapidly and later in this article I will introduce an IoT module that enables you to make your own IoT device without advanced programming and electronics knowledge. Md. Khairul Alam is an Assistant Professor at the University of Asia Pacific, Dhaka, Bangladesh. He is an independent Cricket developer and does not work for Things On Edge. 42 Fig.1. Main components of an IoT system [image credit: Rohm Semiconductor]. 2. Connectivity At the heart of IoT is ‘connectivity’, which is vital for all IoT devices. To enable remote monitoring and control an IoT device must connect to a server, and IoT designs are mostly based on a client-server model. In a typical client-server system, a server provides resources to one or more clients. The server can be a web server or mail server, and client examples include a smartphone, laptop or tablet. One server can provide resources to multiple clients simultaneously. In a dedicated IoT system, an IoT device and mobile apps act like a client and the server can be a Cloud or local server. It has been observed that many developers, especially hobbyists, do not want to use the Cloud. They prefer to set up their own servers and services within their own local network to save time, avoid subscription fees and to enhance privacy. Whether connecting to a local or Cloudbased server, you need to adopt a wired or wireless connection medium like Ethernet, Wi-Fi, GPRS, Bluetooth or LoRa. Each of these has advantages and trade-offs in terms of range, bandwidth and power consumption, so choosing the right one for your device is very important. Many developers prefer Wi-Fi because it is already widely adopted and almost everyone has Wi-Fi at home. There is no need for an extra device such as a proprietary IoT hub, which would introduce an extra layer of complexity translating proprietary RF signals to Wi-Fi; and also the extra cost, around £50 ($65). Wi-Fi also has greater bandwidth compared to other options. However, there is a big downside to Wi-Fi, which has greatly reduced its adoption in the IoT space – power consumption. Power requirements do not make Wi-Fibased IoT impossible, it’s just that not many companies have set themselves the challenge of addressing this issue. A few companies have started innovating in this space; Ring and Sonoff devices are good examples. Another company – Things On Edge – is one step ahead in this field. Although they don’t make a full IoT device, they have developed a compact Wi-Fi module to enable other makers to build their own Wi-Fi-connected IoT devices with excellent power efficiency. We will return to their product a little later in this article. 3. Data processing in the server Once the data is collected and stored, the server software may need to perform some Fig.2. The all-important ESP8266 chip. Practical Electronics | June | 2021 of your microcontroller IoT project. Often, you need embedded software engineering skills to perform this task. True, there are many YouTube tutorials and plenty of sample code available on the web, on which you can base your code development, but you will still have to do most of the heavy lifting yourself. Power matters Collected/processed information needs to be delivered to the end-user in some way, which can be achieved with a graphical dashboard, smartphone app or sending notification through text message or email. Also, users sometimes might want to interact with devices through apps. For example, a user may want to turn a smart light on or off using a mobile app. Another big problem with ESP8266 is its voltage compatibility and power consumption. It can consume the whole energy of a 1000mAh battery in less than a day – it’s power hungry. A further issue is its operating voltage range. It can tolerate 3V to 3.6V, which is not directly compatible with most commercially available battery technologies. If you use two AA battery in series to make 3V then you can only use a very small portion of the battery energy before the combined voltage drops below 3V. If you want to use a Li-ion cell or three AA cells then you must use some sort of voltage regulator or converter before connecting it to the chip to protect it from over-voltage damage. Beginners and even more experienced developers face difficulties solving this problem. If a designer really wants to solve it in a neat way in a small form factor then this is a big issue as they have to create a dedicated PCB design and produce a specialised board for their device. Besides, if you plan to power it from the battery using a voltage converter you must implement some sort of sleeping mechanism to keep your device alive for a couple of weeks without replacing the battery. If you are either a new or a learning maker then you are guaranteed to spend several sleepless nights solving these problems to make a reliable long-lived battery powered IoT device. Making your own IoT device Cricket is the solution Fig.3. Cricket’s pins and the peripherals you can connect to them. processing on the gathered data according to user requirements. Such processing might be simply checking sensor data; for example, humidity, temperature or a device’s state (on or off). However, in some cases complex processing is required; for example, identifying objects or predicting local weather by using machine-learning models. 4. User interface To get started with making an IoT device you need hardware that The good news is there are now a few companies addressing these can connect to the internet. The device should also have some issues and innovating in this space. They solve the problems I capability to attach a sensor and sample data from it. There are lots mentioned above by providing ‘product-ready’ IoT boards. One of development boards available in the market with that capability; of them is Things On Edge (www.thingsonedge.com) who offer the ESP8266 Node MCU is one of them. At the moment, it is one an ultra-low-power ESP8266-based IoT module called ‘Cricket’. of the most popular, cost effective and powerful IoT development Making a battery powered IoT device has never been easier as it can boards with built-in Wi-Fi functionality. be powered directly from regular batteries (eg, AAA, AA). Also, no The ESP8266 used on the board is a very popular System coding, programming or complex wiring is required. Fig.3 shows on Chip (SoC) IC manufactured by the Chinese company Cricket’s simple connections to different sensors and a battery. Espressif – see Fig.2. It consists of a 32-bit microcontroller and a Cricket is an ultra-low-power, battery-powered IoT Wi-Fi Wi-Fi transceiver (transmitter and receiver). It offers 11 GPIOs, module. It doesn’t require IoT hubs, any coding or programming which allow analogue input, digital input/output, PWM (pulse to connect your devices to a network. It comes with pre-installed width modulation) output and UART, SPI and I2C serial data software and free optional Internet services (MQTT, COTA). You can configure Cricket from a phone, laptop or remote COTA service communication protocols. Those last three are widely used in from any web browser. This means you do it entirely over the embedded systems. Most microcontrollers have at least one of air without connecting it to a USB cable. You can manage your them integrated in hardware. You can find a lot of sensors, display panels and other peripherals supporting these protocols for interfacing with microcontrollers. For example, most GPS and GSM modules use UART, whereas OLED displays or the MAX30102 (pulse oximeter sensor) use I2C. There are also some OLED displays that support the SPI protocol. The ESP8266 has a built-in Wi-Fi transceiver so you can easily connect it to the Internet via your Wi-Fi router. When you are connected to the Internet you can send or receive data using the chip from any part of the world. The chip can also work as a web server. Imagine the power of this tiny chip! You can make almost any IoT project using this device – a remote air pollution meter, temperature logging system, humidity and temperature monitor, smart home device, Wi-Fi-controlled robot, or anything else you can dream up. The reality though, is that these microcontrollers can’t do anything without coding and programming. This requires significant effort and a lot of time to write, upload, test Fig.4. Physical layout and pinout of a Cricket module. The device measures and troubleshoot before you can make a working version just 16.4 x 37.2mm – easily small enough for miniature portable technology. Practical Electronics | June | 2021 43 Fig.5. Three steps for making an IoT device using a battery powered Cricket module. device(s) remotely and integrate them to other systems using either MQTT or HTTP protocols. (If you’re not familiar with MQTT, don’t worry – I’ll cover this shortly.) Cricket can be powered directly from a 1.5V AAA battery without any boost converter (it has one built-in). Another great feature is it has a 3.3V output that you can use to power up your sensor using the same AAA battery. You can connect any 3.3V-compatible analogue or digital sensor. Some common analogue sensors that you can attach to Cricket are: LDR (light-dependent resistor), flex, analogue position, sound, LM35 or TIP36 temperature, pressure, moisture, assorted analogue gas detectors (air quality, LPG, CO2, CO), flame, rain, distance, weight and many others. Some common digital sensor you can directly use with the Cricket are PIR motion, button switch, fire detector, gas detector, vibration, magnetic door, parking and so on. Cricket handles power consumption very efficiently using an RTC (real-time clock) which makes it ideal for battery powered IoT device applications. It can run for several years using two AAA batteries. Of course, battery lifespan does depend on how frequently the device transmits data to a network. For example, imagine you wanted to make a device to monitor the soil moisture of a plant by checking the moisture level three or four times a day. You can set it all up easily from Cricket’s configuration panel. In this example, if you set it for operation four times a day then the device can serve more than two years from two AAA alkaline cells. Knowing the battery level for a remote device is an important feature. It's useful knowing when to replace batteries so that you don’t miss important data. Cricket has this functionality too – it comes with a built-in battery monitor and integrated temperature sensor. Thus, Cricket can monitor not only its own battery level but also its own temperature without using external sensors. Fig.4 shows the physical layout and pinout of a Cricket module. 44 Last, but not least, making a Cricketbased IoT device is not a matter of days. With Cricket you can build a complete IoT device in minutes with just three easy steps (see Fig.5). Step 1 First, attach your peripherals (sensor, button, switch…) to either the Cricket’s analogue or digital pins (an analogue peripheral to the analogue pin; digital peripheral to digital pins). Next, attach the battery to the BATT pin and GND. A single AAA cell is fine, but use two for longer life. Step 2 After attaching your peripherals you need to configure your Cricket and set its Wi-Fi credentials to read and send peripheral data to the server. You can do it graphically from a web browser – it’s easy. Step 3 The final step is to set up your preferred mobile app or web dashboard for receiving and monitoring data from the Cricket. Cricket supports MQTT and HTTP protocols, so you can integrate your device into almost any software and service. The software ecosystem Cricket inhabits is huge – you can choose from Home Assistant, Node-RED, Grafana, IFTTT, Blynk, Adafruit IO, automate.io, Domoticz and others. MQTT and HTTP protocols We’ve mentioned MQTT several times – but what is it? MQTT stands for 'Message Queuing Telemetry Transport', a simple lightweight messaging protocol created by IBM in 1999. It was primarily designed to create a reliable machine-to-machine (m2m) communication protocol. Over 20 years later it has become the most popular messaging protocol in IoT applications for device-to-Cloud and device-to-device communication. It has been widely adopted in most home automation systems and almost all Cloud services support MQTT. We use a client and server communication technique for serving Internet content, where a browser act as a client and the content is on the server. Unlike client-server, MQTT is a client and broker communication technique. In MQTT the clients (more accurately the devices) don’t send messages directly to each other but instead communicate through an MQTT broker. The device sending the data is called a ‘publisher’ and the receiving device is called a ‘subscriber’. If two devices want to communicate with each other they become connected via a common broker through a common channel called a ‘topic’. The word ‘topic’ refers to an alphanumeric string that the broker uses to filter messages for each connected client. The topic consists of one or more topic levels. Each topic level is separated by a forward slash (topic level separator). For example, myhome/kitchen/temp is a valid MQTT topic. Messages are published by things using a topic. When a thing subscribes to a specific topic, that device receives the message instantly if any other device publishes a message in that topic. Any device can publish to one or more topics, and at the same time it can subscribe to one or more topics. So, it is a bidirectional multi-device communication protocol. The MQTT broker takes care of the security, connectivity, authentication, message delivery and message storage. To learn more about the MQTT protocol, visit: hivemq.com/mqtt-protocol The above explained the basics of MQTT, but as a maker you will reasonably ask, ‘how do we actually use it in a device?’. Every MQTT broker has an address (eg, test.mosquitto.org) and a port number (eg, 1883). We use an address and a port number of a broker to set them on the IoT device to connect to that specific broker. For a secure connection you may also need to use a username and password. To publish a message you then create and use a topic in the program. A device that wants to receive that message must subscribe to this specific topic. Cricket has its own MQTT broker, and every Cricket is preconfigured for that broker. You don’t need to set anything Practical Electronics | June | 2021 unless you choose to use your own or a third-party MQTT broker. You can configure it graphically using a web browser. Every Cricket comes with a unique serial number which is a part of every MQTT topic of that Cricket, and every Cricket publishes data following a specific topic format (eg, /serial/param). You can access detailed information about this in Cricket’s documentation (www.thingsonedge.com/ documentation). simple temperature monitor using a Cricket IoT module and the ThingSpeak IoT platform. To do this you will need to configure the ThingSpeak platform and the following hardware: 1 × Cricket IoT module 1 × 2-slot AAA battery Fig.6. Choosing My Channels from the Channels dropdown. holder 2 × AAA battery HTTP operation ThingSpeak As well as MQTT, Cricket also supports HTTP (Webhook). HTTP works as a requestresponse protocol between a client and server. Webhook is an HTTP API on the server side. Every HTTP server has a unique URL address and any function on a server can be triggered by sending an HTTP request to that URL address. Usually, the HTTP address is a link composed with a unique private token string and only clients who have this address can send a request. There are different methods of creating requests, such as GET and POST (the most common ones). POST is used to send data to a server and GET is used to request data from the server. For example, suppose we want to publish sensor readings to a server. Then a simple HTTP POST request format can be as follows: Let’s start with ThingSpeak. This is an open-source IoT platform and you can send sensor data from Cricket to the Cloud in a few minutes Fig.7. Creating a new channel. using this IoT platform. It supports both MQTT and HTTP protocol and you can display real-time data using ThingSpeak ‘widgets’. You don’t have to use ThingSpeak; there are lots of alternatives, such as Blynk, Ubidots and Adafruit IO which can also be used easily with the Cricket. For now, we’ll stick to ThingSpeak, which is easy to configure with the following steps. Fig.8. Configuring the channel properties. http-host?api_key=your-api-key &temperature=value1&humidity= value2 Fig.9. The private view of the channel. Here, http-host will be a real HTTP URL address and your-api-key will be replaced with your own private api key for that host. In an HTTP request the name and value is separated by a = character. The name-value pairs are separated by a & character. The data sent to the server with POST is stored in the message body of the HTTP request. In the body request, data can also be send as a JSON (JavaScript Object Notation) object, as follows: { "field1": "30", "field2": "60" } Webhooks can be used to connect two different applications or services. So, leveraging Webhook you can connect Cricket with different third-party Internet service like IFTTT, Automate.io, Zapier, Facebook, email and others. Let’s make an IoT device! Some of the above may seem a little complex and ‘jargony’, but it’s actually much simpler to use than explain. In fact, we’ve now collected enough knowledge about IoT, so let’s apply that knowledge and make a Practical Electronics | June | 2021 Fig.10. Modifying ThingSpeak's default widget. 45 start this process, click on the My Channels sub-menu from the Channels dropdown (see Fig.6). A new page will open. Click on New Channel and a channel setting page will open, as shown in Fig.7. Step 2 Fig.11. Choosing the right widget. Give the channel a name and also provide two different names for Field 1 and Field 2. All other choices are optional. To save your configuration, click on Save Channel at the bottom of the page. Fig.8 explains how to do it. A channel with two charts will be created automatically, as in Fig.9. If you look carefully at the chart you will find that the field names you set earlier have appeared as the labels of the y-axes of the charts. The data for one field is temperature and the other is battery voltage level. We’ll set the data of these fields with an HTTP POST request from the Cricket. Step 3 Fig.12. Configuring the properties of the widget. Step 1 Open your browser and go to https://thingspeak.com – register for a free account and log in to that account. To collect and display data from Cricket you need to create a ‘channel’. To By default, ThingSpeak creates a line chart (graph) for all the fields. Let’s replace the chart for the battery level (field 2) with a more intuitive gauge. First, remove the field 2 chart by pressing the ‘×’ button in the top-right corner of chart 2 and then click on Add Widgets – as explained in Fig.10. The widget selection panel will appear, as shown in Fig.11. Choose Gauge and click on Next. It will lead you to the gauge configuration form. Choose a name and enter it in the name field and select field 2 from the field dropdown. All the other fields are optional. You can decorate the gauge by setting different colours for different ranges, as shown in Fig.12. After configuring, click on Create and a nice gauge will be generated for you. Step 4 For sending data using HTTP POST we need the host address and the API key. To get these, click on the API Keys tab and go to the API Requests section. From ‘Write a Channel Feed’ copy the selected portion (it starts with https:// and finishes before &field1) which includes the host address with your own private API key. This will be the HTTP POST URL and will be used to configure the Cricket’s communication type. This is explained visually in Fig.13. Step 5 Fig.13. Getting the API key and channel feed. Now the hardware – solder the red wire (+) from the battery holder to the Cricket’s BATT pin and the black wire (–) to the GND pin of the Cricket. The diagram (Fig.14) explains these connections. Step 6 Fig.14. Battery connection, LED and switch position for a Cricket. 46 Insert the batteries into the battery holder (check polarity and do use good quality, branded alkaline or ideally lithium types – cheap ones compromise performance and reliability). Press the Cricket’s button and check the blue LED glows. Keep pressing the button until the LED starts blinking (approximately five seconds). Cricket will now operate as a Wi-Fi hotspot. Practical Electronics | June | 2021 Fig.15. Connecting Cricket to a computer via a Wi-Fi network. Fig.17. Configuring Cricket for HTTP_POST and payload. Fig.16. Saving Wi-Fi name and password in Cricket. Fig.18. The completed dashboard shows a graph of the temperature and a battery gauge. Step 7 Go to the Wi-Fi option from your laptop and connect to toe_device – see Fig.15. Open the browser and go to this address: http://192.168.4.1 (this may happen automatically). Step 8 Put your Wi-Fi network’s name in the SSID field and the password in the Password field of the newly opened browser page and click the CONNECT button. When the status changes to CONNECTED (as in Fig.16) your Cricket is connected to the Internet. Step 9 Go to the Config tab and paste the copied text (Step 4) in the HTTP_POST URL field. (Note: if HTTP_POST is not set as the connectivity type, then click on default type until HTTP_POST appears.) Next, put the following JSON text in the payload field: {"field1":"#temp", "field2":"#batt"} The temperature of the internal temperature sensor will be set as the field1 value and the battery voltage level will be set as the field2 value. Turn on the RTC by sliding the on/off button to the right. Set the value for how often you want to send data to the server (once a minute in my case, but remember that power consumption is directly related to the wake-up time). Just like the RTC, enable the battery monitor and the temperature sensor by sliding the button to the right. It will activate data transmission to the Cloud. See Fig.17 for a visual explanation of the configuration. Finally, click on the power icon in the top-right corner of the page to load and restart the Cricket. After restarting it will start sending data to your ThingSpeak Cloud account at one-minute intervals. Go to your ThingSpeak channel and you will see Practical Electronics | June | 2021 the data in real time from the dashboard, as shown in Fig.18. (Note: if Cricket does not flash at your specified interval and data does not appear, then try power-cycling your Cricket.) Summary In this article I’ve provided an introduction to IoT, how it works and how you can build your own devices and connect them to phones, laptops and a software ecosystem. You also learned about the challenges makers face when building IoT devices and how emerging technologies like Cricket can overcome painful power and programming issues. I hope you have a good understanding of how to build a Wi-Fi-based, battery powered IoT device using Cricket and how to leverage MQTT/HTTP to send data to server. Why don’t you start today? In upcoming issues, I will show how to put together your own Cricket IoT home automation system. Cricket IoT special offer We hope this introduction to Cricket has inspired you to experiment with IoT and build your own lowcost, low-power Internet of Things projects. Things On Edge – the creators of Cricket – have a special offer for PE readers. Cricket’s regular price is £16, but with PE’s special discount code you can buy as many as you like for £13.95. UK shipping is £1.99, or free (worldwide) for purchases over £48. To get your Cricket discount, just enter promo code PE-IOT-JUN21 when you check out at the Things On Edge online shop: www.thingsonedge.com/product-page/wifi-cricket 47