Simple tests

Ensure your device works with this simple test.

examples/featherwing_ina219_simpletest.py
 1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4""" Example to print out the voltage and current using the INA219 """
 5import time
 6from adafruit_featherwing import ina219_featherwing
 7
 8INA219 = ina219_featherwing.INA219FeatherWing()
 9
10while True:
11    print("Bus Voltage:   {} V".format(INA219.bus_voltage))
12    print("Shunt Voltage: {} V".format(INA219.shunt_voltage))
13    print("Voltage:       {} V".format(INA219.voltage))
14    print("Current:       {} mA".format(INA219.current))
15    print("")
16    time.sleep(0.5)
examples/featherwing_joy_simpletest.py
 1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4"""This example zeros the joystick, and prints when the joystick moves
 5   or the buttons are pressed."""
 6import time
 7from adafruit_featherwing import joy_featherwing
 8
 9wing = joy_featherwing.JoyFeatherWing()
10last_x = 0
11last_y = 0
12
13while True:
14    x, y = wing.joystick
15    if (abs(x - last_x) > 3) or (abs(y - last_y) > 3):
16        last_x = x
17        last_y = y
18        print(x, y)
19    if wing.button_a:
20        print("Button A!")
21    if wing.button_b:
22        print("Button B!")
23    if wing.button_x:
24        print("Button X!")
25    if wing.button_y:
26        print("Button Y!")
27    if wing.button_select:
28        print("Button SELECT!")
29    time.sleep(0.01)
examples/featherwing_alphanum_simpletest.py
 1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4"""This example changes the fill, brightness, blink rates,
 5shows number and text printing, displays a counter
 6and then shows off the new marquee features."""
 7
 8from time import sleep
 9from adafruit_featherwing import alphanum_featherwing
10
11display = alphanum_featherwing.AlphaNumFeatherWing()
12
13# Fill and empty all segments
14for count in range(0, 3):
15    display.fill(True)
16    sleep(0.5)
17    display.fill(False)
18    sleep(0.5)
19
20# Display a number and text
21display.print(1234)
22sleep(1)
23display.print("Text")
24
25# Change brightness
26for brightness in range(0, 16):
27    display.brightness = brightness
28    sleep(0.1)
29
30# Change blink rate
31for blink_rate in range(3, 0, -1):
32    display.blink_rate = blink_rate
33    sleep(4)
34display.blink_rate = 0
35
36# Show a counter using decimals
37count = 975.0
38while count < 1025:
39    count += 1
40    display.print(count)
41    sleep(0.1)
42
43# Show the Marquee
44display.marquee("This is a really long message!!!  ", 0.2)
examples/featherwing_dotstar_simpletest.py
 1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4"""
 5This plays various animations
 6and then draws random pixels at random locations
 7"""
 8
 9from time import sleep
10import random
11from adafruit_featherwing import dotstar_featherwing
12
13dotstar = dotstar_featherwing.DotStarFeatherWing()
14
15# HELPERS
16# a random color 0 -> 224
17def random_color():
18    return random.randrange(0, 8) * 32
19
20
21# Fill screen with random colors at random brightnesses
22for i in range(0, 5):
23    dotstar.fill((random_color(), random_color(), random_color()))
24    dotstar.brightness = random.randrange(2, 10) / 10
25    sleep(0.2)
26
27# Set display to 30% brightness
28dotstar.brightness = 0.3
29
30# Create a gradiant drawing each pixel
31for x in range(0, dotstar.columns):
32    for y in range(dotstar.rows - 1, -1, -1):
33        dotstar[x, y] = (y * 42, 255, y * 42, 1)
34
35# Rotate everything left 36 frames
36for i in range(0, 36):
37    dotstar.shift_down(True)
38
39# Draw dual gradiant and then update
40dotstar.auto_write = False
41for y in range(0, dotstar.rows):
42    for x in range(0, 6):
43        dotstar[x, y] = (y * 84, x * 42, x * 42, 1)
44    for x in range(6, 12):
45        dotstar[x, y] = (255 - (y * 84), 255 - ((x - 6) * 42), 255 - ((x - 6) * 42), 1)
46
47# Rotate everything left 36 frames
48for i in range(0, 36):
49    dotstar.shift_left(True)
50    dotstar.shift_up(True)
51    dotstar.show()
52dotstar.auto_write = True
53
54# Shift pixels without rotating for an animated screen wipe
55for i in range(0, 6):
56    dotstar.shift_down()
57
58# Show pixels in random locations of random color
59# Bottom left corner is (0,0)
60while True:
61    x = random.randrange(0, dotstar.columns)
62    y = random.randrange(0, dotstar.rows)
63    dotstar[x, y] = (random_color(), random_color(), random_color())
64    sleep(0.1)
examples/featherwing_neopixel_simpletest.py
 1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4"""
 5This example plays various animations
 6and then draws random pixels at random locations
 7"""
 8
 9from time import sleep
