nRF52 – program sketches “Over the Air”

The electronics will be sealed in a water-tight canister. To simplify the debugging process I want to be able to wirelessly update the microcontroller’s firmware using Bluetooth LE from my iphone or laptop.

So I’ve upgraded to the Adafruit nRF52 Feather microcontroller. This board can be programmed using the Arduino IDE (super easy!) and offers users the ability to update the sketches wirelessly. This is referred to as Over the Air (OTA) Device Firmware Update (DFU) mode.

This is a quick tutorial on how I was able to get OTA DFU working. Please note the following warning about OTA DFU from Adafruit’s website, as of March 11, 2018:

Screen Shot 2018-03-11 at 4.08.29 PM

For this tutorial you will need the following items (sorry I’ve only tested usng iphone + mac)

  • Adafruit nRF52 Feather
  • Micro USB programing cable // connect computer to the Feather
  • iPhone // tested with iOS 11.2.6
  • NRF Toolbox app //to push OTA DFU, tested with V4.4.4
  • Adafruit Bluefruit Connect App // optional, tested with V3.3.1
  • iTunes // wireless file transfer zip files to iPhone, tested with V12.7.3.46
  • iphone data transfer cable // connect iPhone to laptop via USB
  • Arduino IDE // set to have verbose output during compilation, tested with V1.8.5


Step 0

Download and install the NRF Toolbox app. Optionally, you can also choose to install the Adafruit Bluefruit Connect App. *Note – the Adafruit App also offers OTA DFU, but I was not able to figure this out yet – hopefully in the near future this will work and then you would only need the Adafruit app. Also – I like the Adafruit UI better than the NRF Toolbox when testing UART messages, just a personal preference.*


Step 1

Setup your Arduino IDE following the instruction on the Adafruit Learning Guide. Then verify everything is working with their included blink.ino sketch in the nRF52 Feather examples.

Step 2

Upload the sketch “_03_TEST_BLE_UART.ino” (shown below) using a wired USB connection to the nRF52 Feather. This sketch will set the Feather into BLE search mode so that you can connect to the device. Once a connection is established you can open a UART connection and receive messages to the iphone.

This is an example for our nRF52 based Bluefruit LE modules

Pick one up today in the adafruit shop!

Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!

MIT license, check LICENSE for more information
All text above, and the splash screen below must be included in
any redistribution



BLEUart bleuart;

void setup(void)
Serial.println(F("Adafruit Bluefruit52 Controller App Example"));


// Configure and start the BLE Uart service

// Set up the advertising packet

// Start advertising

// initialize digital pin LED_BUILTIN as an output.

void setupAdv(void)

// Include the BLE UART (AKA 'NUS') 128-bit UUID

// There is no room for 'Name' in the Advertising packet
// Use the optional secondary Scan Response packet for 'Name' instead

@brief Constantly poll for new command or response data
void loop(void)
// send message to BLE UART
bleuart.println(" BLE UART TEST - 00");

// flash the onboard red LED
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW



Step 3

Open up the Adafruit app and verify that the UART message is correct. It should look something like this:

Adafruit Bluefruit Connect App

Step 4

Setup the Arduino IDE for verbose output.

Screen Shot 2018-03-11 at 3.44.12 PM

Step 5

Modify the message within the sketch to say something new. I updated the end of the message so say “99” and saved it with a new file name “_03_TEST_BLE_UART_II.ino”.

Screen Shot 2018-03-11 at 4.20.42 PM

This is the new sketch that we want to wirelessly send to the nRF52 Feather and have it update over the air. At this point, hit the VERIFY button, but do NOT upload this new sketch to the board. This is how we test to verify the the OTA DFU worked in the later steps. If you accidentally upload this new code to the board, just change the message back to the original before proceeding.

With the verbose output during compilation turned ON, you should see messages at the bottom of the Arduino IDE screen. One of these messages tells us the location of a ZIP file that was created during the compile process – WE NEED THIS ZIP FILE!

Look for the directory location, it is a temporary file – copy and paste the address into the SEARCH toolbar. You may need to delete the zip file name, and just look for the folder.

Screen Shot 2018-03-11 at 4.26.58 PM.png

Once you find the folder that is holding the zip file, it will look something like THIS:

Screen Shot 2018-03-11 at 4.34.08 PM

Copy/paste the zip file to the desktop or your downloads folder.

Step 6

Setup your iphone + NRF Toolbox app to receive wireless file transfers.  The NRF Toolbox app provides instructions.

Open the NRF Toolbox app and click on the “DFU” button, then click on “Select File”, then click on “User Files” and then click on “How to…” for the instructions about syncing iTunes with the iphone for zip file transfer to the app.

With iTunes open and the iphone paired to the laptop, transfer the zip file to the NRF Toolbox app. You will need to use a USB to setup the paired connection, but once it has been setup you can wirelessly transfer the zip files from the laptop to the iphone app. YAY – no more cables!

Screen Shot 2018-03-11 at 4.44.34 PM

