Esempio n. 1
0
 def __init__(self, airly_handler, open_weather_handler):
     self.airly_handler = airly_handler
     self.open_weather_handler = open_weather_handler
     self.lcd = I2cLcd(1, DEFAULT_I2C_ADDR, 2, 16)
     self.airly = None
     self.open_weather = None
     self.addCustomChars()
Esempio n. 2
0
def test_main():
    i2c = I2C(scl=Pin(5), sda=Pin(4), freq=400000)
    lcd = I2cLcd(i2c, DEFAULT_I2C_ADDR, 2, 16)
    pcf = PCF8574(i2c, ADDR)
    keymap = [
        '123A',
        '456B',
        '789C',
        '*0#D'
    ]
    charmap = {
        '1': '.1',    '2': 'abc2', '3': 'def3',
        '4': 'ghi4',  '5': 'jkl5', '6': 'mno6',
        '7': 'pqrs7', '8': 'tuv8', '9': 'wxyz9',
                      '0': '_0',
    }
    keypad = Keypad(pcf, keymap, charmap)

    lcd.clear()
    lcd.show_cursor()
    try:
        word = keypad.get_word(lcd)
        print("Got {} as input".format(word))
    except Exit:
        print('Received exit')

    lcd.clear()
    try:
        word = keypad.get_word(lcd, True)
        print("Got {} as input".format(word))
    except Exit:
        print('Received exit')
Esempio n. 3
0
def test_main():
    """Test function for verifying basic functionality."""
    lcd = I2cLcd(1, DEFAULT_I2C_ADDR, 2, 16)
    lcd.blink_cursor_on()
    #lcd.putstr("Please wait\ninitialising")
    time.sleep(0.5)
    lcd.clear()
    lcd.blink_cursor_off()
    count = 0
    total = len(sys.argv)  # nmumber of arguments in string
    msg1 = sys.argv[1:]  # get everything after python script name
    text_line, l_number, p_number = msg1  # strip out the text and the line ref
    line_number = int(l_number) - 1
    pos_number = int(p_number) - 1
    #move_to(self, cursor_x, cursor_y):
    while True:
        lcd.move_to(pos_number, line_number)
        #lcd.putstr(time.strftime('%b %d %Y\n%H:%M:%S', time.localtime()))
        #time.sleep(1)
        lcd.backlight_on()
        lcd.putstr(str(text_line))
        #lcd.putstr(time.strftime('%b %d %Y\n%H:%M:%S', time.localtime()))
        #lcd.putstr(datetime.datetime.now().time()), 3)
        # Write just the time to the display
        time.sleep(1)
        exit()
Esempio n. 4
0
def main():
    #activeName, activeFuncs =  [[] for i in range(2)] For when we are going to use multiple sensors
    sensorFuncs = {'light': 'light', 'distance': 'dist', 'temperature': 'temp'}
    for sensor in [item for item in dir(active_sensors) if not item.startswith("__")]:
        if eval('active_sensors.'+sensor) == 1:
            activeName = sensor
            activeFuncs = sensorFuncs[sensor]
    exec('import read_'+activeFuncs)
    exec('sensor = read_'+activeFuncs+'.read_'+activeFuncs+'()')
    sleep(1)
    try:
        i2c = I2C(scl=Pin(p_I2Cscl_lbl),sda=Pin(p_I2Csda_lbl))
        lcd = I2cLcd(i2c, 0x27,2,16)
        lcd.clear()
        lcd.scrollstr('Preparing to measure '+activeName)
        lcd.clear()
        lcd.putstr("Ready!\n"+chr(0)+'Listo!')

        while True:
            first = button.value()
            sleep(0.01)
            second = button.value()
            if first and not second:
                exec('sensor.print_'+activeFuncs+'()')
            elif not first and second:
                pass
    except:
        print('LCD not registered...')