10import random
11from adafruit_featherwing import neopixel_featherwing
12
13neopixel = neopixel_featherwing.NeoPixelFeatherWing()
14
15# HELPERS
16# a random color 0 -> 224
17def random_color():
18    return random.randrange(0, 8) * 32
19
20
21# Fill screen with random colors at random brightnesses
22for i in range(0, 5):
23    neopixel.fill((random_color(), random_color(), random_color()))
24    neopixel.brightness = random.randrange(2, 10) / 10
25    sleep(0.2)
26
27# Set display to 30% brightness
28neopixel.brightness = 0.3
29
30# Create a gradiant drawing each pixel
31for x in range(0, neopixel.columns):
32    for y in range(neopixel.rows - 1, -1, -1):
33        neopixel[x, y] = (y * 63, 255, y * 63)
34
35# Rotate everything left 36 frames
36for i in range(0, 36):
37    neopixel.shift_down(True)
38    sleep(0.1)
39
40# Draw dual gradiant and then update
41# neopixel.auto_write = False
42for y in range(0, neopixel.rows):
43    for x in range(0, 4):
44        neopixel[x, y] = (y * 16 + 32, x * 8, 0)
45    for x in range(4, 8):
46        neopixel[x, y] = ((4 - y) * 16 + 32, (8 - x) * 8, 0)
47neopixel.show()
48
49# Rotate everything left 36 frames
50for i in range(0, 36):
51    neopixel.shift_left(True)
52    neopixel.shift_up(True)
53    neopixel.show()
54    sleep(0.1)
55neopixel.auto_write = True
56
57# Shift pixels without rotating for an animated screen wipe
58for i in range(0, neopixel.rows):
59    neopixel.shift_down()
60    sleep(0.4)
61
62# Show pixels in random locations of random color
63# Bottom left corner is (0,0)
64while True:
65    x = random.randrange(0, neopixel.columns)
66    y = random.randrange(0, neopixel.rows)
67    neopixel[x, y] = (random_color(), random_color(), random_color())
68    sleep(0.1)
examples/featherwing_sevensegment_simpletest.py
 1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4"""This example changes the fill, brightness, blink rates,
 5shows number and text printing, displays a counter
 6and then shows off the new marquee features."""
 7
 8from time import sleep
 9from adafruit_featherwing import sevensegment_featherwing
10
11display = sevensegment_featherwing.SevenSegmentFeatherWing()
12
13# Fill and empty all segments
14for count in range(0, 3):
15    display.fill(True)
16    sleep(0.5)
17    display.fill(False)
18    sleep(0.5)
19
20# Display a number and text
21display.print(1234)
22sleep(1)
23display.print("FEED")
24
25# Change brightness
26for brightness in range(0, 16):
27    display.brightness = brightness
28    sleep(0.1)
29
30# Change blink rate
31for blink_rate in range(3, 0, -1):
32    display.blink_rate = blink_rate
33    sleep(4)
34display.blink_rate = 0
35
36# Show a counter using decimals
37count = 975.0
38while count < 1025:
39    count += 1
40    display.print(count)
41    sleep(0.1)
42
43# Display a Time
44hour = 12
45for minute in range(15, 26):
46    display.print("{}:{}".format(hour, minute))
47    sleep(1)
48
49# Show the Marquee
50display.marquee("Deadbeef 192.168.100.102... ", 0.2)
examples/featherwing_rtc_simpletest.py
 1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4"""
 5This example will allow you to set the date and time
 6and then loop through and display the current time
 7"""
 8import time
 9from adafruit_featherwing import rtc_featherwing
10
11days = ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday")
12
13# Create the RTC instance:
14rtc = rtc_featherwing.RTCFeatherWing()
15
16# pylint: disable-msg=using-constant-test
17if True:  # Change this to True to set the date and time
18    rtc.set_time(13, 34)  # Set the time (seconds are optional)
19    print(rtc.now)
20    rtc.set_date(16, 1, 2016)  # Set the date
21    print(rtc.now)
22    rtc.year = 2019  # Set just the Year
23    print(rtc.now)
24    rtc.month = 2  # Set Just the Month
25    print(rtc.now)
26    rtc.hour = 16  # Set just the hour
27    print(rtc.now)
28    rtc.weekday = 6  # Set just the day of the week (Sunday = 0)
29    print(rtc.now)
30    rtc.unixtime = 1550335257  # Or set the date and time with a unix timestamp
31
32# Main loop:
33while True:
34    now = rtc.now
35    print(
36        "The date is {} {}/{}/{}".format(
37            days[now.weekday], now.day, now.month, now.year
38        )
39    )
40    print("The time is {}:{:02}:{:02}".format(now.hour, now.minute, now.second))
41    print("The UNIX timestamp is {}".format(rtc.unixtime))
42    print("The number of days in the current month is {}".format(rtc.get_month_days()))
43    if rtc.is_leap_year():
44        print("This year is a leap year")
45    else:
46        print("This year is not a leap year")
47    time.sleep(1)  # wait a second
examples/featherwing_gps_simpletest.py
 1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4"""
 5This example will connect to the GPS at the default 9600 baudrate and
 6update once per second. Initialization is automatically handled and there
 7are some additional features such as MPH and KPH calculations.
 8"""
 9import time
10from adafruit_featherwing import gps_featherwing
11
12# Create a GPS featherwing instance.
13gps = gps_featherwing.GPSFeatherWing()
14
15# Main loop runs forever printing the location, etc. every second.
16last_print = time.monotonic()
17while True:
18    # Make sure to call gps.update() every loop iteration and at least twice
19    # as fast as data comes from the GPS unit (usually every second).
20    # This returns a bool that's true if it parsed new data (you can ignore it
21    # though if you don't care and instead look at the has_fix property).
22    gps.update()
23    # Every second print out current location details if there's a fix.
24    current = time.monotonic()
25    if current - last_print >= 1.0:
26        last_print = current
27        if not gps.has_fix:
28            # Try again if we don't have a fix yet.
29            print("Waiting for fix...")
30            continue
31        # Print out details about the fix like location, date, etc.
32        print("=" * 40)  # Print a separator line.
33        print(
34            "Fix timestamp: {}/{}/{} {:02}:{:02}:{:02}".format(
35                gps.timestamp.tm_mon,  # Grab parts of the time from the
36                gps.timestamp.tm_mday,  # struct_time object that holds
37                gps.timestamp.tm_year,  # the fix time.  Note you might
38                gps.timestamp.tm_hour,  # not get all data like year, day,
39                gps.timestamp.tm_min,  # month!
40                gps.timestamp.tm_sec,
41            )
42        )
43        print("Latitude: {0:.6f} degrees".format(gps.latitude))
44        print("Longitude: {0:.6f} degrees".format(gps.longitude))
45        print("Fix quality: {}".format(gps.fix_quality))
46        # Some attributes beyond latitude, longitude and timestamp are optional
47        # and might not be present.  Check if they're None before trying to use!
48        if gps.satellites is not None:
49            print("# satellites: {}".format(gps.satellites))
50        if gps.altitude is not None:
51            print("Altitude: {} meters".format(gps.altitude))
52        if gps.speed_knots is not None:
53            print("Speed (Knots): {} knots".format(gps.speed_knots))
54        if gps.speed_mph is not None:
55            print("Speed (Miles Per Hour): {} MPH".format(gps.speed_mph))
56        if gps.speed_kph is not None:
57            print("Speed (KM Per Hour): {} KPH".format(gps.speed_kph))
58        if gps.track_angle is not None:
59            print("Track angle: {} degrees".format(gps.track_angle))
60        if gps.horizontal_dilution is not None:
61            print("Horizontal dilution: {}".format(gps.horizontal_dilution))
62        if gps.height_geoid is not None:
63            print("Height geo ID: {} meters".format(gps.height_geoid))
examples/featherwing_matrix_simpletest.py
 1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4"""
 5This example will demonstrate some graphic effects and then
 6draw a smiley face and shift it around the display
 7"""
 8import time
 9from adafruit_featherwing import matrix_featherwing
