def texts(self, text1, text2=None): self.i2cbus2 = SMBus(1) self.oled = ssd1306(self.i2cbus2) direction1 = str(text1[0]) file_name = 'left_arr.png' if direction1 == '1': file_name = 'left_arr.png' elif direction1 == '2': file_name = 'up_arr.png' elif direction1 == '3': file_name = 'right_arr.png' img = Image.open(file_name) draw_text = str(text1[1]) font = ImageFont.truetype("Car_Num.ttf", 45) draw = ImageDraw.Draw(img) draw.text((64, 0), draw_text, 'black', font) flip1 = img.transpose(Image.FLIP_LEFT_RIGHT) result = flip1.transpose(Image.FLIP_TOP_BOTTOM) img.save('test.png') displaying = result.resize((128, 32)).convert('1') self.oled.canvas.bitmap((0, 32), displaying, fill=1) self.oled.display()
def __init__(self): self.reading_calibration = True # Initialise wiimote, will be created at beginning of loop. self.wiimote = None # Instantiate CORE / Chassis module and store in the launcher. self.core = core.Core(VL53L0X.tof_lib) GPIO.setwarnings(False) self.GPIO = GPIO self.challenge = None self.challenge_thread = None # Shutting down status self.shutting_down = False self.killed = False # WiiMote LED counter to indicate mode # NOTE: the int value will be shown as binary on the wiimote. self.MODE_NONE = 1 self.MODE_RC = 2 self.MODE_WALL = 3 self.MODE_MAZE = 4 self.MODE_CALIBRATION = 5 self.mode = self.MODE_NONE # create oled object, nominating the correct I2C bus, default address self.oled = ssd1306(VL53L0X.i2cbus)
def __init__(self): self.reading_calibration = True # Initialise wiimote, will be created at beginning of loop. self.wiimote = None # Instantiate CORE / Chassis module and store in the launcher. self.core = core.Core(VL53L0X.tof_lib) GPIO.setwarnings(False) self.GPIO = GPIO self.challenge = None self.challenge_thread = None # Shutting down status self.shutting_down = False self.killed = False # Mode/Challenge Dictionary self.menu_list = OrderedDict(( (Mode.MODE_POWER, "Power Off"), (Mode.MODE_RC, "RC"), (Mode.MODE_WALL, "Wall"), (Mode.MODE_MAZE, "Maze"), (Mode.MODE_CALIBRATION, "Calibration") )) self.current_mode = Mode.MODE_NONE self.menu_mode = Mode.MODE_RC # Create oled object, nominating the correct I2C bus, default address # Note: Set to None if you need to disable screen self.oled = ssd1306(VL53L0X.i2cbus)
def texts(direction, text): i2cbus = SMBus(1) oled = ssd1306(i2cbus) file_name = '' if direction == '1': file_name = 'up_arr.png' elif direction == '2': file_name = 'left_arr.png' elif direction == '3': file_name = 'right_arr.png' img = Image.open(file_name) draw_text = text font = ImageFont.truetype("Car_Num.ttf", 45) draw = ImageDraw.Draw(img) draw.text((64, 0), draw_text, 'black', font) img.save('print.png') logo = img.resize((128, 32)).convert('1') oled.canvas.bitmap((0, 0), logo, fill=1) logo = Image.open('pi_logo.png').resize((128, 32)).convert('1') oled.canvas.bitmap((0, 33), logo, fill=1) for i in range(90): oled.display() oled.cls()
def init_oled(): """ initialize oled-disply """ global oled, font i2cbus = smbus.SMBus(1) oled = ssd1306(i2cbus) font = ImageFont.truetype(FONT_NAME,FONT_SIZE) oled.cls()
def __init__(self): from smbus import SMBus # These are the only two variant lines !! i2cbus = SMBus(1) # # 1 = Raspberry Pi but NOT early REV1 board self.oled = ssd1306(i2cbus) self.draw = self.oled.canvas # "draw" onto this canvas, then call display() to send the canvas contents to the hardware. print(" Oled Bus Conneted = Okidoky") self.padding = 2 self.shape_width = 20 self.top = self.padding self.bottom = self.oled.height - self.padding - 1 self.boolean_state = False
def init(self): # Display einrichten i2cbus = SMBus(1) # 0 = Raspberry Pi 1, 1 = Raspberry Pi > 1 self.oled = ssd1306(i2cbus) # Ein paar Abkürzungen, um den Code zu entschlacken self.draw = self.oled.canvas # Schriftarten festlegen self.fontSmall = ImageFont.truetype('FreeSans.ttf', 13) self.fontBig = ImageFont.truetype('FreeSans.ttf', 55) # Display zum Start löschen self.oled.cls() self.oled.display()
def texts(self, lines, inits = ''): self.i2cbus2 = SMBus(1) self.oled = ssd1306(self.i2cbus2) if inits == '': for i, line in enumerate(lines): direction1 = str(line[0]) file_name = 'left_arr.png' if direction1 == '1': file_name = 'left_arr.png' elif direction1 == '2': file_name = 'up_arr.png' elif direction1 == '3': file_name = 'right_arr.png' file = '/home/pi/Desktop/python/nav_display/' + file_name img = Image.open(file) draw_text = str(line[1]) font = ImageFont.truetype("/home/pi/Desktop/python/nav_display/Car_Num.ttf", 45) draw = ImageDraw.Draw(img) draw.text((64, 32 * i), draw_text, 'black', font) flip1 = img.transpose(Image.FLIP_LEFT_RIGHT) result = flip1.transpose(Image.FLIP_TOP_BOTTOM) else: direction1 = lines[0] file_name = 'left_arr.png' if direction1 == '1': file_name = 'left_arr.png' elif direction1 == '2': file_name = 'up_arr.png' elif direction1 == '3': file_name = 'right_arr.png' file = '/home/pi/Desktop/python/nav_display/' + file_name img = Image.open(file) draw_text = str(lines[1]) font = ImageFont.truetype("/home/pi/Desktop/python/nav_display/Car_Num.ttf", 45) draw = ImageDraw.Draw(img) draw.text((64, 0), draw_text, 'black', font) flip1 = img.transpose(Image.FLIP_LEFT_RIGHT) result = flip1.transpose(Image.FLIP_TOP_BOTTOM) displaying = result.resize((128,32)).convert('1') self.oled.canvas.bitmap((0,32), displaying, fill = 1) self.oled.display()
def __init__(self): # Initialise controller and bind now self.controller = None self.current_batt = None # Initialise GPIO self.GPIO = GPIO self.GPIO.setwarnings(False) self.GPIO.setmode(self.GPIO.BCM) # Instantiate CORE / Chassis module and store in the launcher. self.core = core.Core(self.GPIO) self.challenge = None self.challenge_thread = None # Shutting down status self.shutting_down = False self.killed = False # Mode/Challenge Dictionary self.menu_list = OrderedDict(( (Mode.MODE_POWER, "Power Off"), (Mode.MODE_REBOOT, "Reboot"), (Mode.MODE_KILL_PROCESS, "Kill Process"), (Mode.MODE_RC, "RC"), (Mode.MODE_MAZE, "Maze"), (Mode.MODE_SPEED, "Speed"), # (Mode.MODE_SPEED_LINEAR, "Linear Speed"), (Mode.MODE_RAINBOW, "Rainbow"), (Mode.MODE_WIPE_RAINBOW_MEMORY, "Wipe Rainbow Memory"), (Mode.MODE_WHITE_CALIBRATE, "Camera Calibrate"), (Mode.MODE_TOF_CALIBRATE, "TOF Calibrate"))) self.current_mode = Mode.MODE_NONE self.menu_mode = Mode.MODE_RC # Create oled object # Note: Set to None if you need to disable screen try: self.oled = ssd1306(self.core.i2cbus) except: print("Failed to get OLED") self.oled = None
def texts(port, text1, text2=None): i2cbus = SMBus(port) oled = ssd1306(i2cbus) direction1 = text1[0] file_name = '' if direction1 == '1': file_name = 'left_arr.png' elif direction1 == '2': file_name = 'up_arr.png' elif direction1 == '3': file_name = 'right_arr.png' img = Image.open(file_name) draw_text = text1[1] font = ImageFont.truetype("Car_Num.ttf", 45) draw = ImageDraw.Draw(img) draw.text((64, 0), draw_text, 'black', font) logo = img.resize((128, 32)).convert('1') oled.canvas.bitmap((0, 0), logo, fill=1) if text2 != None: direction2 = text2[0] file_name = '' if direction1 == '1': file_name = 'up_arr.png' elif direction1 == '2': file_name = 'left_arr.png' elif direction1 == '3': file_name = 'right_arr.png' img = Image.open(file_name) draw_text = text2[1] font = ImageFont.truetype("Car_Num.ttf", 45) draw = ImageDraw.Draw(img) draw.text((64, 0), draw_text, 'black', font) logo = img.resize((128, 32)).convert('1') oled.canvas.bitmap((0, 32), logo, fill=1) oled.display()
def main(): sensor = CO2Sensor() i2cbus = SMBus(1) # 1 = Raspberry Pi but NOT early REV1 board fnt = ImageFont.truetype("FreeSans.ttf", 25) oled = ssd1306( i2cbus ) # create oled object, nominating the correct I2C bus, default address while True: array = sensor.get() celsius = (array.get("temp") - 32) * 5.0 / 9.0 celsiusAsStr = "{:.0f}".format(celsius) value = str(array.get("ppa")) + ' ppm\n' + celsiusAsStr + ' Grad' print(value) # Printing onto display #oled.canvas.rectangle((0, 0, oled.width-1, oled.height-1), outline=1, fill=0) oled.cls() oled.canvas.multiline_text((5, 10), value, font=fnt, fill=1) # now display that canvas out to the hardware oled.display() time.sleep(1)
def __init__(self): self.i2cbus = SMBus(1) self.oled = ssd1306(self.i2cbus) self.font = ImageFont.truetype('/home/pi/Code/FreeSans.ttf', 10) self.font2 = ImageFont.truetype('/home/pi/Code/FreeSans.ttf', 11) self.font3 = ImageFont.truetype('/home/pi/Code/FreeSans.ttf', 18) self.font4 = ImageFont.truetype('/home/pi/Code/FreeSans.ttf', 36) self.disp = self.oled.canvas self.padding = 1 self.top = self.padding self.bottom = self.oled.height - self.padding self.left = self.padding self.right = self.oled.width - self.padding self.line1 = 17 self.line2 = 29 self.line3 = 41 self.line4 = 53 self.lines = [self.line1, self.line2, self.line3, self.line4] self.column1 = self.left + 2 self.column2 = self.left + 64 self.column3 = self.right - 44 self.selector = 0 self.interfaces = [] self.currentMenu = None self.b = None self.busy = False self.exit = False self.lock = Lock() self.stepsPerDeg = 1 self.stepsPerUnit = 1 self.motorStepTime = 0.01 self.sequenceStartTime = 0 self.timeStamp = 0 self.lastRun = 0 self.xEvent = threading.Event() self.rEvent = threading.Event() return
#!/usr/bin/env python # RASPBERRY PI VERSION # NOTE: You need to have PIL installed for your python at the Pi from lib_oled96 import ssd1306 from time import sleep from PIL import ImageFont, ImageDraw, Image font = ImageFont.load_default() from smbus import SMBus # These are the only two variant lines !! i2cbus = SMBus(1) # # 1 = Raspberry Pi but NOT early REV1 board oled = ssd1306(i2cbus) draw = oled.canvas # "draw" onto this canvas, then call display() to send the canvas contents to the hardware. # Draw some shapes. # First define some constants to allow easy resizing of shapes. padding = 2 shape_width = 20 top = padding bottom = oled.height - padding - 1 # Draw a rectangle of the same size of screen draw.rectangle((0, 0, oled.width - 1, oled.height - 1), outline=1, fill=0) # Move left to right keeping track of the current x position for drawing shapes. x = padding # Draw an ellipse. draw.ellipse((x, top, x + shape_width, bottom), outline=1, fill=0)
def __init__(self): self.i2cbus = SMBus(1) # 1 = Raspberry Pi but NOT early REV1 board self.oled = ssd1306(self.i2cbus) # create oled object, nominating the correct I2C bus, default address self.canvas = self.oled.canvas self.root = RootElement("root", [128, 64], self) self.cls()
sys.path.append('/usr/local/lib/python2.7/dist-packages/') #Append path accordingly import http.client, urllib.parse, json #For http request import os #To play audio import time import re #To remove unnecessary stuff from langdetect import detect #To detect language from twython import TwythonStreamer #Get twitter api from random import randint #Random Generator from lib_oled96 import ssd1306 #I2C 0.96" OLED Display from smbus import SMBus from PIL import ImageFont, ImageDraw, Image #Graphic library transWd = ['Next up', 'In other stories', 'Next', 'Looking at other stories', 'Going on', 'Going on next'] #Transition words i2cbus = SMBus(1) # 1 = Raspberry Pi but NOT early REV1 board oled = ssd1306(i2cbus) # create oled object, nominating the correct I2C bus, default address # Search terms TERMS = ['#news'] FOLLOW = ['BBCBreaking','breakingviews'] ttsHost = "https://speech.platform.bing.com" #TTS Host # Twitter application authentication APP_KEY = '<API KEY here>' APP_SECRET = '<API SECRET here>' OAUTH_TOKEN = '<ACCESS TOKEN here>' OAUTH_TOKEN_SECRET = '<ACCESS TOKEN SECRET here>' def getSpeech(msg): #-------------------HTTP REQUEST---------------------------
#!/usr/bin/env python from lib_oled96 import ssd1306 from PIL import ImageFont from smbus import SMBus i2cbus = SMBus(1) # 1 = Raspberry Pi but NOT early REV1 board oled = ssd1306( i2cbus ) # create oled object, nominating the correct I2C bus, default address # we are ready to do some output ... # put border around the screen: oled.canvas.rectangle((0, 0, oled.width - 1, oled.height - 2), outline=1, fill=0) # Write two lines of text. font = ImageFont.truetype('FreeMonoBold.ttf', 16) oled.canvas.text((10, 0), 'MANDA CHOPP', fill=1, font=font) font = ImageFont.truetype('FreeSans.ttf', 20) oled.canvas.text((0, 12), 'T', fill=1, font=font) oled.canvas.text((0, 28), 'T', fill=1, font=font) oled.canvas.text((0, 44), 'T', fill=1, font=font) # now display that canvas out to the hardware oled.display()
# Imports # import time #benötigt für sleep etc from ADS1x15 import ADS1115 # um die AD Wandler zu deklarieren from lib_oled96 import ssd1306 # Bibliothek für SSD1306 OLED Displays (spezielle Version für 0.96 Zoll Version mit 128x64 Pixel) from smbus import SMBus # alle Peripherie nutzt den i2c Bus -> SMBus auf dem Raspberry # Objektdeklarationen # i2cbus = SMBus(1) # i2c Bus 1 am Raspberry Pi an Pins 2 & 3 oled = ssd1306(i2cbus) # OLED Objekt erstellen adc1 = ADS1115( address=0x48, busnum=1 ) # ADS auf Hauptplatine initialisieren. Addresse 0x48 ist ADDR->GND adc2 = ADS1115( address=0x49, busnum=1 ) # ADS auf Erweiterungsplatine initialisieren. Addresse 0x49 ist ADDR -> VCC # Variablen & Konstanten # GAIN = 1 # Gain vom ADS einstellen. Mögliche Werte siehe Library # Für Hauptplatine main_faktor = 0.188 # Auflösung des ACS712 einstellen. Grundwert nach Datenblatt ist 0.185V/A. Durch Messung mit Last ermittelt. main_r1 = 47148 # Widerstand R1 für den Spannungsteiler Eingangsspannung. Nominal 12V auf 3.3V main_r2 = 18152 # Widerstand R2 für den Spannungsteiler Eingangsspannung # Für Erweiterungsplatine exp1_faktor = 0.185 # Auflösung des ACS712 einstellen. Grundwert nach Datenblatt ist 0.185V/A. Durch Messung mit Last ermittelt. exp1_r1 = 51000 # Widerstand R1 für den Spannungsteiler Eingangsspannung. Nominal 9V auf 3.3V exp1_r2 = 27000 # Widerstand R2 für den Spannungsteiler Eingangsspannung
font = ImageFont.load_default() from smbus import SMBus # These are the only two variant lines !! i2cbus = SMBus(0) # # 1 = Raspberry Pi but NOT early REV1 board def get_ip_address(ifname): s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) return socket.inet_ntoa(fcntl.ioctl( s.fileno(), 0x8915, struct.pack('256s', ifname[:15]) )[20:24]) oled = ssd1306(i2cbus) draw = oled.canvas # "draw" onto this canvas, then call display() to send the canvas contents to the hardware. draw.rectangle((0, 0, oled.width-1, oled.height-1), outline=20, fill=0) font = ImageFont.truetype('/root/lib_oled96/FreeSans.ttf', 14) draw.text((0, 0), 'You\'re Listening to', font=font, fill=1) draw.text((0, 15), 'Cat Radio Online', font=font, fill=1) #draw.text((0, 30), "Time: %s" %time.strftime("%H:%M:%S"), font=font, fill=1) draw.text((0, 45), 'IP:'+get_ip_address('eth0'), font=font, fill=1) oled.display() loopCheck=0 previousTime=0 while True: draw.rectangle((0, 45, oled.width-1, 30), outline=0, fill=0)
def update(draw, font): draw.rectangle([0, 0, oled.width + 1, oled.height + 1], fill=0) y_off = 0 draw.text((0, y_off), "CPU: {0:3.1f}°C".format(get_cpu_temp()), font=font, fill=1) y_off += 0.90 * FONT_SIZE draw.text((0, y_off), "Load: {0:4.2f}".format(get_load()), font=font, fill=1) oled.display() # --- main program --------------------------------------------------------- if __name__ == '__main__': i2cbus = SMBus(1) oled = ssd1306(i2cbus, height=32) draw = oled.canvas font = ImageFont.truetype(FONT_PATH, FONT_SIZE) while True: update(draw, font) time.sleep(UPDATE_INT)
#!/usr/bin/env python from lib_oled96 import ssd1306 from PIL import Image, ImageDraw, ImageFont oled = ssd1306( flip_screen=True ) # create oled object, nominating the correct I2C bus, default address # we are ready to do some output ... fnt = ImageFont.truetype('/home/pi/oled/lib_oled96/FreeMono.ttf', 18) # put border around the screen: oled.canvas.rectangle((0, 0, oled.width - 1, oled.height - 1), outline=1, fill=0) # Write two lines of text. oled.canvas.text((4, 4), 'HelloWWWWW', font=fnt, fill=1) oled.canvas.text((40, 40), 'World!', font=fnt, fill=1) # now display that canvas out to the hardware oled.display()
self.show_state() time.sleep(0.1) count += 1 self.core.set_neutral(False) if __name__ == "__main__": import RPi.GPIO as GPIO GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) core = core.Core(GPIO) oled = None try: oled = ssd1306(core.i2cbus) except: print("Failed to get OLED") oled = None follower = Tof_Calibrate(core, oled) try: follower.run() except (KeyboardInterrupt) as e: # except (Exception, KeyboardInterrupt) as e: # Stop any active threads before leaving follower.stop() core.cleanup() print("Quitting")
def get_message(self): data = self.client_socket.recv(1024).decode() if not data: return data = data.split('/', 10) print(data) # disp 2 # check validation and delete if data[0] == '': return False # elif data[0] == 'delete': # loop_end = False # for i in self.lines: # for p, k in enumerate(self.lines[i]): # if data[1] == k[1]: # self.lines[i].pop(p) # loop_end = True # break # if loop_end: # break # let's delete number if there's already exist numberplate """ Algorithm 1. find number 2_1. if exist number delete number 2_2. if not exist number continue """ loop_end = False for i, k in enumerate(self.lines): for count, line in enumerate(self.lines[k]): if data[1] in line: self.lines[k].pop(count) loop_end = True break if loop_end: break # setting datas - self.lines for i, k in enumerate(self.lines): if k == data[2]: loop_end = False for p in self.lines[k]: if data[2] in p: p[0] = data[0] loop_end = True if loop_end: break else: self.lines[k].append(data) # send datas for i, k in enumerate(self.lines): self.select_disp(int(i) + 1) print('datas :', i, self.lines[k]) if len(self.lines[k]) == 0: self.i2cbus2 = SMBus(1) self.oled = ssd1306(self.i2cbus2) self.oled.onoff(0) else: self.texts(self.lines[k])
from lib_oled96 import ssd1306 from PIL import ImageFont from smbus import SMBus import logging import numpy as np i2cBus = SMBus(1) oled = ssd1306(i2cBus) draw = oled.canvas fnt = ImageFont.truetype('FreeMonoBold.ttf', 17) width = 16 height = 16 pos = [[], [4, 26], [24, 26], [44, 26], [4, 46], [24, 46], [44, 46]] def draw_line(): draw.rectangle((63, 0, 65, 64), outline=1, fill=1) def draw_config(switch, config): add = 64 if switch == 1 else 0 draw.text((5 + add, 5), "Sw: " + "AB"[switch], fill=1, font=fnt) for i in range(1, 7): fill = config[i - 1] if fill is None: draw.rectangle((pos[i][0] + add, pos[i][1], pos[i][0] + width + add, pos[i][1] + height), outline=1, fill=0) draw.text((pos[i][0] + 3 + add, pos[i][1] - 1), "?", fill=1, font=fnt) else: draw.rectangle((pos[i][0] + add, pos[i][1], pos[i][0] + width + add, pos[i][1] + height), outline=fill, fill=fill)