enabling the three pushbutton switches on the adafruit featherwing oled

When last I wrote about the Feather RP2040 and the Featherwing OLED 128×32 ( /2022/02/05/tinkering-with-the-black-adafruit-feather-rp2040/ ), I’d mentioned I’d like to enable the three switches on the edge of the Featherwing labeled ‘A’, ‘B’, and ‘C’. The code posted herewith has that enabled. I now have both the Featherwing and the NeoPixel ring attached to the Feather RP2040. I had to make a slight change to what the NeoPixel ring’s DIN (data in) line was attached to because it turns out that the ‘A’ switch on the Featherwing wants to use that same pin as an input. You can see the code changes and additions in the highlighted sections below.

When the code is executing, pressing any of the buttons will print “Button … pressed” only once on the REPL. When that button is released then “Button … released” is printed. This is simple early code without anything substantial hooked into those button checks, but the framework presented here should inspire something more interesting.

The next stage will be to add code back in to manipulate the OLED display. I hope that code will be a bit more streamlined than my earlier example.

import timeimport boardimport neopixelfrom digitalio import DigitalInOut, Direction, Pull# Define all three buttons, A, B, and C.#a_pressed = b_pressed = c_pressed = Falsea_button = DigitalInOut(board.D9)a_button.direction = Direction.INPUTa_button.pull = Pull.UPb_button = DigitalInOut(board.D6)b_button.direction = Direction.INPUTb_button.pull = Pull.UPc_button = DigitalInOut(board.D5)c_button.direction = Direction.INPUTc_button.pull = Pull.UP# For the single neopixel on the Feather itself.#s_neopixel = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2, auto_write=False, pixel_order=neopixel.GRB)# For the 12 neopixel ring attached to the Feather.#neopixel_ring = neopixel.NeoPixel(board.D10, 12, brightness=0.2, auto_write=True, pixel_order=neopixel.GRB)def cycle_color(color):s_neopixel.fill(color)s_neopixel.show()for i in range(len(neopixel_ring)):neopixel_ring[i-1] = (0,0,0,0) # turn LED offneopixel_ring[i] = colorneopixel_ring.show()time.sleep(.05)while True:if (a_button.value is not True):if (not a_pressed):print('Button A pressed')a_pressed = Trueelse:if (a_pressed):print('Button A released')a_pressed = Falseif (b_button.value is not True):if (not b_pressed):print('Button B pressed')b_pressed = Trueelse:if (b_pressed):print('Button B released')b_pressed = Falseif (c_button.value is not True):if (not c_pressed):print('Button C pressed')c_pressed = Trueelse:if (c_pressed):print('Button C released')c_pressed = Falsecycle_color((64,0,0,0)) # redcycle_color((0,64,0,0)) # greencycle_color((0,0,64,0)) # bluecycle_color((64,16,0,0)) # orangecycle_color((0,32,32,0)) # cyancycle_color((0,0,0,0)) # black (LED off)

adding a neopixel ring to the black adafruit feather rp2040

Two posts back I wrote about adding a NeoPixel stick with eight NeoPixels to the Black Adafruit Feather RP2040. In this quick post I take the code from the Feather STM32 driving the NeoPixel stick and quickly “port” it to the Feather RP2040 driving a NeoPixel ring with 12 NeoPixel LEDs. Both Feathers are running their specific version of Circuit Python version 7.1.1. The story behind how I acquired the NeoPixel ring is interesting. One day last year, while visiting the Parallax website ( https://www.parallax.com ) I came across a sale of a mystery box of components (Adafruit has the equivalent). So I bit and bought one, just to see what I’d get. When the mystery box arrived it had a lot of interesting components, one of which was the NeoPixel ring. I had no use for the ring at the time and put it back in the box and put the box on the shelf with a lot of other boxes with components I keep in case… Forward six months or so and I came across a sale of the NeoPixel sticks, so I bought one along with the STM32 Feather.

Today as I was cleaning and reorganizing I came across that mystery box and remembered I had the NeoPixel ring in it. I pulled it out, soldered some wires to it, plugged it into the Feather RP2040 using the same pins as with the Feather STM32 and copied the STM32’s code over to the RP2040. I had to make two changes to one line of code at line 14:

  1. Change the number of NeoPixel LEDS from 8 to 12, and
  2. Change the NeoPixel type from neopixel.GRBW to neopixel.GRB because there is no white on the NeoPixel ring.

Once that was done the behavior of the NeoPixel ring was essentially identical with the NeoPixel stick.

import timeimport boardimport neopixel # For the single neopixel on the feather itself.#sneopixel = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2, auto_write=False, pixel_order=neopixel.GRB) # For the eight neopixel board attached to the feather.#pixelboard = neopixel.NeoPixel(board.D5, 12, brightness=0.2, auto_write=True, pixel_order=neopixel.GRB) def cycleColor(color):sneopixel.fill(color)sneopixel.show()for i in range(len(pixelboard)):pixelboard[i-1] = (0,0,0,0) # turn LED offpixelboard[i] = colorpixelboard.show()time.sleep(.05) while True:cycleColor((64,0,0,0)) # redcycleColor((0,64,0,0)) # greencycleColor((0,0,64,0)) # bluecycleColor((64,16,0,0)) # orangecycleColor((0,32,32,0)) # cyancycleColor((0,0,0,0)) # black (LED off)

And once again the video clip was made with my iPhone 11 Pro, and it’s as crappy as the last one. I will work diligently to learn how to do a much better job of videoing these types of devices. They look far better in person.