Low Power Lora Radio
Sometimes a project is purely just a bit of fun. The justification, if any, is icing on the cake.
In this case, I wanted to learn about LoRa (Long Range) radio systems. I also wanted to try out SparkFun's Artemis compute module, based on the Ambiq Apollo3 Blue processor. Since the Artemis is designed for power efficiency, it seemed like a good idea to make the system battery powered. Finally, it seemed that I should add the footprint for one of my AC current sensor boards, because maybe remote current sensing might be an interesting thing to do.
The prototype setup was very traditional. It used an Artemis Blackboard (since replaced by the Artemis Redboard) and flying wires to attach to a pre-made PCB wired in the same fashion as a standard plugboard. On the plugboard PCB was one of my current sensors (the purple board), and the little RFM95W LoRa radio (the tiny green board at the very back). The RFM95 was mounted via bare wire stubs about 3/8 inch long. That allowed me to adapt the radio's 2mm pin spacing to the standard 0.1 inch spacing on the plugboard PCB. The giant connector is for a logic analyzer so that I could debug the SPI interface bringup.
This setup worked well enough to tell me that it was time for a circuit board.
One other goal was to have the resulting system fit inside a waterproof box I bought from Aliexpress. Without giving away too much at this point, you can see that the first PCB revision fit very nicely, following the contours of the box quite well.
Now I can replicate that mechanical layer in any new design and know it will fit in the box, and that all the mounting screws line up with the plastic bosses underneath.
One part of the V1 design that worked out well was the USB serial interface. Or more correctly, the lack of a USB serial interface. These days, bootloader software in conjunction with generic USB serial chips are used to enable software development environments like Arduino to program the flash inside the target processor. I mostly don't care about the bootloaders because I use a Segger hardware debugger to develop the software, and the debugger writes the flash without need of a bootloader. Therefore, I didn't feel like adding all the USB serial interface parts because they just take up board space and cost money. But then, I had another good idea. Aliexpress sells little generic USB serial boards that contain all the right parts that I was proposing to leave off my board. If I added the footprint for the connector of one of these generic interface boards, then if a project needed USB serial or wanted to use Arduino, I could just plug in a board. The best part is that I bought a pile of generic CH340 serial boards off Aliexpress for 55 cents each. I can't even buy the parts that cheaply, much less account for the time for me to put all the parts on my board. It seemed like a total win-win.
Once that decision was made, another opportunity came up. The USB serial boards derive their power from the AC mains via their USB connection. In addition, an on-board voltage regulator allows the serial boards to supply 3.3V at up to a few hundred milliamps to whatever the interface is plugged into. I added a simple diode power combiner to my board so that if USB power exists, the system uses it. If not, the battery takes over. I also added a circuit that would allow the Artemis to get interrupts regarding changes in the statea of the USB power. That would allow Artemis software that was expecting to be AC powered to drop into a lower power "emergency battery mode" when it knew that that AC was gone. For example, a system might have an always-on LCD display that could be selectively shut down during power emergencies to save power.
The project design was not difficult from a technical perspective. The mechanical outline took some time to match the contours of the box. The electrical design was nothing special: some I2C peripherals, some SPI peripherals, some GPIO, a CR123 battery. The only thing I was really concerned about was how to solder down the Artemis. The Apollo3 processor on the Artemis comes in a BGA package. For a typical hobbyist, a BGA package is a showstopper. If you read the SparkFun blog on the matter, working with the BGA package was pretty daunting even for them. The point of the Artemis module is that Sparkfun does the extra hard BGA soldering, and converts it to a pattern that is more manageable by hobbyist reflow soldering means. In theory, it means that we get to use a BGA package without the BGA pain. But as the old saying goes, "In theory, there is no difference between theory and practice. In practice, there is." The proof would be in the pudding.
Make no mistake, the Artemis module has done the heavy lifting by mounting the BGA processor, but the module itself still has a lot of really tiny pads. This pic was shot by holding my phone to the eyepiece of a microscope. The pads might look small, but if you see the board in person, you would see that they are really small. For comparison, capacitor C8 down in the lower right is a normal 0603 resistor. That's pretty small unless you are one of those annoyingly steady-handed people who can tweezer down 0402 or even 0201 parts. Not me, that's for sure.
At this point in my soldering career, I was still placing all the solder down by hand using a hypodermic solder syringe dispenser. I had not graduated to stencils. I think that was mainly because I like to experiment and make new versions of a board "just because", and that would require buying new stencils for every board spin.
Without a stencil, all I could do was squirt solder paste from my hypodermic dispenser onto a piece of paper, then use the tip of an exacto knife to take a bit of solder and apply it to the pad. It looks a bit messy here, but I had no other option.
Sharp-eyed people will notice that I didn't tent the vias in the area under the module. Well, I thought I had, but forgot to check that before fab'ing the boards. Even sharper-eyed people might notice that I painted on a tiny bit of clear insulating coating over each via. Why? Let's just say that I have had disastrous solder shorts form under a processor before, and that experience taught me all about tenting.
Out of the Toaster Oven
Putting the solder down took a long time, but it only took 6 minutes in my toaster oven to solder all the joints. The resistors and caps looked fine, but it's impossible to tell what the joints looked like underneath the Artemis. There were no obvious power shorts, so all I could do was cross my fingers and hook up the debugger...
Unbelievably, the result was pure joy: the debugger connected, downloaded my test program, and stopped patiently at the first line of main().
Starting the program fired up the current monitor, and it dutifully started generating output. The radio passed its sanity testing on the SPI link, and things were looking good.
The version 1 board worked pretty well. Most importantly, it proved that I would be able to solder an Artemis. V1 had two fatal flaws though: my reverse battery protection implementation was flawed, and I had wired up my vertical version of a standard horizontal SparkFun QWIIC connector exactly backwards. It turns out there is a major difference in how the pins are laid out on my vertical connectors versus the SparkFun horizontal connectors. Sometimes even double-checking is not enough, if all you are doing is double-checking the same wrong connections.
Not that it really bothered me, because I like making boards. And so version 2 came to be.
But first, a diversion. My artist daughter likes to hand embroider patches and put them on her Instagram. Maybe a year ago, she made this one. It was my favorite, and the most time-consuming one she ever made because the entire surface is embroidered. The quote is a reference to the start of a Futurama episode. For xmas, she gave me the original. It was the best present ever!
While she was visiting for the holiday, I asked if she could apply her prodigious Adobe skills and extract the basic design from that photo as a file of vector data. Of course she could! It took her a couple hours.
I imported the data into Eagle, my PCB layout program. My design rule checker went from 0 errors to 3187 errors. But I can be persistent when I want to be, and 3 days later, I had it down to a mere 26 "approved" errors, so I sent the board off for fabrication.
This time, I took the plunge and ordered my first stencil. The exacto blade solder application process was just too tedious to contemplate doing for a second time.
Six days later, I had V1.1 boards and a stainless steel stencil in hand. I got ENIG (gold plated) boards this time to give the stars some color. They look great in person!
The V1.1 fixed the V1.0 bugs, but it also added some functionality. In particular, it added a pair of 8-pin 1mm JST connectors just to break out a spare bunch of the Artemis' IO pins. If this board ever needs to be repurposed, now there is an easy way to attach things. The connectors are wired with similar functionality, so external hardware could plug into either port and it should work. Each port can be configured as an I2C interface, or as an SPI interface with multiple hardware-supported CS pins. The pins can also be redefined as GPIO, with options for PWM and ADC inputs too.
Connector IOM1 is special in one regard because it allows for software control of the 3.3V power going to the connector. The Apollo3 processor on the board has a couple of special GPIOs connected to larger FETs, meaning that they can source or sink significantly more current than a regular GPIO pin. Connector IOM1 defaults to use one of those special high-side FETs as its power source.
Finally, I tried out my first stencil. It's a lot like welding: it takes a long time to jig the parts together, and seconds to perform the actual weld.
My registration was not perfect. You can see that the solder is in the upper left of each pad. The theory behind the solder mask is that the molten solder would really prefer to move off the mask and onto the pad. I figured that it was close enough, and that I would only be able to do better by random luck., so I decided to go for it as-is.
You can also see that I fixed my tenting issue. Now all the vias under the module are protected.
The soldering did not go perfectly though. My initial power-to-GND short circuit test was a complete fail: I had a dead short somewhere on the board. I took a quick scan of the board and didn't see any problems, so naturally I assumed that the problem was under the Artemis. I removed a few components and cut a trace and proved that the Artemis was not at fault. That made me do a more careful search on the rest of the components, and I found a solder bridge on one of the new JST connectors. I really should have done a more careful search to start with. I got the excess solder removed, the components reinstalled, the cut trace jumpered, and the board booted perfectly.
The reverse battery protection circuit works now. The QWIIC connector is wired properly. The new JST connectors are functional. A USB serial board can be plugged in to power the system, and I tested the ability of the Arduino environment to use the serial board and Artemis bootloader to program and run a Blinky example. All good!
There was nothing left to do except play with the radio, so I did. I really know nothing about radios and RF, so it was going to be a learning experience. One thing I do know is that the radio transmit and receive performance is related to the length of the antenna. In theory, the little piece of copper wire antenna will act as a 1/4 wave antenna, That means that the length of that antenna should be basically 1/4 of the wavelength of the frequency being used. At 915 MHz, the antenna should be 81.9mm. My theory was that would start with a really long piece of wire on the transmitter and cut it shorter and shorter while measuring the signal strength of the received signal.
To measure the signal strength, I picked up an RTL-SDR from Amazon, which is a cheap "Software Defined Radio". I used the program "Spektrum" which is a spectrum analyzer. It can show you the strength of the received signal. Here is an example of the spectrum analyzer showing me the how it sees a packet being transmitted by my V1.1 board.
Then, I would cut the antenna to a known length, use Spektrum to measure the signal strength being received by the SDR, note the result in an Excel spreadsheet, and repeat. It was a tedious morning, but I got Excel to generate a graph of the results, seen below.
Again, I don't know much about RF at all, but two things seemed weird. For starters, theory says that the antenna should be best at about 82mm, the 1/4 wavelength of 915MHz. This test showed best performance at 69 or 70 mm, which is 15% shorter. And not only that, I could get even better performance with a length of about 230 mm. That length does not seem to correspond to anything like a multiple of the quarter wavelength. Mysteries.
As a practical test, I cut the antenna on my Artemis board to 70 mm. Then I cut the antenna on a Moteino M0 running an RFM95W as Arduino to 70mm as well. I set the Artemis in my office workspace in the house, and I took the Moteino for a walk down the street while running from a LiPo battery. I have an OLED on the Moteino so it could report the received signal strength of my Artemis packets as I walked around. With the Artemis transmitting at the minimum power of 5dB (3 millwatts), I could get about 1000 feet from the house before the reception became unreliable. That's 1000 feet through the interior and then exterior walls of a log cabin, and then through a dense forest for the full distance. It will certainly be good enough for my purposes.
One final note, you can see a fancy spiral-would antenna mounted on the board in one of the pictures above. I got those from Aliexpress advertised as being 915 MHz LoRa antennas. I tested the performance of that antenna using the same spectrum analyzer setup as with the straight piece of wire tests above. It's performance precisely matched the very worst performance of the straight wire antenna: -24 dB. Again, I really don't know what I'm doing, so maybe there is some antenna tuning or matching that needs to happen. Or maybe it is Aliexpress selling "buyer beware" antennas. My experience is that most of the time Aliexpress sellers are awesome, but sometimes they are not. For now, I have a bag of 100 lousy antennas. At least they were super cheap!