Part 2
In Part 1 of this article series, Brian took a fresh look at the Particle line of IoT modules and their associated Particle cloud service. This month, he’ll describe the last of the basic integration categories that can be used with the Particle cloud for real-world projects as well as the hardware/programming of the project’s devices.
Remote Control/Status Monitoring
The third basic category of functions that you might want to perform with Particle devices and the Particle cloud is remote control/status monitoring. In this case, you could be using either a computer program or a cell phone app that displays a “dashboard” that allows you to send commands to a remote Particle device(s). Optionally, the remote Particle device could also return data of some sort (from sensors and so forth).
Writing a native cell phone app is not a trivial undertaking, even if you are an experienced “C” programmer who programs embedded microcontrollers (MCUs). It’s even more difficult if the cell phone is an iOS device. Apple is very focused on security, which makes getting an app onto an iPhone a slower, more difficult process.
MIT University has written a web-based application called MIT App Inventor that makes the task of writing a cell phone app much simpler. Initially it only worked with Android phones, due to the extra steps that Apple demands for getting an app onto iOS devices. Recently, however, it has added limited support for iOS devices.
I personally use iOS devices on a daily basis. However, when I recently discovered the Android GUI-O app, I bought an Android cell phone to allow me to try it out (“GUI-O: A “Virtual” Front Panel For ESP32 Projects,” Circuit Cellar 389, December 2022) [1]. I thought that since the MIT App Inventor worked on both platforms, I could use it to write an iOS app that worked with the Particle cloud/devices. However, the MIT App Inventor works much better with Android devices, so I decided to stick to using my Android phone for initial testing purposes.

This is the Designer page of the MIT App Inventor program. Here, you drag-drop the icons needed to make up the dashboard(s) for your phone app. The App Inventor is a web-based application, so there is no need to install any files on your PC.
The MIT App Inventor is web-based, and programming is done by dragging and dropping various program elements into your workspace. For the graphic user interface (GUI) on the phone’s screen, you drag and drop various icons that will make up your app’s “dashboard.” For the actual program code, which implements the actions associated with the dashboard’s icons, you move to the “Blocks” screen. Here, each program statement is made up of a series of graphical blocks, which are snapped together in much the same way you would assemble a jigsaw puzzle. Figure 1 shows the Designer screen of the MIT App Inventor program—this is where you design the app’s Dashboard. Figure 2 is the “Blocks” screen, where you write the underlying “code” that implements the GUI you have designed. What you see here is only about 30% of a complete program that communicates with a Particle device, and which controls an LED and a servo motor attached to the Particle board. The rest becomes visible when you scroll down the screen.

