Ejemplo n.º 1
0
 def __init__(self):
     cols = 16
     rows = 2
     i2c = busio.I2C(board.SCL, board.SDA)
     self.lcd = char_lcd.Character_LCD_RGB_I2C(i2c, cols, rows)
     self.lcd.color = [100, 0, 0]
     self.lcd.message = 'Moin!'
Ejemplo n.º 2
0
def init_lcd_display():
    cols = 16
    rows = 2
    i2c = busio.I2C(board.SCL, board.SDA)
    lcd = char_lcd.Character_LCD_RGB_I2C(i2c, cols, rows)
    lcd.clear()
    return lcd
Ejemplo n.º 3
0
def getIPAddress():
    global lcd, i2c, lcd_columns, lcd_rows
    #This will set up a socket and using this, we can most reliably determine our IP address.
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    s.connect(('10.255.255.255', 1))
    i2c = busio.I2C(board.SCL, board.SDA)
    lcd = character_lcd.Character_LCD_RGB_I2C(i2c, lcd_columns, lcd_rows)
    return s.getsockname()[0]
Ejemplo n.º 4
0
 def __init__(self):
     lcd_columns = 16
     lcd_rows = 2
     i2c = busio.I2C(board.SCL, board.SDA)
     self._lcd = character_lcd.Character_LCD_RGB_I2C(i2c, lcd_columns, lcd_rows)
     # load custom chars
     num = 0
     for data in custom_chars:
         self._lcd.create_char(num, list(data))
         num += 1
Ejemplo n.º 5
0
    def __init__(self,
                 resolution=[1280, 720],
                 framerate=27,
                 isoMode="",
                 address=0x04,
                 lcdDimensions=[16, 2]):

        # Defining Communication Variables
        self.address = address
        self.lcmDimensions = lcdDimensions

        self.camera = PiCamera(resolution=resolution, framerate=framerate)
        self.resolution = resolution

        #TODO: Need to move these params to the init function so that they can be customized
        self.sensor_dimensions = [3.76, 2.74]
        self.distortion = np.load('camera_distortion.npy')
        self.intrinsic_params = np.load('camera_intrinsic.npy')
        self.focal_lengths = [
            self.intrinsic_params[0][0] * self.sensor_dimensions[0] /
            resolution[0], self.intrinsic_params[1][1] *
            self.sensor_dimensions[1] / resolution[1]
        ]

        #Configure camera iso and exposure for consistent quality
        if isoMode == "dark":
            self.camera.iso = 1200
        elif isoMode == "bright":
            self.camera.iso = 200
        else:
            #print("Unrecognized iso mode. Setting iso to 700.")
            self.camera.iso = 700

        self.camera.shutter_speed = self.camera.exposure_speed
        self.camera.exposure_mode = 'off'

        time.sleep(2)

        #Preconfigure the camera AWB setting to static values
        gains = self.camera.awb_gains
        self.camera.awb_mode = 'off'
        self.camera.awb_gains = gains

        time.sleep(0.1)

        #Configure i2c Settings
        self.bus = smbus.SMBus(1)
        #Set SDA and SCL to the connection on the I2c
        self.i2c = busio.I2C(board.SCL, board.SDA)

        # Initialise the LCD object
        self.lcd = character_lcd.Character_LCD_RGB_I2C(self.i2c,
                                                       lcdDimensions[0],
                                                       lcdDimensions[1])
        self.turnOnLCD()
    def __init__(self):
        lcd_columns = 16
        lcd_rows = 2

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

        self.lcd = character_lcd.Character_LCD_RGB_I2C(i2c, lcd_columns,
                                                       lcd_rows)
        self.lcd.clear()
        self.lcd.color = [100, 0, 0]

        self.departures: List[Tuple[str, List[Departure]]] = []
        self.current_station = 0
        self.request_update = False
