def __init__(self, hw="spi", port=None, address=0, debug=False, buffering=True, **kwargs): if hw == "spi": if port is None: port = 0 self.serial = spi(port=port, device=address, bcm_DC=6, bcm_RST=5) elif hw == "i2c": if port is None: port = 1 if isinstance(address, basestring): address = int(address, 16) self.serial = i2c(port=port, address=address) else: raise ValueError("Unknown interface type: {}".format(hw)) self.address = address self.busy_flag = Event() self.width = 128 self.height = 64 self.charwidth = 6 self.charheight = 8 self.cols = self.width / self.charwidth self.rows = self.height / self.charheight self.debug = debug self.init_display(**kwargs) BacklightManager.init_backlight(self, **kwargs)
def __init__(self, settings): self.modem_thread = ModemControlThread(settings['Modem'], self.changes_queue, self.ws_cmd_queue, self.ws_res_queue) self.modem_thread.create_serial() self.modem_thread.setName("MC") self.websock_thread = None self.url = "http://" + settings['Server']['url'] self.ws_url = "ws://" + settings['Server']['url'] self.imsi = "imsi1" create_db(settings['Db']) self.dbo = DbOperations(settings['Db']) self.rest_fail_time = 0 self.rest_success_time = 0 self.rest_last_action_success = False if int(settings['Main']['oled']) == 1: self.oled = ssd1306(i2c(port=1, address=0x3C)) self.oled_status = 0 self.status_time = 0 self.use_oled = True # self.draw = canvas(self.oled) with canvas(self.oled) as draw: draw.text((10, 10), "PySimMonitor", fill="white") draw.text((10, 20), "Starting...", fill="white") self.essid = "" self.operator = "" self.csq = 0 self.modem_status_string = "-"
def setup(): global music global ser global oled # Setup Buttons GPIO.setmode(GPIO.BCM) GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(24, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(25, GPIO.IN, pull_up_down=GPIO.PUD_UP) signal.signal(signal.SIGTERM, signal_term_handler) GPIO.add_event_detect(23, GPIO.FALLING, callback=next_track_callback, bouncetime=300) GPIO.add_event_detect(24, GPIO.FALLING, callback=toggle_playback_callback, bouncetime=300) GPIO.add_event_detect(25, GPIO.FALLING, callback=toggle_gps_callback, bouncetime=300) # Setup OLED display oled_i2c = i2c(port=1, address=0x3C) oled = ssd1306(oled_i2c, width=128, height=32) font_awesome = make_font("fontawesome-webfont.ttf", oled.height - 12) font_code2000 = make_font("code2000.ttf", oled.height - 12) # Set up serial for GPS ser = serial.Serial() ser.port = '/dev/ttyAMA0' ser.baudrate = 57600 ser.timeout = 1 try: ser.open() except IOError as err: logging.warning("Unable to connect to GPS module: " + err) with canvas(oled) as draw: music_icon = "\uf001" w, h = draw.textsize(text=music_icon, font=font_awesome) top = (oled.height - h) / 2 draw.text((0, top), text=music_icon, font=font_awesome, fill="white") draw.text((10, top), text=" TuneTrackr", font=font_code2000, fill="white") music = Music() return music, oled, ser, font_code2000
def __init__(self, const=None, serial_interface=None): self._const = const or luma.core.const.common self._serial_interface = serial_interface or i2c() def shutdown_hook(): try: #self.cleanup() a = True except: pass atexit.register(shutdown_hook)
def __init__(self, blank=False): threading.Thread.__init__(self) self.device = i2c(port=1, address=0x3C) self.oled = ssd1306(self.device) self.font = ImageFont.truetype( '/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf', 20) self.statfont = ImageFont.truetype( '/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf', 12) self.botfont = ImageFont.truetype( '/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf', 11) self.blank = blank self.msg_genre = '' self.msg_station = '' self.sleep_time = .05 self.volume = 0 self.msg_pos = 0
def __init__(self, *args, **kwargs): super(Display, self).__init__(*args, **kwargs) self._serial = serial.i2c(port=1, address=Display._ADDRESS) self._device = device.ssd1306(self._serial, width=128, height=64, rotate=0, mode='RGB') self._image = Image.new(self._device.mode, self._device.size) self._draw = ImageDraw.Draw(self._image) font_path = os.path.join(os.path.dirname(__file__), 'RobotoMono-Regular.ttf') self._font = ImageFont.truetype(font_path, 11) self._lock = threading.Lock()
def run(self): print 'Setting up GPIO' GPIO.setmode(GPIO.BCM) self.setup_gpio_pin(self.SCREEN_NEXT_PIN, self.handle_screen_change) self.setup_gpio_pin(self.SCREEN_PREV_PIN, self.handle_screen_change) self.setup_gpio_pin(self.SCREEN_UP_PIN, self.handle_screen_change) self.setup_gpio_pin(self.SCREEN_DOWN_PIN, self.handle_screen_change) self.setup_gpio_pin(self.SCREEN_RESET_PIN, self.handle_screen_reset) print 'Setting up display' serial = i2c(port=self.config.getint('display', 'port'), address=int(self.config.get('display', 'address'), 16)) self.device = ssd1306(serial) if 'sh1106' == self.config.get('display', 'driver'): self.device = sh1106(serial) self.register(CpuScreen()) for iface in [ item.strip() for item in self.config.get('network', 'iface').split(',') ]: self.register(NetworkScreen(iface)) self.register(MemoryScreen()) signal.signal(signal.SIGTERM, lambda num, frame: sys.exit(0)) atexit.register(self.shutdown_hook) self.timestamp = time.time() while True: screen = self.screens[self.screen_index] self.render() time.sleep(screen.sleep_interval())
# Share if you care, do something import os import time import sys from PIL import ImageFont from luma.core.serial import i2c from luma.core.render import canvas from luma.oled.device import ssd1306, ssd1325, ssd1331, sh1106 import RPi.GPIO as GPIO if os.name != 'posix': sys.exit('{} platform not supported'.format(os.name)) TRIG = 23 # Associate pin 23 to TRIG ECHO = 24 # Associate pin 24 to ECHO serial = i2c(port=1, address=0x3C) device = ssd1306(serial, rotate=0) GPIO.setmode(GPIO.BCM) GPIO.setup(TRIG, GPIO.OUT) # Set pin as GPIO out GPIO.setup(ECHO, GPIO.IN) while True: try: GPIO.output(TRIG, False) #Set TRIG as LOW print("Wachten op sensor") time.sleep(2) #Delay of 2 seconds GPIO.output(TRIG, True) #Set TRIG as HIGH time.sleep(0.00001) #Delay of 0.00001 seconds GPIO.output(TRIG, False) #Set TRIG as LOW
def __init__(self): super(LCD, self).__init__() self.serial = i2c(port=1, address=0x3C) self.device = ssd1306(serial, rotate=0)
import json import requests from functools import partial import microdotphat from luma.core.serial import i2c, spi from luma.core.render import canvas from luma.core.virtual import viewport from luma.oled.device import ssd1306 from neopixel import Adafruit_NeoPixel import constants import utils OLED_SERIAL = i2c(port=1, address=0x3C) OLED_SCREEN = ssd1306(OLED_SERIAL, rotate=1) VIRTUAL_OLED_SCREEN = viewport(OLED_SCREEN, width=OLED_SCREEN.width, height=768) NEOPIXEL_STRIP = Adafruit_NeoPixel(constants.NEOPIXEL_LED_COUNT, constants.NEOPIXEL_LED_PIN, constants.NEOPIXEL_LED_FREQ_HZ, constants.NEOPIXEL_LED_DMA, constants.NEOPIXEL_LED_INVERT, constants.NEOPIXEL_LED_BRIGHTNESS) builds = {} pixelColor = 0