This is the Blocks page of the MIT App Inventor program. Here, you drag-drop various block icons which are strung together to make what would be termed “statements” in a conventional program. This concept is derived from the Scratch programming language, targeted at teaching children programming. It also was developed at MIT.
This pictorial representation of programming code is obviously targeted towards children. I first came across this concept when the Raspberry Pi debuted. A block programming language called Scratch was introduced to teach young children programming on the Raspberry Pi. Scratch was developed by Mitch Resnik of the MIT Media Lab, and you can see that the concept was later extended to the MIT App Inventor.
Using the MIT App Inventor, children can be easily taught to make cell phone apps that do things that would interest them. However, it’s quite a bit more complicated to write an app that, for example, can communicate with Particle devices via the Particle cloud. Luckily, Jim Schrempp and Bob Glicksman have done most of the heavy lifting for us by developing a template and an associated example program that can be used to:
- Log in to the Particle cloud from the phone, and obtain the necessary API keys and so forth that are needed to access the Particle cloud for a specific User ID or device.
- Store those authentication keys in a small database on the phone.
- Perform simple control functions on the remote Particle device.
- Read variables and/or GPIO pin status from the Particle device.
This template and sample program can be found on GitHub, a link to which is available on Circuit Cellar’s Article Materials and Resources web page [2]. The example that they supply performs the functions shown in the above list. There are two main parts to this example:
- The MIT App Inventor code that runs on the cell phone—This is provided as both a pre-compiled hex file that can be directly uploaded to the cell phone and as the MIT App Inventor source code for this application.
- The firmware that runs on the Particle device itself—Specifically, this example was written for a Particle Photon module, which is a Wi-Fi device and a predecessor of the Argon module. The Photon code is compatible with the Argon device, which is what I used.
Along with the programs for both the phone and the Particle device, there is a GitHub folder for documentation. “Installation and User Manual” describes the cell phone app, and “Programming Notes” describes the Particle cloud and Particle device implementation. These well-written documents are much longer than this article, so I’m not going to try and replicate that information here.
If you want to start up quickly (without learning anything about MIT App Inventor programming), you can just download the following file directly to your Android phone:
CommunicateWithParticleDemoApp.apk
This is done by plugging your phone into your computer, and answering the prompt that pops up on the Android phone with the “transfer files” option. Then you copy this file to the flash drive (emulated by your cell phone) that pops up in Windows File Explorer. If you then open the Android “File Manager” app on your phone, navigate to this file, and click on it, the MIT App Inventor program that implements this Particle demo program will be installed.
When you run this demo app, you must first click on the small, oval Setup button at the bottom left of the screen. This will bring up a new screen where you must enter your Particle login information. You should then be able to select the specific Particle module that you wish to communicate with. All the necessary login/authentication keys are then stored on your phone using the MIT App Inventor’s TinyDB database. This setup procedure only has to be performed once, due to its being stored in the TinyDB database mechanism.
Assuming that you have programmed a Particle module with the “Test_MIT” firmware from the GitHub site, you should be able to interact with it using the CommunicateWithParticleDemoApp on your phone. If this works OK, you can go on to import the example’s source code into the MIT App Inventor using the Projects tab and the Import Project selection. You can then examine the program and make any changes needed to fit your use case. While I had no previous experience with the App Inventor program, Glicksman’s documentation is detailed. The details of configuring the App Inventor’s “Web” block to interact with the Particle cloud’s REST API is non-trivial, but the documents describe it clearly.
The final thing that I’ll mention regarding the MIT App Inventor is its ability to debug a program, as you are developing it, on the cell phone itself. This is much quicker than compiling, uploading the resulting .apk file to your phone, and then installing it. To perform this debugging, you must first install the MIT AI2 Companion app on your phone (from the Google Playstore). Using the web-based App Inventor program on your PC, you select the Connect tab and then AI companion. You will then see both a QR code and a six-digit code as seen in Figure 3. When opened, the AI Companion app on your phone will prompt you to enter this code, or alternately allow you to scan this QR code. Once that is done, the computer and phone will interconnect, using the Wi-Fi connectivity provided by your home’s Router/Access Point. The App Inventor program that you are currently working on will appear on the phone’s display and operate just as if it were natively installed on the phone itself. This is impressive!

