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"""
 5
 6import time
 7
 8from adafruit_featherwing import ina219_featherwing
 9
10INA219 = ina219_featherwing.INA219FeatherWing()
11
12while True:
13    print(f"Bus Voltage:   {INA219.bus_voltage} V")
14    print(f"Shunt Voltage: {INA219.shunt_voltage} V")
15    print(f"Voltage:       {INA219.voltage} V")
16    print(f"Current:       {INA219.current} mA")
17    print("")
18    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
 5or the buttons are pressed."""
 6
 7import time
 8
 9from adafruit_featherwing import joy_featherwing
10
11wing = joy_featherwing.JoyFeatherWing()
12last_x = 0
13last_y = 0
14
15while True:
16    x, y = wing.joystick
17    if (abs(x - last_x) > 3) or (abs(y - last_y) > 3):
18        last_x = x
19        last_y = y
20        print(x, y)
21    if wing.button_a:
22        print("Button A!")
23    if wing.button_b:
24        print("Button B!")
25    if wing.button_x:
26        print("Button X!")
27    if wing.button_y:
28        print("Button Y!")
29    if wing.button_select:
30        print("Button SELECT!")
31    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
 9
10from adafruit_featherwing import alphanum_featherwing
11
12display = alphanum_featherwing.AlphaNumFeatherWing()
13
14# Fill and empty all segments
15for count in range(0, 3):
16    display.fill(True)
17    sleep(0.5)
18    display.fill(False)
19    sleep(0.5)
20
21# Display a number and text
22display.print(1234)
23sleep(1)
24display.print("Text")
25
26# Change brightness
27for brightness in range(0, 16):
28    display.brightness = brightness
29    sleep(0.1)
30
31# Change blink rate
32for blink_rate in range(3, 0, -1):
33    display.blink_rate = blink_rate
34    sleep(4)
35display.blink_rate = 0
36
37# Show a counter using decimals
38count = 975.0
39while count < 1025:
40    count += 1
41    display.print(count)
42    sleep(0.1)
43
44# Show the Marquee
45display.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
 9import random
10from time import sleep
11
12from adafruit_featherwing import dotstar_featherwing
13
14dotstar = dotstar_featherwing.DotStarFeatherWing()
15
16
17# HELPERS
18# a random color 0 -> 224
19def random_color():
20    return random.randrange(0, 8) * 32
21
22
23# Fill screen with random colors at random brightnesses
24for i in range(0, 5):
25    dotstar.fill((random_color(), random_color(), random_color()))
26    dotstar.brightness = random.randrange(2, 10) / 10
27    sleep(0.2)
28
29# Set display to 30% brightness
30dotstar.brightness = 0.3
31
32# Create a gradiant drawing each pixel
33for x in range(0, dotstar.columns):
34    for y in range(dotstar.rows - 1, -1, -1):
35        dotstar[x, y] = (y * 42, 255, y * 42, 1)
36
37# Rotate everything left 36 frames
38for i in range(0, 36):
39    dotstar.shift_down(True)
40
41# Draw dual gradiant and then update
42dotstar.auto_write = False
43for y in range(0, dotstar.rows):
44    for x in range(0, 6):
45        dotstar[x, y] = (y * 84, x * 42, x * 42, 1)
46    for x in range(6, 12):
47        dotstar[x, y] = (255 - (y * 84), 255 - ((x - 6) * 42), 255 - ((x - 6) * 42), 1)
48
49# Rotate everything left 36 frames
50for i in range(0, 36):
51    dotstar.shift_left(True)
52    dotstar.shift_up(True)
53    dotstar.show()
54dotstar.auto_write = True
55
56# Shift pixels without rotating for an animated screen wipe
57for i in range(0, 6):
58    dotstar.shift_down()
59
60# Show pixels in random locations of random color
61# Bottom left corner is (0,0)
62while True:
63    x = random.randrange(0, dotstar.columns)
64    y = random.randrange(0, dotstar.rows)
65    dotstar[x, y] = (random_color(), random_color(), random_color())
66    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
 9import random
