Exemple #1
0
# THE SOFTWARE.
import time
import digitalio
import board
import adafruit_ssd1306
import urllib, json
import socket

from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont

import subprocess

# Raspberry Pi pin configuration:
oled_reset = digitalio.DigitalInOut(board.D4)

# Change these
# to the right size for your display!
WIDTH = 128
HEIGHT = 64  # Change to 64 if needed
BORDER = 5
i2c = board.I2C()
disp = adafruit_ssd1306.SSD1306_I2C(WIDTH, HEIGHT, i2c, addr=0x3C, reset=oled_reset)


# Initialize library.

url = "http://oeebox/fsm/monitor.dal"

Exemple #2
0
# Simple example to send a message and then wait indefinitely for messages
# to be received.  This uses the default RadioHead compatible GFSK_Rb250_Fd250
# modulation and packet format for the radio.

import board
import busio
import digitalio

import adafruit_rfm69

# Define radio parameters.
RADIO_FREQ_MHZ = 915.0  # Frequency of the radio in Mhz. Must match your
# module! Can be a value like 915.0, 433.0, etc.

# Define pins connected to the chip, use these if wiring up the breakout according to the guide:
CS = digitalio.DigitalInOut(board.CE1)
RESET = digitalio.DigitalInOut(board.D25)
# Or uncomment and instead use these if using a Feather M0 RFM69 board
# and the appropriate CircuitPython build:
# CS = digitalio.DigitalInOut(board.RFM69_CS)
# RESET = digitalio.DigitalInOut(board.RFM69_RST)

# Initialize SPI bus.
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)

# Initialze RFM radio
rfm69 = adafruit_rfm69.RFM69(spi, CS, RESET, RADIO_FREQ_MHZ)

# Optionally set an encryption key (16 byte AES key). MUST match both
# on the transmitter and receiver (or be set to None to disable/the default).
rfm69.encryption_key = (
Exemple #3
0
import time
import board
import busio
import digitalio
from adafruit_max7219 import bcddigits

spi_mosi = board.GP3
spi_clk = board.GP2
pin_cs = board.GP5
bt_left = board.GP7     # GPIO 17 = GP7  (11)
bt_right = board.GP14   # GPIO 26 = GP14 (37)

button_l = digitalio.DigitalInOut(bt_left)
button_l.direction = digitalio.Direction.INPUT
button_l.pull = digitalio.Pull.UP

button_r = digitalio.DigitalInOut(bt_right)
button_r.direction = digitalio.Direction.INPUT
button_r.pull = digitalio.Pull.UP

spi = busio.SPI(spi_clk, MOSI=spi_mosi)

cs = digitalio.DigitalInOut(pin_cs)

display = bcddigits.BCDDigits(spi, cs, nDigits=8)
display.clear_all()
display.show_str(0,'8.8.8.8.8.8.8.8.')
#display.show_str(0,'{:9.3f}'.format(-1234.567))
display.show()

old0 = button_l.value
Exemple #4
0
def getLed(pin):
    led = digitalio.DigitalInOut(pin)
    led.direction = digitalio.Direction.OUTPUT
    led.value = True
    return led
Exemple #5
0
def main():
    spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
    i2c = busio.I2C(board.SCL, board.SDA)
    ecs = digitalio.DigitalInOut(board.CE0)
    dc = digitalio.DigitalInOut(board.D22)
    rst = digitalio.DigitalInOut(board.D27)
    busy = digitalio.DigitalInOut(board.D17)

    # You'll need to get a token from openweathermap.org, looks like:
    # 'b6907d289e10d714a6e88b30761fae22'
    OPEN_WEATHER_TOKEN = 'f1525c6af313ad137fea6d36606822c9'

    # Use cityname, country code where countrycode is ISO3166 format.
    # E.g. "New York, US" or "London, GB"
    LOCATION = "Wenatchee, US"
    DATA_SOURCE_URL = "http://api.openweathermap.org/data/2.5/weather"

    if len(OPEN_WEATHER_TOKEN) == 0:
        raise RuntimeError(
            "You need to set your token first. If you don't already have one, you can register for a free account at https://home.openweathermap.org/users/sign_up"
        )

    # Set up where we'll be fetching data from
    params = {"q": LOCATION, "appid": OPEN_WEATHER_TOKEN}
    data_source = DATA_SOURCE_URL + "?" + urllib.parse.urlencode(params)

    # Initialize the Display
    display = Adafruit_SSD1675(
        122,
        250,
        spi,
        cs_pin=ecs,
        dc_pin=dc,
        sramcs_pin=None,
        rst_pin=rst,
        busy_pin=busy,
    )

    display.rotation = 1

    gfx = Weather_Graphics(display, am_pm=True, celsius=False)
    weather_refresh = None

    # Try to read from the weather device
    try:
        bme280 = Adafruit_BME280_I2C(i2c)
    except InputError as e:  #TODO actually catch the proper exception and handle it
        pass

    while not exit.is_set():
        try:
            # only query the weather every 10 minutes (and on first run)
            if (not weather_refresh) or (time.monotonic() -
                                         weather_refresh) > 300:
                response = urllib.request.urlopen(data_source)
                if response.getcode() == 200:
                    value = response.read()
                    print("Response is", value)
                    gfx.display_weather(value, bme280)
                    weather_refresh = time.monotonic()
                else:
                    print("Unable to retrieve data at {}".format(url))
            gfx.update_time()
            print('gonna wait for 3 mins')
            exit.wait(180)  # wait 5 minutes before updating anything again
            print('done waiting for 3 mins')
        except subprocess.CalledProcessError as e:
            print('caught error in subprocess')
            print(e)

    else:
        print('exiting')
        gfx.clear_display()
        time.sleep(1)
        sys.exit(0)
Exemple #6
0
import busio
import digitalio
import adafruit_max31855
import RPi.GPIO as gpio

zones = np.array([17, 27,
                  23])  #pin number on pi that controls each zone  (1,2,3)

#setup to turn on off the gpio to control relays
gpio.setmode(gpio.BCM)
for z in zones:
    gpio.setup(int(z), gpio.OUT)

#setup for themocoulple boards
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
cs1 = digitalio.DigitalInOut(board.D4)
cs2 = digitalio.DigitalInOut(board.D25)
cs3 = digitalio.DigitalInOut(board.D12)

thermo1 = adafruit_max31855.MAX31855(spi, cs1)
thermo2 = adafruit_max31855.MAX31855(spi, cs2)
thermo3 = adafruit_max31855.MAX31855(spi, cs3)

#################################################################################################
#inputs
#gets the file name of the firing shcedule to use
#if nothin is typed it allow you to enter a fixed setpoint value
setFileName = input(
    "Enter file name of the firing schedule(press enter to use fixed value)\n")
if setFileName == "":
    setFile = False
Exemple #7
0
#!/usr/bin/python3
import board
import digitalio
import busio

print("Hello blinka!")

# Try to great a Digital input
pin = digitalio.DigitalInOut(board.D4)
print("Digital IO ok!")

# Try to create an I2C device
i2c = busio.I2C(board.SCL, board.SDA)
print("I2C ok!")

# Try to create an SPI device
#spi = busio.SPI(board.SCLK, board.MOSI, board.MISO)
#print("SPI ok!")

print("done!")
Exemple #8
0
    ret_value["stale_shares"] = stale_shares
    return ret_value

if len(sys.argv) != 3 or (sys.argv[1] != "ethermine" and sys.argv[1] != "flexpool" and sys.argv[1] != "hiveon"):
    print("Usage: sudo python3 miner.py ethermine|flexpool|hiveon wallet")
    exit

pool = sys.argv[1]
wallet = sys.argv[2]
if wallet.startswith("0x"):
    wallet = wallet[2:]

value_api_url = "https://api.coingecko.com/api/v3/simple/price?ids=ethereum&vs_currencies=usd"

# Configuration for CS and DC pins (these are FeatherWing defaults on M0/M4):
cs_pin = digitalio.DigitalInOut(board.CE0)
dc_pin = digitalio.DigitalInOut(board.CE1)
reset_pin = None

# Config for display baudrate (default max is 24mhz):
BAUDRATE = 24000000

# Setup SPI bus using hardware SPI:
spi = busio.SPI(clock=SCK, MOSI=MOSI, MISO=MISO)


# Create the ST7789 display:
disp = hx8357.HX8357(spi, cs=cs_pin, dc=dc_pin, rst=reset_pin, baudrate=BAUDRATE,
                     width=99, height=99)

# Create blank image for drawing.
Exemple #9
0
# set an initial color to use in case the user uses arrows before choosing a color.
color = [0, 0, 255]  # Bright Blue
fade_color = [0, 0, 64]  # Deeper Blue

# Declare a NeoPixel object on led_pin with num_leds as pixels
# No auto-write.
# Set brightness to max.
# We will be using FancyLED's brightness control.

# "pixels" will refer to the cpx's 10 onboard neopixels
# pixel = neopixel.NeoPixel(board.NEOPIXEL, 10, brightness=0.2, auto_write=False)
# "strip" will refer to neopixel strand attached to the cpx, with data pin at A1
strip = neopixel.NeoPixel(led_pin, num_leds, brightness=1, auto_write=False)

ledmode = 0  # button press counter, switch color palettes
button = digitalio.DigitalInOut(board.BUTTON_A)
button.switch_to_input(pull=digitalio.Pull.DOWN)

# FancyLED allows for assigning a color palette using these formats:
# * The first (5) palettes here are mixing between 2-elements
# * The last (3) palettes use a format identical to the FastLED Arduino Library
# see FastLED - colorpalettes.cpp

# Erin St. Blaine offers these colors in her tutorial
# https://learn.adafruit.com/animated-neopixel-gemma-glow-fur-scarf/circuitpython-code
# I don't use them all, so feel free to experiment.

blue = [fancy.CRGB(0, 0, 0), fancy.CRGB(75, 25, 255)]

forest = [
    fancy.CRGB(0, 255, 0),  # green
Exemple #10
0
    @classmethod
    def _print_sta(cls, rep):
        pass

    @classmethod
    def _print_per(cls, rep):
        pass

    @classmethod
    def print_hex(cls, hexs):
        return '0x' + ''.join([hex(h).strip('0x').zfill(2) for h in hexs])


if __name__ == '__main__':
    # reset to start with a clean buffer
    rst = digitalio.DigitalInOut(board.D22)
    rst.direction = digitalio.Direction.OUTPUT
    rst.value = False
    time.sleep(1)
    rst.value = True
    time.sleep(1)

    imu = BNO080_I2C(0x4a, 3)
    imu.get_shtp_errors()
    prod_inf = imu.get_prod_inf()
    print(
        f"Product info: {imu.print_hex(prod_inf[0])}\n{imu.print_hex(prod_inf[1])}"
    )

    # imu.start_calib()
Exemple #11
0
Adafruit Playground Bluefruit board with busio
and custom lib/adafruit_apds9960/apds9960.py file
sending WASD and ENTER commands to Adobe Xd prototype
"""

import board
import time
import digitalio
import busio
import usb_hid
from adafruit_apds9960.apds9960 import APDS9960
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
from adafruit_hid.keycode import Keycode

killswitch = digitalio.DigitalInOut(board.SLIDE_SWITCH)
killswitch.direction = digitalio.Direction.INPUT
killswitch.pull = digitalio.Pull.UP

i2cA = busio.I2C(board.A1, board.A2)
apdsG = APDS9960(i2cA)
apdsG.enable_gesture = True
apdsG.enable_proximity = True

# default gesture_proximity_threshold = 50 (range 0-255)"""
apdsG.gesture_proximity_threshold = 0
# default gesture_gain = 2 (range 0-3)"""
apdsG.gesture_gain = 3
# default gesture_fifo_threshold = 1 (range 0-3)"""
apdsG.gesture_fifo_threshold = 3
# default gesture_dimensions = 1 (range 0-3)"""
Exemple #12
0
import board
import digitalio

killpin = digitalio.DigitalInOut(
    board.D17)  #assign killcmd to GPIO pin 18 on Raspberry Pi
killpin.direction = digitalio.Direction.OUTPUT  #assign direction of pin to output/write
killpin.value = False  #initialize pin value to 0


#wait for user input to either activate/deactivate switch
def kill_reboot():
    cmd = input()
    if cmd == "k":
        return True
    elif cmd == "r":
        return False


def main():
    killpin = digitalio.DigitalInOut(board.D17)
    killpin.direction = digitalio.Direction.OUTPUT
    killpin.value = False

    print("k = kill\nr = reboot")

    while True:
        switch = kill_reboot()
        killpin.value = switch


main()
from PIL import Image, ImageDraw, ImageFont
import adafruit_ssd1306


# This function allows us to grab any of our IP addresses
def get_ip_address(ifname):
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    return socket.inet_ntoa(
        fcntl.ioctl(
            s.fileno(),
            0x8915,  # SIOCGIFADDR
            struct.pack('256s', str.encode(ifname[:15])))[20:24])


# Setting some variables for our reset pin etc.
RESET_PIN = digitalio.DigitalInOut(board.D4)
TEXT = ''

# Very important... This lets py-gaugette 'know' what pins to use in order to reset the display
i2c = board.I2C()
oled = adafruit_ssd1306.SSD1306_I2C(128, 64, i2c, addr=0x3d, reset=RESET_PIN)

# This sets TEXT equal to whatever your IP address is, or isn't
try:
    TEXT = get_ip_address(
        'wlan0')  # WiFi address of WiFi adapter. NOT ETHERNET
except IOError:
    try:
        TEXT = get_ip_address(
            'eth0')  # WiFi address of Ethernet cable. NOT ADAPTER
    except IOError:

# This example is for use on (Linux) computers that are using CPython with
# Adafruit Blinka to support CircuitPython libraries. CircuitPython does
# not support PIL/pillow (python imaging library)!

import time
import subprocess
from board import SCL, SDA, D4
import busio
import digitalio
from PIL import Image, ImageDraw, ImageFont
import adafruit_ssd1305

# Define the Reset Pin
oled_reset = digitalio.DigitalInOut(D4)

# Create the I2C interface.
i2c = busio.I2C(SCL, SDA)

# Create the SSD1305 OLED class.
# The first two parameters are the pixel width and pixel height.  Change these
# to the right size for your display!
disp = adafruit_ssd1305.SSD1305_I2C(128, 32, i2c, reset=oled_reset)

# Clear display.
disp.fill(0)
disp.show()

# Create blank image for drawing.
# Make sure to create image with mode '1' for 1-bit color.
Exemple #15
0
             ]  # Mandalorian charater sequence that is shown on the display
glyphdelays = [
    0.50, 0.50, 0.50, 0.50, 0.50
]  # Time that each character group is shown 0.50 is 500 milliseconds, or 1/2 of a second
graphiclist = []
#graphiclist   = [ "m1.jpg", "m2.jpg", "m3.jpg", "m4.jpg", "m5.jpg"]
graphicdelays = [1.0, 1.0, 1.0, 1.0, 1.0]

# Config for display baudrate (default max is 24mhz):
BAUDRATE = 64000000
#BAUDRATE = 24000000

# Setup SPI bus using hardware SPI:
spi = board.SPI()
# Configuration for CS and DC pins (these are PiTFT defaults):
cs_pin = digitalio.DigitalInOut(board.CE0)
dc_pin = digitalio.DigitalInOut(board.D25)
reset_pin = digitalio.DigitalInOut(board.D24)

# pylint: disable=line-too-long
# Create the display:
if DISPLAY == "1.14 LCD":
    FONTSIZE = 124
    disp = st7789.ST7789(spi,
                         rotation=90,
                         width=135,
                         height=240,
                         x_offset=53,
                         y_offset=40,
                         cs=cs_pin,
                         dc=dc_pin,
    P1: value
    (and so on, same for MCP13)
}
...
IMU_1: {
    ax: value
    ay: value
    ...
}

'''

# INITIALIZE MCPs #
spi = busio.SPI(clock=board.SCK, MISO=board.MISO, MOSI=board.MOSI)

cs5 = digitalio.DigitalInOut(board.D5)
cs6 = digitalio.DigitalInOut(board.D6)
cs13 = digitalio.DigitalInOut(board.D13)

mcp5 = MCP.MCP3008(spi, cs5)
mcp6 = MCP.MCP3008(spi, cs6)
mcp13 = MCP.MCP3008(spi, cs13)

# INITIALIZE IMUs #
channel = 1
imu_address_1 = 0x69
imu_address_2 = 0x68
bus = SMBus(channel)
bus.write_byte_data(imu_address_1, 0x06, 0x01)
bus.write_byte_data(imu_address_2, 0x06, 0x01)
time.sleep(0.5)
Exemple #17
0
"""
'button_press_on_off.py'.

=================================================
lightswitch-like operation with two buttons and a led
"""

import board
import digitalio

led = digitalio.DigitalInOut(board.D13)
led.switch_to_output()
btn1 = digitalio.DigitalInOut(board.D2)
btn1.switch_to_input()
btn2 = digitalio.DigitalInOut(board.D3)
btn2.switch_to_input()

while True:
    if not btn1.value:
        led.value = False
    elif not btn2.value:
        led.value = True
# The pins we'll use, each will have an internal pullup
keypress_pins = [board.A1, board.A2]
# Our array of key objects
key_pin_array = []
# The Keycode sent for each button, will be paired with a control key
keys_pressed = [Keycode.A, "Hello World!\n"]
control_key = Keycode.SHIFT

# The keyboard object!
time.sleep(1)  # Sleep for a bit to avoid a race condition on some systems
keyboard = Keyboard(usb_hid.devices)
keyboard_layout = KeyboardLayoutUS(keyboard)  # We're in the US :)

# Make all pin objects inputs with pullups
for pin in keypress_pins:
    key_pin = digitalio.DigitalInOut(pin)
    key_pin.direction = digitalio.Direction.INPUT
    key_pin.pull = digitalio.Pull.UP
    key_pin_array.append(key_pin)

# For most CircuitPython boards:
led = digitalio.DigitalInOut(board.LED)
# For QT Py M0:
# led = digitalio.DigitalInOut(board.SCK)
led.direction = digitalio.Direction.OUTPUT

print("Waiting for key pin...")

while True:
    # Check each pin
    for key_pin in key_pin_array:
Exemple #19
0
import audioio
import board
import digitalio

import time
import neopixel

pixels = neopixel.NeoPixel(board.NEOPIXEL, 10, brightness=.2)
pixels.fill((0, 0, 0))
pixels.show()

# enable the speaker
spkrenable = digitalio.DigitalInOut(board.SPEAKER_ENABLE)
spkrenable.direction = digitalio.Direction.OUTPUT
spkrenable.value = True

# make the 2 input buttons
buttonA = digitalio.DigitalInOut(board.BUTTON_A)
buttonA.direction = digitalio.Direction.INPUT
buttonA.pull = digitalio.Pull.DOWN

buttonB = digitalio.DigitalInOut(board.BUTTON_B)
buttonB.direction = digitalio.Direction.INPUT
buttonB.pull = digitalio.Pull.DOWN

# The two files assigned to buttons A & B
audiofiles = ["no-thats-not-gonna-do-it.wav"]

def flash(wait):
    pixels.fill((0, 255, 255))
    pixels.show()
import board
import digitalio
import time

import busio
import adafruit_ina219

i2c_bus = busio.I2C(board.SCL, board.SDA)

led = digitalio.DigitalInOut(board.LED)
led.direction = digitalio.Direction.OUTPUT

# Create library object on our I2C port
ina219 = adafruit_ina219.INA219(i2c_bus, 0x41)

while True:
    led.value = True
    time.sleep(1)

    print("Bus Voltage:     {} V".format(ina219.bus_voltage))
    print("Shunt Voltage:   {} mV".format(ina219.shunt_voltage / 1000))
    print("Load Voltage:    {} V".format(ina219.bus_voltage +
                                         ina219.shunt_voltage))
    print("Current:         {} mA".format(ina219.current))
    print("")

    led.value = False
    time.sleep(4)
Exemple #21
0
import board
import busio
import digitalio
import adafruit_requests as requests
from adafruit_wiznet5k.adafruit_wiznet5k import WIZNET5K
import adafruit_wiznet5k.adafruit_wiznet5k_socket as socket

print("Wiznet5k WebClient Test")

TEXT_URL = "http://wifitest.adafruit.com/testwifi/index.html"
JSON_URL = "http://api.coindesk.com/v1/bpi/currentprice/USD.json"

cs = digitalio.DigitalInOut(board.D10)
spi_bus = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)

# Initialize ethernet interface with DHCP
eth = WIZNET5K(spi_bus, cs)

# Initialize a requests object with a socket and ethernet interface
requests.set_socket(socket, eth)

print("Chip Version:", eth.chip)
print("MAC Address:", [hex(i) for i in eth.mac_address])
print("My IP address is:", eth.pretty_ip(eth.ip_address))
print("IP lookup adafruit.com: %s" %
      eth.pretty_ip(eth.get_host_by_name("adafruit.com")))

#eth._debug = True
print("Fetching text from", TEXT_URL)
r = requests.get(TEXT_URL)
print('-' * 40)
Exemple #22
0
    def __init__(
        self,
        cols,
        rows,
        diode_orientation=DiodeOrientation.COLUMNS,
        rollover_cols_every_rows=None,
    ):
        self.len_cols = len(cols)
        self.len_rows = len(rows)

        # A pin cannot be both a row and column, detect this by combining the
        # two tuples into a set and validating that the length did not drop
        #
        # repr() hackery is because CircuitPython Pin objects are not hashable
        unique_pins = {repr(c) for c in cols} | {repr(r) for r in rows}
        assert (len(unique_pins) == self.len_cols +
                self.len_rows), 'Cannot use a pin as both a column and row'
        del unique_pins
        gc.collect()

        self.diode_orientation = diode_orientation

        # __class__.__name__ is used instead of isinstance as the MCP230xx lib
        # does not use the digitalio.DigitalInOut, but rather a self defined one:
        # https://github.com/adafruit/Adafruit_CircuitPython_MCP230xx/blob/3f04abbd65ba5fa938fcb04b99e92ae48a8c9406/adafruit_mcp230xx/digital_inout.py#L33

        if self.diode_orientation == DiodeOrientation.COLUMNS:
            self.outputs = [
                x if x.__class__.__name__ is 'DigitalInOut' else
                digitalio.DigitalInOut(x) for x in cols
            ]
            self.inputs = [
                x if x.__class__.__name__ is 'DigitalInOut' else
                digitalio.DigitalInOut(x) for x in rows
            ]
            self.translate_coords = True
        elif self.diode_orientation == DiodeOrientation.ROWS:
            self.outputs = [
                x if x.__class__.__name__ is 'DigitalInOut' else
                digitalio.DigitalInOut(x) for x in rows
            ]
            self.inputs = [
                x if x.__class__.__name__ is 'DigitalInOut' else
                digitalio.DigitalInOut(x) for x in cols
            ]
            self.translate_coords = False
        else:
            raise ValueError('Invalid DiodeOrientation: {}'.format(
                self.diode_orientation))

        for pin in self.outputs:
            pin.switch_to_output()

        for pin in self.inputs:
            pin.switch_to_input(pull=digitalio.Pull.DOWN)

        self.rollover_cols_every_rows = rollover_cols_every_rows
        if self.rollover_cols_every_rows is None:
            self.rollover_cols_every_rows = self.len_rows

        self.len_state_arrays = self.len_cols * self.len_rows
        self.state = bytearray(self.len_state_arrays)
        self.report = bytearray(3)
Exemple #23
0
import board
import digitalio
import time

led = digitalio.DigitalInOut(board.D3)
led.direction = digitalio.Direction.OUTPUT

print("Idle Mode is enabled...")

while True:
    led.Value = False
strumUP.pull = Pull.UP

strumDOWN = DigitalInOut(board.D23)
strumDOWN.direction = Direction.INPUT
strumDOWN.pull = Pull.UP

#  setup for cherry mx switches on neck
note_pins = [
    board.D14, board.D2, board.D3, board.D4, board.D5, board.D6, board.D7,
    board.D8, board.D9, board.D10, board.D11, board.D12
]

note_buttons = []

for pin in note_pins:
    note_pin = digitalio.DigitalInOut(pin)
    note_pin.direction = digitalio.Direction.INPUT
    note_pin.pull = digitalio.Pull.UP
    note_buttons.append(note_pin)

#  setup for rotary switch
oct_sel_pins = [
    board.D24, board.D25, board.D26, board.D27, board.D28, board.D29,
    board.D30, board.D31
]

octave_selector = []

for pin in oct_sel_pins:
    sel_pin = digitalio.DigitalInOut(pin)
    sel_pin.direction = digitalio.Direction.INPUT
"""Simple test for RGB character LCD"""
import time
import board
import digitalio
import pulseio
import adafruit_character_lcd.character_lcd as characterlcd

# Modify this if you have a different sized character LCD
lcd_columns = 16
lcd_rows = 2

# Metro M0/M4 Pin Config:
lcd_rs = digitalio.DigitalInOut(board.D7)
lcd_en = digitalio.DigitalInOut(board.D8)
lcd_d7 = digitalio.DigitalInOut(board.D12)
lcd_d6 = digitalio.DigitalInOut(board.D11)
lcd_d5 = digitalio.DigitalInOut(board.D10)
lcd_d4 = digitalio.DigitalInOut(board.D9)
red = pulseio.PWMOut(board.D3)
green = pulseio.PWMOut(board.D5)
blue = pulseio.PWMOut(board.D6)

# Initialise the LCD class
lcd = characterlcd.Character_LCD_RGB(
    lcd_rs,
    lcd_en,
    lcd_d4,
    lcd_d5,
    lcd_d6,
    lcd_d7,
    lcd_columns,
Exemple #26
0
"""
Example of using the library manually send Acknowledgement (ACK)
messages without using the nRF24L01's ACK payloads feature.
"""
import time
import board
import digitalio

# if running this on a ATSAMD21 M0 based board
# from circuitpython_nrf24l01.rf24_lite import RF24
from circuitpython_nrf24l01.rf24 import RF24

# change these (digital output) pins accordingly
ce = digitalio.DigitalInOut(board.D4)
csn = digitalio.DigitalInOut(board.D5)

# using board.SPI() automatically selects the MCU's
# available SPI pins, board.SCK, board.MOSI, board.MISO
spi = board.SPI()  # init spi bus object

# initialize the nRF24L01 on the spi bus object
nrf = RF24(spi, csn, ce)

# set the Power Amplifier level to -12 dBm since this test example is
# usually run with nRF24L01 transceivers in close proximity
nrf.pa_level = -12

# addresses needs to be in a buffer protocol object (bytearray)
address = [b"1Node", b"2Node"]

# to use different addresses on a pair of radios, we need a variable to
# Write the time for the Adafruit DS3231 real-time clock.
# Limor Fried/Anne Barela for Adafruit Industries

import time
import board
import busio as io
import digitalio
import adafruit_ds3231

i2c = io.I2C(board.SCL, board.SDA)

# Create the RTC instance:
rtc = adafruit_ds3231.DS3231(i2c)

LED13 = digitalio.DigitalInOut(board.D13)
LED13.direction = digitalio.Direction.OUTPUT

# pylint: disable-msg=using-constant-test
if True:
    #                     year, mon, date, hour, min, sec, wday, yday, isdst
    t = time.struct_time((2019,   7,    10,   17,  00,   0,    0,   -1,    -1))
    # you must set year, mon, date, hour, min, sec and weekday
    # yearday is not supported
    # isdst can be set but we don't do anything with it at this time
    print("Setting time to:", t)     # uncomment for debugging
    rtc.datetime = t
    print("Done!")
    LED13.value = True
# pylint: enable-msg=using-constant-test
Exemple #28
0
"""Rotary Trinkey NeoPixel color picker example"""
import rotaryio
import digitalio
import board
from rainbowio import colorwheel
import neopixel

print("Rotary Trinkey color picker example")

pixel = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.5)
encoder = rotaryio.IncrementalEncoder(board.ROTA, board.ROTB)
switch = digitalio.DigitalInOut(board.SWITCH)
switch.switch_to_input(pull=digitalio.Pull.DOWN)

last_position = -1
color = 0  # start at red
while True:
    position = encoder.position
    if last_position is None or position != last_position:
        print(position)
        if not switch.value:
            # change the color
            if position > last_position:  # increase
                color += 1
            else:
                color -= 1
            color = (color + 256) % 256  # wrap around to 0-256
            pixel.fill(colorwheel(color))
        else:
            # change the brightness
            if position > last_position:  # increase
import board
import digitalio
import os
import subprocess
import time
button = digitalio.DigitalInOut(board.D4)
button.direction = digitalio.Direction.INPUT
prev_value = True
print("inital button value:", button.value)
while 1:
    button = digitalio.DigitalInOut(board.D4)
    button.direction = digitalio.Direction.INPUT
    x = button.value
    if x and prev_value != x:
        #subprocess.Popen("sudo python3 /home/tobiasravn/Desktop/code_pc/main.py 1", shell=True)
        #subprocess.call(['xterm', '-e', 'python bb.py'], cwd='/home/tobiasravn/Desktop/code/', shell =True)
        subprocess.call([
            "gnome-terminal", "-e",
            "sudo python3 /home/tobiasravn/Desktop/code_pc/main.py"
        ])
        while button.value:
            pass
        print("Whaiting to clean up the program...")
        time.sleep(3)

    prev_value = x
Exemple #30
0
"""Simple example to print acceleration data to console"""
import time
import digitalio
import board
import busio
import adafruit_lis3dh

# Set up accelerometer on I2C bus, 4G range:
i2c = busio.I2C(board.SCL, board.SDA)
int1 = digitalio.DigitalInOut(board.D5)
accel = adafruit_lis3dh.LIS3DH_I2C(i2c, int1=int1)
accel.range = adafruit_lis3dh.RANGE_4_G
accel.set_tap(1, 100)

while True:
    x, y, z = accel.acceleration
    print(x, y, z)
    time.sleep(0.1)
    if accel.tapped:
        print("Tapped!")