Step 7

Now when you open the NRF Toolbox app and go into the DFU mode,  you should see the zip file in your “USER” files. Pair to the nRF52 Feather, select the zip file and hit UPLOAD. You will see a progress bar to verify the upload is happening. If you see a “Connecting” message for more than 5 seconds then something is not correct and you will need to abort the upload. This may even require that you reflash the firmware via the USB cable.



Once the DFU process is complete, the nRF52 Feather will reboot itself. Open up the UART using the iphone app and check the message to see if it has changed to “99”. It should look like this if everything worked!



YAHOO! Now we can update the code running on the microcontroller wirelessly.

BUT remember, this has the potential to brick your microcontroller so it is not recommended that you do this – at this time. Based on the Adafruit help forum, is sounds like they are working to make this process safe and reliable from within the Adafruit Bluefruit Connect app – so I’ll try to figure that out later.




Buoy Float – pool filter

I’ve decided to resurrect an old idea and use a pool chlorine filter as the primary floatation for the buoy project. While I have been very attached to the yellow 3D printed sphere, I’ve had concerns that using an entirely 3D printed hull was not the most practical choice.

So… looks like I am back to one of my original designs…



The yellow sphere is not very easy to manufacture (long print time…) and it combined both the floatation and electronics housing into a single form factor. If something where to strike the yellow sphere and damage the hull, it’s likely the impact would cause a leak and ruin the electronics inside. After more consideration, I’d prefer to have a redundant design that would be more resilient to damage and allow me to quickly/easily transfer the electronics to a different float if needed.
For this latest idea the electronics are housed inside a canister that can be secured into the center of a standard pool float, the type used to dispense chlorine into residential pools. I sourced mine online and found several options ranging from $8 – $15  with free shipping.

Ocean Buoy - 1

The canister will be water tight. It is made up to three pieces: a top part that will hold a round solar panel, a bottom piece to hold the electronics and battery, and a black gasket sandwiched in-between the top and bottom pieces which forms a water tight seal. The top/bottom parts were 3D printed in white ABS on a Lulzbot Taz 6, super awesome printer! I printed my own gasket from black Ninja Flex filament, is is very flexible and feels like rubber. Not sure how it will hold up to sea water… more experiments are needed!

Ocean Buoy - 2Ocean Buoy - 3

The 3D printed parts are not yet water tight, so I’m going to try and infuse them with marine epoxy. Maybe I’ll try using a vacuum bag method or some way to force the epoxy into all the voids and crevices. This will give the parts added strength and make them suitable for being submerged underwater. Thats the thought, at least.

I’m use 316 stainless steel hardware ordered from McMaster-Carr. They have EVERYTHING! The twist-resistant threaded inserts were press-fit into the top of the canister after drilling out 4.7mm holes. They inserts appear to be holding up pretty well, even after repeated use. But it may be a good idea to use some epoxy for added strength during the installation. One change for next time, I’ll be ordering 10mm long machine screws.

Buoy - Hardware


The bottom part of the canister has two tabs that are designed to interlock with the pool float.  These mimic the same functionality as  the tabs molded into the lid of the pool float and provide a snap lock. To mount the canister into the pool float,  you drop the canister into the float,  insert to metal posts of the tool into the top of canister, and rotate 180 degrees to lock the canister securely in place. Ocean Buoy - 4Ocean Buoy - 5

The 3D printed tool has two metal posts, 1/8″ diameter riots, jammed into the handle. The metal posts fit into two receiving holes in the top of the canister and allow the user to lock the canister into the float.Ocean Buoy - 6Ocean Buoy - 7Ocean Buoy - 8Ocean Buoy - 10Ocean Buoy - 11

The top piece of the canister will hold a round solar panel. I’ll use marine epoxy to secure it in place. The solar panel is rated for a 0.6W output.  I am hopeful that I can drill a hole through the solar panel to allow the LoRa antenna to poke through. While this is a round solar panel,  the actual solar cells are rectangular so there is some empty space on either side of the cells. Ocean Buoy - 13



LoRa Radio – test #1 : one mile

LoRa Radio

I’d like to transmit data from a buoy floating in the water to a base station on shore. Power consumption and broadcast range are primary considerations. The amount of data being transmitted is expected to be minimal.

Screen Shot 2017-11-28 at 12.11.50 AM

I purchased two of the Adafruit RFM95W LoRa Radios to see if this might be a suitable solution. They were fairly inexpensive so I figured it was worth a test. The modules transmit on a license-free frequency and the Adafruit website says signals can travel 2 km – 20 km (1.4 – 12.4 miles) depending on the type of antenna used.

During the Thanksgiving holiday I had the opportunity to test the range of two LoRa radios in a neighborhood in Eugene, Oregon.  I wired up an Arduino Uno and Pro Trinket following the Adafruit provides tutorial, see their tutorial for all the details.