10from time import sleep
11
12from adafruit_featherwing import neopixel_featherwing
13
14neopixel = neopixel_featherwing.NeoPixelFeatherWing()
15
16
17# HELPERS
18# a random color 0 -> 224
19def random_color():
20    return random.randrange(0, 8) * 32
21
22
23# Fill screen with random colors at random brightnesses
24for i in range(0, 5):
25    neopixel.fill((random_color(), random_color(), random_color()))
26    neopixel.brightness = random.randrange(2, 10) / 10
27    sleep(0.2)
28
29# Set display to 30% brightness
30neopixel.brightness = 0.3
31
32# Create a gradiant drawing each pixel
33for x in range(0, neopixel.columns):
34    for y in range(neopixel.rows - 1, -1, -1):
35        neopixel[x, y] = (y * 63, 255, y * 63)
36
37# Rotate everything left 36 frames
38for i in range(0, 36):
39    neopixel.shift_down(True)
40    sleep(0.1)
41
42# Draw dual gradiant and then update
43# neopixel.auto_write = False
44for y in range(0, neopixel.rows):
45    for x in range(0, 4):
46        neopixel[x, y] = (y * 16 + 32, x * 8, 0)
47    for x in range(4, 8):
48        neopixel[x, y] = ((4 - y) * 16 + 32, (8 - x) * 8, 0)
49neopixel.show()
50
51# Rotate everything left 36 frames
52for i in range(0, 36):
53    neopixel.shift_left(True)
54    neopixel.shift_up(True)
55    neopixel.show()
56    sleep(0.1)
57neopixel.auto_write = True
58
59# Shift pixels without rotating for an animated screen wipe
60for i in range(0, neopixel.rows):
61    neopixel.shift_down()
62    sleep(0.4)
63
64# Show pixels in random locations of random color
65# Bottom left corner is (0,0)
66while True:
67    x = random.randrange(0, neopixel.columns)
68    y = random.randrange(0, neopixel.rows)
69    neopixel[x, y] = (random_color(), random_color(), random_color())
70    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
 9
10from adafruit_featherwing import sevensegment_featherwing
11
12display = sevensegment_featherwing.SevenSegmentFeatherWing()
13
14# Fill and empty all segments
15for count in range(0, 3):
16    display.fill(True)
17    sleep(0.5)
18    display.fill(False)
19    sleep(0.5)
20
21# Display a number and text
22display.print(1234)
23sleep(1)
24display.print("FEED")
25
26# Change brightness
27for brightness in range(0, 16):
28    display.brightness = brightness
29    sleep(0.1)
30
31# Change blink rate
32for blink_rate in range(3, 0, -1):
33    display.blink_rate = blink_rate
34    sleep(4)
35display.blink_rate = 0
36
37# Show a counter using decimals
38count = 975.0
39while count < 1025:
40    count += 1
41    display.print(count)
42    sleep(0.1)
43
44# Display a Time
45hour = 12
46for minute in range(15, 26):
47    display.print(f"{hour}:{minute}")
48    sleep(1)
49
50# Show the Marquee
51display.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"""
 8
 9import time
10
11from adafruit_featherwing import rtc_featherwing
12
13days = ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday")
14
15# Create the RTC instance:
16rtc = rtc_featherwing.RTCFeatherWing()
17
18if True:  # Change this to True to set the date and time
19    rtc.set_time(13, 34)  # Set the time (seconds are optional)
20    print(rtc.now)
21    rtc.set_date(16, 1, 2016)  # Set the date
22    print(rtc.now)
23    rtc.year = 2019  # Set just the Year
24    print(rtc.now)
25    rtc.month = 2  # Set Just the Month
26    print(rtc.now)
27    rtc.hour = 16  # Set just the hour
28    print(rtc.now)
29    rtc.weekday = 6  # Set just the day of the week (Sunday = 0)
30    print(rtc.now)
31    rtc.unixtime = 1550335257  # Or set the date and time with a unix timestamp
32
33# Main loop:
34while True:
35    now = rtc.now
36    print(f"The date is {days[now.weekday]} {now.day}/{now.month}/{now.year}")
37    print(f"The time is {now.hour}:{now.minute:02}:{now.second:02}")
38    print(f"The UNIX timestamp is {rtc.unixtime}")
39    print(f"The number of days in the current month is {rtc.get_month_days()}")
40    if rtc.is_leap_year():
41        print("This year is a leap year")
42    else:
43        print("This year is not a leap year")
44    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"""
 9
