The biggest feature of the Arduino Nano RP2040 Connect is in the name: being able to connect to WiFi. This means that you can use it for IoT projects and anything else that could benefit from WiFi connectivity. The Nina W102 uBlox module on the board is an ESP32 and connects to the RP2040 via SPI. As a result, it's compatible with the ESP32 SPI CircuitPython libraries with a few pin modifications. The example below is modified from the Adafruit_CircuitPython_ESP32SPI library example.

You can access the code by downloading the Project Bundle. To do this, click on the Download Project Bundle button in the window below. It will download as a zipped folder.

'''Adapted from the Adafruit_CircuitPython_ESP32SPI
library example esp32spi_simpletest.py:
https://github.com/adafruit/Adafruit_CircuitPython_ESP32SPI/
blob/master/examples/esp32spi_simpletest.py '''

import board
import busio
from digitalio import DigitalInOut
import adafruit_requests as requests
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
from adafruit_esp32spi import adafruit_esp32spi

# Get wifi details and more from a secrets.py file
try:
    from secrets import secrets
except ImportError:
    print("WiFi secrets are kept in secrets.py, please add them there!")
    raise

print("Arduino Nano RP2040 Connect webclient test")

TEXT_URL = "http://wifitest.adafruit.com/testwifi/index.html"

#  ESP32 pins
esp32_cs = DigitalInOut(board.CS1)
esp32_ready = DigitalInOut(board.ESP_BUSY)
esp32_reset = DigitalInOut(board.ESP_RESET)

#  uses the secondary SPI connected through the ESP32
spi = busio.SPI(board.SCK1, board.MOSI1, board.MISO1)

esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)

requests.set_socket(socket, esp)

if esp.status == adafruit_esp32spi.WL_IDLE_STATUS:
    print("ESP32 found and in idle mode")
print("Firmware vers.", esp.firmware_version)
print("MAC addr:", [hex(i) for i in esp.MAC_address])

for ap in esp.scan_networks():
    print("\t%s\t\tRSSI: %d" % (str(ap['ssid'], 'utf-8'), ap['rssi']))

print("Connecting to AP...")
while not esp.is_connected:
    try:
        esp.connect_AP(secrets["ssid"], secrets["password"])
    except RuntimeError as e:
        print("could not connect to AP, retrying: ", e)
        continue
print("Connected to", str(esp.ssid, "utf-8"), "\tRSSI:", esp.rssi)
print("My IP address is", esp.pretty_ip(esp.ip_address))

print(
    "IP lookup adafruit.com: %s" % esp.pretty_ip(esp.get_host_by_name("adafruit.com"))
)

print("Fetching text from", TEXT_URL)
r = requests.get(TEXT_URL)
print("-" * 40)
print(r.text)
print("-" * 40)
r.close()

print("Done!")

Upload the Code and Libraries to the Arduino Nano RP2040 Connect

After downloading the Project Bundle, plug your board into the computer USB port. You should see a new flash drive appear in the computer's File Explorer or Finder (depending on your operating system) called CIRCUITPY. Unzip the folder and copy the lib folder and arduino_nano_rp2040_connect_wifi.py file to the Arduino Nano RP2040 Connect's CIRCUITPY drive. Then, rename arduino_nano_rp2040_connect_wifi.py to code.py

You'll also need to create a secrets.py file to access your SSID and network password. More information on the secrets.py file can be found here in this Learn Guide.

Your Arduino Nano RP2040 Connect CIRCUITPY drive should look like this after copying the lib folder, secrets.py file and code.py file.

Nina W102 uBlox Module and SPI

The ESP32 SPI connections on the Arduino Nano RP2040 Connect are a little different than other ESP32 SPI connections with CircuitPython. The Nina W102 uBlox module uses a secondary SPI connection to communicate with the RP2040 microcontroller rather than the default SPI for the board. As a result, the pins needed to connect to the ESP32 in the CircuitPython code are:

esp32_cs = DigitalInOut(board.CS1)
esp32_ready = DigitalInOut(board.ESP_BUSY)
esp32_reset = DigitalInOut(board.ESP_RESET)

spi = busio.SPI(board.SCK1, board.MOSI1, board.MISO1)

After making those pin adjustments though, you'll be able to create connected CircuitPython projects.

REPL Output

After running the code, you should see an output with this information in the REPL. It includes the ESP32 firmware version, the Arduino Nano RP2040 Connect's MAC address, your surrounding WiFi networks, your IP address after connecting to your network and the results of a ping test to the Adafruit WiFi Test.

This guide was first published on Jun 04, 2021. It was last updated on 2021-06-04 14:46:06 -0400.

This page (WiFi) was last updated on Sep 21, 2021.

Text editor powered by tinymce.