Ejemplo n.º 7
0
def initializeLCD():
    # Modify this if you have a different sized Character LCD
    lcd_columns = 16
    lcd_rows = 2

    # Initialise I2C bus.
    i2c = busio.I2C(board.SCL, board.SDA)

    # Initialise the LCD class
    lcd = character_lcd.Character_LCD_RGB_I2C(i2c, lcd_columns, lcd_rows)

    # Turn on LCD backlight
    lcd.color = [100, 0, 0]

    return i2c, lcd
Ejemplo n.º 8
0
    def _init_lcd(self, lcd_columns, lcd_rows):
        try:
            if self._lcd_type is None:
                raise Exception("No LCD define")

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

            if self._lcd_type == "sainsmart_charlcd_led":
                self._lcd = character_lcd_rgb_i2c.Character_LCD_RGB_I2C(
                    i2c, lcd_columns, lcd_rows)

                self._lcd._mcp.iodira = set_bit(self._lcd._mcp.iodira, 5, 0)

                # Turn on backlight
                self._lcd._mcp.gpioa = set_bit(self._lcd._mcp.gpioa, 5, 0)

            elif self._lcd_type == "adafruit_charlcd_mono":
                self._lcd = character_lcd_i2c.Character_LCD_I2C(
                    i2c, lcd_columns, lcd_rows)
            elif self._lcd_type == "adafruit_charlcd_rgb":
                self._lcd = character_lcd_rgb_i2c.Character_LCD_RGB_I2C(
                    i2c, lcd_columns, lcd_rows)
        except:
            self._logger.debug(sys.exc_info())
Ejemplo n.º 9
0
def init_lcd():
    '''
        Params: lcd_columns - number of culumns the LCD Screen has (int)
                lcd_rows    - number of rwos the LCD Screen has (int)
                i2c         - calling i2c program
                lcd         - setting lcd screen
        
        Returns: lcd 
    '''
    
    lcd_columns = 16
    lcd_rows = 2
    i2c = busio.I2C(board.SCL, board.SDA)
    lcd = character_lcd.Character_LCD_RGB_I2C(i2c, lcd_columns, lcd_rows)

    return lcd
Ejemplo n.º 10
0
def configure_communication():
    """Configures i2c devices and bus for communication with LCD and Arduino"""
    lcd_columns = 16
    lcd_rows = 2

    # Initialise I2C bus.
    bus = smbus.SMBus(1)
    #Set SDA and SCL to the connection on the I2c
    i2c = busio.I2C(board.SCL, board.SDA)

    # Initialise the LCD class
    lcd = character_lcd.Character_LCD_RGB_I2C(i2c, lcd_columns, lcd_rows)
    lcd.clear()
    #Sets background colour of the LCD
    lcd.color = [100, 0, 0]
    time.sleep(1)
    return bus, i2c, lcd
def initialize_display(lcd_lock, wake_up):
	i2c = busio.I2C(board.SCL, board.SDA)	# Initialize I2C bus
	lcd_columns = 16						# Set LCD dimensions
	lcd_rows = 2

	global lcd
	lcd = character_lcd.Character_LCD_RGB_I2C(i2c, lcd_columns, lcd_rows)	# Initialize lcd module object

	lcd.text_direction = lcd.LEFT_TO_RIGHT	# Set text direction
	lcd.clear()								# Clear LCD screen
	lcd.color = [100, 0, 0]					# Set LCD color and turn backlight on


	# Initialize and start the listener thread and the timer for turning the display off.
	screen_timer = threading.Timer(20.0, lcd_power, args=[lcd_lock])
	listener_thread = threading.Thread(target=has_button_been_pressed, args=[lcd_lock, screen_timer, wake_up])
	listener_thread.daemon = True		# Set daemon flag so that this thread terminates after the main one does.
	screen_timer.start()
	listener_thread.start()
