WIRING: Anode (+) side of nOOds go to GPIO pins, cathode (-) to ground. Current-limiting resistor can go at either end.
This is merely a schematic diagram, you might be using gator clips or a breadboard or whatnot:
# Adafruit nOOds digital control using GPIO pins. # Uses 3 nOOds, anode (+) to GPIO pin, cathode (-) to ground. # A current-limiting resistor (e.g. 220 Ohm) can go at either end. import time import board import digitalio # This uses the 3 adjacent SPI pins on QtPy RP2040, but any pins will do. PINS = (board.SCK, board.MISO, board.MOSI) # List of pins, one per nOOd # Convert pin number list to pin object list, initialize to OFF pin_list = [digitalio.DigitalInOut(pin) for pin in PINS] for pin in pin_list: pin.direction = digitalio.Direction.OUTPUT pin.value = False # All off to start while True: # Repeat forever... for pin in pin_list: # For each pin... pin.value = True # nOOd on time.sleep(0.5) # Pause 1/2 sec pin.value = False # nOOd off
// Adafruit nOOds digital control using GPIO pins. // Uses 3 nOOds, anode (+) to GPIO pin, cathode (-) to ground. // A current-limiting resistor (e.g. 220 Ohm) can go at either end. // This uses the 3 adjacent SPI pins on QtPy RP2040, but any pins will do. uint8_t pins[] = { SCK, MISO, MOSI }; // List of pins, one per nOOd #define NUM_PINS (sizeof(pins) / sizeof(pins[0])) void setup() { for (uint8_t i=0; i<NUM_PINS; i++) pinMode(pins[i], OUTPUT); } void loop() { for (uint8_t i=0; i<NUM_PINS; i++) { // For each pin... digitalWrite(pins[i], HIGH); // nOOd on delay(500); // Pause 1/2 sec digitalWrite(pins[i], LOW); // nOOd off } }
# Adafruit nOOds "analog" (PWM) brightness control using GPIO. # Uses 3 nOOds, anode (+) to GPIO pin, cathode (-) to ground. # A current-limiting resistor (e.g. 220 Ohm) can go at either end. import math import time import board import pwmio # This uses the 3 adjacent SPI pins on QtPy RP2040, but any pins will do. PINS = (board.SCK, board.MISO, board.MOSI) # List of pins, one per nOOd GAMMA = 2.6 # For perceptually-linear brightness # Convert pin number list to PWMOut object list pin_list = [pwmio.PWMOut(pin, frequency=1000, duty_cycle=0) for pin in PINS] while True: # Repeat forever... for i, pin in enumerate(pin_list): # For each pin... # Calc sine wave, phase offset for each pin, with gamma correction. # If using red, green, blue nOOds, you'll get a cycle of hues. phase = (time.monotonic() - 2 * i / len(PINS)) * math.pi brightness = int((math.sin(phase) + 1.0) * 0.5 ** GAMMA * 65535 + 0.5) pin.duty_cycle = brightness
// Adafruit nOOds "analog" (PWM) brightness control using GPIO. // Uses 3 nOOds, anode (+) to GPIO pin, cathode (-) to ground. // A current-limiting resistor (e.g. 220 Ohm) can go at either end. // This uses the 3 adjacent SPI pins on QtPy RP2040, but most pins will do. // Some boards have specific limitations for which pins support PWM! uint8_t pins[] = { SCK, MISO, MOSI }; // List of pins, one per nOOd #define GAMMA 2.6 // For perceptually-linear brightness #define NUM_PINS (sizeof(pins) / sizeof(pins[0])) void setup() { for (uint8_t i=0; i<NUM_PINS; i++) pinMode(pins[i], OUTPUT); } void loop() { for (uint8_t i=0; i<NUM_PINS; i++) { // # For each pin... // Calc sine wave, phase offset for each pin, with gamma correction. // If using red, green, blue nOOds, you'll get a cycle of hues. float phase = (millis() / 1000.0 - 2.0 * i / (float)NUM_PINS) * M_PI; int brightness = int(pow((sin(phase) + 1.0) * 0.5, GAMMA) * 255 + 0.5); analogWrite(pins[i], brightness); } }
WIRING: Anode (+) side of nOOds go to VIN pins, cathode (-) to numbered breakout pins. Current-limiting resistors are not needed.
This is merely a schematic diagram, you might be using gator clips or a breadboard or whatnot:
IMPORTANT: These code examples are fairly brief. If using AW9523 LED driver as part of a bigger program, set up the driver and pins as early as possible! The chip’s power-on state does not provide the 18.5 mA current control to LEDs. A tiny blip on startup is harmless, but LEDs shouldn’t be kept in this state for any length of time. Related, this is why the examples favor upper pin numbers on the breakout board; these pins provide some current control on power up, though still higher than we’d like (37 mA vs 18.5). Initialization corrects all of this! If this power blip is still a concern, or your code’s unable to get to initialization quickly, it’s perfectly acceptable to add current-limiting resistors.
Because the AW9523 is a current sink (rather than source), you’ll notice when initializing pins, and in the digital control examples, that the logic is inverted: 1
or True
(CircuitPython) or HIGH
(Arduino) indicates off, 0
or False
(CircuitPython) or LOW
(Arduino) is on.
# Adafruit nOOds digital control using AW9523 LED driver breakout. # Uses 3 nOOds, anode (+) to VIN row, cathode (-) to pins labeled 13-15. import time import board import adafruit_aw9523 PINS = (13, 14, 15) # List of pins, one per nOOd # Instantiate AW9523 on STEMMA I2C bus. This was tested on QT Py RP2040. # Other boards might require board.I2C() instead of board.STEMMA_I2C(). aw = adafruit_aw9523.AW9523(board.STEMMA_I2C()) # Activate pins while converting pin number list to pin object list pin_list = [aw.get_pin(pin) for pin in PINS] for pin in pin_list: pin.switch_to_output(value=True) # Initialize pin OFF while True: # Repeat forever... for pin in pin_list: # For each pin... pin.value = False # nOOd on time.sleep(0.5) # Pause 1/2 sec pin.value = True # nOOd off
// Adafruit nOOds digital control using AW9523 LED driver breakout. // Uses 3 nOOds, anode (+) to VIN row, cathode (-) to pins labeled 13-15. #include <Adafruit_AW9523.h> uint8_t pins[] = { 13, 14, 15 }; // List of pins, one per nOOd #define NUM_PINS (sizeof(pins) / sizeof(pins[0])) Adafruit_AW9523 aw; void setup() { // &Wire1 here refers to the STEMMA connector on QT Py RP2040. // On some boards, that might be &Wire or can just be omitted. if (!aw.begin(0x58, &Wire1)) { Serial.begin(); while(!Serial); Serial.println("AW9523 not found. Check wiring!"); while (1); // halt } for (uint8_t i=0; i<NUM_PINS; i++) { aw.pinMode(pins[i], OUTPUT); aw.digitalWrite(pins[i], HIGH); // nOOd off } } void loop() { for (uint8_t i=0; i<NUM_PINS; i++) { // For each pin... aw.digitalWrite(pins[i], LOW); // nOOd on delay(500); // Pause 1/2 sec aw.digitalWrite(pins[i], HIGH); // nOOd off } }
# Adafruit nOOds analog brightness control using AW9523 LED driver breakout. # Uses 3 nOOds, anode (+) to VIN row, cathode (-) to pins labeled 13-15. import math import time import board import adafruit_aw9523 GAMMA = 2.6 # For perceptually-linear brightness PINS = (13, 14, 15) # List of pins, one per nOOd # Instantiate AW9523 on STEMMA I2C bus. This was tested on QT Py RP2040. # Other boards might require board.I2C() instead of board.STEMMA_I2C(). aw = adafruit_aw9523.AW9523(board.STEMMA_I2C()) for pin in PINS: aw.get_pin(pin).switch_to_output(value=True) # Activate pin, initialize OFF aw.LED_modes |= 1 << pin # Enable constant-current on pin while True: # Repeat forever... for i, pin in enumerate(PINS): # For each pin... # Calc sine wave, phase offset for each pin, with gamma correction. # If using red, green, blue nOOds, you'll get a cycle of hues. phase = (time.monotonic() - 2 * i / len(PINS)) * math.pi brightness = int((math.sin(phase) + 1.0) * 0.5 ** GAMMA * 255 + 0.5) aw.set_constant_current(pin, brightness)
// Adafruit nOOds analog brightness control using AW9523 LED driver breakout. // Uses 3 nOOds, anode (+) to VIN row, cathode (-) to pins labeled 13-15. #include <Adafruit_AW9523.h> uint8_t pins[] = { 13, 14, 15 }; // List of pins, one per nOOd #define GAMMA 2.6 // For perceptually-linear brightness #define NUM_PINS (sizeof(pins) / sizeof(pins[0])) Adafruit_AW9523 aw; void setup() { // &Wire1 here refers to the STEMMA connector on QT Py RP2040. // On some boards, that might be &Wire or can just be omitted. if (!aw.begin(0x58, &Wire1)) { Serial.begin(); while(!Serial); Serial.println("AW9523 not found. Check wiring!"); while (1); // halt } for (uint8_t i=0; i<NUM_PINS; i++) { aw.pinMode(pins[i], AW9523_LED_MODE); aw.analogWrite(pins[i], 0); // nOOd off } } void loop() { for (uint8_t i=0; i<NUM_PINS; i++) { // For each pin... // Calc sine wave, phase offset for each pin, with gamma correction. // If using red, green, blue nOOds, you'll get a cycle of hues. float phase = (millis() / 1000.0 - 2.0 * i / (float)NUM_PINS) * M_PI; int brightness = int(pow((sin(phase) + 1.0) * 0.5, GAMMA) * 255 + 0.5); aw.analogWrite(pins[i], brightness); } }
Text editor powered by tinymce.