コード例 #1
0
def print_to_lcd():
    """ Print values to a 2x16 LCD display if it is provided with connections described """
    lcd = Adafruit_CharLCD(rs=26,
                           en=19,
                           d4=13,
                           d5=6,
                           d6=5,
                           d7=21,
                           cols=16,
                           lines=2)
    lcd.clear()
    lcd.set_cursor(0, 0)
    lcd.message("DHT22 Program")
    lcd.set_cursor(0, 1)
    lcd.message("Waiting...")
    sleep(2)
    try:
        while True:
            hum, temp = get_values()
            lcd.clear()
            lcd.set_cursor(0, 0)
            lcd.message("Temp: {0:.2f} C".format(temp))
            lcd.set_cursor(0, 1)
            lcd.message("Humi: {0:.2f} %".format(hum))
            sleep(5)
    except KeyboardInterrupt:
        print('Exiting...')
        lcd.clear()
        lcd.set_cursor(0, 0)
        lcd.message("OFFLINE")
コード例 #2
0
class LCD:
    def __init__(self):
        self.lcd = Adafruit_CharLCD(25, 24, 23, 17, 21, 22, 16, 2)

    def data_print(self, msg, a, b):
        #self.lcd.clear()
        self.lcd.set_cursor(a, b)
        self.lcd.message(msg)

    def lcd_clear(self):
        self.lcd.clear()
コード例 #3
0
ファイル: DHT22.py プロジェクト: weiserhei/raspy
from Adafruit_CharLCD import Adafruit_CharLCD
from time import sleep
import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM)

lcd = Adafruit_CharLCD(rs=4,
                       en=17,
                       d4=18,
                       d5=22,
                       d6=23,
                       d7=24,
                       cols=16,
                       lines=2)

lcd.set_cursor(0, 0)
lcd.clear()

sensor = Adafruit_DHT.DHT22
pin = 25

while True:

    humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
    # print(humidity)
    # print(temperature)

    line1 = "Temp: " + str(temperature) + "*C"
    line2 = "Humidity: " + str(round(humidity, 2)) + "%"
    lcd.set_cursor(0, 0)
    lcd.message(line1)
コード例 #4
0
ファイル: Adafruit_LCD.py プロジェクト: weiserhei/raspy
#       case 228: return  225; break; // ae
#       case 246: return  239; break; // oe
#       case 252: return  245; break; // ue
#       case 223: return  226; break; // ss
#       case 176: return  223; break; // grad/degree
#       default:  return  ascii; break;
#   }
# }

lcd.message('                Hallo Flo')
# lcd.set_cursor(16, 1)
# lcd.message('Lurch :-)')
# scroll text on display
for x in range(0, 24):
    lcd.move_right()
    sleep(.1)

sleep(2)

lcd.clear()

lcd.set_cursor(16, 0)
lcd.message("Du ")
lcd.set_cursor(16, 1)
lcd.message("Kl" + chr(239) + "tenclown \x03")
lcd.home()
lcd.set_cursor(16, 1)
# scroll text on display
for x in range(0, 16):
    lcd.move_left()
    sleep(.1)
コード例 #5
0
ファイル: doubleSwitch.py プロジェクト: weiserhei/raspy
# !/usr/bin/env python
# Author: Thiele
# Trigger on cable disconnect
# IMPORTANT! Both Pins connected to 3.3 V

from Adafruit_CharLCD import Adafruit_CharLCD
import time
import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM)

lcd = Adafruit_CharLCD(rs=4, en=17,
                       d4=18, d5=22, d6=23, d7=24,
                       cols=16, lines=2)

lcd.set_cursor(0, 0)
BUTTON1 = 27
GPIO.setup(BUTTON1, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

BUTTON2 = 20
GPIO.setup(BUTTON2, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

start_time = 0

def startTimer(channel):

    print("Button 1 pressed!")
    lcd.message("Mutombo Start!")
    # start timer
    global start_time
    start_time = time.time()
コード例 #6
0
ファイル: Adafruit_LCD.py プロジェクト: weiserhei/raspy
#       case 228: return  225; break; // ae
#       case 246: return  239; break; // oe
#       case 252: return  245; break; // ue
#       case 223: return  226; break; // ss
#       case 176: return  223; break; // grad/degree
#       default:  return  ascii; break;
#   }
# }

lcd.message('                Hallo Flo')
# lcd.set_cursor(16, 1)
# lcd.message('Lurch :-)')
# scroll text on display
for x in range(0, 24):
    lcd.move_right()
    sleep(.1)

sleep(2)

lcd.clear()

lcd.set_cursor(16, 0)
lcd.message("Du ")
lcd.set_cursor(16, 1)
lcd.message("Kl" + chr(239) + "tenclown \x03")
lcd.home()
lcd.set_cursor(16, 1)
# scroll text on display
for x in range(0, 16):
    lcd.move_left()
    sleep(.1)
コード例 #7
0
class _LcdProc(Process):
    ''' The process which manages the LCD output. '''
    def __init__(self, queues):
        ''' Initialize the LCD display '''
        Process.__init__(self, name="LCD")

        self.inQueue = queues[0]  # to read from
        self.outQueue = queues[1]  # to write to

        # LCD PINS
        self.PIN_RS = 26  # RS pin of LCD
        self.PIN_E = 19  # enable pin of LCD
        self.PIN_DB = [13, 6, 5, 11]  # data pins for LCD
        self.LCD_COL_SIZE = 2  # number of charactes available vertically on LCD
        self.LCD_ROW_SIZE = 16  # the number of characters available horizontally on LCD
        self.PIN_BLT = None

        self.DEF_MSG_LEN = 10  # the default space allocated for displaying a message on LCD

        self.PIN_LCD_BACKLIGHT = 20  # backlight pin for LCD
        # the Adafruit LCD object
        self.lcd = Adafruit_CharLCD(self.PIN_RS, self.PIN_E, self.PIN_DB[0],
                                    self.PIN_DB[1], self.PIN_DB[2],
                                    self.PIN_DB[3], self.LCD_COL_SIZE,
                                    self.LCD_ROW_SIZE)

        self.curr_screen = []

        # fill current screen with empty
        for i in range(self.LCD_COL_SIZE * self.LCD_ROW_SIZE):
            self.curr_screen.append(" ")

        # turn on the display
        if (self.PIN_BLT != None):
            GPIO.setmode(GPIO.BCM)
            GPIO.setup(PIN_BLT, GPIO.OUT)
            GPIO.output(self.PIN_BLT, 1)

    def run(self: '_LcdProc') -> None:
        ''' The main loop of the process waits for something to print, then prints it '''
        while True:
            # check for data to print
            data = self.inQueue.get()
            # start a new thread to print data to LCD
            t = threading.Thread(target=self._write_message, args=(data, ))
            t.start()

    def _update_osd(self: '_LcdProc', overlay: '[str]') -> None:
        ''' Display the overlay on the LCD sccreen. Given overrlay which is a list of characters
        for each position of the lcd screen, Loop through each character, and write to the 
        correct position in the LCD screen individually.

        REQ: len(overlay) is even
        REQ: each item in overlay is a single character
        '''
        # only update
        for i in range(len(overlay)):
            if self.curr_screen[i] != overlay[i]:
                # do if the current character is different from the overlay character at this position
                row = int(i >= self.LCD_ROW_SIZE)
                col = i % self.LCD_ROW_SIZE

                # set the position of the cursor, and write a character
                self.lcd.set_cursor(col, row)
                self.lcd.message(overlay[i])
                # remember the state of the current screen
                self.curr_screen[i] = overlay[i]

    def _create_osd_layer(self: '_LcdProc', data: 'str',
                          dType: 'int') -> [str]:
        ''' Given the data, and a type, return an overlay layer which is a list of 
        characters in positions corresponding to the position of each pixel. Depending on the type,
        the characters will be positioned differently. Data can be positioned in any programed position below.
        
        REQ: data is a string of characters
        REQ: dType an int that is handled below 
        '''

        new_screen = []
        # clear the screen layer
        for i in range(self.LCD_ROW_SIZE * self.LCD_COL_SIZE):
            new_screen.append(" ")

        if dType == 1:
            # 10 character message
            dbug(PARCEL, str(len(new_screen)) + " and " + str(len(data)))
            for i in range(len(data)):
                new_screen[i] = data[i]

        elif dType == 2:
            # temperature top right (print from right to left)
            new_screen[15] == "C"
            new_screen[14] == "°"
            if len(data) == 1:
                # single digit temperatures
                new_screen[13] == data
            elif len(data) == 2:
                # double digit temperatures
                new_screen[12] == data[0]
                new_screen[13] == data[1]

        return new_screen

    def _new_message_scroll(self: '_LcdProc', message: 'str',
                            length: 'int') -> [[str]]:
        ''' Given a message, create a list of overlays to be displayed on LCD screen.
        If the message is less than the given length, create ony one layer, or one list
        of list of characters. Otherwise, create enough layers for there to be a full loop 
        cycle of the string printed.
        '''
        full_scroll_arr = [
        ]  # contains list of list of strings for full scroll
        lcd_arr = []  # contains the current scroll

        # if message shorter than or equal to 16 characters, no need to scroll
        if (len(message) <= length):
            for i in range(len(message)):
                lcd_arr.append(message[i])

            full_scroll_arr.append(lcd_arr)
            return full_scroll_arr

        # add extra spaces so tail is not connected to head while scrolling
        message += "  "

        # populate the char_arr with whitespace
        for i in range(length):
            lcd_arr.append(" ")

        # populate with content
        for i in range(len(message) + 1):
            a = 0
            for j in range(i, i + length):
                k = j
                if (j >= len(message)):
                    k = j - len(message)

                lcd_arr[a] = message[k]
                a += 1
            # remember the scroll instance
            full_scroll_arr.append(deepcopy(lcd_arr))

        # return all scroll instances for full scroll effect
        return full_scroll_arr

    def _clear(self: '_LcdProc') -> None:
        ''' Clear the LCD screen, along with the overlay in memory. '''
        self.lcd.clear()
        # clear screen in memory
        for i in range(self.LCD_COL_SIZE * self.LCD_ROW_SIZE):
            self.curr_screen[i] = " "

    def _write_message(self: '_LcdProc', message: 'str') -> None:
        ''' Given a message, write the message to screen. '''

        message_layers = self._new_message_scroll(message, 10)
        for i in range(len(message_layers)):
            start = time.time()
            osd_layer = self._create_osd_layer(message_layers[i], 1)
            self._update_osd(osd_layer)  # display on screen
            dbug(PARCEL, time.time() - start)
            time.sleep(0.5)
        dbug(PARCEL, "---------------------------------")
        return
コード例 #8
0
sensor1 = 23
sensor2 = 18

GPIO.setmode(GPIO.BCM)

GPIO.setup(sensor1,GPIO.IN)
GPIO.setup(sensor2,GPIO.IN)

firebase = firebase.FirebaseApplication('https://login-f0a7b.firebaseio.com/', None)
firebase.put('https://login-f0a7b.firebaseio.com/Barrier','servo_in',False)
firebase.put('https://login-f0a7b.firebaseio.com/Barrier','servo_out',False)

lcd.message('READY')
time.sleep(1)
lcd.set_cursor(0,0)#col,row (start with 0-1 for row, col 0-15)
lcd.message('    Welcome!\n   ==smApps==')
time.sleep(1)
pi.set_servo_pulsewidth(25, 1000) # position anti-clockwise
pi.set_servo_pulsewidth(24, 1000) # position anti-clockwise
count=4
lcd.clear()
lcd.message('   ==smApps==')

def entering(count):
    servo_in = firebase.get('https://login-f0a7b.firebaseio.com/Barrier','servo_in')
    if servo_in == True:
        print("open in")
        pi.set_servo_pulsewidth(25, 2000) # position clockwise
        
        if GPIO.input(sensor1):
コード例 #9
0
ファイル: keypad.py プロジェクト: tim-van-dijck/project-omega
                       d6=17,
                       d7=18,
                       cols=16,
                       lines=2)

# turn on screen
backlight = 4
GPIO.setup(backlight, GPIO.OUT)
GPIO.output(backlight, 1)

header = "Geef pincode in:\n"

lcd.clear()
lcd.message(header)

lcd.set_cursor(5, 1)

MATRIX = [["1", "2", "3"], ["4", "5", "6"], ["7", "8", "9"], ["*", "0", "#"]]

ROW = [26, 19, 13, 6]
COL = [21, 20, 16]

code = ""


def getCode():
    global code

    for j in range(3):
        GPIO.setup(COL[j], GPIO.OUT)
        GPIO.output(COL[j], 1)
コード例 #10
0
ファイル: 1-wire.py プロジェクト: tomasKromer/Compost
	
def read_temp(temp_sensor):
	lines = temp_raw(temp_sensor)
	while lines[0].strip()[-3:] != 'YES':
		time.sleep(0.2)
		lines = temp_raw()
	temp_output = lines[1].find('t=')
	if temp_output != -1:
		temp_string = lines[1].strip()[temp_output+2:]
		temp_c = float(temp_string) / 1000.0
		return temp_c

"""Si estan todos los sensores conectados va a imprimir sus mediciones"""
while True:
	while i in range(6)
		lcd.set_cursor(0,0)                         # Set cursor to first line
		lcd.message('Temp: %d C' % read_temp(addr_sensor[i]))            # Print temperature on LCD
		time.sleep(5)
    time.sleep(1)
	hum_1, temp_1 = dht.read_retry(dht.DHT22, pin_sen_1)
	hum_2, temp_2 = dht.read_retry(dht.DHT22, pin_sen_2)
	hum_3, temp_3 = dht.read_retry(dht.DHT22, pin_sen_3)
	hum_4, temp_4 = dht.read_retry(dht.DHT22, pin_sen_4)
	lcd.set_cursor(0,0)                         # Set cursor to first line
	lcd.message('Temp: %d C' % temp_1)            # Print temperature on LCD
	lcd.set_cursor(0,1)                         # Set cursor on second line
	lcd.message('Humi: %d %%' % humi_1)           # Print Humidity on LCD
	time.sleep(5)
	lcd.set_cursor(0,0)                         # Set cursor to first line
	lcd.message('Temp: %d C' % temp_2)            # Print temperature on LCD
	lcd.set_cursor(0,1)                         # Set cursor on second line
コード例 #11
0
ファイル: keypad.py プロジェクト: timpressive/project-omega
GPIO.setmode(GPIO.BCM)
lcd = Adafruit_CharLCD(rs=24, en=23,
                       d4=22, d5=27, d6=17, d7=18,
                       cols=16, lines=2)

# turn on screen
backlight = 4
GPIO.setup(backlight, GPIO.OUT)
GPIO.output(backlight, 1)

header = "Geef pincode in:\n"

lcd.clear()
lcd.message(header)

lcd.set_cursor(5,1)

MATRIX = [ ["1","2","3"],
	   ["4","5","6"],
	   ["7","8","9"],
	   ["*","0","#"] ]

ROW = [26,19,13,6]
COL = [21,20,16]

code = ""

def getCode():
	global code

	for j in range (3):