Ejemplo n.º 12
0
    def __init__(self, menuItems, aspectRatio):

        # initialize menu parameters
        self.aspectRatio = aspectRatio  # display dimensions
        self.lcd_columns = aspectRatio[0]  # columns
        self.lcd_rows = aspectRatio[1]  # rows
        self.absPointer = 0  # absolute pointer to item in list
        self.relPointer = 0  # pointer relative to start of bracket
        self.bracketPos = 0  # start of bracket
        self.menuItems = menuItems  # list of menu items passed on init
        self.menuSize = len(self.menuItems)  # number of menu items

        # Initialise I2C bus.
        self.i2c = busio.I2C(board.SCL, board.SDA)

        # Initialise the LCD class
        self.lcd = character_lcd.Character_LCD_RGB_I2C(self.i2c,
                                                       self.lcd_columns,
                                                       self.lcd_rows)

        # start menu
        self.runMenu()
Ejemplo n.º 13
0
"""Simple test for I2C RGB character LCD shield kit"""
import time
import board
import busio
import adafruit_character_lcd.character_lcd_rgb_i2c as character_lcd
import smbus

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

# Initialise I2C bus.
i2c = busio.I2C(board.SCL, board.SDA)

# Initialise the LCD class
lcd = character_lcd.Character_LCD_RGB_I2C(i2c, lcd_columns, lcd_rows)

# for RPI version 1, use “bus = smbus.SMBus(0)”
bus = smbus.SMBus(1)

# This is the address we setup in the Arduino Program
address = 0x04


def writeNumber(value):
    bus.write_byte(address, value)
    # bus.write_byte_data(address, 0, value)
    return -1


def readNumber():
Ejemplo n.º 14
0
import os
import time
import board
import busio
import adafruit_character_lcd.character_lcd_rgb_i2c as character_lcd

from threading import Barrier
import radio 
import phatbeat
import subprocess

import socket
import threading 

i2c = busio.I2C(board.SCL, board.SDA)
lcd = character_lcd.Character_LCD_RGB_I2C(i2c, 16, 2)

global radio
radio = radio.Radio(lcd)
radio.play()

os.system("ping -c 1 google.com")
time.sleep(5)

def lcd_buttonthread():
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

    while True:
        if lcd.select_button:
            try:
                s.connect(('10.255.255.255', 1))
Ejemplo n.º 15
0
import socket
import fcntl
import struct
import os
import board
import busio
import time
import adafruit_character_lcd.character_lcd_rgb_i2c as lcd

cols = 16
rows = 2
i2c = busio.I2C(board.SCL, board.SDA)
lcd = lcd.Character_LCD_RGB_I2C(i2c, cols, rows)

lcd.message = "Loading ..."


def get_ip(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])


while True:
    try:
        print(get_ip(b'wlan0'))
        lcd.color = [50, 50, 100]
        lcd.message = get_ip(b'wlan0')
    except:
        lcd.color = [100, 0, 0]
def I2C_Handler(input_pipe, size, address, color=[255, 0, 0]):
    #Initialize I2C objects
    i2c_bus = busio.I2C(board.SCL, board.SDA)
    lcd = character_lcd.Character_LCD_RGB_I2C(i2c_bus, size[1], size[0])
    lcd.clear()

    #Initialize SMbus object
    sm_bus = SMBus(1)

    #Initialize variables
    I2C_FPS = 100  #Frame rate control for thread to conserve resources
    I2C_Start = 0
    data = [0, 0]
    data_in = ctypes.c_int8

    #Initialize LCD screen
    lcd.clear()
    lcd.color = color
    lcd.message = "Init LCD Handler Done"

    while (True):
        #Record time
        I2C_Start = time.time()
        #Data shape:
        #[cmd, content]

        #Non-blocking read of pipe waiting for input
        if (input_pipe.poll()):
            data = input_pipe.recv()
        #Switch on command portion of data to figure out what to do
        if (data[0] == I2C_CMD.LCD_CLR_MSG
            ):  #Clear LCD and send it a string to display
            try:
                #time.sleep(0.1)
                lcd.clear()
                lcd.message = str(data[1])
                pass
            except:
                print("SM Bus Error!")
        elif (data[0] == I2C_CMD.WRITE_ARDU):  #Write to the arduino
            try:
                print(data[1])
                sm_bus.write_byte_data(address, 0, int(data[1]))
            except:
                print("SM Bus Error!")
                sm_bus = SMBus(1)
        elif (data[0] == I2C_CMD.FETCH_ANGLE
              ):  #Fetch the angle from the arduino
            #print(sm_bus.read_byte_data(address, 0))
            try:
                #Need to preserve the sign to make this sensible, use ctypes for that
                data_in = ctypes.c_int8(sm_bus.read_byte_data(address, 0))
                #Convert data in from byte to degree angle
                data_in = data_in.value / 128 * 180

                #Send angle down pipe
                input_pipe.send(data_in)
            except:
                print("SM Bus Error!")
        #Clear data
        data[0] = 0
        #print("Sleep Time: " + str(max(1/I2C_FPS - (time.time() - I2C_Start),0)))

        #Frame lock the thread to preserve resources
        time.sleep(max(1 / I2C_FPS - (time.time() - I2C_Start), 0))
