Skip to content

Arduion Nano RP2040 Connect Issues #153

@fivdi

Description

@fivdi

When working with CircuitPython 7.1.1 on an Arduion Nano RP2040 Connect it should be possible to access a number of pins on the ESP32. However, accessing two of these pins results in errors being thrown. The pins on the ESP32 that can't be successfully accessed are pins A6 and A7, both of which are broken out to the GPIO header on the Arduino. A6 and A7 correspond to GPIO36 and GPIO35 on the ESP32 respectively (see page 3 of this document).

Issue With Digital Read

Attempting to use GPIO35 as a digital input with the following program:

import board
import busio
from digitalio import DigitalInOut 
from adafruit_esp32spi import adafruit_esp32spi

# Configure ESP32
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)
esp32 = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)

# Configure GPIO35 on the ESP32 as an input, then read and print its value
esp32.set_pin_mode(35, 0)
print(esp32.set_digital_read(35))

results in the following error being thrown:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/lib/adafruit_esp32spi/adafruit_esp32spi.py", line 867, in set_digital_read
AssertionError: Please update nina-fw to 1.5.0 or above.

The error message suggests updating to nina-fw 1.5.0 or above. This issue is occuring on a Arduino Nano RP2040 Connect which uses the Arduino version of nina-fw and not the Adafruit fork of nina-fw. Today, the latest version of the Arduino version of nina-fw is 1.4.8 so the error is suggesting an update to the Adafruit fork, 1.5.0 or above. However, according to this issue the Adafruit fork of nina-fw isn't compatible with the Arduino Nano RP2040 Connect.

This issue can be resolved by removing these two lines of method set_digital_read. Version 1.4.8 of the Arduino version of nina-fw has everything that is needed to perform digital reads successfully.

Issue With Analog Read

There is a similar issue with analog read. Attempting to use GPIO35 (A7) as an analog input with the following program:

import board
import busio
from digitalio import DigitalInOut 
from adafruit_esp32spi import adafruit_esp32spi

# Configure ESP32
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)
esp32 = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)

# Read and print the analog value of GPIO35 (A7)
print(esp32.set_analog_read(7))

results in the following error being thrown:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/lib/adafruit_esp32spi/adafruit_esp32spi.py", line 887, in set_analog_read
AssertionError: Please update nina-fw to 1.5.0 or above.

This issue can be resolved by removing these two lines of method set_analog_read. Version 1.4.8 of the Arduino version of nina-fw has everything that is needed to perform analog reads successfully.

Now a new error is thrown:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/lib/adafruit_esp32spi/adafruit_esp32spi.py", line 890, in set_analog_read
RuntimeError: buffer size must match format

This issue can be resolved by changing this line:

        resp_analog = struct.unpack("<i", resp[0])

to this:

        resp_analog = struct.unpack("<H", resp[0])

This change is needed because the Arduino version of nina-fw uses a 2-byte uint16_t to store analog values and the Adafruit fork uses a 4 byte int to store analog values. I don't know if this change would break things for other boards.

As can be seen, the implementation details of the Arduino and Adafruit versions of nina-fw are drifting apart in ways that can make things difficult for people using CircuitPython on the Arduion Nano RP2040 Connect. If would be good if these issues were resolved.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions