#!/usr/bin/python #show IP address on the LCD Plate at startup #CHoke import Adafruit_CharLCD as LCD import time import subprocess lcd = LCD.Adafruit_CharLCDPlate() Name = subprocess.check_output("hostname").strip() displayText = Name IP = subprocess.check_output(["hostname", "-I"]) refresh = True wrefresh = True while (True): if lcd.is_pressed(LCD.SELECT): if wrefresh: lcd.clear() lcd.set_backlight(1) lcd.message("Hello World\n") refresh = True wrefresh = False elif lcd.is_pressed(LCD.UP): if wrefresh: lcd.clear() lcd.set_backlight(1) lcd.message("I Like Tacos")
#!/usr/bin/env python import time import RPi.GPIO as GPIO from mfrc522 import SimpleMFRC522 import mysql.connector import Adafruit_CharLCD as LCD db = mysql.connector.connect(host="localhost", user="******", passwd="smartalec", database="playcard") cursor = db.cursor() reader = SimpleMFRC522() lcd = LCD.Adafruit_CharLCD(4, 24, 23, 17, 18, 22, 16, 2, 5) lcd.set_backlight(0) q = True try: while q: lcd.clear() lcd.message(' Scan Card to\n Register it') id, text = reader.read() ied = "SELECT id FROM users WHERE rfid_uid = '" + str( (hex(id)[2:10])) + "'" # print(ied) cursor.execute(ied) cursor.fetchone() # print(cursor.rowcount) if cursor.rowcount == -1:
import picamera from picamera import PiCamera import speech_recognition as sr import RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) GPIO.setup(3, GPIO.OUT) GPIO.setup(13, GPIO.OUT) GPIO.setup(21, GPIO.OUT) GPIO.setup(12, GPIO.IN) GPIO.setup(16, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(19, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(26, GPIO.IN, pull_up_down=GPIO.PUD_UP) lcd = LCD.Adafruit_CharLCD(9, 11, 8, 7, 5, 6, 16, 2) lcd.create_char(1,[7, 5, 7, 32, 32, 32, 32, 32]) lcd.clear() def Komunikat_głosowy(tekst): os.system( 'espeak "'+tekst+'" --stdout -a 200 -s 180 -p 40 | aplay 2>/dev/null' ) while True: r = sr.Recognizer() with sr.Microphone() as źródło_dźwięku: r.adjust_for_ambient_noise(źródło_dźwięku) try: print("Wydaj polecenie") wypowiedziane_słowo = r.listen(źródło_dźwięku) print("Przetwarzam ...")
def lcd_clear(): LCD.clear()
#!/usr/bin/python import time from Adafruit_CharLCD import * PIN_RS = 25 PIN_EN = 24 PIN_DB4 = 23 PIN_DB5 = 17 PIN_DB6 = 27 PIN_DB7 = 22 if __name__ == '__main__': print "LCD Test Program" display = Adafruit_CharLCD(PIN_RS, PIN_EN, PIN_DB4, PIN_DB5, PIN_DB6, PIN_DB7, 16, 2) #display.enable_display(True) #display.home() display.clear() #display.message("Hallo!") while 1: print ">", cmd = raw_input() if cmd == "home" or cmd == "h": display.home() elif cmd == "clear" or cmd == "c": display.clear() elif cmd == "enable" or cmd == "e": display.enable_display(True)
gpio.setmode(gpio.BCM) #declaring LCD pins lcd_rs = 17 lcd_en = 18 lcd_d4 = 27 lcd_d5 = 22 lcd_d6 = 23 lcd_d7 = 10 lcd_backlight = 2 lcd_columns = 16 #Lcd column lcd_rows = 2 #number of LCD rows lcd = LCD.Adafruit_CharLCD(lcd = LCD.Adafruit_CharLCD(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7, lcd_columns, lcd_rows, lcd_backlight) port = ("/dev/ttyAMA0") # the serial port to which the pi is connected. #create a serial object ser = serial.Serial(port, baudrate = 9600, timeout = 0.5) while 1: try: data = ser.readline() except: print("loading") #wait for the serial port to churn out data if data[0:6] == '$GPGGA': # the long and lat data are always contained in the GPGGA string of the NMEA data
def configure_lcd(self): self.lcd = Adafruit_CharLCD(LCD_RS, LCD_EN, [LCD_DATA_1, LCD_DATA_2, LCD_DATA_3, LCD_DATA_4])
GPIO.setmode(GPIO.BCM) ipin = 26 aan = False GPIO.setup(16, GPIO.OUT) GPIO.setup(21, GPIO.OUT) GPIO.setup(ipin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) rs, en, d4, d5, d6, d7, backlight, cols, rows = 25, 24, 23, 17, 18, 22, 4, 16, 2 ph = 0 lcd = LCD.Adafruit_CharLCD(rs, en, d4, d5, d6, d7, cols, rows, backlight) # Map functie voor converteren waarde ph meter def map(x, in_min, in_max, out_min, out_max): return float(x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min # WRITE functie voor log file laatste stand systeem bij unexpected powerdown def writeFile(motorStand, PH): fo = open("/home/pi/Documents/file.txt", "w") fo.write("Wat was de laatste motor stand?: \n") fo.write(str(motorStand) + "\n") fo.write("Wat was de laatst gemeten PH-waarde?: \n") fo.write(str(PH) + "\n")
def test_lcd(): # Raspberry Pi pin configuration: lcd_rs = 27 # Note this might need to be changed to 21 for older revision Pi's. lcd_en = 22 lcd_d4 = 25 lcd_d5 = 24 lcd_d6 = 23 lcd_d7 = 18 lcd_backlight = 4 # Define LCD column and row size for 16x2 LCD. lcd_columns = 16 lcd_rows = 2 print("Init LCD") # Initialize the LCD using the pins above. lcd = LCD.Adafruit_CharLCD(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7, lcd_columns, lcd_rows, lcd_backlight) lcd.enable_display(True) print("Message - 'Hello World") # Print a two line message lcd.message('Hello\nworld!') # Wait 5 seconds time.sleep(5.0) print('Show cursor') # Demo showing the cursor. lcd.clear() lcd.show_cursor(True) lcd.message('Show cursor') time.sleep(5.0) print('Blink cursor') # Demo showing the blinking cursor. lcd.clear() lcd.blink(True) lcd.message('Blink cursor') time.sleep(5.0) print("reset") # Stop blinking and showing cursor. lcd.show_cursor(False) lcd.blink(False) time.sleep(5) print("Scroll...") # Demo scrolling message right/left. lcd.clear() message = 'Scroll' lcd.message(message) for i in range(lcd_columns - len(message)): time.sleep(0.5) lcd.move_right() for i in range(lcd_columns - len(message)): time.sleep(0.5) lcd.move_left() time.sleep(5) # Demo turning backlight off and on. print('Flash backlight\nin 5 seconds...') lcd.clear() lcd.message('Flash backlight\nin 5 seconds...') time.sleep(5.0) print("Turn backlight off") # Turn backlight off. lcd.set_backlight(0) time.sleep(5.0) print("Goodbye") # Change message. lcd.clear() lcd.message('Goodbye!') # Turn backlight on. lcd.set_backlight(1) time.sleep(5)
import random import time import Adafruit_CharLCD as LCD import RPi.GPIO as GPIO # Start Raspberry Pi configuration # Raspberry Pi pin designations lcd_rs = 27 lcd_en = 22 lcd_d4 = 25 lcd_d5 = 24 lcd_d6 = 23 lcd_d7 = 18 lcd_backlight = 4 # Define LCD column and row size for a 16x4 LCD. lcd_columns = 16 lcd_rows = 4 # Instantiate an LCD object lcd = LCD.Adafruit_CharLCD(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7, lcd_columns, lcd_rows, lcd_backlight) # Print a two line welcoming message lcd.message('Lets play nim\ncomputer vs human') # Wait 5 seconds time.sleep(5.0) # Clear the screen lcd.clear() # Setup GPIO pins # Set the BCM mode GPIO.setmode(GPIO.BCM) # Inputs GPIO.setup(12, GPIO.IN, pull_up_down = GPIO.PUD_DOWN) GPIO.setup(13, GPIO.IN, pull_up_down = GPIO.PUD_DOWN)
#!/usr/bin/python import time as time import Adafruit_CharLCD as LCD import sys as sys # Initialize the LCD using the pins lcd = LCD.Adafruit_CharLCDPlate(address=0x20) def change_color(color): if color == "blue": lcd.set_color(0.0, 0.0, 1.0) elif color == "red": lcd.set_color(1.0, 0.0, 0.0) elif color == "green": lcd.set_color(0.0, 1.0, 0.0) elif color == "white": lcd.set_color(1.0, 1.0, 1.0) else: print(str(color) + " is not defined") def set_text(text): if len(text) <= 33: lcd.message(text) else: print("Message is too long, should be lower that 16 chars") already_done = False if len(sys.argv) > 1:
def setup(self): self.lcd = LCD.Adafruit_CharLCDPlate() self.lcd.set_color(0.0, 0.0, 1.0)
import RPi.GPIO as GPIO import Adafruit_CharLCD as LCDLib import math import time import random #import connection from aldenC import * from subprocess import call kioskNumber = 1 lcd = LCDLib.Adafruit_CharLCDBackpack() print("Initalized lcd library") lcd.set_backlight(0) max_len = 4 row_pins = [16, 6, 12, 13] col_pins = [19, 20, 21] color_pins = [18, 23] txt = "" #server_ip = "96.225.21.203" #server_port = 25565 #server_connection = Connection(server_ip, server_port) #server_connections.connect() #lcd.message("ID: ") #server_ip = "96.225.21.203" #server_port = 25565 #server_connection = connection.Connection(server_ip,server_port) #server_connection.connect() color_dict = { "white": 0,
lcd_rows = 2 # Define Buzzer pin buzzerPin = 18 # Define Segment Address segment = SevenSegment.SevenSegment(address=0x70) # Initialize the display. Must be called once before using the display. segment.begin() global temperature, humidity, start, end, duration # Try to grab a sensor reading. Use the read_retry method which will retry up # to 15 times to get a sensor reading (waiting 2 seconds between each retry). humidity, temperature = Adafruit_DHT.read_retry(sensor, pin) # Initialize the LCD using the pins lcd = LCD.Adafruit_CharLCDBackpack(address=0x21) # Comment the line below to convert the temperature to Celcius. temperature = temperature * 9 / 5.0 + 32 # added the line to get closer to designated temperature rather than room temperature temperature *= 2 # defining username, password, and headers for servicenow user = '******' pwd = 'kasper440' headers = {"Content-Type": "application/json", "Accept": "application/json"} # Time variables to set time.sleep SNUpdate = 15 SNGet = 10 # identifying sensor and pin and returning the temp and humidity
import Adafruit_CharLCD as LCD import time import random import smbus bus = smbus.SMBus(1) arduino = 12 rs = 12 en = 16 D4 = 18 D5 = 23 D6 = 24 D7 = 25 lcd_columns = 16 lcd_rows = 2 lcd = LCD.Adafruit_CharLCD(rs, en, D4, D5, D6, D7, lcd_columns, lcd_rows) carMap = [ 0b00000, 0b00000, 0b10100, 0b11110, 0b11111, 0b11110, 0b10100, 0b00000 ] StageMap = [ 0b10001, 0b01010, 0b00100, 0b11111, 0b11111, 0b00100, 0b01010, 0b10001 ] GoalMap = [ 0b00100, 0b01111, 0b10100, 0b10100, 0b01111, 0b00101, 0b11110, 0b00100 ] NegativeHeartMap = [ 0b00000, 0b01010, 0b10101, 0b10001, 0b10001, 0b01010, 0b00100, 0b00000 ] HeartMap = [ 0b00000, 0b01010, 0b11111, 0b11111, 0b11111, 0b01110, 0b00100, 0b00000
def init(self): self._lcd = LCD.Adafruit_CharLCDPlate()
# Define LCD column and row size for 16x2 LCD. lcd_columns = 16 lcd_rows = 2 # Alternatively specify a 20x4 LCD. # lcd_columns = 20 # lcd_rows = 4 # Initialize the LCD using the pins lcd = LCD.Adafruit_RGBCharLCD(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7, lcd_columns, lcd_rows, lcd_red, lcd_green, lcd_blue, enable_pwm=True) # Show some basic colors. lcd.set_color(1.0, 0.0, 0.0) lcd.clear() lcd.message('RED') time.sleep(3.0) lcd.set_color(0.0, 1.0, 0.0) lcd.clear() lcd.message('GREEN')
import Adafruit_CharLCD as LCD mypath = "/home/pi/Desktop/Techtile/MidiFiles/" import math import time from os import listdir from os.path import isfile, join import pyttsx3 import Adafruit_CharLCD as LCD from adafruit_lcd_plate_menu import MenuNode from adafruit_lcd_plate_menu import CharMenuDisplay # Instantiate and configure Adafruit's Char LCD Plate lib adafruit_char_lcd_plate = LCD.Adafruit_CharLCDPlate() adafruit_char_lcd_plate.set_color(0.0, 0.0, 1.0) adafruit_char_lcd_plate.set_backlight(True) # Initate speaker voice condition engine = pyttsx3.init() rate = engine.getProperty('rate') volume =engine.getProperty('volume') voices = engine.getProperty('voices') engine.setProperty('rate', rate-30) engine.setProperty('volume', volume + 30) engine.setProperty('voice', 'english+f1') # or voices[13].id mypath = "/home/pi/Desktop/Techtile/MidiFiles/" files = [f for f in listdir(mypath) if isfile(join(mypath, f))]
class GPIOController: RPM_1_LEVEL = 17 RPM_2_LEVEL = 18 RPM_3_LEVEL = 27 RPM_4_LEVEL = 22 RPM_5_LEVEL = 23 SEG7_A = 16 SEG7_B = 25 SEG7_C = 5 SEG7_D = 6 SEG7_E = 13 SEG7_F = 21 SEG7_G = 20 LCD_RS = 4 LCD_EN = 10 LCD_DATA_1 = 19 LCD_DATA_2 = 26 LCD_DATA_3 = 24 LCD_DATA_4 = 12 numbers = { 0:(0,0,0,0,0,0,1), 1:(1,0,0,1,1,1,1), 2:(0,0,1,0,0,1,0), 3:(0,0,0,0,1,1,0), 4:(1,0,0,1,1,0,0), 5:(0,1,0,0,1,0,0), 6:(0,1,0,0,0,0,0), 7:(0,0,0,1,1,1,1), 8:(0,0,0,0,0,0,0), 9:(0,0,0,0,1,0,0)} def __init__(self): GPIO.setmode(GPIO.BCM) #self.configure_leds() self.configure_7_segments() self.configure_lcd() self.lcd = None def configure_leds(self): GPIO.setup(RPM_1_LEVEL,GPIO.OUT) GPIO.setup(RPM_2_LEVEL,GPIO.OUT) GPIO.setup(RPM_3_LEVEL,GPIO.OUT) GPIO.setup(RPM_4_LEVEL,GPIO.OUT) GPIO.setup(RPM_5_LEVEL,GPIO.OUT) def configure_7_segments(self): GPIO.setup(self.SEG7_A,GPIO.OUT, initial=1) GPIO.setup(self.SEG7_B,GPIO.OUT, initial=1) GPIO.setup(self.SEG7_C,GPIO.OUT, initial=1) GPIO.setup(self.SEG7_D,GPIO.OUT, initial=1) GPIO.setup(self.SEG7_E,GPIO.OUT, initial=1) GPIO.setup(self.SEG7_F,GPIO.OUT, initial=1) GPIO.setup(self.SEG7_G,GPIO.OUT, initial=1) def configure_lcd(self): self.lcd = Adafruit_CharLCD(LCD_RS, LCD_EN, [LCD_DATA_1, LCD_DATA_2, LCD_DATA_3, LCD_DATA_4]) def update_leds(self, telemetry_data): rpm_percentage = int((telemetry_data.rpm / telemetry_data.max_rpm) * 100) if (rpm_percentage > 95): GPIO.output(self.RPM_1_LEVEL,GPIO.HIGH) GPIO.output(self.RPM_2_LEVEL,GPIO.HIGH) GPIO.output(self.RPM_3_LEVEL,GPIO.HIGH) GPIO.output(self.RPM_4_LEVEL,GPIO.HIGH) GPIO.output(self.RPM_5_LEVEL,GPIO.HIGH) elif (rpm_percentage > 91): GPIO.output(self.RPM_1_LEVEL,GPIO.HIGH) GPIO.output(self.RPM_2_LEVEL,GPIO.HIGH) GPIO.output(self.RPM_3_LEVEL,GPIO.HIGH) GPIO.output(self.RPM_4_LEVEL,GPIO.HIGH) GPIO.output(self.RPM_5_LEVEL,GPIO.LOW) elif (rpm_percentage > 87): GPIO.output(self.RPM_1_LEVEL,GPIO.HIGH) GPIO.output(self.RPM_2_LEVEL,GPIO.HIGH) GPIO.output(self.RPM_3_LEVEL,GPIO.HIGH) GPIO.output(self.RPM_4_LEVEL,GPIO.LOW) GPIO.output(self.RPM_5_LEVEL,GPIO.LOW) elif (rpm_percentage > 84): GPIO.output(self.RPM_1_LEVEL,GPIO.HIGH) GPIO.output(self.RPM_2_LEVEL,GPIO.HIGH) GPIO.output(self.RPM_3_LEVEL,GPIO.LOW) GPIO.output(self.RPM_4_LEVEL,GPIO.LOW) GPIO.output(self.RPM_5_LEVEL,GPIO.LOW) elif (rpm_percentage > 80): GPIO.output(self.RPM_1_LEVEL,GPIO.HIGH) GPIO.output(self.RPM_2_LEVEL,GPIO.LOW) GPIO.output(self.RPM_3_LEVEL,GPIO.LOW) GPIO.output(self.RPM_4_LEVEL,GPIO.LOW) GPIO.output(self.RPM_5_LEVEL,GPIO.LOW) else: GPIO.output(self.RPM_1_LEVEL,GPIO.LOW) GPIO.output(self.RPM_2_LEVEL,GPIO.LOW) GPIO.output(self.RPM_3_LEVEL,GPIO.LOW) GPIO.output(self.RPM_4_LEVEL,GPIO.LOW) GPIO.output(self.RPM_5_LEVEL,GPIO.LOW) def update_7_segments(self, telemetry_data): if (telemetry_data.current_gear < 10): GPIO.output(self.SEG7_A, self.numbers[telemetry_data.current_gear][0]) GPIO.output(self.SEG7_B, self.numbers[telemetry_data.current_gear][1]) GPIO.output(self.SEG7_C, self.numbers[telemetry_data.current_gear][2]) GPIO.output(self.SEG7_D, self.numbers[telemetry_data.current_gear][3]) GPIO.output(self.SEG7_E, self.numbers[telemetry_data.current_gear][4]) GPIO.output(self.SEG7_F, self.numbers[telemetry_data.current_gear][5]) GPIO.output(self.SEG7_G, self.numbers[telemetry_data.current_gear][6]) def update_lcd(self, telemetry_data): self.lcd.clear() self.lcd.message(str(int(Convert.speed_to_kph(telemetry_data.speed))) + " KPH") def update_all(self, telemetry_data): self.update_7_segments(telemetry_data) self.update_leds(telemetry_data) self.update_lcd(telemetry_data)
elif background is 'Green': screen.set_color(0, 1, 0) elif background is 'White': screen.set_color(1, 1, 1) else: screen.set_color(1, 1, 1) screen.clear() screen.message(messageText) os.system('clear') print(messageText) # HARDWARE SETUP # ----------------- # Create instances of LCD object and begin communications lcd = LCD.Adafruit_RGBCharLCD(LCD_RS, LCD_EN, LCD_D4, LCD_D5, LCD_D6, LCD_D7, LCD_COLS, LCD_ROWS, LCD_RED, LCD_GREEN, LCD_BLUE) # Create instances of PN532 object and begin communications reporting back version pn532 = PN532.PN532(cs=PN532_SSEL, sclk=PN532_SCLK, mosi=PN532_MOSI, miso=PN532_MISO) pn532.begin() ic, ver, rev, support = pn532.get_firmware_version() tempMessage = ('Found Card Reader\nFirmware version {0}.{1}'.format(ver, rev)) lcd_message(lcd,'Blue',tempMessage) time.sleep(3) # Configure PN532 to communicate with MiFare cards. pn532.SAM_configuration() # Configure GPIO pins on the pi. GPIO.setup([RELAY1], GPIO.OUT)
mlplayer.set_media_player(player) mlplayer.set_media_list(medialist) GPIO.setmode(GPIO.BCM) PLAY_BUTTON=11 STOP_BUTTON=7 BACK_BUTTON=4 FORWARD_BUTTON=10 GPIO.setup(PLAY_BUTTON, GPIO.IN) GPIO.setup(STOP_BUTTON, GPIO.IN) GPIO.setup(BACK_BUTTON, GPIO.IN) GPIO.setup(FORWARD_BUTTON, GPIO.IN) lcd = Adafruit_CharLCD() lcd.clear() lcd.message("Hit play!") def handle_changed_track(event, player): media = player.get_media() media.parse() artist = media.get_meta(vlc.Meta.Artist) or "Unknown artist" title = media.get_meta(vlc.Meta.Title) or "Unknown song title" album = media.get_meta(vlc.Meta.Album) or "Unknown album" lcd.clear() lcd.message(title+"-"+"\n") #+artist+"\n") lcd.message(datetime.datetime.now().strftime('%b %d %H:%M')) playerem = player.event_manager()
def lcd_print(msg): LCD.message(msg)