10
11matrix = matrix_featherwing.MatrixFeatherWing()
12
13# Create a Fade-in Effect
14matrix.brightness = 0
15matrix.fill(True)
16for level in range(0, 16):
17    matrix.brightness = level
18    time.sleep(0.1)
19
20# Show the different Blink Rates
21for level in range(3, -1, -1):
22    matrix.blink_rate = level
23    time.sleep(4)
24
25# Create a Fade-out Effect
26for level in range(15, -1, -1):
27    matrix.brightness = level
28    time.sleep(0.1)
29matrix.fill(False)
30
31# Reset the brightness to full
32matrix.brightness = 15
33
34# Clear the Screen
35matrix.fill(False)
36
37# Draw a Smiley Face
38for row in range(2, 6):
39    matrix[row, 0] = 1
40    matrix[row, 7] = 1
41
42for column in range(2, 6):
43    matrix[0, column] = 1
44    matrix[7, column] = 1
45
46matrix[1, 1] = 1
47matrix[1, 6] = 1
48matrix[6, 1] = 1
49matrix[6, 6] = 1
50matrix[2, 5] = 1
51matrix[5, 5] = 1
52matrix[2, 3] = 1
53matrix[5, 3] = 1
54matrix[3, 2] = 1
55matrix[4, 2] = 1
56
57# Move the Smiley Face Around
58while True:
59    for frame in range(0, 8):
60        matrix.shift_right()
61    for frame in range(0, 8):
62        matrix.shift_down(True)
63    for frame in range(0, 8):
64        matrix.shift_left()
65    for frame in range(0, 8):
66        matrix.shift_up(True)
examples/featherwing_minitft_simpletest.py
 1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4"""
 5This example display a CircuitPython console and
 6print which button that is being pressed if any
 7"""
 8import time
 9from adafruit_featherwing import minitft_featherwing
10
11minitft = minitft_featherwing.MiniTFTFeatherWing()
12
13while True:
14    buttons = minitft.buttons
15
16    if buttons.right:
17        print("Button RIGHT!")
18
19    if buttons.down:
20        print("Button DOWN!")
21
22    if buttons.left:
23        print("Button LEFT!")
24
25    if buttons.up:
26        print("Button UP!")
27
28    if buttons.select:
29        print("Button SELECT!")
30
31    if buttons.a:
32        print("Button A!")
33
34    if buttons.b:
35        print("Button B!")
36
37    time.sleep(0.001)
examples/featherwing_tempmotion_simpletest.py
 1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4"""
 5This example will show the current temperature in the Serial Console
 6whenever the FeatherWing senses that it has been tapped
 7"""
 8
 9import time
10from adafruit_featherwing import tempmotion_featherwing
11
12temp_motion = tempmotion_featherwing.TempMotionFeatherWing()
13temp_motion.enable_tap_detection()
14while True:
15    if temp_motion.events["tap"]:
16        print("The temperature is %f" % temp_motion.temperature)
17    time.sleep(1)

