Moving from uno to nano

I created a project using a breadboard and an arduino uno rev4 wifi. It is my first project so I started most functionality based on the examples, this includes for example connecting to wifi, doing http calls to a server...

Now I've created a soldered perfboard with an arduino nano iot on it. I had assumed the code would be portable but this does not seem to be the case.

Ideally I would like to create a common codebase that uses the same components so I can alternate between prototyping on the breadboard and the uno and creating a smaller version with the nano.

If that is not possible I would still like to retain a single codebase to share as much as possible and use different implementations where necessary depending on the target device. How would I go about including/excluding specific files based on the compilation target?

So far I have at least two parts of the application that do not appear to work on the nano:

  • wifi+http using WiFiS3 (as per the uno example). Is there a library that works on both?
  • eeprom: i use eeprom to store a persistant value (a generated identity)

I managed to get the project compiled for both devices.

The WifiNINA library compiles for the nano but not for the uno. It does appear that it has the exact same API as the WifiS3 though, so I am currently using this to switch implementations.

#if defined(ARDUINO_UNOWIFIR4)
#include <WiFiS3.h>
#elif defined(ARDUINO_SAMD_NANO_33_IOT)
#include <WiFiNINA.h>
#include <SPI.h>
#endif

I had trouble tracking down the name ARDUINO_UNOWIFIR4 though, finally found it by grepping the arduino folder for some random strings. Is there a centralized list of these definitions?

For the EEPROM i used the flash-as-eeprom library (GitHub - cmaglie/FlashStorage: A convenient way to store data into Flash memory on the ATSAMD21 and ATSAMD51 processor family) and switched using this:

#if defined(ARDUINO_UNOWIFIR4)
#include <EEPROM.h>
#elif defined(ARDUINO_SAMD_NANO_33_IOT)
#include <FlashAsEEPROM.h>
#endif

Note that I added an additional line of code:

#if defined(ARDUINO_SAMD_NANO_33_IOT)
// need to commit the eeprom to flash when using the flash alternative
EEPROM.commit();
#endif

This compiles successfully for both devices. The nano also appears to connect correctly to the wifi and the eeprom data survives a power cycle.

So, there is no problem now, right?

Why not use a Nano IOT for the breadboard prototyping? With header pins installed (facing downward), the Nano IOT can be directly inserted into a breadboard.

I think that name comes from adding "ARDUINO_" to the text from the build.board line in the boards.txt file. This is a list from all the Arduino board packages I currently have on my computer:

adafruit_circuitplayground_m0.build.board=SAMD_CIRCUITPLAYGROUND_EXPRESS
arduino_due_x.build.board=SAM_DUE
arduino_due_x_dbg.build.board=SAM_DUE
arduino_zero_edbg.build.board=SAMD_ZERO
arduino_zero_native.build.board=SAMD_ZERO
atmegang.build.board=AVR_NG
bt.build.board=AVR_BT
chiwawa.build.board=AVR_INDUSTRIAL101
circuitplay32u4cat.build.board=AVR_CIRCUITPLAY
diecimila.build.board=AVR_DUEMILANOVE
esplora.build.board=AVR_ESPLORA
ethernet.build.board=AVR_ETHERNET
fio.build.board=AVR_FIO
gemma.build.board=AVR_GEMMA
giga.build.board=GIGA
leonardo.build.board=AVR_LEONARDO
leonardoeth.build.board=AVR_LEONARDO_ETH
lilypad.build.board=AVR_LILYPAD
LilyPadUSB.build.board=AVR_LILYPAD_USB
megaADK.build.board=AVR_ADK
mega.build.board=AVR_MEGA2560
mega.menu.cpu.atmega1280.build.board=AVR_MEGA
mega.menu.cpu.atmega2560.build.board=AVR_MEGA2560
micro.build.board=AVR_MICRO
mini.build.board=AVR_MINI
minima.build.board=MINIMA
mkr1000.build.board=SAMD_MKR1000
mkrfox1200.build.board=SAMD_MKRFox1200
mkrgsm1400.build.board=SAMD_MKRGSM1400
mkrnb1500.build.board=SAMD_MKRNB1500
mkrvidor4000.build.board=SAMD_MKRVIDOR4000
mkrwan1300.build.board=SAMD_MKRWAN1300
mkrwan1310.build.board=SAMD_MKRWAN1310
mkrwifi1010.build.board=SAMD_MKRWIFI1010
mkrzero.build.board=SAMD_MKRZERO
mzero_bl.build.board=SAM_ZERO
mzero_pro_bl.build.board=SAM_ZERO
mzero_pro_bl_dbg.build.board=SAM_ZERO
nano33ble.build.board=ARDUINO_NANO33BLE
nano_33_iot.build.board=SAMD_NANO_33_IOT
nano.build.board=AVR_NANO
nanorp2040connect.build.board=NANO_RP2040_CONNECT
nona4809.build.board=AVR_NANO_EVERY
one.build.board=AVR_LININO_ONE
#opta_analog.build.board=OPTA_ANALOG
#opta_digital.build.board=OPTA_DIGITAL
#portenta_c33.build.board=PORTENTA_C33
portenta_x8.build.board=PORTENTA_X8
pro.build.board=AVR_PRO
robotControl.build.board=AVR_ROBOT_CONTROL
robotMotor.build.board=AVR_ROBOT_MOTOR
tian.build.board=SAMD_TIAN
tian_cons.build.board=SAMD_TIAN
uno2018.build.board=AVR_UNO_WIFI_REV2
uno.build.board=AVR_UNO
unomini.build.board=AVR_UNO
unor4wifi.build.board=UNOWIFIR4
unowifi.build.board=AVR_UNO_WIFI_DEV_ED
yun.build.board=AVR_YUN
yunmini.build.board=AVR_YUNMINI

While the API may be the same of very similar, the hardware is different. The Nano has a NINA-W102 WiFi chip onboard, while the UNO R4 has an ESP32-S3

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.