For convenient debugging of your App Inventor program, you need to install the AI2 Companion app on your phone. Pairing the App Inventor program on your PC with your phone is accomplished by using the six-digit code shown here, or scanning the QR code shown here.
With things working so well on my Android phone, I was curious to see how the MIT App Inventor app would work on my iPhone and iPad. Unlike Android devices, you can’t just download executable programs to iOS devices—you have to obtain them from Apple’s App Store. I’m not an Apple developer, nor do I have an Apple Mac computer (needed to run the SDK for developing iOS apps). I expect that if one meets those two criteria, there is probably a way to download iOS apps directly to an iPhone during the development process. However, I’m not in a position to know this, one way or the other.
For iOS devices, the way that App Inventor apps can get around this is by loading the “MIT App Inventor” app onto your iOS device from the Apple App Store. While it is still called “MIT App Inventor” when installed on an iOS device, it actually performs more like the AI2 Companion app on an Android device. That is, it prompts you for the same six-digit code/QR code that the App Companion expects, obtained from the web-based MIT App Inventor program running on your PC. I was able to get this to work with simple MIT App Inventor example programs. Whatever MIT App Inventor app you’ve “loaded” to your iOS device will persist on that device if you merely exit the program—since in iOS, an exited app is still loaded in RAM, in the background. However, if you close the app and restart it, you’ll have to scan the QR code and download the app from your PC all over again. Unless I’m missing something, the functionality of MIT App Inventor for iOS devices leaves much to be desired. Also, I found that loading Bob Glicksman’s “CommunicateWithParticleDemoApp” onto my iPad didn’t work at all on my iOS devices. It got hung up in the Setup function, where it communicates with the Particle cloud to get authentication credentials and so forth. Therefore, I’ll stick to using the Android phone for MIT App Inventor apps.
In this article’s project, of the three basic types of Particle Cloud integrations previously described, only the Alert Notification type is used. Next, let’s look at the way I implemented the RF transport mechanism between the remote IoT devices and my Particle gateway device.
The iBeacon Protocol
One of the attractions of the newer Particle modules is their Bluetooth 5 capability, due to their using:
- The Nordic nRF52840 System-on-a-Chip (SoC) in the case of the Argon and Boron LTE;
- The Realtek RTL8721DM MCU in the case of the Photon 2.
It made sense to use BLE connectivity to connect remote sensor modules to my Particle Argon “gateway.” A Nordic ARM SoC would have also been a logical choice for the remotes, since the Nordic SoCs have quite low power consumption. However, Nordic uses their own custom SDK for their SoCs. I wasn’t inclined to learn a totally new IDE after having spent a lot of time in the past trying to learn the Eclipse-based IDEs used for STMicroelectronics STM32 Arm MCUs, as well as a similar IDE used by Silicon Labs’ ARM MCUs.
Instead, I decided to use Espressif’s ESP32 MCUs, since they are common, inexpensive, and I’ve already used them before. Not all ESP32xx modules handle BLE connectivity, but I’ve used the original ESP32 and the ESP32-C3, both of which include BLE capability. The ESP32-S2 doesn’t include BLE, however.
The BLE protocol can be quite daunting to learn. It tries to cover a lot of bases, and differentiates the many different services that it can provide using long, cryptic UUIDs (128-bit Universally Unique Identifiers). However, a generic UART service has been defined that is fairly easy to use. Nordic themselves have defined the Nordic UART Service (NUS), which basically does the same thing as the generic UART service.
However, while investigating the BLE protocols, I came across Apple’s iBeacon protocol. Such beacon protocols are unabashedly advertising delivery tools. Apple’s original idea was to place such “beacons” strategically in retail stores and the like. They hoped to convince customers to install beacon-friendly apps on their iPhones. Then, as you wandered through a store, your phone would “wake up” and serve up links to advertising content on the web. From what I can tell, people didn’t really buy into this scheme. However, the iBeacon protocol is supported by libraries for both the Particle and ESP32. In my opinion, it lends itself quite nicely to a use case in which simple IoT sensors need to send data to a central gateway. Let’s look at the iBeacon protocol in a bit more detail.
The remote IoT sensor is the iBeacon, and it sends out a small BLE packet at either a fixed interval, or possibly only when a condition is sensed that calls for an alert to be sent. This is a small packet containing some identification information, and a few mandatory data fields which are just integer values. There is no receipt acknowledgement required for this beacon packet, so it is somewhat like a UDP datagram. However, unlike a UDP datagram, the iBeacon contains no destination address—it merely “broadcasts.” The act of transmitting this iBeacon data packet is called advertising, which is quite appropriate, since the iBeacon protocol was originally developed for retail advertising purposes.
At the Gateway end, the BLE SoC must do a periodic beacon scan to sense the presence of any nearby iBeacons. The scan process is completely non-discriminatory—it will discover any iBeacons, regardless of their particular ID.
Let’s first look at the code that is needed to accomplish this at the IoT sensor end. For the sensor units, I am using an ESP32 MCU and need to include the ESP32 “BLEDevice.h” and “BLEBeacon.h” library files to enable BLE functionality. Each IoT module needs to have a Beacon UUID defined. The easiest way to generate such a UUID is to go to www.uuidgenerator.net, and get one (or more) there. When you want to start advertising, the following lines of code are executed:
BLEDevice::init(“”);
pAdvertising = BLEDevice::getAdvertising();
setBeacon();
pAdvertising->start(); // Start advertising
It’s not necessary to completely understand what is happening in these lines of code, except that the setBeacon() function is contained elsewhere in my example code. It basically fills up the iBeacon frame, as shown in Figure 4. Note that iBeacon packets are only 29 bytes long. That is one reason why iBeacon messaging can be performed using so little power.

The Bluetooth Beacon packets are 29 bytes in length. The first three bytes are general beacon values. For Apple iBeacons, the structure of the last 26 bytes is defined as shown here.
There are two 16-bit integer fields included in the iBeacon packet shown in Figure 4: Minor and Major. These were originally designed to identify the location within the store where the iBeacon is located and the particular store’s number, respectively. For this project, I use the Major field to hold the remote sensor’s unit number. I use the Minor field to hold either the true/false status of some condition being monitored, or the value of some parameter that is being measured (temperature, and so forth). The iBeacon packet also contains an 8-bit field for measured RF power. I don’t use it for that purpose, but instead use it to store the condition of the sensor unit’s battery (0-100%).
At the Gateway end, either a Particle Argon (Wi-Fi/BLE) or Boron (Cellular/BLE) could be used. Both have the same physical footprint and pinout, and my application software would be basically the same since the Particle OS handles the cloud interconnection functions and makes the transmission method (Wi-Fi or Cellular) more or less transparent to the application program itself.
I used a Particle Argon board for the gateway. To implement the iBeacon scanner, I include the “BeaconScanner.h” file at the head of my program. This is one of the standard Particle libraries. The scanning function in this library will also discover beacons other than iBeacons (such as Eddystone, Kontact, Laird, and so on). When I call this library, I only include the iBeacon argument as I’m not interested in the other types.
With either the Argon or Boron modules, the Particle OS handles all the details of the connection to the Particle cloud, in the background. Therefore, my code can perform these iBeacon scans in the “loop” section of the main program. I do a scan as often as I deem necessary to ensure that I don’t miss any iBeacon messages. At the IoT sensor end, the iBeacon advertisement packets are repeated for 10 seconds when an alert condition is sensed, thus guaranteeing that messages are not dropped.
void loop() { AlarmFlag=false; unsigned long now = millis(); if (Particle.connected() && (now- scannedTime) > 5000) { scannedTime = now; Scanner.scan(10, SCAN_IBEACON); Vector<iBeaconScan> beacons = Scanner.getiBeacons(); while(!beacons.isEmpty()) { iBeaconScan beacon = beacons.takeFirst(); lcd->clear(); lcd->print(beacon.getRssi()); lcd->setCursor(0,1); lcd->print(“Unit#: “); unitNumber = beacon.getMajor(); lcd->print(unitNumber); lcd->setCursor(0,2); lcd->print(“Alarm Status: “); AlarmFlag= beacon.getMinor(); lcd->print(AlarmFlag); lcd->setCursor(0,3); lcd->print(“Battery= “); condition= beacon.getPower(); lcd->print(condition); lcd->setCursor(12,3); lcd->print(“MSG#”); lcd->print(BatteryMessages[unitNumber]); if (AlarmFlag == 1) { if (AlarmMessages[unitNumber] <2){ sprintf(buffer,”{\”alarm\”: %2d}”,unitNumber); Particle.publish(“alarm”, buffer); AlarmMessages[unitNumber]++; } } else { AlarmMessages[unitNumber]=0; } if (condition < 30 ) { // Battery below 30% if (BatteryMessages[unitNumber] < 2) { sprintf(buffer,”\”unit%02d\”: %2d”,unitNumber,condition); Particle.publish(“battery”, buffer); BatteryMessages[unitNumber]++; } } else { BatteryMessages[unitNumber]=0; } delay(2000); // leave LCD display up for 2 sec } }}
LISTING 1
This code, which resides in the loop() section of the Argon gateway device, will scan to detect any iBeacons within range, evaluate the values it receives, and contact the Particle cloud to initiate a push notification on my cell phone.
The scanning operation is done in the loop() section of the program, as shown in Listing 1. After checking that the Argon gateway device is still connected to the Particle cloud, and that 5 seconds has elapsed since the last scan, a scan is performed using the following statements:
Scanner.scan(10, SCAN_IBEACON);
Vector<iBeaconScan> beacons = Scanner.getiBeacons();
This scans only for Apple iBeacons, and can handle up to 10 of them. The beacons.isEmpty() function is used to sense when any iBeacons have been detected, and if so, the function beacons.takeFirst() selects the first iBeacon found (if more than one is present). Next, the beacon functions getMajor(), getMinor() and getPower() retrieve the iBeacon’s major, minor and measured power values. In this application, these represent the unit number, Alarm flag, and battery condition respectively. These are displayed on the Gateway’s LCD display.
There are two reports that I want to send to the Particle cloud:
- An alarm condition—In this case, it’s a water leak detection, but it could be any condition that any remote unit determines is an out-of-bounds condition.
- A battery condition—The remote units measure the LiPo battery voltage after a specified number of boot ups (from deep sleep) have occurred. This variable is mapped as 0% = 3.5V and 99% = 4.1V, and is sent out using the iBeacon’s Measured Power parameter.
These reports are sent to the Particle cloud server, using the Particle.publish command. The alarm condition is published as “alarm,” and the battery condition is published as “battery.” Since both conditions will ultimately result in a notification being sent to my phone, I maintain two arrays, AlarmMessages and BatteryMessages, to keep track of how many reports have been sent, by type and by unit. These values are used to limit the number of messages sent to two, for any given unit’s alarm or battery condition. Once a weak battery is replaced, or the alarm condition disappears, these message counts revert to zero.
In the case of an alarm condition, the value that I publish for “alarm” is the remote’s unit number. However, for the battery condition, the value that I publish is a string containing both the unit number and the battery percentage (the mapping for which was defined above). This string is basically the message that is displayed on the phone when the push notification is received.
Whenever these reports are sent by the Argon gateway using Particle.publish() they will appear in the Event List of the web-based Particle Console—assuming you have selected “My devices” and clicked on the Particle board that is acting as the Gateway. However, nothing else would happen unless an integration has been defined, as described in the Alerts section in Part 1 of this column series (Circuit Cellar 402, January 2024) [3].
Hardware-Remote Sensor Units
For the remote units, I needed an MCU that had BLE capability as well as the ability to go into a deep sleep mode to extend battery life. The ESP32 family is the best-known and least-expensive MCU that I know of for this task. As I mentioned, both the original ESP32 and the newer ESP32-C3 have BLE capability, but skip the ESP32-S2 as it does not have Bluetooth capability.
While the ESP32 itself has a deep sleep mode, if you use ESP32 development boards to build the remote sensor units, you should be aware that some of these boards draw a significant amount of power even when the ESP32 MCU is in deep sleep mode. Such boards should be avoided.
— ADVERTISMENT—
—Advertise Here—
I found two ESP32 dev boards that draw little power beyond that which is needed by the ESP32 MCU itself. They are:
- DFRobot DFR0868 (Beetle)—This tiny board contains an ESP32-C3 as well as a TP4057 LiPo cell charger chip. The onboard RT9080 LDO has a low IQ of only 2µA. The LiPo charging LED is only on when the LiPo cell is charging (via the USB-C socket). [4]
- DFRobot DFR0478 (FireBeetle)—This board contains the original ESP32 MCU and is also designed for low-power use. It uses a TP4056X LiPo charger and an RT9080 LDO (2µA IQ). The CH340C USB-Serial bridge chip is only powered up when the board is being powered by the USB port. DFRobot claims the deep sleep current for this board is only 15µA. [5]
Either of these boards is suitable for the remote sensor units. Please refer to Figure 5 for the schematic diagram of a unit built around the DFR0868 dev. board. A 3.6V LiPo cell is connected to the BAT terminal on the DFR0868 board. Note that while the DFR0868 contains a LiPo charging chip, that chip doesn’t provide automatic disconnection of the LiPo cell when its voltage drops too low (which can destroy the cell). That is addressed by R1,R2 and C1, which make up a high-impedance voltage divider. This allows the ESP32-C3’s ADC to monitor the battery voltage and pass it along to the gateway, which, in turn, will send out an alert when it gets too low. GPIO1 is configured as a digital input with no internal pullup. It is pulled up externally to VCC via R4, a 1MΩ resistor. The C1 capacitor is across the two wires that act as water leak electrodes, and it removes any AC noise that might be present. Resistor R3 provides some ESD protection to GPIO1. If a water leak bridges the two electrodes, the voltage on GPIO1 will drop below VCC/2 and its input state will switch from a “1” to a “0.” When the ESP32-C3 next wakes up from deep sleep, it will sense this change and start advertising as an iBeacon. A buzzer unit with an internal driver is connected to GPIO7 and provides an audible alert if a leak occurs.

This is a schematic diagram of a remote unit that monitors for water leaks. It uses a DFRobot DFR0868 module, which contains an Espressif ESP32-C3, a LiPo battery charger, and a low IQ LDO regulator.
Notice that I show a Reset switch and a programming jumper. There is no USB-Serial bridge chip on this board because the ESP32-C3 itself contains an internal USB port. When it comes from the factory, the ESP32-C3 on the DFR0868 board has been programmed with its USB CDC Serial port enabled upon boot. This allows you to connect the DFR0868 board to your PC’s USB port and Flash program it via the Arduino IDE. However, this flashing capability will disappear the first time you program the board—unless you click on the Arduino IDE Tools tab, navigate to the “USB CDC on Boot” item, and enable it.
I didn’t consider this ahead of time and, as a result, I thought I had “bricked” the ESP32-C3. However, it turns out that even with the USB CDC port disabled, you can still program the ESP32-C3 using its Rx and Tx UART pins. However, you will need to:
- Add a Reset switch (using the RST SMD pad on the DFR0868);
- Add a jumper between IO9 and ground during flashing, to place the ESP32-C3 in flash mode;
- Use a USB-Serial Port cable between your PC and the DFR0868 dev board.
Before re-flashing the ESP32-C3 in this way, you must also remember to enable the USB CDC on Boot option in the Arduino IDE.
Apart from rescuing you from this situation, the addition of the Reset switch and programming jumper are also needed if the program you are running on the ESP32-C3 goes into deep sleep, shortly after reset. In this scenario, it is hard to flash the chip from the Arduino IDE, since the MCU is in deep sleep except for a short interval at boot up. Therefore, the Arduino IDE will just report that there is no ESP32-C3 device to program. With the IO9 jumper in place, when you hit the Reset button, the ESP32 will boot up in the Flash programming mode (instead of running the active program that is going into deep sleep so quickly).
Alternately, for the DFR0478 (FireBeetle) board, an original ESP32 MCU is used along with a USB-Serial bridge chip. In this case, there is no need to enable the USB CDC on Boot option since it doesn’t apply. The CH340C USB-Serial bridge chip also controls the Reset and GPIO lines necessary to place the ESP32 MCU in Flash mode. This eliminates the problem described above, in which a program goes into deep sleep shortly after reset and can’t be seen by the host PC, for flashing purposes.
Figure 6 is a photo of a leak detector board using the tiny DFR0868 Beetle dev board. A thin blue wire connects the RST pad on the Beetle with the Reset switch that I added. The three terminals labelled GRT were used to connect the USB-Serial Port cable—needed only because I forgot to enable the USB CDC on Boot option as described above. A bigger LiPo battery is connected for normal use, but the tiny one shown is okay for testing.
Figure 7 is a block diagram of the operation of the leak detection units. It is self-explanatory except for the 1-second delay after the short beep. I initially found that the battery measurement varied drastically—even though I was taking the average of 10 ADC readings. This variation disappeared after I allowed for a 1-second delay from reset, before the readings were started.
At the beginning of the ESP32-C3 leak detector program, the two following lines define the deep sleep time in seconds, as well as the number of re-boots between battery checks:
#define GPIO_DEEP_SLEEP_DURATION 3
// sleep 3 seconds
#define SLEEPS_PER_BATTERY_REPORT 2
// 2 re-boots/bat. Check
In the program that I have uploaded to the Circuit Cellar Article Materiald and Resources web page, these were set to the low values shown above, to aid in testing. They should be made much longer for actual use—likely 15 minutes of deep sleep between leak checks, and 50 reboots between battery checks.
Argon Gateway Circuitry
I use a Particle Argon module for the BLE to Internet gateway (to the Particle cloud). As mentioned earlier, the Argon spends most of its time in the loop() function where it constantly scans for iBeacons. All remote sensor units are configured as iBeacons, and communicate with the Argon gateway via BLE.
Figure 8 is the schematic diagram of the Argon gateway unit. The Argon module is powered via its micro USB socket using a 5V USB adapter. The Argon module comes with an external Wi-Fi stick-on patch antenna which connects to the module using a U.FL connector. While the Argon has a built-in Bluetooth chip antenna, you could also add a Pulse Electronics W3334B0100 external Bluetooth antenna to get a good BLE range if the Argon is mounted in a metal enclosure [6]. The external Bluetooth antenna connects to a U.FL socket on the Argon module. I didn’t see much difference in the BLE RSSI readings between this external antenna and the patch antenna on the Argon PCB—when the Argon wasn’t enclosed in a metal cabinet.
If you use an external Bluetooth antenna, you have to switch to the external antenna using the following statement:
BLE.selectAntenna(BleAntennaType::EXTERNAL);
I use a 20-character by 4-line LCD display with an integral I2C backpack for the unit’s status display. The I2C backpacks generally contain I2C pull-up resistors, but I added pull-up resistors R1,R2 in case they weren’t present. I use a small buzzer unit with a built-in driver to indicate if a water leak or other alarm situation is detected, on any of the remote modules. Switch S1 allows you to silence this alarm once you have recognized that an alarm situation exists. There is an LED that is used to indicate if any unit has reported a low-battery condition. All of these alarm conditions are also sent to the user via a push notification, triggered by a Particle Webhook that connects to the Pushover cloud service. This integration was described in Part 1 of the series [3].
Bricked Modules
In developing MCU projects, no one likes the thought of a “bricked” MCU, but it can happen. A bricked MCU is one in which the native bootloader has been overwritten or otherwise destroyed. The result is a device that is harder or even impossible to re-flash.
— ADVERTISMENT—
—Advertise Here—
All the Particle devices are capable of over-the-air reprogramming, which is the only way they can be reprogrammed if you are using Particle’s Web-based IDE. When using the Particle Workbench PC application, you have an added option of re-flashing the device over USB.
However, there are things that you can do in your application code that will hamper or prevent either (or both) of these two re-flashing methods from working. I’ve experienced cases where the web-based IDE indicated that it had successfully re-flashed a Particle device, when in reality, nothing had changed.
While I don’t know the underlying details for all Particle devices, in general, they contain a bootloader that will directly respond to a re-flashing request received via USB. That is to say, like an ESP32, they can be re-flashed without pressing any reset, mode buttons on the board. Unlike an ESP32 however, it’s possible for the Particle device to get in a state where it doesn’t respond directly to USB commands, and instead needs to be placed in the low-level DFU bootloader mode. Briefly, this is accomplished by pressing the Reset button with the mode button already pressed. The mode button must remain pressed until the RGB LED on the Particle device starts to flash yellow. Once in DFU mode, you can then successfully re-flash the device over USB.
Without going into detail, there are other errors that can occur that disrupt the device’s OS itself, or the authentication keys (and so on) that are needed to allow the device to connect to the Particle cloud (as well as your wireless access point). Particle has written a number of Developer Tools which can help to solve these issues. These tools are all described at the Particle Docs website, a link to which is available on Circuit Cellar’s Article Materials and Resources web page [7].
Device Doctor is one of the early tools that they provided, and which I’ve made use of more times than I’d like to admit. More recently, they have added many more tools—notably, the USB Serial and BLE Serial tools.
One helpful feature of these tools is that they are browser-based and can connect to your device directly, via USB. So, for example, in Device Doctor, you can repair whatever has gone wrong with a device’s OS/bootloader—it will present you with a list of any devices that are plugged into USB, and you go from there.
These web-based tools require the WebSerial API in order to work. When you run these tools, it will mention that the Chrome web browser is needed to run them. However, I’ve found that the Microsoft Edge browser also supports the WebSerial API, and it works fine.
Newest Particle Modules
While I was writing this series, Particle announced the new Photon 2 module as well as the Boron LTE. Neither was immediately available at my regular distributor, DigiKey. While this article series waited in the publishing queue, they became available, and I’ve purchased some of each.
Both modules are a departure from their prior generation. The Photon 2 contains a Realtek RTL8721DM MCU. This MCU has a QSPI 8MB Flash memory chip connected to it. This results in much more available memory than was available on the previous generation Photon device (containing an STM MCU). The Photon 2’s memory is as follows:
- 2MB maximum user application program space
- 3MB of user-available RAM
- 2MB Flash file system
The Photon 2 datasheet doesn’t mention what chip they are using for the Wi-Fi and BLE functions. That is because the RTL8721DM MCU contains all of these RF functions. The Wi-Fi is both 2.4 and 5GHz compatible, and can use either the PCB antenna on the module itself or an external one. There is an integrated switch to select between the two. The BLE function uses the same antenna as the Wi-Fi and the command to switch between the external and PCB antenna is:
(STARTUP(BLE.selectAntenna(ANT_EXTERNAL));)/// or ANT_INTERNAL
The new Boron LTE module sticks with the Nordic nRF52840 for its MCU and uses a u-blox SARA R510S-01B LTE module (for North America). Unlike the earlier generation Particle Electron (that I used in Circuit Cellar 342 [8]), this module contains an eSIM rather than a discrete SIM card.
While I now have both of these new modules, I’ve only tried out the Photon 2, which is the replacement for the Particle Argon board.
Two features of the Particle development environment are:
- The program code is tailored after the Arduino Sketch format;
- The APIs linking your application code to the underlying hardware act as a hardware abstraction layer (HAL) to a large extent. So, in theory, code written for the MCU in earlier generations should work with an entirely different MCU used in a subsequent generation.
With the new Photon 2, I quickly ran into a few cases where code that I had written for the Argon (as well as examples on the Particle cloud server) would not compile for the Photon 2. So, you should be aware that code migration to a newer generation may not be perfectly transparent—especially if you are depending upon third party libraries that are hosted on the Particle server.
— ADVERTISMENT—
—Advertise Here—
Conclusion
I think that Particle has made quite a bit of progress since I tried out their early products four years ago. For small developers such as myself, ongoing free access to the Particle cloud is important. Granted, the Particle cloud does not store data like an MQTT cloud server would. But it does provide a secure connection protocol between the Particle IoT modules and the cloud—all of which is handled by the Particle OS and requires little knowledge on the developer’s part.
The no-charge cellular coverage that is part of the Particle Sandbox account is also a desirable feature. This allows you to develop a program on your Particle Boron, for example, without any of the hassle of setting up a data plan for cellular coverage. I was impressed that I was able to fire up my four-year-old Electron board and connect it to the Particle cloud (using the free Sandbox account), even though I had long since de-activated the SIM card and stopped paying for the older data plan that was in use at the time. The OTA programming capability works well with the Particle devices, and is simpler to use than OTA programming on an ESP32, for example.
There is also something to be said about the fact that the Particle cloud service doesn’t itself handle data storage but instead relies upon “integrations” with other cloud services. From my limited cloud experience in the past, I have found that cloud service providers often change services or conditions from time to time. If one had to make firmware changes on each remote device to handle such changes, it would be a big task. Instead, it might be a lot easier to make changes to the Particle cloud “integration” (on the Particle cloud server itself), which can accommodate any changes made by third party cloud services from time to time.
RESOURCES
DFRobot | www.dfrobot.com
Particle | www.particle.io
REFERENCES
[1] Brian Millier, “GUI-O: A “Virtual” Front Panel For ESP32 Projects.” Circuit Cellar 389, December 2022.
[2] App Inventor Particle Photon Test on GitHub:
https://github.com/TeamPracticalProjects/MIT-App-Inventor-Particle-Photon-test
[3] Brian Millier, “PICKING UP MIXED SIGNALS: Particle IoT Platform Update: Part 1.” Circuit Cellar 402, January 2024.
[4] DFRobot ESP32-C3 Beetle module (DFR0868): https://www.digikey.ca/en/products/detail/dfrobot/DFR0868/16678683?s=N4IgTCBcDaICIDEBKAGAHANjSAugXyA
[5] DFRobot DFR0478 FireBeetle: https://www.digikey.com/en/products/detail/dfrobot/DFR0478/7398878
[6] Pulse Electronics W3334B0100 External Bluetooth Antenna: https://www.digikey.ca/en/products/detail/dfrobot/DFR0868/16678683?s=N4IgTCBcDaICIDEBKAGAHANjSAugXyA
[7] Particle Tools—Particle Docs: https://docs.particle.io/tools/tools/
[8] Brian Millier, “PICKING UP MIXED SIGNALS: Easing into the IoT Cloud (Part 2): Modules in Action.” Circuit Cellar 342, January 2019.

Brian Millier runs Computer Interface Consultants. He was an instrumentation engineer in the Department of Chemistry at Dalhousie University (Halifax, NS, Canada) for 29 years.

