OTA for Arduino Nano RP2040 Connect

This tutorial describes how to use Internet OTA for Arduino Nano RP2040 Connect. OTA Updates are done over the Internet using the connection with Thinger.io.

Requirements

Example for Arduino Nano RP2040 Connect

Create Project

In Visual Studio Code, create a new Platformio Project for Arduino Nano RP2040 Connect

image

Configure project

Modify platform.ini file to include thinger.io library and WiFiNINA for Internet connectivity:

[env:nanorp2040connect]
platform = raspberrypi
board = nanorp2040connect
framework = arduino
lib_deps = 
    WiFiNINA
    thinger.io

Update source code

In your main.cpp file, set the default example:

#define THINGER_SERIAL_DEBUG

#include <ThingerMbed.h>
#include <ThingerMbedOTA.h>
#include "arduino_secrets.h"

ThingerMbed thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);
ThingerMbedOTA ota(thing);

// cannot connect? Update WiFiNiNA and add iot.thinger.io SSL Certificate
// https://support.arduino.cc/hc/en-us/articles/360016119219

void setup() {

  // open serial for debugging
  Serial.begin(115200);

  // configure LED_BUILTIN for output
  pinMode(LED_BUILTIN, OUTPUT);

  // configure wifi network
  thing.add_wifi(SSID, SSID_PASSWORD);

  // pin control example (i.e. turning on/off a light, a relay, etc)
  thing["led"] << digitalPin(LED_BUILTIN);

  // resource output example (i.e. reading a sensor value, a variable, etc)
  thing["millis"] >> outputValue(millis());

  // start thinger task
  thing.start();

  // more details at http://docs.thinger.io/arduino/
}

void loop() {
  // use loop as in normal Arduino Sketch
  // use thing.lock() thing.unlock() if using variables exposed on thinger resources
}

Create also the arduino_secrets.h file, with the following details (adapting to your own Thinger.io username, device identifier, device credentials, and WiFi):

#define USERNAME "username"
#define DEVICE_ID "device"
#define DEVICE_CREDENTIAL "credential"

#define SSID "your_wifi_name"
#define SSID_PASSWORD "your_wifi_password"

Flash device

Now, upload your device (first time need to be done with the device connected to your computer) and ensure in serial monitor that the device is connected to the platform:

It is possible to also access to the Thinger.io console and check that the device API is working fine with the led and millis resources defined in the code:

OTA Update

Now, select your device by pressing the rocket icon in the bottom taskbar. If the Thinger.io VSCode extension is not configured, it will ask for the Thinger.io token with the permissions listed on requirements section.

image

Search and select your device:

image

And now, the device name is near the rocket icon:

image

Now, we are going to update the code, i.e., adding a serial debug:

void loop() {
  Serial.println("Remote OTA Update!");
  delay(5000);
}

To update the new version, just press the PLAY button near to the device switcher. It will compile the new version automatically, and will upload the firmware over the Internet.

image

After the update, the device will reboot automatically, and the new code will be running. We can veify the OTA update by checking the console output: