Пример #1
0
BORDER = 5

i2c = board.I2C()
tca = [
    adafruit_tca9548a.TCA9548A(i2c, address=0x70),
    adafruit_tca9548a.TCA9548A(i2c, address=0x71)
]

disp = []  # Display list

#Set up displays
for i in range(9):
    try:
        disp.append(
            adafruit_ssd1306.SSD1306_I2C(WIDTH,
                                         HEIGHT,
                                         tca[i // 7][i % 7],
                                         addr=0x3c))
    except Exception as e:
        disp.append(None)
        print('oled setup failed, index ', i, 'on tca module 0-2: ', i // 7)


def show(ind, text):
    global disp
    fontsize = 24  # arbitrary static
    font = ImageFont.truetype(
        "Calibri.ttf",
        fontsize)  #if it does set font size appropriately using Calibri.

    if (type(ind) != int):
        raise TypeError('display selector must be an integer')
Пример #2
0
    def __init__(self, min_speed=10, max_speed=26):
        # Create I2C interfaces.
        self.i2c_display = busio.I2C(board.SCL, board.SDA)
        self.i2c_accel = I2C(
            11)  # GPIO23 = SDA, GPIO24 = SCL -- enable the i2c-gpio overlay!

        # Update minimum and maximum speeds (in pixels / second)
        self.min_speed = min_speed
        self.max_speed = max_speed
        self.current_speed = min_speed  # to start

        # Create list of obstacles (empty to start)
        self.obstacles = []

        # Create a variable to hold the score
        self.score = 0

        # Create a dino 🦖
        self.dino = Dino(self)

        # The PiOLED is 128 pixels x 32 pixels, and communicates over I2C, so we need to give it the I2C interface created above.
        self.display = adafruit_ssd1306.SSD1306_I2C(128, 32, self.i2c_display)

        # Initialize the accelerometer.
        self.accelerometer = adafruit_mpu6050.MPU6050(self.i2c_accel)

        # Initialize the UI button.
        self.button = digitalio.DigitalInOut(board.D26)
        self.button.direction = digitalio.Direction.INPUT
        self.button.pull = digitalio.Pull.UP

        # Variable to hold acceleration (updated often from the MPU6050)
        self.acceleration = [0, 0, 0]

        # Variable to hold gyro data (updated often from the MPU6050)
        self.gyro = [0, 0, 0]

        # Time that we last added an obstacle
        self.last_added_obstacle = time.time_ns() / 1000000000

        # Get display width & height.
        self.width = self.display.width
        self.height = self.display.height

        # Create blank image for drawing.
        # Make sure to create image with mode '1' for 1-bit color.
        # 1-bit color means the only options are full brightness (fill=255) or off (fill=0) -- this display is monochrome.
        self.image = Image.new('1', (self.width, self.height))

        # Get drawing object to draw on image.
        self.draw = ImageDraw.Draw(self.image)

        # Draw a black filled box to clear the image.
        self.draw.rectangle((0, 0, self.width, self.height), outline=0, fill=0)

        # Draw a line at the bottom of the screen (height = 31 & width = 127 because they start at 0, so we are drawing from (0, 31) to (128, 31)).
        # This is the ground for the dino game. The line also is at full brightness (fill=255), 3 pixels high (width=3), and has curved edges (joint="curve").
        # self.draw.line([(0, self.height), (self.width, self.height)], fill=255, width=3, joint="curve")

        # Draw the ground for the dino game (see where we make the bitmap on line 18). Fill = white (255). TODO get final line #
        self.draw.bitmap((0, 27), bitmap(bitmaps["ground"]), fill=255)

        # Update display. (not the obstacles because we haven't started yet)
        self.update_display()

        if not self.dino.calibration_exists:
            print(
                "Calibrating gyro in 3 seconds. Please put the MPU6050 down on a flat surface with the Z axis (chip) pointing up."
            )
            time.sleep(3)
        self.dino.calibrate()

        # Time that the game started (for screen recording)
        self.start = time.time_ns() / 1000000  # milliseconds

        # Start the game! Call the update() function every 0.01 seconds.
        # This returns a function that will stop the loop.
        self.stop1 = call_repeatedly(0.01, self.update)

        self.stop2 = call_repeatedly(0.0001, self.get_acceleration)
Пример #3
0
import board
import busio
from digitalio import DigitalInOut, Direction, Pull
from PIL import Image, ImageDraw, ImageFont
from adafruit_htu21d import HTU21D
import adafruit_ssd1306

# Load the default font into object
font = ImageFont.load_default()

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

# Create the SSD1306 OLED class.
disp = adafruit_ssd1306.SSD1306_I2C(128, 64, i2c)

# Input pins:
button_A = DigitalInOut(board.D5)
button_A.direction = Direction.INPUT
button_A.pull = Pull.UP

button_B = DigitalInOut(board.D6)
button_B.direction = Direction.INPUT
button_B.pull = Pull.UP

button_L = DigitalInOut(board.D27)
button_L.direction = Direction.INPUT
button_L.pull = Pull.UP

button_R = DigitalInOut(board.D23)
Пример #4
0
def main(argv):
    i2c = busio.I2C(board.SCL, board.SDA)

    # Create the TCA9548A object and give it the I2C bus
    tca = adafruit_tca9548a.TCA9548A(i2c)
    tail_font = ImageFont.truetype(
        '/home/pi/in-the-pattern/oled/16x8pxl-mono.ttf', 38)

    input_leg = ''
    input_tail = ''
    clear_oled = "false"
    pattern_direction = "l"

    try:
        opts, args = getopt.getopt(argv, "hl:t:c:p:",
                                   ["leg=", "tail=", "clear=", "pattern="])
    except getopt.GetoptError:
        print(
            'aip.py -l <pattern leg> -t <tail number> -c <clear {leg, all}>, -p <pattern {l or r}>\nAcceptable pattern legs are upwind, crosswind, downwind, base, or final'
        )
        sys.exit(2)
    for opt, arg in opts:
        if opt == '-h':
            print(
                'aip.py -l <pattern leg> -t <tail number>\nAcceptable pattern legs are upwind, crosswind, downwind, base, or final'
            )
            sys.exit()
        elif opt in ("-l", "--leg"):
            input_leg = arg
        elif opt in ("-t", "--tail"):
            input_tail = arg
        elif opt in ("-c", "--clear"):
            clear_oled = arg
        elif opt in ("-p", "--pattern"):
            pattern_direction = arg

    if pattern_direction != "r":
        pattern_direction = "l"

    # multiplexer index for each OLED
    pattern_leg = {}
    pattern_leg['downwind'] = 4
    if pattern_direction == "l":
        pattern_leg['upwind'] = 2
        pattern_leg['crosswind'] = 3
        pattern_leg['base'] = 5
        pattern_leg['final'] = 6
    else:
        pattern_leg['upwind'] = 6
        pattern_leg['crosswind'] = 5
        pattern_leg['base'] = 3
        pattern_leg['final'] = 2

    tail_number = input_tail

    leg = input_leg
    leg_name = adafruit_ssd1306.SSD1306_I2C(128, 32, tca[pattern_leg[leg]])
    if clear_oled == "leg":
        leg_name.fill(0)
        leg_name.show()
        sys.exit()
    if clear_oled == "all":
        for leg in pattern_leg.keys():
            leg_name = adafruit_ssd1306.SSD1306_I2C(128, 32,
                                                    tca[pattern_leg[leg]])
            leg_name.fill(0)
            leg_name.show()
        sys.exit()

    W, H = (leg_name.width, leg_name.height)
    leg_name.fill(0)
    leg_name.show()
    tail_number_img = Image.new("1", (W, H))
    draw_tail_number = ImageDraw.Draw(tail_number_img)
    w, h = draw_tail_number.textsize(
        tail_number, font=tail_font
    )  #Figure out the height and width of tail number so we can center it
    draw_tail_number.text(((W - w) / 2, (H - h) / 2),
                          tail_number,
                          font=tail_font,
                          fill=255)
    offset = 0
    # if input_leg == "upwind":
    # for i in range(0,16):
    #     leg_name.scroll(-8,0)
    #     leg_name.show()
    # leg_name.image(tail_number_img)
    # leg_name.show()
    leg_name.image(tail_number_img)
    leg_name.show()
Пример #5
0
# Basic example of clearing and drawing pixels on a SSD1306 OLED display.
# This example and library is meant to work with Adafruit CircuitPython API.
# Author: Tony DiCola
# License: Public Domain

# Import all board pins.
import board
from board import SCL, SDA
import busio

# Import the SSD1306 module.
import adafruit_ssd1306


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

# Create the SSD1306 OLED class.
# The first two parameters are the pixel width and pixel height.  Change these
# to the right size for your display!
display = adafruit_ssd1306.SSD1306_I2C(128, 32, i2c)
# Alternatively you can change the I2C address of the device with an addr parameter:
#display = adafruit_ssd1306.SSD1306_I2C(128, 32, i2c, addr=0x31)

# Clear the display.  Always call show after changing pixels to make the display
# update visible!
display.fill(0)

display.show()
Пример #6
0
OLED_X_SIZE = 128
OLED_Y_SIZE = 32

# Create sensor object, communicating over the board's default I2C bus
i2c = board.I2C()
sht3 = adafruit_sht31d.SHT31D(i2c)

bmp280 = adafruit_bmp280.Adafruit_BMP280_I2C(i2c, address=0x76)
bmp280.sea_level_pressure = 1013.25

RESET_PIN = digitalio.DigitalInOut(board.D4)
i2c_oled = busio.I2C(SCL, SDA)
display = adafruit_ssd1306.SSD1306_I2C(OLED_X_SIZE,
                                       OLED_Y_SIZE,
                                       i2c_oled,
                                       addr=0x3C,
                                       reset=RESET_PIN)
display.fill(0)
display.show()
'''
for y in range(OLED_Y_SIZE):
    for x in range(OLED_X_SIZE):
        display.pixel(x, y, 1)
    display.show()
'''

#font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", 9)
#font = ImageFont.truetype("/usr/share/fonts/truetype/freefont/FreeSans.ttf", 8)
#font = ImageFont.load_default()
#font = ImageFont.truetype("/usr/share/fonts/truetype/noto/NotoSansTelugu-Bold.ttf", 12)
from board import SCL, SDA
import busio
import adafruit_ssd1306
from PIL import Image, ImageDraw, ImageFont
WIDTH = 128
HEIGHT = 64
i2c = busio.I2C(SCL, SDA)
oled = adafruit_ssd1306.SSD1306_I2C(WIDTH, HEIGHT, i2c, addr=0x3c)
image = Image.new('1', (oled.width, oled.height))
draw = ImageDraw.Draw(image)
draw.rectangle((0, 0, oled.width, oled.height), outline=255, fill=255)
draw.rectangle((0, 0, oled.width, oled.height), outline=0, fill=0)
oled.image(image)
oled.show()
Пример #8
0
busDictionary = {
    1: {
        'SDA': pins.SDA,
        'SCL': pins.SCL
    },
    3: {
        'SDA': pins.D17,
        'SCL': pins.D27
    },
    4: {
        'SDA': pins.D23,
        'SCL': pins.D24
    },
    5: {
        'SDA': pins.D18,
        'SCL': pins.D22
    }
}
busNumbers = [1, 3, 4, 5]

busList = [
    busio.I2C(busDictionary[x]['SCL'], busDictionary[x]['SDA'])
    for x in busNumbers
]

displayList = [
    adafruit_ssd1306.SSD1306_I2C(128, 64, x, addr=0x3c) for x in busList
]

for i, display in enumerate(displayList):
    runDisplay(display, i)
Пример #9
0
cycles = 10
cycletime = 30

counter = 0
temp_av = 0
hum_av = 0
light_av = 0

analogin = AnalogIn(board.LIGHT)
lora_reset_pin = DigitalInOut(board.A2)
lora_reset_pin.direction = Direction.OUTPUT
switch_pin = DigitalInOut(board.SLIDE_SWITCH)
switch_pin.direction = Direction.INPUT
switch_pin.pull = Pull.UP
i2c = io.I2C(board.SCL, board.SDA)
oled = adafruit_ssd1306.SSD1306_I2C(64, 48, i2c)
dht = adafruit_dht.DHT22(board.A3)
uart_lora = io.UART(board.TX, board.RX, baudrate=56700)


def sensor_autodetect():
    i2c.try_lock()
    addresses = i2c.scan()
    i2c.unlock()
    print(addresses)


def read_light():
    peak = analogin.value * 330 // (2**16)
    if debug:
        print('Light: ' + str(analogin.value) + ' => ' + str(int(peak)))
Пример #10
0
import adafruit_ssd1306
# library for needed functions
from oled_display.utils import get_ip_address, get_gpu_usage

DIPLAY_IP = True

# Create the I2C interface.
i2c = busio.I2C(SCL, SDA)
# OLED pixels
WIDTH = 128
HEIGHT = 32

# Create the SSD1306 OLED class.
# The first two parameters are the pixel width and pixel height.  Change these
# to the right size for your display!
display = adafruit_ssd1306.SSD1306_I2C(WIDTH, HEIGHT, i2c)
# Alternatively you can change the I2C address of the device with an addr parameter:
# display = adafruit_ssd1306.SSD1306_I2C(128, 32, i2c, addr=0x3c)

# Create a sigle bit image of size (WIDTH, HEIGHT)
image = Image.new('1', (WIDTH, HEIGHT))
# Create a draw object to manipulate image
draw = ImageDraw.Draw(image)
# Draw a black filled box to clear the image
draw.rectangle((0, 0, WIDTH, HEIGHT), outline=0, fill=0)

# Define a padding
padding = -2
# Top and lower padding
top = padding
bottom = HEIGHT - padding
# Create library object using our Bus I2C port
i2c = busio.I2C(board.SCL, board.SDA)
bme680 = adafruit_bme680.Adafruit_BME680_I2C(i2c, 0x76)

# change this to match the location's pressure (hPa) at sea level
bme680.sea_level_pressure = 1013.25

# A reset line may be required if there is no auto-reset circuitry
reset_pin = DigitalInOut(board.D10)

# use the 0.96" OLED Screen
wireling.selectPort(OLED96_port)
display = adafruit_ssd1306.SSD1306_I2C(128,
                                       64,
                                       i2c,
                                       addr=0x3c,
                                       reset=reset_pin)  # 0.96" Screen

# Load a font
font = ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf',
                          14)

while True:
    # Select the sensor port to get data
    wireling.selectPort(BME680_port)

    tmpC = bme680.temperature
    tmpF = (tmpC * 1.8) + 32

    tmp = "Temp: %0.1f F" % tmpF
Пример #12
0
    def __init__(self, lcd_dev=None, lcd_settings_dict=None, font=None):
        self.disp = None
        self.font = font
        self.font_size = 10

        if lcd_dev:
            self.logger = logging.getLogger("{}_{}".format(
                __name__,
                lcd_dev.unique_id.split('-')[0]))
            self.interface = lcd_dev.interface
            self.lcd_x_characters = lcd_dev.x_characters
            self.line_y_dimensions = [0, 8, 16, 24, 32, 40, 48, 56]
            self.lcd_type = lcd_dev.lcd_type

            if self.interface == "I2C":
                self.i2c_address = lcd_dev.location
                self.i2c_bus = lcd_dev.i2c_bus
            elif self.interface == "SPI":
                self.spi_bus = lcd_dev.spi_bus
                self.spi_device = lcd_dev.spi_device
                self.pin_dc = lcd_dev.pin_dc
                self.pin_reset = lcd_dev.pin_reset
                self.pin_cs = lcd_dev.pin_cs

        elif lcd_settings_dict:
            self.logger = logging.getLogger("{}_{}".format(
                __name__, lcd_settings_dict["unique_id"].split('-')[0]))
            self.interface = lcd_settings_dict["interface"]
            self.lcd_x_characters = lcd_settings_dict["x_characters"]
            self.line_y_dimensions = lcd_settings_dict["line_y_dimensions"]
            self.lcd_type = lcd_settings_dict["lcd_type"]
            self.font_size = lcd_settings_dict["font_size"]

            if self.interface == "I2C":
                self.i2c_address = lcd_settings_dict["i2c_address"]
                self.i2c_bus = lcd_settings_dict["i2c_bus"]
            elif self.interface == "SPI":
                self.spi_bus = lcd_settings_dict["spi_bus"]
                self.spi_device = lcd_settings_dict["spi_device"]
                self.pin_dc = lcd_settings_dict["pin_dc"]
                self.pin_reset = lcd_settings_dict["pin_reset"]
                self.pin_cs = lcd_settings_dict["pin_cs"]

        if self.interface == 'I2C':
            if self.lcd_type == '128x32_pioled_circuit_python':
                self.disp = adafruit_ssd1306.SSD1306_I2C(
                    128,
                    32,
                    ExtendedI2C(self.i2c_bus),
                    addr=int(str(self.i2c_address), 16))
            elif self.lcd_type == '128x64_pioled_circuit_python':
                self.disp = adafruit_ssd1306.SSD1306_I2C(
                    128,
                    64,
                    ExtendedI2C(self.i2c_bus),
                    addr=int(str(self.i2c_address), 16))

        elif self.interface == 'SPI':
            import Adafruit_GPIO.SPI as SPI
            if self.lcd_type == '128x32_pioled_circuit_python':
                self.disp = adafruit_ssd1306.SSD1306_SPI(128,
                                                         32,
                                                         spi=SPI.SpiDev(
                                                             self.spi_bus,
                                                             self.spi_device),
                                                         dc=self.pin_dc,
                                                         reset=self.pin_reset,
                                                         cs=self.pin_cs)
            elif self.lcd_type == '128x64_pioled_circuit_python':
                self.disp = adafruit_ssd1306.SSD1306_SPI(128,
                                                         64,
                                                         spi=SPI.SpiDev(
                                                             self.spi_bus,
                                                             self.spi_device),
                                                         dc=self.pin_dc,
                                                         reset=self.pin_reset,
                                                         cs=self.pin_cs)

        if not self.disp:
            self.logger.error(
                "Unable to set up display. Check the LCD settings.")
Пример #13
0
 def __init__(self, addr):
     self.i2c = board.I2C()
     self.oled = adafruit_ssd1306.SSD1306_I2C(128, 32, self.i2c, addr=addr)
     self.font = ImageFont.load_default()
     self.clear()
Пример #14
0
# \\python\comm\i2c_SSD1306_org.py
# https://github.com/adafruit/Adafruit_Python_SSD1306

#	ORA	VCC	pin_01 : 3V3
#	WHT	GND	pin_06 : GND
#	MAG	SDA	pin_03 : BCM_02
#	YEL	SCL	pin_05 : BCM_03

from board import SCL, SDA
import busio
import adafruit_ssd1306

i2c = busio.I2C(SCL, SDA)

pix_width = 128
pix_height = 64

# create OLED class, change right size for display; address parm is optional
display = adafruit_ssd1306.SSD1306_I2C(pix_width, pix_height, i2c)

# clear display; always call show after changing pixels to make update visible!
display.fill(0)

display.show()

print("DONE")
Пример #15
0
import busio
import board

from digitalio import DigitalInOut, Direction, Pull

# Import the SSD1306 module.
import adafruit_ssd1306

# Import the RFM69 radio module.
import adafruit_rfm69

# Create the I2C interface.
i2c = busio.I2C(board.SCL, board.SDA)
 
# 128x32 OLED Display
display = adafruit_ssd1306.SSD1306_I2C(128, 32, i2c, addr=0x3c)

# Clear the display.
display.fill(0)
display.show()
width = display.width
height = display.height

# Configure Packet Radio
CS = DigitalInOut(board.CE1)
RESET = DigitalInOut(board.D25)
FREQ = 915.0
ID = 0

spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
rfm69 = adafruit_rfm69.RFM69(spi, CS, RESET, FREQ)
Пример #16
0
import board
import busio
import digitalio
import adafruit_ssd1306

i2c = busio.I2C(board.SCL, board.SDA)
reset_pin = digitalio.DigitalInOut(board.D9)  # any pin!

#init OLED
oled = adafruit_ssd1306.SSD1306_I2C(128, 32, i2c, addr=0x3C, reset=reset_pin)
num = 0

#print hello world

# message = 'round {}'.format(num)
# oled.fill(0)
# oled.text(message, 0, 0, 1)
# oled.text('World', 0, 10, 1)
# oled.show()

while True:
    message = 'round {}'.format(num)
    oled.fill(0)
    oled.text(message, 0, 0, 1)
    oled.show()
    num = num + 1
Пример #17
0
WIDTH = 128
HEIGHT = 32  # Change to 64 if needed
BORDER = 5

# How long to delay between each update
delay_time_ms = 250

# Define the Reset Pin
oled_reset = None 

# init i2c
i2c = board.I2C()

# 128x32 display with hardware I2C:
oled = adafruit_ssd1306.SSD1306_I2C(WIDTH, HEIGHT, i2c, addr=0x3C, reset=oled_reset)

print ("Running with the following display:")
print (oled)
print ()
print ("Will update the OLED display every " + str(delay_time_ms) + "ms (approximately)")

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

# Create blank image for drawing.
# Make sure to create image with mode '1' for 1-bit color.
image = Image.new("1", (oled.width, oled.height))

# Get drawing object to draw on image.
Пример #18
0
def control_OLED():
    '''
    Funtion to manage OLED readouts of light, moisture, and temperature
    '''
    print('OLED Started')

    # Setup for Light sensor
    #i2c_light = busio.I2C(board.SCL, board.SDA)
    #sensor = adafruit_tsl2591.TSL2591(i2c_light)

    # Setup for STEMMA sensor
    #i2c_bus = busio.I2C(SCL, SDA)

    #ss = Seesaw(i2c_bus, addr=0x36)

    # Setup for OLED

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

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

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

    # Create blank image for drawing.
    # Make sure to create image with mode '1' for 1-bit color.
    width = disp.width
    height = disp.height
    image = Image.new('1', (width, height))

    # Get drawing object to draw on image.
    draw = ImageDraw.Draw(image)

    # Draw a black filled box to clear the image.
    draw.rectangle((0, 0, width, height), outline=0, fill=0)

    # Draw some shapes.
    # First define some constants to allow easy resizing of shapes.
    padding = -2
    top = padding
    bottom = height - padding
    # Move left to right keeping track of the current x position for drawing shapes.
    x = 0

    # Load default font.
    #font = ImageFont.load_default()

    # Alternatively load a TTF font.  Make sure the .ttf font file is in the

    font = ImageFont.truetype(
        '/home/pi/virtEnv1/plant_care_system/slkscrb.ttf', 8)

    while True:
        #i2c_bus = busio.I2C(SCL, SDA)
        #ss = Seesaw(i2c_bus, addr=0x36)
        # Get moisture and temperature readings
        touch = ss.moisture_read()
        temp = ss.get_temp()
        temp = 9 / 5 * temp + 32
        #print('Temp: ', str(temp))
        #print('Moisture: ', str(touch))
        # Get visible light reading
        light = sensor.visible
        #print('Light: ', str(light))
        #print('-----------------------------------')

        time.sleep(5)
        # Draw a black filled box to clear the image.
        draw.rectangle((0, 0, width, height), outline=0, fill=0)

        # Write four lines of text.
        draw.text((x, top + 0), "Moisture: " + str(touch), font=font, fill=255)
        draw.text((x, top + 8),
                  "Temp: " + str(round(temp, 2)),
                  font=font,
                  fill=255)
        draw.text((x, top + 16), "Light: " + str(light), font=font, fill=255)
        draw.text((x, top + 25), "Water Smartly!", font=font, fill=255)

        # Display image.
        disp.image(image)
        disp.show()
        time.sleep(1)
        disp.fill(0)
Пример #19
0
For use with ssd1306

Written by: Carlin Kartchner
"""

import board
import busio as io
import adafruit_ssd1306
import random

# Board dimensions
xdim = 128
ydim = 64

i2c = io.I2C(board.SCL, board.SDA)
oled = adafruit_ssd1306.SSD1306_I2C(128, 64, i2c, addr=0x3C)


def inverter(p, invert):
    if invert:
        p = p ^ 1  # Bitwise XOR
    return p


def row_sweep(file, dir='t2b', invert=False):
    """
    Update dipslay one row at a time

    :file: name of image file in same directory as main.py
    :dir: direction row sweeps
    :invert: switch whether the pixel is on/off when displayed
Пример #20
0
#!/usr/bin/env python

# This example doesn't use the slower PIL library which would cause
# flickering in character movement.
print("Loading")
import board
import busio
import adafruit_ssd1306
from time import sleep

display = adafruit_ssd1306.SSD1306_I2C(128, 32, busio.I2C(board.SCL, board.SDA), addr=0x3c)

display.fill(0)
display.show()

print("Animating A zigzag...")
x = 0

print("x start: " + str(x))

while x < 128:
  print(x)
  display.pixel(x, 16, 1)
  display.show()
  sleep(0.0000001)
  display.fill(0)
  x = x + 1
while x > 0:
  print(x)
  display.pixel(x, 16, 1)
  display.show()
Пример #21
0
import time
import busio
from digitalio import DigitalInOut, Direction, Pull
import board
import adafruit_ssd1306
import adafruit_rfm9x
import sys
import datetime

MyDateTime = datetime.datetime(2016, 1, 3, 8, 30, 20)

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

reset_pin = DigitalInOut(board.D4)
display = adafruit_ssd1306.SSD1306_I2C(128, 32, i2c, reset=reset_pin)
# Clear the display.
display.fill(0)
display.show()
width = display.width
height = display.height

# Configure LoRa Radio
CS = DigitalInOut(board.CE1)
RESET = DigitalInOut(board.D25)
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
rfm9x = adafruit_rfm9x.RFM9x(spi,
                             CS,
                             RESET,
                             915.0,
                             preamble_length=8,
                             high_power=True,
Пример #22
0
import board
import digitalio
from PIL import Image, ImageDraw, ImageFont
import adafruit_ssd1306
import sys
# Setting some variables for our reset pin etc.
RESET_PIN = digitalio.DigitalInOut(board.D4)

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

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

# Load a font in 2 different sizes.
font = ImageFont.truetype('/home/pi/python-OBD/b.ttf', 28)

image = Image.new('1', (display.width, display.height))
draw = ImageDraw.Draw(image)
draw.text((0, 30), '!olleH', font=font, fill=255)
display.image(image)
display.show()

x = sys.argv[1]
# Draw the text
# draw.text((34, 0), 'Hello!', font=font, fill=255)
#draw.text("Hello",34,0,color=0xFF0000,font_name=font)

#display.text(x,0,34,0xFFFFF, font_name=font, size=2)
Пример #23
0
# Create I2c bus
i2c = busio.I2C(board.SCL, board.SDA)

# Define display dimensions and I2C address
WIDTH = 128
HEIGHT = 64
ADDR = 0x3d

# Create the digital out used for display reset
rst = DigitalInOut(board.D7)

# Create the display
display = adafruit_ssd1306.SSD1306_I2C(WIDTH,
                                       HEIGHT,
                                       i2c,
                                       addr=ADDR,
                                       reset=rst)
display.fill(0)
display.show()

# Loop forever drawing random pixels
while True:
    for _ in range(500):
        x = random.randrange(WIDTH)
        y = random.randrange(HEIGHT)
        display.pixel(x, y, 1)
    display.show()
    time.sleep(0.5)
    display.fill(0)
    def __init__(self):
        self.i2c = busio.I2C(board.SCL, board.SDA)
        self.oled = adafruit_ssd1306.SSD1306_I2C(128, 32, self.i2c)

        self.oled.fill(0)
        self.oled.show()
Пример #25
0
import busio
from PIL import Image, ImageDraw, ImageFont
import time
# Import the SSD1306 module.
import adafruit_ssd1306


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

# Create the SSD1306 OLED class.
# The first two parameters are the pixel width and pixel height.  Change these
# to the right size for your display!
#display = adafruit_ssd1306.SSD1306_I2C(128, 32, i2c)
# Alternatively you can change the I2C address of the device with an addr parameter:
disp = adafruit_ssd1306.SSD1306_I2C(128, 64, i2c, addr=0x3c)

# Clear the display.  Always call show after changing pixels to make the display
# update visible!
disp.fill(0)

disp.show()

width = disp.width
height = disp.height
image = Image.new('1', (width, height))

# Get drawing object to draw on image.
draw = ImageDraw.Draw(image)

# Draw a black filled box to clear the image.
Пример #26
0
class MenuDisplay:
    is_enabled = True
    text_block = ["Dadda", "Random", "Lily", "Xander"]
    selected_level = 0
    dy = 2             # The number of pixes to move each step of scroll animation
    time_diff = 0.001  # time to sleep each step of scroll animation
    y_movement = 0     # holds the value of which way the scroll animation will go for next scroll
    triangle_width = 8 # width of triangle

    i2c = busio.I2C(SCL, SDA)
    disp = adafruit_ssd1306.SSD1306_I2C(128, 32, i2c)

    image = 0
    draw = 0

    def draw_triangle(self, draw, width, height, screen_height):
        mid_height = screen_height / 2
        triangle_left_x = 0
        #top left 
        triangle_p0 = (triangle_left_x, mid_height - (height / 2))
        #bottom left
        triangle_p1 = (triangle_left_x, mid_height + (height / 2))
        #middle right
        triangle_p2 = (triangle_left_x + width, mid_height)

        draw.polygon( [triangle_p0, triangle_p1, triangle_p2], fill=255)

    def init(self):
        self.selected_level = 0 #reset to 0 regardless of what it was previously set to
        self.disp.fill(0)
        self.disp.show()

        self.width = self.disp.width
        self.height = self.disp.height
        self.midheight = self.height / 2

        self.image = Image.new("1", (self.width, self.height))
        self.draw = ImageDraw.Draw(self.image)

        self.disp.fill(0)

        self.padding = -2
        self.top = self.padding
        self.bottom = self.height - self.padding

        self.font_size = 16

        print("Width = %d, Height = %d" % (self.width, self.height))

        self.font = ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf', self.font_size)

        self.draw_triangle(self.draw, self.triangle_width, self.font_size, self.height)
        self.disp.image(self.image)
        self.disp.show()

        self.x = self.triangle_width + 4
        self.y = self.midheight - self.font_size / 2

        self.text_position = []
        
        for i in range(len(self.text_block)):
            self.text_position.append( ( self.x, self.y + (self.font_size * i) ) )

        for i in range(len(self.text_position)):
            self.text_position[i] = (self.text_position[i][0], self.text_position[i][1])
            self.draw.text( self.text_position[i], self.text_block[i], font=self.font, fill=255)
        self.disp.image(self.image)
        self.disp.show()

        print("Selected level: %s %s" % (self.selected_level, self.text_block[self.selected_level]))

    def __init__(self):
        self.init()

    def animate(self):
        for i in range(int(self.font_size / self.dy)):
            time.sleep(self.time_diff)

            self.draw.rectangle((0, 0, self.width, self.height), outline=0, fill=0)
            self.draw_triangle(self.draw, self.triangle_width, self.font_size, self.height)
            for i in range(len(self.text_position)):
                self.text_position[i] = (self.text_position[i][0], self.text_position[i][1] + self.y_movement)
                self.draw.text( self.text_position[i], self.text_block[i], font=self.font, fill=255)
            self.disp.image(self.image)
            self.disp.show()
        self.y_movement = 0

    def up_action(self):
        if(self.y_movement == 0 and self.selected_level > 0):
            print ("Up moving")
            self.y_movement = self.dy
            self.selected_level -= 1

    def down_action(self):
        if (self.y_movement == 0 and self.selected_level < (len(self.text_block) - 1)):
            print ("Down moving")
            self.y_movement = -1 * self.dy
            self.selected_level += 1

    def level_name(self):
        return self.text_block[self.selected_level]

    def blank_screen(self):
        self.draw.rectangle((0, 0, self.width, self.height), outline=0, fill=0)
        self.disp.image(self.image)
        self.disp.show()

    def disable(self):
        print ("Disable screen")
        self.is_enabled = False
        self.blank_screen()

    def enable(self):
        self.is_enabled = True
        self.init()
Пример #27
0
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT

import board
import busio
import adafruit_ssd1306

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

# Create the SSD1306 OLED class.
# The first two parameters are the pixel width and pixel height.  Change these
# to the right size for your display!
oled = adafruit_ssd1306.SSD1306_I2C(128, 32, i2c)


# Helper function to draw a circle from a given position with a given radius
# This is an implementation of the midpoint circle algorithm,
# see https://en.wikipedia.org/wiki/Midpoint_circle_algorithm#C_example for details
def draw_circle(xpos0, ypos0, rad, col=1):
    x = rad - 1
    y = 0
    dx = 1
    dy = 1
    err = dx - (rad << 1)
    while x >= y:
        oled.pixel(xpos0 + x, ypos0 + y, col)
        oled.pixel(xpos0 + y, ypos0 + x, col)
        oled.pixel(xpos0 - y, ypos0 + x, col)
        oled.pixel(xpos0 - x, ypos0 + y, col)
        oled.pixel(xpos0 - x, ypos0 - y, col)
Пример #28
0
    # line 3
    draw.text((x0, 45), line_3, font=smallfont, fill=255)
    # display result
    disp.image(image)
    disp.show()


if __name__ == "__main__":
    city_name = "Bussum"  #"Almere Stad"
    country_code = "NL"
    print(f"Weersrapport voor {city_name} in {country_code}:")

    # prepare OLED-display ...
    # 1. setup display
    i2c = busio.I2C(board.SCL, board.SDA)
    disp = adafruit_ssd1306.SSD1306_I2C(128, 64, i2c, addr=0x3c, reset=None)
    # fonts can be found in '/usr/share/fonts/truetype/
    smallfont = ImageFont.truetype('FreeSans.ttf', 12)
    largefont = ImageFont.truetype('FreeSans.ttf', 33)
    # 2. clear display
    disp.fill(0)
    disp.show()
    # 3. make an image to draw on in 1-bit color
    width = disp.width
    height = disp.height
    image = Image.new('1', (width, height))
    draw = ImageDraw.Draw(image)

    # get weather data for city...
    service = OpenWeaterMap(city_name, country_code)
    #service._test(city_name, country_code, wait=300)
Пример #29
0
#
# Ported to Pillow by Melissa LeBlanc-Williams for Adafruit Industries from Code available at:
# https://learn.adafruit.com/adafruit-oled-displays-for-raspberry-pi/programming-your-display

# Imports the necessary libraries...
import time
import board
import digitalio
from PIL import Image, ImageDraw, ImageFont
import adafruit_ssd1306

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

i2c = board.I2C()
oled = adafruit_ssd1306.SSD1306_I2C(128, 64, i2c, addr=0x3D, reset=RESET_PIN)

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

# Create blank image for drawing.
image = Image.new("1", (oled.width, oled.height))
draw = ImageDraw.Draw(image)

# Load a font in 2 different sizes.
font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf",
                          16)
font2 = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf",
                           24)
Пример #30
0
    def __init__(self):
        global display_instance
        display_instance = self
        self.is_running = AtomicValue(True)
        self.is_painting = AtomicValue(False)
        self.pilimg = Image.new('1', (config.WIDTH, config.HEIGHT))
        self.draw = ImageDraw.Draw(self.pilimg)

        if config.SHOW_STATS:
            # Performance counters
            self._frames = 0
            self._started_at = None
            self._last_report = 0
            self._last_report_at = None
            self._avg_lock = 0
            self._avg_render = 0
            self._avg_write = 0

        if config.USE_EMU:
            # Create the window using pyglet
            self.window = pyglet.window.Window(visible=False, resizable=True)
            self.old_on_key_press = self.window.on_key_press
            # AttributeError: 'CocoaWindow' object has no attribute 'on_key_release'
            # self.old_on_key_release = self.window.on_key_release
            self.window.on_key_press = on_key_press
            self.window.on_key_release = on_key_release
            self.window.on_draw = on_draw
            self.original_on_close = self.window.on_close
            self.window.on_close = on_close

            checks = pyglet.image.create(32, 32,
                                         pyglet.image.CheckerImagePattern())
            self.background = pyglet.image.TileableTexture.create_for_image(
                checks)

            # Enable alpha blending, required for image.blit.
            glEnable(GL_BLEND)
            glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

            self.window.width = config.WIDTH + 64
            self.window.height = config.HEIGHT + 64
            self.window.set_visible()

            self.fps_display = FPSDisplay(self.window)
        else:
            GPIO.setmode(GPIO.BCM)

            # Create the I2C interface.
            self.i2c = busio.I2C(board.SCL, board.SDA)
            # Create the SSD1306 OLED class.
            if USE_MICRO:
                self.disp = adafruit_ssd1306.SSD1306_I2C(
                    config.WIDTH, config.HEIGHT, self.i2c)
            else:
                self.disp = Adafruit_SSD1306.SSD1306_128_64(rst=RST)
                self.disp.begin()

            for button in config.ALL_BUTTONS:
                GPIO.setup(button, GPIO.IN, pull_up_down=GPIO.PUD_UP)
                GPIO.add_event_detect(button,
                                      GPIO.BOTH,
                                      callback=gpio_callback,
                                      bouncetime=20)

        self.vm = Manager()
        self.clear()
        self.scheduler = sched.scheduler(time.time, time.sleep)
        # First event comes later
        self.sched_event = self.scheduler.enter(1, 1, self.on_sched_event, ())

        t = threading.Thread(target=self.scheduler.run)
        t.start()