Esempio n. 5
0
def main():
    # Initialise display
    lcd = I2cLcd(16, 2)
    sensor = W1ThermSensor()

    try:
        while True:
            celsius = sensor.get_temperature(W1ThermSensor.DEGREES_C)
            farenheit = sensor.get_temperature(W1ThermSensor.DEGREES_F)
            temp_msg = '%sC - %sF' % (round(celsius, 1), round(farenheit, 1))
            lcd.set_line(1, 'Temperature:')
            lcd.set_line(2, temp_msg)
            lcd.display_message(3)

            local_now = datetime.now()
            current_date = local_now.strftime('%a, %d %b %Y')
            lcd.set_line(1, current_date)
            lcd.set_line(2, get_time())
            lcd.display_message(1)
            lcd.set_line(2, get_time())
            lcd.display_message(1)
            lcd.set_line(2, get_time())
            lcd.display_message(0.5)

    except KeyboardInterrupt:
        pass
    finally:
        lcd.clear_display()
Esempio n. 6
0
def test_main():
    """Test function for verifying basic functionality."""
    print("Running test_main")
    ''' use I2C0 , and must change baudrate to 50kHz '''
    i2c = I2C(0, I2C.MASTER, baudrate=50000)
    lcd = I2cLcd(i2c, DEFAULT_I2C_ADDR, 2, 16)
    lcd.putstr("It Works!\nSecond Line")
    delay(3000)
    lcd.clear()
    count = 0
    while True:
        lcd.move_to(0, 0)
        lcd.putstr("%7d" % (millis() // 1000))
        delay(1000)
        count += 1
        if count % 10 == 3:
            print("Turning backlight off")
            lcd.backlight_off()
        if count % 10 == 4:
            print("Turning backlight on")
            lcd.backlight_on()
        if count % 10 == 5:
            print("Turning display off")
            lcd.display_off()
        if count % 10 == 6:
            print("Turning display on")
            lcd.display_on()
        if count % 10 == 7:
            print("Turning display & backlight off")
            lcd.backlight_off()
            lcd.display_off()
        if count % 10 == 8:
            print("Turning display & backlight on")
            lcd.backlight_on()
            lcd.display_on()
Esempio n. 7
0
 def print_dist_start(self, samp_max=1000, interval=5):
     sleep_microsec = int(1000 * interval)
     pause_microsec = 1000
     i2c = I2C(scl=Pin(p_I2Cscl_lbl), sda=Pin(p_I2Csda_lbl))
     try:
         lcd = I2cLcd(i2c, 0x27, 2, 16)
         lcdF = 1
     except:
         lcdF = 0
     sample_num = 1  # Start sample number at 0 so we can count the number of samples we take
     while sample_num <= samp_max:  # This will repeat in a loop, until we terminate with a ctrl-c
         dist = self.sensor.distance()  # Obtain a distance reading
         sleep_ms(pause_microsec)  # Sleep for 1 sec
         print("Sample: ", sample_num, ',',
               str(dist) + " cm")  # print the sample number and distance
         print(
             "\n"
         )  # Print a line of space between temp readings so it is easier to read
         if lcdF == 1:
             lcd.clear()  # Sleep for 1 sec
             lcd.putstr("Sample: " + str(sample_num) + "\nDist: " +
                        str(dist) + " cm")
         sleep_ms(
             max(sleep_microsec - pause_microsec, 0)
         )  # Wait 5 sec, before repeating the loop and taking another reading
         sample_num += 1  # Increment the sample number for each reading
     if lcdF == 1:
         lcd.clear()
         lcd.putstr("Done!")
         sleep_ms(2000)
         lcd.clear()
Esempio n. 8
0
def test_main():
    """Test function for verifying basic functionality."""
    lcd = I2cLcd(1, DEFAULT_I2C_ADDR, 2, 16)
    lcd.blink_cursor_on()
    lcd.putstr("Please wait!\ninitialising")
    time.sleep(3)
    lcd.clear()
    lcd.blink_cursor_off()
Esempio n. 9
0
 def print_dist(self):
     i2c = I2C(scl=Pin(p_I2Cscl_lbl), sda=Pin(p_I2Csda_lbl))
     try:
         lcd = I2cLcd(i2c, 0x27, 2, 16)
         lcdF = 1
     except:
         lcdF = 0
     dist = self.sensor.distance()
     print(str(dist) + " cm")
     if lcdF == 1:
         lcd.clear()  # Sleep for 1 sec
         lcd.putstr(str(dist) + " cm")
def test_main():
    """Test function for verifying basic functionality."""
    lcd = I2cLcd(1, DEFAULT_I2C_ADDR, 2, 16)
    lcd.blink_cursor_on()
    lcd.putstr("Please wait!\ninitialising")
    time.sleep(3)
    lcd.clear()

    lcd.blink_cursor_off()
    while True:
        lcd.move_to(0, 0)
        lcd.putstr(time.strftime('%b %d %Y\n%H:%M:%S', time.localtime()))
        time.sleep(1)
Esempio n. 11
0
def test_main():
    """Test function for verifying basic functionality."""
    lcd = I2cLcd(1, DEFAULT_I2C_ADDR, 2, 16)
    lcd.blink_cursor_on()
    lcd.putstr("It Works!\nSecond Line")
    time.sleep(3)
    lcd.clear()

    # custom characters: battery icons - 5 wide, 8 tall
    #lcd.custom_char(0, bytearray([0x0E,0x1B,0x11,0x11,0x11,0x11,0x11,0x1F]))  # 0% Empty
    #lcd.custom_char(1, bytearray([0x0E,0x1B,0x11,0x11,0x11,0x11,0x1F,0x1F]))  # 16%
    #lcd.custom_char(2, bytearray([0x0E,0x1B,0x11,0x11,0x11,0x1F,0x1F,0x1F]))  # 33%
    #lcd.custom_char(3, bytearray([0x0E,0x1B,0x11,0x11,0x1F,0x1F,0x1F,0x1F]))  # 50%
    #lcd.custom_char(4, bytearray([0x0E,0x1B,0x11,0x1F,0x1F,0x1F,0x1F,0x1F]))  # 66%
    #lcd.custom_char(5, bytearray([0x0E,0x1B,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F]))  # 83%
    #lcd.custom_char(6, bytearray([0x0E,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F]))  # 100% Full
    #lcd.custom_char(7, bytearray([0x0E,0x1F,0x1B,0x1B,0x1B,0x1F,0x1B,0x1F]))  # ! Error
    #for i in range(8):
    #    lcd.putchar(chr(i))
    #time.sleep(3)
    #lcd.clear()
    lcd.blink_cursor_off()

    count = 0
    while True:
        lcd.move_to(0, 0)
        lcd.putstr(time.strftime('%b %d %Y\n%H:%M:%S', time.localtime()))
        time.sleep(1)
        count += 1
        if count % 10 == 3:
            print ("Turning backlight off")
            lcd.backlight_off()
        if count % 10 == 4:
            print ("Turning backlight on")
            lcd.backlight_on()
        if count % 10 == 5:
            print ("Turning display off")
            lcd.display_off()
        if count % 10 == 6:
            print ("Turning display on")
            lcd.display_on()
        if count % 10 == 7:
            print ("Turning display & backlight off")
            lcd.backlight_off()
            lcd.display_off()
        if count % 10 == 8:
            print ("Turning display & backlight on")
            lcd.backlight_on()
            lcd.display_on()
        exit()
Esempio n. 12
0
def setup():
    global backlight_enabled
    global lcd
    # The PCF8574 has a jumper selectable address: 0x20 - 0x27
    DEFAULT_I2C_ADDR = 0x27
    lcd = I2cLcd(1, DEFAULT_I2C_ADDR, 2, 16)
    lcd.blink_cursor_off()
    lcd.hide_cursor()
    lcd.putstr("   Welcome to\n     DannyPC")
    time.sleep(1)
    lcd.clear()
    backlight_enabled = MyButton.is_light_on(16)
    print("backlight enabled", backlight_enabled)
    if not backlight_enabled:
        lcd.backlight_off()
Esempio n. 13
0
 def print_temp(self):
     i2c = I2C(scl=Pin(p_I2Cscl_lbl), sda=Pin(p_I2Csda_lbl))
     try:
         lcd = I2cLcd(i2c, 0x27, 2, 16)
         lcdF = 1
     except:
         lcdF = 0
     self.ds.convert_temp(
     )  # Obtain temp readings from each of those sensors
     sleep_ms(
         750
     )  # Sleep for 750 ms, to give the sensors enough time to report their temperature readings
     print(self.ds.read_temp(self.roms[0]), ' C')
     if lcdF == 1:
         lcd.clear()  # Sleep for 1 sec
         lcd.putstr("Temp: " +
                    str(round(self.ds.read_temp(self.roms[0]), 2)) + " C")
Esempio n. 14
0
def main():
    # Initialise display
    lcd = I2cLcd(16, 2)

    try:
        while True:
            lcd.set_line(1, 'Hello World!')
            lcd.set_line(2, 'Lorem ipsum sit')
            lcd.display_message(3)

            lcd.set_line(1, 'Be kind; rewind.')
            lcd.set_line(2, 'Party on, dudes!')
            lcd.display_message(3)

    except KeyboardInterrupt:
        pass
    finally:
        lcd.clear_display()
Esempio n. 15
0
def test_main():
    i2c = I2C(scl=Pin(5), sda=Pin(4), freq=400000)
    lcd = I2cLcd(i2c, DEFAULT_I2C_ADDR, 2, 16)
    for s in range(3, 0, -1):
        lcd.clear()
        lcd.move_to(0, 0)
        lcd.putstr("Conected at {}\n"
                   "Light test in {}".format(DEFAULT_I2C_ADDR, s))
        sleep_ms(1000)

    for s in range(3, 0, -1):
        lcd.clear()
        lcd.move_to(0, 0)
        lcd.putstr("Light test On\n" "Off in {}".format(s))
        sleep_ms(500)
        lcd.backlight_off()
        sleep_ms(500)
        lcd.backlight_on()

    lcd.display_off()
    lcd.clear()
Esempio n. 16
0
def mainScreen():
    ''' Main Screen '''
    lcd.custom_char(0, customChar.RecordSym('offleft'))
    lcd.custom_char(1, customChar.RecordSym('offright'))
    lcd.custom_char(2, customChar.RecordSym('onleft'))
    lcd.custom_char(3, customChar.RecordSym('onright'))
    lcd.move_to(0, 0)
    lcd.putchar(chr(0))
    lcd.move_to(1, 0)
    lcd.putchar(chr(1))
    lcd.move_to(5, 0)
    lcd.putstr(time.strftime('%m/%d %H:%M', time.localtime()))


LCD_I2C_ADDR = 0x3f
lcd = I2cLcd(1, LCD_I2C_ADDR, 2, 16)
introScreen()

from google.cloud import datastore

#Initialize global variables to be used
minFreq = 0
maxFreq = 0
samprate = 0
incremFreq = 0
timer1 = 0
timer2 = 0
TIMER1_TIME = 15
TIMER2_TIME = 20
#BASE_PATH = '/tmp/'
SDDIR = '/media/card/'
Esempio n. 17
0
    '1': '.1',
    '2': 'abc2',
    '3': 'def3',
    '4': 'ghi4',
    '5': 'jkl5',
    '6': 'mno6',
    '7': 'pqrs7',
    '8': 'tuv8',
    '9': 'wxyz9',
    '0': '_0',
}

i2c = I2C(scl=Pin(5), sda=Pin(4), freq=40000000)
pcf = PCF8574(i2c, KEY_ADDR)
keypad = Keypad(pcf, KEYMAP, CHARMAP)
lcd = I2cLcd(i2c, LCD_ADDR, 2, 16)
pcf1 = PCF8574(i2c, 57)
pcf2 = PCF8574(i2c, 58)
opto_mask = 0b11111111

storrage = Storrage()


class SettingsErr(Exception):
    pass


class CancelSignal(Exception):
    pass

Esempio n. 18
0
# This file is executed on every boot (including wake-boot from deepsleep)

# code block from original boot.py on STM32 Micropython v1.13
#import machine
#import pyb
#pyb.country('US') # ISO 3166-1 Alpha-2 code, eg US, GB, DE, AU
##pyb.main('main.py') # main script to run after this one
##pyb.usb_mode('VCP+MSC') # act as a serial and a storage device
##pyb.usb_mode('VCP+HID') # act as a serial device and a mouse
# Import platform-specific definitions

from platform_defs import *

from machine import Pin, I2C
from i2c_lcd import I2cLcd
from time import sleep

try:
    i2c = I2C(scl=Pin(p_I2Cscl_lbl), sda=Pin(p_I2Csda_lbl))
    lcd = I2cLcd(i2c, 0x27, 2, 16)
    exclam_u = bytearray([0x00, 0x04, 0x00, 0x00, 0x04, 0x04, 0x04, 0x04])
    lcd.custom_char(0, exclam_u)
    lcd.putstr('Hello\n' + chr(0) + 'Hola!')
    sleep(5)
except:
    pass
def test_main():
    lcd = I2cLcd(1, DEFAULT_I2C_ADDR, 2, 16)
    lcd.blink_cursor_on()
    time.sleep(3)
    lcd.clear()
    exit()
Esempio n. 20
0
#	 lcd.putchar('x')
# 13. To print a custom character:
#	 happy_face = bytearray([0x00, 0x0A, 0x00, 0x04, 0x00, 0x11, 0x0E, 0x00])
#	 lcd.custom_char(0, happy_face)
#	 lcd.putchar(chr(0))
'''

#'''
from time import sleep_ms, ticks_ms 
from machine import I2C, Pin 
from i2c_lcd import I2cLcd 

DEFAULT_I2C_ADDR = 0x20

i2c = I2C(scl=Pin(22), sda=Pin(21), freq=400000) 
lcd = I2cLcd(i2c, DEFAULT_I2C_ADDR, 2, 16)

lcd.clear()
lcd.putstr('Example # 2')
sleep_ms(1000)
count = 0

while True:
    print('Counter: {}'.format(count))
    lcd.clear() # Clears the LCD,
                # Sets the cursor position to 0,0 
    lcd.putstr('Counter: {}' .format(count))
    count = count + 1
    sleep_ms(1000)

#'''
"""Implements a HD44780 character LCD connected via PCF8574 on I2C."""

from i2c_lcd import I2cLcd
import time

# The PCF8574 has a jumper selectable address: 0x20 - 0x27
DEFAULT_I2C_ADDR = 0x3f
lcd = I2cLcd(1, DEFAULT_I2C_ADDR, 2, 16)
lcd.blink_cursor_on()
lcd.putstr("Please waiting - initialising")
time.sleep(3)
lcd.clear()
lcd.move_to(0, 0)
lcd.backlight_on()
time.sleep(1)
lcd.putstr(time.strftime('%b %d %Y\n%H:%M:%S', time.localtime()))
time.sleep(1)


Esempio n. 22
0
        self.screen.clear()

    def home(self):
        self.screen.home()

    def color(self, r, g, b):
        self.backlight.set_color(r, g, b)

    def move(self, col, row):
        self.screen.setCursor(col, row)


if __name__ == "__main__":
    from time import sleep_ms, ticks_ms
    from machine import I2C, Pin
    from i2c_lcd import I2cLcd

    i2c = I2C(scl=Pin(2), sda=Pin(0), freq=400000)

    lcd = i2c_lcd.I2cLcd(i2c, 0x27, 2, 16)
    lcd.putstr("Hello ernitron\nIt's working!")
    lcd.clear()
    lcd.putstr("Using dhylands\npython_lcd")

    lcd = I2cLcd(i2c, 0x27, 4, 20)
    lcd.putstr(
        "WeMos D1 Mini with  PCF8574 I2C backpackWorks with HD44780s:08x2 16x1 16x2 20x4"
    )
    lcd.clear()
    lcd.putstr("line 1\nline 2\nline 3\nline 4")