Other Examples

examples/featherwing_dotstar_palette_example.py
 1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4"""
 5This creates a palette of colors, draws a pattern and
 6rotates through the palette creating a moving rainbow.
 7"""
 8
 9from math import sqrt, cos, sin, radians
10from adafruit_featherwing import dotstar_featherwing
11
12dotstar = dotstar_featherwing.DotStarFeatherWing()
13
14# Remap the calculated rotation to 0 - 255
15def remap(vector):
16    return int(((255 * vector + 85) * 0.75) + 0.5)
17
18
19# Calculate the Hue rotation starting with Red as 0 degrees
20def rotate(degrees):
21    cosA = cos(radians(degrees))
22    sinA = sin(radians(degrees))
23    red = cosA + (1.0 - cosA) / 3.0
24    green = 1.0 / 3.0 * (1.0 - cosA) + sqrt(1.0 / 3.0) * sinA
25    blue = 1.0 / 3.0 * (1.0 - cosA) - sqrt(1.0 / 3.0) * sinA
26    return (remap(red), remap(green), remap(blue))
27
28
29palette = []
30pixels = []
31
32# Generate a rainbow palette
33for degree in range(0, 360):
34    color = rotate(degree)
35    palette.append(color[0] << 16 | color[1] << 8 | color[2])
36
37# Create the Pattern
38for y in range(0, dotstar.rows):
39    for x in range(0, dotstar.columns):
40        pixels.append(x * 30 + y * -30)
41
42# Clear the screen
43dotstar.fill()
44
45# Start the Animation
46dotstar.auto_write = False
47while True:
48    for color in range(0, 360, 10):
49        for index in range(0, dotstar.rows * dotstar.columns):
50            palette_index = pixels[index] + color
51            if palette_index >= 360:
52                palette_index -= 360
53            elif palette_index < 0:
54                palette_index += 360
55            dotstar[index] = palette[palette_index]
56        dotstar.show()
examples/featherwing_neopixel_palette_example.py
 1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4"""
 5This creates a palette of colors, draws a pattern and
 6rotates through the palette creating a moving rainbow.
 7"""
 8
 9from math import sqrt, cos, sin, radians
10from adafruit_featherwing import neopixel_featherwing
11
12neopixel = neopixel_featherwing.NeoPixelFeatherWing()
13
14# Remap the calculated rotation to 0 - 255
15def remap(vector):
16    return int(((255 * vector + 85) * 0.75) + 0.5)
17
18
19# Calculate the Hue rotation starting with Red as 0 degrees
20def rotate(degrees):
21    cosA = cos(radians(degrees))
22    sinA = sin(radians(degrees))
23    red = cosA + (1.0 - cosA) / 3.0
24    green = 1.0 / 3.0 * (1.0 - cosA) + sqrt(1.0 / 3.0) * sinA
25    blue = 1.0 / 3.0 * (1.0 - cosA) - sqrt(1.0 / 3.0) * sinA
26    return (remap(red), remap(green), remap(blue))
27
28
29palette = []
30pixels = []
31
32# Generate a rainbow palette
33for degree in range(0, 360):
34    color = rotate(degree)
35    palette.append(color[0] << 16 | color[1] << 8 | color[2])
36
37# Create the Pattern
38for y in range(0, neopixel.rows):
39    for x in range(0, neopixel.columns):
40        pixels.append(x * 30 + y * -30)
41
42# Clear the screen
43neopixel.fill()
44
45# Start the Animation
46neopixel.auto_write = False
47while True:
48    for color in range(0, 360, 10):
49        for index in range(0, neopixel.rows * neopixel.columns):
50            palette_index = pixels[index] + color
51            if palette_index >= 360:
52                palette_index -= 360
53            elif palette_index < 0:
54                palette_index += 360
55            neopixel[index] = palette[palette_index]
56        neopixel.show()