adafruit / adafruit/Adafruit_CircuitPython_ESP32SPI
RGB LED doesn't turn off on arduino nano connect 2040
- Dominant language
- Python
- Stars
- 102
- Forks
- 71
- Avg merge
- 2d 1h
- Merged PRs (30d)
- 1
Description
The following code on the Arduino Nano Connect 2040 results in a dim white light:
```py
import time
import board
import busio
from digitalio import DigitalInOut
from adafruit_esp32spi import adafruit_esp32spi
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)
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
# The LED-related part:
import adafruit_rgbled
from adafruit_esp32spi import PWMOut
LEDR = 27
LEDG = 25
LEDB = 26
RED_LED = PWMOut.PWMOut(esp, LEDR)
GREEN_LED = PWMOut.PWMOut(esp, LEDG)
BLUE_LED = PWMOut.PWMOut(esp, LEDB)
status_light = adafruit_rgbled.RGBLED(RED_LED, GREEN_LED, BLUE_LED, invert_pwm=True)
status_light.color = (0,0,0)
```
To be able to turn it off, I used `esp.set_digital_write` and ended up changing the PWM pin to digital when the duty cycle is 0 or 100% like this:
```py
class PWMOut2(PWMOut.PWMOut):
@property
def duty_cycle(self):
return super().duty_cycle()
@duty_cycle.setter
def duty_cycle(self, duty_cycle):
self._is_deinited()
if not isinstance(duty_cycle, (int, float)):
raise TypeError("Invalid duty_cycle, should be int or float.")
duty_cycle /= 65535.0
if not 0.0 <= duty_cycle <= 1.0:
raise ValueError("Invalid duty_cycle, should be between 0.0 and 1.0")
# If the value is 0 or 1, turn into a digital pin instead of PWM
if duty_cycle == 0.0:
self._esp.set_pin_mode(self._pwm_pin,1)
self._esp.set_digital_write(self._pwm_pin, False)
elif duty_cycle == 1.0:
self._esp.set_pin_mode(self._pwm_pin,1)
self._esp.set_digital_write(self._pwm_pin, True)
else:
self._esp.set_analog_write(self._pwm_pin, duty_cycle)
RED_LED = PWMOut2(esp, LEDR)
GREEN_LED = PWMOut2(esp, LEDG)
BLUE_LED = PWMOut2(esp, LEDB)
status_light = adafruit_rgbled.RGBLED(RED_LED, GREEN_LED, BLUE_LED, invert_pwm=True)
status_light.color = (0,0,0)
```
This might be an issue with the Nina firmware or the board's design, but I wonder if it would be ok to have that kind of things in the base code, or if it would be better to make a community library for the Nano.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reproducing the provided Arduino Nano Connect 2040 example and inspect PWMOut.PWMOut duty-cycle handling together with adafruit_rgbled.RGBLED. Confirm whether setting status_light.color to (0,0,0) leaves a dim light, and determine whether the behavior belongs in the base code; done means the RGB LED reliably turns off through the normal interface.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- embedded-iot
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100