Example Code

Of course, we don’t just leave you with the board and a “good luck”; here are some code examples to get you started with your FeatherWing.

Make sure to visit the example code repo on Github for more example code.

These examples have been tested with the Adafruit Feather M4 Express, depending on which Feather you’re using, some modifications might be needed.

CircuitPython

Tested with CircuitPython 6.0. Additional libraries are needed, see README.md for details.

Initializing the LCD

import adafruit_ili9341
import displayio
import board

displayio.release_displays()

spi = board.SPI()
tft_cs = board.D9
tft_dc = board.D10

display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs)
display = adafruit_ili9341.ILI9341(display_bus, width=320, height=240)

Using the Touch Screen

import board, digitalio
import tsc2004

i2c = board.I2C()

touch = tsc2004.TSC2004(i2c)
while not touch.touched:
    pass

print(touch.read_data())

Using the Keyboard

from bbq10keyboard import BBQ10Keyboard
import board

i2c = board.I2C()
kbd = BBQ10Keyboard(i2c)

while kbd.key_count == 0:
    pass

print(kbd.keys)

Using the GPIO Expander

from bbq10keyboard import BBQ10Keyboard
import board
import digitalio
import time

i2c = board.I2C()
kbd = BBQ10Keyboard(i2c)

card_detect = kbd.get_pin(1)

# use the same API as digitalio.DigitalInOut
card_detect.switch_to_input(pull=digitalio.Pull.UP)

prev_value = card_detect.value

while True:
    if card_detect.value != prev_value:
        print('Card Detect: %d' % card_detect.value)

        prev_value = card_detect.value

    time.sleep(0.5)

Using the microSD card

import board, digitalio
import adafruit_sdcard
import storage, os

spi = board.SPI()
sd_cs = board.D5

sdcard = adafruit_sdcard.SDCard(spi, digitalio.DigitalInOut(sd_cs))
vfs = storage.VfsFat(sdcard)
storage.mount(vfs, '/sd')

print(os.listdir('/sd/'))

Using the Neopixel

import board,
import neopixel

neopix_pin = board.D11

pixels = neopixel.NeoPixel(neopix_pin, 1)
pixels[0] = 0xFF00FF

Arduino

Initializing the LCD

#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>

#define TFT_CS 9
#define TFT_DC 10

Adafruit_ILI9341 tft(TFT_CS, TFT_DC);

void setup()
{
  tft.begin();
  tft.setRotation(1);
  tft.println("Hello World");
}

Using the Touch Screen

#include <TSC2004.h>

TSC2004 ts;

void setup() {
  Serial.begin(9600);

  ts.begin();
}

void loop() {
  if (!ts.touched()) {
    return;
  }

  const TS_Point p = ts.getPoint();

  Serial.print("(");
  Serial.print(p.x);
  Serial.print(", ");
  Serial.print(p.y);
  Serial.print(", ");
  Serial.print(p.z);
  Serial.println(")");
}

Using the Keyboard

#include <BBQ10Keyboard.h>

BBQ10Keyboard keyboard;

void setup()
{
  Wire.begin();
  keyboard.begin();
  while (!keyboard.keyCount()) {
    ;
  }
  const BBQ10Keyboard::KeyEvent key = keyboard.keyEvent();
}

Using the microSD card

#include <SD.h>

#define SD_CS 5

void setup()
{
  SD.begin(SD_CS);
  File root = SD.open("/");
}

Using the Neopixel

#include <Adafruit_NeoPixel.h>

#define NEOPIXEL_PIN 11

Adafruit_NeoPixel pixels(1, NEOPIXEL_PIN, NEO_GRB + NEO_KHZ800);

void setup()
{
    pixels.begin();
    pixels.setPixelColor(0, pixels.Color(255, 0, 255));
    pixels.show();
}

void loop()
{
    delay(1000);
}
Last modified August 5, 2024