Ejemplo n.º 17
0
    def __init__(self,
                 rows: int,
                 columns: int,
                 rs_pin: DigitalInOut,
                 en_pin: DigitalInOut,
                 d7_pin: DigitalInOut,
                 d6_pin: DigitalInOut,
                 d5_pin: DigitalInOut,
                 d4_pin: DigitalInOut,
                 colour_lcd: bool,
                 i2c_enabled: bool,
                 red_pin: PWMOut = None,
                 green_pin: PWMOut = None,
                 blue_pin: PWMOut = None,
                 backlight_pin: DigitalInOut = None,
                 button_controller: ButtonController = None):
        """
        Create a Display object to simplify LCD operations.

        The pins need to be specified as following:
        digitalio.DigitalInOut( board.<PIN> )

        For colours:
        pulseio.PWMOut( board.<PIN> )

        If it's a colour LCD, the pins for RED, GREEN and BLUE must be specified. backlight_pin can remain None.
        If it's a mono LCD, the backlight pin has to be specified.

        :param rows: Amount of rows on the LCD.
        :param columns: Amount of columns on the LCD.
        :param rs_pin: Location where the RS pin is connected on the board.
        :param en_pin: Location where the EN pin is connected on the board.
        :param d7_pin: Location where the D7 pin is connected on the board.
        :param d6_pin: Location where the D6 pin is connected on the board.
        :param d5_pin: Location where the D5 pin is connected on the board.
        :param d4_pin: Location where the D4 pin is connected on the board.

        :param colour_lcd: Whether it's a colour display or not.
        :param i2c_enabled: Whether the screen has buttons or not.

        :param red_pin: Location where the RED pin is connected on the board.
        :param blue_pin: Location where the BLUE pin is connected on the board.
        :param green_pin: Location where the GREEN pin is connected on the board.

        :param backlight_pin: Location where the backlight pin is connected on the board.

        :param button_controller: A Button Controller class.
        """

        # Set a global variable for checking if it's a colour LCD or not.
        # Then set the colour tuple for a blue screen.
        self.is_colour_lcd = colour_lcd
        self.is_i2c = i2c_enabled
        self.colour = None
        self.set_colour(0, 0, 100)

        # Set a global variable with the dimensions
        self.dimensions = (columns, rows)

        if self.is_i2c:
            if self.is_colour_lcd:
                self.lcd = i2crgb.Character_LCD_RGB_I2C(
                    button_controller.i2c, columns, rows)
            else:
                self.lcd = i2cmono.Character_LCD_I2C(button_controller.i2c,
                                                     columns, rows)
        else:
            # Initialise the LCD screen (type depending on the type of screen).
            if self.is_colour_lcd:
                self.lcd = charlcd.Character_LCD_RGB(rs_pin, en_pin, d4_pin,
                                                     d5_pin, d6_pin, d7_pin,
                                                     columns, rows, red_pin,
                                                     blue_pin, green_pin)
            else:
                self.lcd = charlcd.Character_LCD_Mono(rs_pin, en_pin, d4_pin,
                                                      d5_pin, d6_pin, d7_pin,
                                                      columns, rows,
                                                      backlight_pin)