10import time
11
12from adafruit_featherwing import gps_featherwing
13
14# Create a GPS featherwing instance.
15gps = gps_featherwing.GPSFeatherWing()
16
17# Main loop runs forever printing the location, etc. every second.
18last_print = time.monotonic()
19while True:
20    # Make sure to call gps.update() every loop iteration and at least twice
21    # as fast as data comes from the GPS unit (usually every second).
22    # This returns a bool that's true if it parsed new data (you can ignore it
23    # though if you don't care and instead look at the has_fix property).
24    gps.update()
25    # Every second print out current location details if there's a fix.
26    current = time.monotonic()
27    if current - last_print >= 1.0:
28        last_print = current
29        if not gps.has_fix:
30            # Try again if we don't have a fix yet.
31            print("Waiting for fix...")
32            continue
33        # Print out details about the fix like location, date, etc.
34        print("=" * 40)  # Print a separator line.
35        print(
36            "Fix timestamp: {}/{}/{} {:02}:{:02}:{:02}".format(  # noqa: UP032
37                gps.timestamp.tm_mon,  # Grab parts of the time from the
38                gps.timestamp.tm_mday,  # struct_time object that holds
39                gps.timestamp.tm_year,  # the fix time.  Note you might
40                gps.timestamp.tm_hour,  # not get all data like year, day,
41                gps.timestamp.tm_min,  # month!
42                gps.timestamp.tm_sec,
43            )
44        )
45        print(f"Latitude: {gps.latitude:.6f} degrees")
46        print(f"Longitude: {gps.longitude:.6f} degrees")
47        print(f"Fix quality: {gps.fix_quality}")
48        # Some attributes beyond latitude, longitude and timestamp are optional
49        # and might not be present.  Check if they're None before trying to use!
50        if gps.satellites is not None:
51            print(f"# satellites: {gps.satellites}")
52        if gps.altitude is not None:
53            print(f"Altitude: {gps.altitude} meters")
54        if gps.speed_knots is not None:
55            print(f"Speed (Knots): {gps.speed_knots} knots")
56        if gps.speed_mph is not None:
57            print(f"Speed (Miles Per Hour): {gps.speed_mph} MPH")
58        if gps.speed_kph is not None:
59            print(f"Speed (KM Per Hour): {gps.speed_kph} KPH")
60        if gps.track_angle is not None:
61            print(f"Track angle: {gps.track_angle} degrees")
62        if gps.horizontal_dilution is not None:
63            print(f"Horizontal dilution: {gps.horizontal_dilution}")
64        if gps.height_geoid is not None:
65            print(f"Height geo ID: {gps.height_geoid} meters")
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"""
 8
 9import time
10
11from adafruit_featherwing import matrix_featherwing
12
13matrix = matrix_featherwing.MatrixFeatherWing()
14
15# Create a Fade-in Effect
16matrix.brightness = 0
17matrix.fill(True)
18for level in range(0, 16):
19    matrix.brightness = level
20    time.sleep(0.1)
21
22# Show the different Blink Rates
23for level in range(3, -1, -1):
24    matrix.blink_rate = level
25    time.sleep(4)
26
27# Create a Fade-out Effect
28for level in range(15, -1, -1):
29    matrix.brightness = level
30    time.sleep(0.1)
31matrix.fill(False)
32
33# Reset the brightness to full
34matrix.brightness = 15
35
36# Clear the Screen
37matrix.fill(False)
38
39# Draw a Smiley Face
40for row in range(2, 6):
41    matrix[row, 0] = 1
42    matrix[row, 7] = 1
43
44for column in range(2, 6):
45    matrix[0, column] = 1
46    matrix[7, column] = 1
47
48matrix[1, 1] = 1
49matrix[1, 6] = 1
50matrix[6, 1] = 1
51matrix[6, 6] = 1
52matrix[2, 5] = 1
53matrix[5, 5] = 1
54matrix[2, 3] = 1
55matrix[5, 3] = 1
56matrix[3, 2] = 1
57matrix[4, 2] = 1
58
59# Move the Smiley Face Around
60while True:
61    for frame in range(0, 8):
62        matrix.shift_right()
63    for frame in range(0, 8):
64        matrix.shift_down(True)
65    for frame in range(0, 8):
66        matrix.shift_left()
67    for frame in range(0, 8):
68        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"""
 8
 9import time
10
11from adafruit_featherwing import minitft_featherwing
12
13minitft = minitft_featherwing.MiniTFTFeatherWing()
14
15while True:
16    buttons = minitft.buttons
17
18    if buttons.right:
19        print("Button RIGHT!")
20
21    if buttons.down:
22        print("Button DOWN!")
23
24    if buttons.left:
25        print("Button LEFT!")
26
27    if buttons.up:
28        print("Button UP!")
29
30    if buttons.select:
31        print("Button SELECT!")
32
33    if buttons.a:
34        print("Button A!")
35
36    if buttons.b:
37        print("Button B!")
38
39    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
10
11from adafruit_featherwing import tempmotion_featherwing
12
13temp_motion = tempmotion_featherwing.TempMotionFeatherWing()
14temp_motion.enable_tap_detection()
15while True:
16    if temp_motion.events["tap"]:
17        print(f"The temperature is {temp_motion.temperature}")
18    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 cos, radians, sin, sqrt
10
11from adafruit_featherwing import dotstar_featherwing
12
13dotstar = dotstar_featherwing.DotStarFeatherWing()
14
15
16# Remap the calculated rotation to 0 - 255
17def remap(vector):
18    return int(((255 * vector + 85) * 0.75) + 0.5)
19
20
21# Calculate the Hue rotation starting with Red as 0 degrees
22def rotate(degrees):
23    cosA = cos(radians(degrees))
24    sinA = sin(radians(degrees))
25    red = cosA + (1.0 - cosA) / 3.0
26    green = 1.0 / 3.0 * (1.0 - cosA) + sqrt(1.0 / 3.0) * sinA
27    blue = 1.0 / 3.0 * (1.0 - cosA) - sqrt(1.0 / 3.0) * sinA
28    return (remap(red), remap(green), remap(blue))
29
30
31palette = []
32pixels = []
33
34# Generate a rainbow palette
35for degree in range(0, 360):
36    color = rotate(degree)
37    palette.append(color[0] << 16 | color[1] << 8 | color[2])
38
39# Create the Pattern
40for y in range(0, dotstar.rows):
41    for x in range(0, dotstar.columns):
42        pixels.append(x * 30 + y * -30)
43
44# Clear the screen
45dotstar.fill()
46
47# Start the Animation
48dotstar.auto_write = False
49while True:
50    for color in range(0, 360, 10):
51        for index in range(0, dotstar.rows * dotstar.columns):
52            palette_index = pixels[index] + color
53            if palette_index >= 360:
54                palette_index -= 360
55            elif palette_index < 0:
56                palette_index += 360
57            dotstar[index] = palette[palette_index]
58        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 cos, radians, sin, sqrt
10
11from adafruit_featherwing import neopixel_featherwing
12
13neopixel = neopixel_featherwing.NeoPixelFeatherWing()
14
15
16# Remap the calculated rotation to 0 - 255
17def remap(vector):
18    return int(((255 * vector + 85) * 0.75) + 0.5)
19
20
21# Calculate the Hue rotation starting with Red as 0 degrees
22def rotate(degrees):
23    cosA = cos(radians(degrees))
24    sinA = sin(radians(degrees))
25    red = cosA + (1.0 - cosA) / 3.0
26    green = 1.0 / 3.0 * (1.0 - cosA) + sqrt(1.0 / 3.0) * sinA
27    blue = 1.0 / 3.0 * (1.0 - cosA) - sqrt(1.0 / 3.0) * sinA
28    return (remap(red), remap(green), remap(blue))
29
30
31palette = []
32pixels = []
33
34# Generate a rainbow palette
35for degree in range(0, 360):
36    color = rotate(degree)
37    palette.append(color[0] << 16 | color[1] << 8 | color[2])
38
39# Create the Pattern
40for y in range(0, neopixel.rows):
41    for x in range(0, neopixel.columns):
42        pixels.append(x * 30 + y * -30)
43
44# Clear the screen
45neopixel.fill()
46
47# Start the Animation
48neopixel.auto_write = False
49while True:
50    for color in range(0, 360, 10):
51        for index in range(0, neopixel.rows * neopixel.columns):
52            palette_index = pixels[index] + color
53            if palette_index >= 360:
54                palette_index -= 360
55            elif palette_index < 0:
56                palette_index += 360
57            neopixel[index] = palette[palette_index]
58        neopixel.show()