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.

In the example below, click the Download Project Bundle button below to download the necessary libraries and the code.py file in a zip file. Extract the contents of the zip file, open the directory Arduino_Nano_RP2040_Connect/arduino_nano_rp2040_connect_wifi/ and then click on the directory that matches the version of CircuitPython you're using and copy the contents of that directory to your CIRCUITPY drive.

Your CIRCUITPY drive should now look similar to the following image:

CIRCUITPY
# SPDX-FileCopyrightText: 2021 Liz Clark for Adafruit Industries
#
# SPDX-License-Identifier: MIT

'''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!")

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 Jun 04, 2021.

This page (WiFi) was last updated on Mar 20, 2023.

Text editor powered by tinymce.