The Pro Trinket was setup as the Transmitter, this was located at the house. The Uno was setup as the Receiver and plugged into my laptop so I could watch the serial monitor as I walked around the neighbor hood. I was happily surprised, the radios transmitted one mile through in the suburban area with lots of trees and buildings in the way. While this isn’t ground breaking news, it was nice to conduct a real-world test and verify the websites claim. Below is the google maps screen shot from my phone that was used to verify the distance of approximately one mile.


Unfortunately I had to end the walk-about when it began to rain. But I plan to conduct more range tests to see how far these little radios and -2dB quad band antennas can broadcast. One interesting observation: I was not getting all of the data being sent from the transmitter at the house. The simple “hello world” example sketch included a counter to track the number of messages being sent out by the transmitter. At the end, it appears that every fifth message was being received. I’ll need to learn more about mitigating this issue in the future, but for now this is a good enough “first test”.

Screen Shot 2017-11-27 at 10.01.23 PM

Terrain will play in big factor  in determining maximum range, so I’d also like to run another test over a large body of water to see how the signal attenuates. This would be more similar to the conditions experience when the buoy is deployed. Maybe I can use a kayak and deploy a really simple buoy in the harbor and see if I can receive a message from my office building in Sausalito, CA.

More exploration onto the world or radios is needed!



New Circuit Board Design – r2

Version – 2

I’ve been learning how to use Eagle CAD to layout circuit boards and export gerber files. We have an Othermill CNC machine at work so I am beginning to prototype double sided boards for the buoy. This is the second version of my initial design – or what I am calling r2. *More info on my first design below…*


This copper board is essentially a larger “mother board” with headers for each of the smaller breakout boards to plug into. I used headers rather than soldering the breakout boards directly to the copper so that I can reuse the modules or replace them if needed. I expect I’ll go through several revisions and improvements as I learn more.

The following breakout boards are included on the copper board:

  • Microcontroller (MCU) >>> Adafruit Pro Trinket 3V 12MHz
  • Radio >>> Xbee Series 1 — sending data to second Xbee + FTDI cable + laptop
  • Inertial measurement unit (IMU) > Adafruit BNO055 sensor; accelerometer, gyroscope, magnetometer
  • GPS >>> GPS module for time and position information
  • Data logging > SD card read/write + micro SD card

So far so good, my r2 board is working and all of the individual modules are wired up correctly. But there are still improvements that need to be made. For example, the board cannot function on battery power yet. I included a connection for adding a small lipo battery + charger, but it is not hooked up correctly – I need to update the traces so that the BAT pin on the microcontroller goes to all Vin pins on the breakout boards instead of the BUS pin. *Ooops*

Version – 1

Below are images of my first double sided circuit board. I finished this one evening in October and soldered all the headers onto the copper board using some liquid flux and a small soldering iron with a sharp tip. You can see that some of the 1/64″ holes did not get drill through all the way.

Unfortunately, I made the mistake of connecting the microcontroller BUS pin to all my breakout boards via their 3V3 pins. The BUS pin provides 5V and up to 500 mA of current when the microcontroller is powered by the micro USB. When I attempted to upload the firmware via the USB cable, I accidentally burnt the Xbee radio and had to order two new modules. Luckily I only had the Xbee + MCU plugged into the copper board at that time so the delicate Xbee was the only fatality.

Lesson learned. Send all power into the modules via their 5V or Vin pins; Adafruit typically includes a 3v3 compatible voltage regulator so their boards are 5V/3V safe (if you wire up the correct pin).


More updates will include:

  • adding a Real Time Clock
  • adding an RGB LED
  • adding a temperature probe
  • redesign the board to be a circle shape
  • add a LoRa radio or other transmitter
  • fix the lipo battery problem
  • add a solar charger circuit

Version – 3

I’ve already started to incorporate updates to the design. Below is an example of the board with an added ground plane and the addition of an RGB LED and room for a digital temp sensor. Once I get the board to a more polished stage, I plan to share the source files and include a schematic drawing. But that has not been completed yet.

Screen Shot 2017-11-27 at 11.13.30 PMScreen Shot 2017-11-27 at 11.13.46 PM

Project Development – Stages

Stalled, but not forgotten!

Need to break this down into bite-size pieces.

I’ve decided to reevaluate the project scope and break it down into three distinct stages. Hopefully this will help to give me focus so I can make some progress. I’d like to get something in the water by the start of the new year!

Below are some scribbles from my note book:


Right now I’m still at Stage 1.

But I will focus on this new list of tasks and try to prevent myself from meandering too far from this list. Stage 1 is meant to be super simple/quick so that I can “fail early, and fail often”.  Hope this helps…

Buoy design – 95mm diameter

I recently built a smaller buoy design while I continue to work on the IMU code. The previous buoy was approximately 150mm in diameter and had room for lights, GPS, a large li-po battery and a considerably bigger microcontroller. This latest version is based on the electronics from a previous post and only needs to house a trinketpro, Xbee, and BNO005 IMU from Adafruit.

Old vs new design.


Project files for CAD and STL here.

Continue reading