コード例 #1
0
ファイル: commonTasks.py プロジェクト: cjg342/feeder
def print_to_LCDScreen (message):
    try:
        lcd = Adafruit_CharLCD()
        lcd.begin(16,2)
        for x in range(0, 16):
            for y in range(0, 2):
                lcd.setCursor(x, y)
                lcd.message('>')
                time.sleep(.025)
        lcd.noDisplay()
        lcd.clear()
        lcd.message(str(message))
        for x in range(0, 16):
            lcd.DisplayLeft()
        lcd.display()
        for x in range(0, 16):
            lcd.scrollDisplayRight()
            time.sleep(.05)
        # lcd.noDisplay()
        # lcd.display()
        # lcd.blink()
        # lcd.noCursor()
        # lcd.clear()
        # lcd.noBlink()
        # lcd.begin(16, 2)
        # lcd.setCursor(7, 0)
        # lcd.message('123')
        # lcd.message('x')
        # lcd.clear()
        return 'ok'
    except Exception,e:
        return e
コード例 #2
0
ファイル: lcd.py プロジェクト: flarecast/lcd-reactor
    class Display(Thread):
        # TODO: move this to a config file
        COLS = 16
        ROWS = 2
        COL_OFFSET = 2 # You may choose to add an offset to the original position
        DURATION = 15
        PREFIX = "WARNING: "

        def __init__(self, msg):
            Thread.__init__(self)
            LCDReactor.Display.START_POSITION = LCDReactor.Display.COLS - LCDReactor.Display.COL_OFFSET
            self.msgs = [LCDReactor.Display.PREFIX, msg]
            self.lcd = CharLCD(pin_rs=2, pin_e=4, pins_db=[3, 14, 25, 24])

        def init_display(self):
            self.lcd.clear()
            self.lcd.begin(LCDReactor.Display.COLS, LCDReactor.Display.ROWS)

        def display_message(self):
            self.lcd.setCursor(LCDReactor.Display.START_POSITION, 0)
            self.lcd.message(self.msgs[0])
            self.lcd.setCursor(LCDReactor.Display.START_POSITION, 1)
            self.lcd.message(self.msgs[1])

        def shift_text(self):
            self.lcd.DisplayLeft()
            time.sleep(0.3)

        def loop_message(self):
            # Calculate the maximum length and the start position
            # Needed for when the time runs out and the message is in the
            # middle of the LCD
            position = LCDReactor.Display.START_POSITION
            max_len = max(len(self.msgs[0]), len(self.msgs[1]))
            start_time = time.time()

            # Display for n seconds
            while time.time() < start_time + LCDReactor.Display.DURATION:
                self.shift_text()
                position = (position + 1) % max_len

            # If the text is in the middle of the screen, we want to shift it
            # off. The best way is to take the current position and move it
            # until the the position is out of the display.
            # "Out of display" is given by max_len (maximum image size) +
            # START_POSITION, since it starts in the right side of the LCD
            for x in range(position, LCDReactor.Display.START_POSITION + max_len):
                self.shift_text()

            self.lcd.clear()


        def display(self):
            self.init_display()
            self.display_message()
            self.loop_message()

        def run(self):
            self.display()
コード例 #3
0
class GpioDisplay:

    def __init__(self, *_args):
        if GPIO.RPI_REVISION == 2:
            self.lcd = Adafruit_CharLCD(pins_db=[23, 17, 27, 22])
        else:
            self.lcd = Adafruit_CharLCD()
        self.lcd.begin(16,2)

    def clear(self):
        self.lcd.clear()

    def move_to(self, row, col):
        self.lcd.setCursor(row, col)

    def write(self, string):
        self.lcd.message(string)

    def backlight(self, r, g, b):
        # not implemented
        pass
コード例 #4
0
 
POWER_DOWN = 0x00 # No active state
POWER_ON   = 0x01 # Power on
RESET      = 0x07 # Reset data register value
# Start measurement at 1lx resolution. Time typically 120ms
# Device is automatically set to Power Down after measurement.
ONE_TIME_HIGH_RES_MODE_1 = 0x20

 
bus = smbus.SMBus(1)  # Rev 2 Pi uses 1
 
def convertToNumber(data):
  # Simple function to convert 2 bytes of data
  # into a decimal number
  return ((data[1] + (256 * data[0])) / 1.2)
 
def readLight(addr=DEVICE):
  data = bus.read_i2c_block_data(addr,ONE_TIME_HIGH_RES_MODE_1)
  return convertToNumber(data)
lcd.clear()
while True:
    lux = readLight()
    lux=round(lux,2)
    print lux
    print "light Level is " + str(lux) + " lx"
    lcd.setCursor(3,1)
    lux=round(lux,1)
    lcd.message("L:" +str(lux))
    time.sleep(1)

コード例 #5
0
import time
from Adafruit_CharLCD import Adafruit_CharLCD
from time import sleep, strftime
from datetime import datetime

import RPi.GPIO as GPIO, time, os
GPIO.setmode(GPIO.BCM)

lcd = Adafruit_CharLCD()
lcd.begin(16, 2)

lcd.clear()

while True:
    lcd.setCursor(0, 0)
    lcd.message("Hello World")
    time.sleep(2)
    lcd.clear()
    lcd.setCursor(0, 1)
    lcd.message("Hello World !!!!!")
    time.sleep(2)
    lcd.clear()
コード例 #6
0
from Adafruit_CharLCD import Adafruit_CharLCD
import RPi.GPIO as GPIO
from time import sleep

gas = 8
relay2 = 6

GPIO.setmode(GPIO.BCM)
GPIO.setup(6, GPIO.OUT)
GPIO.setup(gas, GPIO.IN)
lcd = Adafruit_CharLCD()

lcd.begin(16, 2)
lcd.clear()

while True:
    if (GPIO.input(gas) == 0):
        lcd.setCursor(13, 0)
        lcd.message("GP")
        print "GP"
        GPIO.output(relay2, True)
        sleep(1)
    else:
        lcd.setCursor(13, 0)
        lcd.message("NG")
        print "NG"
        GPIO.output(relay2, False)
        sleep(1)
コード例 #7
0
relay1 = 5
relay2 = 6
gas = 8
GPIO.setmode(GPIO.BCM)
GPIO.setup(5, GPIO.OUT)
GPIO.setup(6, GPIO.OUT)
GPIO.setup(pir, GPIO.IN)
GPIO.setup(gas, GPIO.IN)

############################################################################################

while True:
    degC, degf = read_temp()
    degC = round(degC, 1)
    print degC
    lcd.setCursor(10, 1)
    lcd.message("T:" + str(degC))
    lux = readLight()
    lux = round(lux, 2)
    print "light Level is " + str(lux) + " lx"
    lcd.setCursor(0, 1)
    lux = round(lux, 1)
    lcd.message("L:" + str(lux))
    humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
    if humidity is not None and temperature is not None:
        humidity = round(humidity, 2)
        print "humidity is " + str(humidity)
        lcd.setCursor(0, 0)
        lcd.message("H:" + str(humidity))
    else:
        print 'Failed to get reading. Try again!'
コード例 #8
0
ファイル: scroller.py プロジェクト: specht/lcd
class Scroller:
    def __init__(self):
        random.seed()
        self.width = 40
        self.height = 2
        self.timeoutmin = 20
        self.timeoutmax = 100
        self.wait_time = 40
        self.separator = ' +++ '
        self.paused = False
        self.paused_loop = 0
        self.busy = False
        self.busy_loop = 0
        self.elapsed = ''
        
        self.lines = []
        self.offset = []
        self.tag = []
        for i in range(self.height):
            self.lines.append('')
            self.offset.append(0)
            self.tag.append('')
            
        self.ascii_art = {}
        self.load_ascii_art()
        
        # 0   - animation running
        # > 0 - animation countdown
        # -1  - animation and countdown disabled
        self.easter_egg_countdown = -1
        
        self.animation_index = self.ascii_art.keys()[random.randrange(0, len(self.ascii_art))]
        self.animation_phase = 0

        self.lcd = Adafruit_CharLCD()
        self.lcd.begin(40, 2)
        self.lcd.define_char(1, [0, 0x10, 0x08, 0x04, 0x02, 0x01, 0, 0])
        self.lcd.define_char(2, [0, 31, 14, 4, 21, 10, 0, 0])
        self.current_lines = ["", ""]
    
    def tr(self, s):
        result = ''.encode('latin-1')
        for c in unicode(s, 'UTF-8'):
            #print(c, ord(c))
            if ord(c) == 92:
                result += u'\x01'.encode('latin-1')
            elif ord(c) < 128:
                result += c.encode('latin-1')
            elif ord(c) == 246:
                result += u'\xef'.encode('latin-1')
            elif ord(c) == 252:
                result += u'\xf5'.encode('latin-1')
            elif ord(c) == 228:
                result += u'\xe1'.encode('latin-1')
            elif ord(c) == 223:
                result += u'\xe2'.encode('latin-1')
            elif ord(c) == 169:
                result += '(c)'.encode('latin-1')
            else:
                pass
                #print(c)
                #print(ord(c))
        return result
            
    def load_ascii_art(self):
        with open('ascii-art.txt') as f:
            while True:
                tag = f.readline().strip()
                if len(tag) == 0:
                    break
                self.ascii_art[tag] = []
                while True:
                    line1 = f.readline().rstrip()
                    if len(line1) == 0:
                        break
                    line2 = f.readline().rstrip()
                    line1 = self.tr(line1)
                    line2 = self.tr(line2)
                    if len(line1) > len(line2):
                        line2 += ' ' * (len(line1) - len(line2))
                    if len(line2) > len(line1):
                        line1 += ' ' * (len(line2) - len(line1))
                    self.ascii_art[tag].append(line1)
                    self.ascii_art[tag].append(line2)

    def set_line(self, i, s = '', tag = ''):
        if s == None:
            s = ''
        if tag == self.tag[i]:
            if self.offset[i] > 0:
                return
        s = self.tr(s)
        if s != self.lines[i]:
            self.lines[i] = s
            self.offset[i] = -self.wait_time
        self.tag[i] = tag
        if self.lines[0] == '' and self.lines[1] == '':
            if self.easter_egg_countdown < 0:
                self.easter_egg_countdown = random.randrange(self.timeoutmin, self.timeoutmax)
                self.animation_index = self.ascii_art.keys()[random.randrange(0, len(self.ascii_art))]
                self.animation_phase = 0
        else:
            self.easter_egg_countdown = -1
        
    def set_paused(self, paused):
        self.paused = paused
        
    def set_busy(self, busy):
        self.busy = busy
        
    def set_elapsed(self, elapsed):
        self.elapsed = elapsed
            
    def render(self):
        result_lines = []
        
        if self.easter_egg_countdown > 0:
            self.easter_egg_countdown -= 1
            
        if self.easter_egg_countdown == 0:
            # animation
            
            for i in range(2):
                offset = -len(self.ascii_art[self.animation_index][i]) + self.animation_phase
                frames = len(self.ascii_art[self.animation_index]) / 2
                part = self.ascii_art[self.animation_index][i + (2 * (self.animation_phase % frames))]
                if offset < 0:
                    part = part[-offset:]
                else:
                    part = (' ' * offset) + part
                part += ' ' * self.width
                part = part[:self.width]
                result_lines.append(part)
                if (offset > self.width):
                    self.easter_egg_countdown = random.randrange(self.timeoutmin, self.timeoutmax)
                    self.animation_index = self.ascii_art.keys()[random.randrange(0, len(self.ascii_art))]
                    self.animation_phase = 0
                    
            self.animation_phase = self.animation_phase + 1
        else:
            # print lines
            for i in range(self.height):
                line = self.lines[i]
                cropped = line
                if len(line) > self.width:
                    cropped += self.separator
                    cropped += line
                offset = self.offset[i]
                if offset < 0:
                    offset = 0
                cropped += ' ' * self.width
                cropped = cropped[offset:(offset + self.width)]
                    
                if i == 0:
                    if self.busy:
                        cropped = cropped[:-2]
                        self.busy_loop = (self.busy_loop + 1) % 4
                        cropped += ' '
                        cropped += ('/-' + u'\x01'.encode('latin-1') + '|')[self.busy_loop]
                if i == 1:
                    if self.paused:
                        cropped = cropped[:-2]
                        self.paused_loop = (self.paused_loop + 1) % 4
                        cropped += ' '
                        cropped += '.oOo'[self.paused_loop]
                    #else:
                        #if self.elapsed != '':
                            #cropped = cropped[:-(len(self.elapsed) + 2)]
                            #cropped += "|%s" % self.elapsed

                if i == 0:
                    cropped = cropped[:-2]
                    cropped += ' '
                    cropped += '"'
                if i == 1:
                    cropped = cropped[:-2]
                    cropped += ' '
                    cropped += u'\x02'.encode('latin-1')

                result_lines.append(cropped)
        #os.system("clear")
        #self.lcd.clear()
        self.lcd.setCursor(0, 0)
        for index, cropped in enumerate(result_lines):
            #if cropped != self.current_lines[index]:
                self.current_lines[index] = cropped
                self.lcd.message(cropped)
                #print(cropped)
                #print(cropped)
        #print()
        
    def animate(self):
        for i in range(self.height):
            line = self.lines[i]
            if len(line) <= self.width:
                self.offset[i] = 0
            else:
                self.offset[i] += 1
                if self.offset[i] == len(line) + len(self.separator):
                    self.offset[i] = -self.wait_time
                    
    def clear(self):
        for i in range(self.height):
            self.set_line(i, '')
コード例 #9
0
from Adafruit_CharLCD import Adafruit_CharLCD
import RPi.GPIO as GPIO
from time import sleep
pir = 27
relay1 = 5
GPIO.setmode(GPIO.BCM)
GPIO.setup(5,GPIO.OUT)
GPIO.setup(pir,GPIO.IN)

lcd = Adafruit_CharLCD()

lcd.begin(16, 2)
lcd.clear()
while True:
    if(GPIO.input(pir) == 1):
        lcd.setCursor(10,0)
        lcd.message("TD")
        print "TD"
        GPIO.output(relay1,True)
        sleep(1)
    else:
        lcd.setCursor(10,0)
        lcd.message("NT")
        print "NT"
        GPIO.output(relay1,False)
        sleep(1)
    
コード例 #10
0
            pingmax = pingnum
        if pingnum < pingmin:
            pingmin = pingnum

    #send the ping value to the highping function
        if pingnum > 100:
            highping.main(pingnum)

    #find the local temp, using the openweathermap city ID
        localtemp = temperature.local(6174041)

        roomtemp = temperature.room(apikey, 'temperature')

        lcd.clear()

        lcd.setCursor(0, 0)
        lcd.message('WANIP %s' % (wanipaddr))

        lcd.setCursor(0, 1)
        lcd.message('Ping %0.2f' % (pingnum))
        lcd.setCursor(0, 2)
        lcd.message('%0.2f %0.2f %0.2f' % (pingavg, pingmin, pingmax))
        lcd.setCursor(0, 3)
        lcd.message('temp:%0.1f room:%0.1f' % (localtemp, roomtemp))

        aio.send('wan-ip', wanipaddr)
        aio.send('ping', pingnum)
        data0 = aio.receive('wan-ip')
        print('Received value: {0}'.format(data0.value))
        data1 = aio.receive('ping')
        print('Received value: {0}'.format(data1.value))
コード例 #11
0
ファイル: SkyPi.py プロジェクト: atimokhin/SkyPi
class SkyPi:

    def __init__(self):
        self.FSM = SkyPi_FSM()
        # flags
        self.redraw_flag = True
        self.wifi_mode_adhoc_flag = False
        # setup LCD screen
        self.lcd = Adafruit_CharLCD()
        self.lcd.begin(16, 2)
        self.lcd.clear()
        self.lcd.message("Start SkyPi_LCDd\n")
        # setup datetime
        self.time_state = True
        self.time_str_fmt = ' %m/%d %H:%M'
        self.datetime_str=datetime.now().strftime(self.time_str_fmt)
        # gps
        self.gps = SkyPi_GPS(SP_CFG.DT_GPS_CHECK)
        # net
        self.net = SkyPi_NET()
        # setup GPIOs
        GPIO.setmode(GPIO.BCM)
        GPIO.setup(SP_CFG.PIN_BUTTON_HC_SETUP,   GPIO.IN, pull_up_down=GPIO.PUD_UP)
        GPIO.setup(SP_CFG.PIN_SWITCH_ADHOC_MODE, GPIO.IN, pull_up_down=GPIO.PUD_UP)


    def Show_GPS_IP(self):
        # gps status
        self._show_gps_status()
        # time
        self._show_time()
        # ip
        self._show_ip()
        # reset redraw_flag
        self.redraw_flag = False
        # monitor button
        self.check_buttons()

    def Change_WiFi_Mode(self,mode):
        if mode == 'A':
            self.net.switch_to_AdHoc()
        elif mode == 'M':
            self.net.switch_to_Managed()
            
    def Setup_HC(self):
        self.lcd.clear()
        self.lcd.setCursor(0,0)
        self.lcd.message('Button pressed\n')
        sleep(1)
        self.lcd.clear()
        self.lcd.setCursor(0,0)
        lat,lon,status = self.gps.get_location()
        self.lcd.message('S:%2d lat:%g' % (status,lat))
        self.lcd.setCursor(0,1)
        self.lcd.message('    lon:%g' % lon)
        self.redraw_flag = True
        sleep(2)
        self.lcd.clear()
        
    def check_buttons(self):
        if GPIO.input(SP_CFG.PIN_BUTTON_HC_SETUP) == False:
            self.Setup_HC()
        if GPIO.input(SP_CFG.PIN_SWITCH_ADHOC_MODE) == False:
            if not self.wifi_mode_adhoc_flag:
                self.Change_WiFi_Mode('A')
                self.wifi_mode_adhoc_flag = True
        else:
            if self.wifi_mode_adhoc_flag:
                self.Change_WiFi_Mode('M')
                self.wifi_mode_adhoc_flag = False
        
    def _show_gps_status(self):
        """
        show GPS status
        """ 
        if ( self.gps.check_gps() or self.redraw_flag ):
            # show GPS info on LCD
            self.lcd.setCursor(0,0)
            self.lcd.message(self.gps.gps_status_str())
                
    def _show_ip(self):
        local_redraw_flag = False
        # if address has changed
        if ( self.net.check_net() or self.redraw_flag ):                     
             # clear previous IP
             self.lcd.setCursor(0,1)
             self.lcd.message(16*' ')
             # new IP
             self.lcd.setCursor(0,1)
             self.lcd.message(self.net.net_status_str())

    def _show_time(self):
        current_datetime_str=datetime.now().strftime(self.time_str_fmt)
        if ( current_datetime_str != self.datetime_str or
             self.redraw_flag ):
            self.datetime_str = current_datetime_str
            self.lcd.setCursor(3,0)
            self.lcd.message(self.datetime_str)
        # blinking ":"
        self.time_state = not self.time_state
        self.lcd.setCursor(15,0)
        if self.time_state:
            self.lcd.message(':')
        else:
            self.lcd.message(' ')
コード例 #12
0
ファイル: gas.py プロジェクト: amitrana3348/nilamdarda16
from Adafruit_CharLCD import Adafruit_CharLCD
import RPi.GPIO as GPIO
from time import sleep
gas = 8
relay2=6

GPIO.setmode(GPIO.BCM)
GPIO.setup(6,GPIO.OUT)
GPIO.setup(gas,GPIO.IN)
lcd = Adafruit_CharLCD()

lcd.begin(16, 2)
lcd.clear()


while True:
    if(GPIO.input(gas) == 0):
        lcd.setCursor(13,0)
        lcd.message("GP")
        print "GP"
        GPIO.output(relay2,True)
        sleep(1)
    else:
        lcd.setCursor(13,0)
        lcd.message("NG")
        print "NG"
        GPIO.output(relay2,False)
        sleep(1)
コード例 #13
0
ファイル: hashtagdisplay.py プロジェクト: pdp7/tweetypi
class HashTagDisplay():
    def __init__(self, cols, rows, delay, debug=False):
        # number of columns on the character LCD (min: 16, max: 20)
        self.cols = cols
        # number of rows on the character LCD (min: 1, max: 4)
        self.rows = rows
        # duration in seconds to allow human to read LCD lines
        self.delay = delay
        # print messages to shell for debugging 
        self.debug = debug
        if debug == True:
            print " cols = {0}".format(cols)
            print " rows = {0}".format(rows)
            print "delay = {0}".format(delay)
        self.lcd = Adafruit_CharLCD()
        self.lcd.begin(cols, rows)

    def search(self, hashtag):
        """ search for tweets with specified hashtag """
        twitter_search = Twitter(domain="search.twitter.com")
        return twitter_search.search(q=hashtag)
    
    def display(self, results):
        """ Display each tweet in the twitter search results """
        for tweet in results.get('results'):
            msg = "@" + tweet.get('from_user') + ": " + tweet.get('text') 
            if self.debug == True:
                print "msg: " + msg
            # break tweet into lines the width of LCD
            lines = textwrap.wrap(msg, self.cols)
            self.printLines(lines)

    def printLines(self, lines):
        """ display each line of the tweet """
        i = 0
        while i < lines.__len__():
            self.lcd.clear()
                
            # print line to each LCD row 
            for row in range(self.rows):

                # display line on current LCD row
                self.lcd.setCursor(0,row)
                self.lcd.message(lines[i])
                i=i+1
                # 200ms delay is now only for visual effect
                # initially added the delay to avoid issue 
                # where garbage characters were displayed:
                # https://github.com/adafruit/Adafruit-Raspberry-Pi-Python-Code/pull/13
                sleep(0.2)

                # no more lines remaining for this tweet
                if i >= lines.__len__():
                    # sleep according to the number of rows displayed
                    row_delay = self.delay / float(self.rows)
                    delay = row_delay * (row+1)
                    if(delay < 1):
                        delay = 1
                    sleep(delay)
                    break

                # pause to allow human to read displayed rows
                if(row+1 >= self.rows):
                     sleep(self.delay)
コード例 #14
0
ファイル: testboxknauf.py プロジェクト: testboxknauf/Update
# Main *****************************************************************
#***********************************************************************
	
	f=open(log_datei,'a' if os.path.exists(log_datei) else 'w')
	f.write("DATALOG\n")
	f.close()

	# Endlosschlaufe
	while 1: 
	
#***********************************************************************
# "Switch case" ********************************************************

				# Menüauswahl
				if n == 0:
					lcd.setCursor(0, 0)
					lcd.message("    Auswahl:    ")
					# Nach links oder rechts?
					if GPIO.input(left) == GPIO.LOW:
						# Vom aktuellen Punkt eins links
						if save < 4:
							save = save + 1
						else:
							save = 1
					if GPIO.input(right) == GPIO.LOW:
						# Vom aktuellen Punkt eins rechts
						if save > 1:
							save = save - 1
						else:
							save = 4
							
コード例 #15
0
ファイル: lcd_display.py プロジェクト: ovalent/homon
class LCD_display(object):
    bus = 1         # Note you need to change the bus number to 0 if running on a revision 1 Raspberry Pi.
    address = 0x20  # I2C address of the MCP230xx chip.
    gpio_count = 8  # Number of GPIOs exposed by the MCP230xx chip, should be 8 or 16 depending on chip.

    # LCD 20x4
    num_columns = 20
    num_lines = 4
    
    def __init__(self, init=True):
        # Create MCP230xx GPIO adapter.
        mcp = MCP230XX_GPIO(self.bus, self.address, self.gpio_count)

        # Create LCD, passing in MCP GPIO adapter.
        self.lcd = Adafruit_CharLCD(pin_rs=1, pin_e=2, pin_bl=7, pins_db=[3,4,5,6], GPIO=mcp)
        if init:
            self.initialisation()
    
    def initialisation(self):
        self.lcd.clear()
        self.lcd.begin(self.num_columns, self.num_lines)
        self.lcd.backlightOn()
        self.lcd.setCursor(0, 0)
        #self.lcd.message(datetime.datetime.now().strftime(' %a %d %b - %H:%M'))
        
    def line_message(self, row, text):
        # set the position (row from 0 to 3)
        self.lcd.setCursor(0, row)
        # display the message
        self.lcd.message(text)
    
    def temperature(self, text):
        #set the position
        self.lcd.setCursor(0, 1)
        #display the message and value
        self.lcd.message("Temperature: %.2f" % text)
        self.lcd.write4bits( 0xDF, True) #display the degree symbol "°"
        self.lcd.message("C")
        
    def humidity(self, text):
        #set the position
        self.lcd.setCursor(0, 2)
        #display the message and value
        self.lcd.message("Humidity:   %.2f%%RH" % text)
        
    def pressure(self, text):
        #set the position
        self.lcd.setCursor(0, 3)
        #display the message and value
        self.lcd.message("Pressure: %.2fhPa" % text)
        
    def date(self):
        #set the position
        self.lcd.setCursor(0, 0)
        #display the message and value
        self.lcd.message(datetime.datetime.now().strftime(' %a %d %b  %H:%M'))
コード例 #16
0
cmd = "ip addr show wlan0 | grep inet | awk '{print $2}' | cut -d/ -f1"

lcd.begin(16, 2)


def run_cmd(cmd):
    p = Popen(cmd, shell=True, stdout=PIPE)
    output = p.communicate()[0]
    return output

tiempo = datetime.now()
fecha = tiempo.strftime('%A %d de %B del %Y')
fecha_mostrar = fecha
i = 0
while 1:
	tiempo = datetime.now()
	lcd.setCursor(0,1)
	lcd.message(tiempo.strftime('%H:%M:%S %p'))

	k = 0
	while (k < 4):
		if len(fecha_mostrar) < 16:
			fecha_mostrar = fecha_mostrar + '...' + fecha
		fecha_mostrar = fecha_mostrar[1:]
		#print(i, fecha_mostrar, len(fecha_mostrar))
		lcd.setCursor(0,0)
		lcd.message(fecha_mostrar)
		sleep(0.25)
		i = i + 1
		k = k + 1
コード例 #17
0
class LCD_display(object):
    bus = 1  # Note you need to change the bus number to 0 if running on a revision 1 Raspberry Pi.
    address = 0x20  # I2C address of the MCP230xx chip.
    gpio_count = 8  # Number of GPIOs exposed by the MCP230xx chip, should be 8 or 16 depending on chip.

    # LCD 20x4
    num_columns = 20
    num_lines = 4

    def __init__(self, init=True):
        # Create MCP230xx GPIO adapter.
        mcp = MCP230XX_GPIO(self.bus, self.address, self.gpio_count)

        # Create LCD, passing in MCP GPIO adapter.
        self.lcd = Adafruit_CharLCD(pin_rs=1,
                                    pin_e=2,
                                    pin_bl=7,
                                    pins_db=[3, 4, 5, 6],
                                    GPIO=mcp)
        if init:
            self.initialisation()

    def initialisation(self):
        self.lcd.clear()
        self.lcd.begin(self.num_columns, self.num_lines)
        self.lcd.backlightOn()
        self.lcd.setCursor(0, 0)
        #self.lcd.message(datetime.datetime.now().strftime(' %a %d %b - %H:%M'))

    def line_message(self, row, text):
        # set the position (row from 0 to 3)
        self.lcd.setCursor(0, row)
        # display the message
        self.lcd.message(text)

    def temperature(self, text):
        #set the position
        self.lcd.setCursor(0, 1)
        #display the message and value
        self.lcd.message("Temperature: %.2f" % text)
        self.lcd.write4bits(0xDF, True)  #display the degree symbol "°"
        self.lcd.message("C")

    def humidity(self, text):
        #set the position
        self.lcd.setCursor(0, 2)
        #display the message and value
        self.lcd.message("Humidity:   %.2f%%RH" % text)

    def pressure(self, text):
        #set the position
        self.lcd.setCursor(0, 3)
        #display the message and value
        self.lcd.message("Pressure: %.2fhPa" % text)

    def date(self):
        #set the position
        self.lcd.setCursor(0, 0)
        #display the message and value
        self.lcd.message(datetime.datetime.now().strftime(' %a %d %b  %H:%M'))
コード例 #18
0
device_folder = glob.glob(base_dir + '28*')[0] # to the base address, 28 and * means wild card is attached
# because actual sensor address starts from 28
device_file = device_folder + '/w1_slave'

def read_temp_raw():
    f = open(device_file, 'r') # read the device file with an attribute of 'r' means Read ONLY
    lines = f.readlines()#lines read the status
    f.close()   # close the file
    return lines

def read_temp():
    lines = read_temp_raw()                 # this is actual process of reading temperature from sensor, and processing it, 
    while lines[0].strip()[-3:] != 'YES':
        time.sleep(0.2)
        lines = read_temp_raw()
    equals_pos = lines[1].find('t=')
    if equals_pos != -1:
        temp_string = lines[1][equals_pos+2:]
        temp_c = float(temp_string) / 1000.0
        temp_f = temp_c * 9.0 / 5.0 + 32.0
        return temp_c, temp_f
lcd.clear()

while True:
    degC,degf=read_temp()
    print degC
    lcd.setCursor(5,1)
    lcd.message("T:"+str(degC))
    time.sleep(1)

コード例 #19
0
relay1 = 5
relay2=6
gas = 8
GPIO.setmode(GPIO.BCM)
GPIO.setup(5,GPIO.OUT)
GPIO.setup(6,GPIO.OUT)
GPIO.setup(pir,GPIO.IN)
GPIO.setup(gas,GPIO.IN)

############################################################################################

while True:
    degC,degf=read_temp()
    degC = round(degC,1)
    print degC
    lcd.setCursor(10,1)
    lcd.message("T:"+str(degC))
    lux = readLight()
    lux = round(lux,2)
    print "light Level is " + str(lux) + " lx"
    lcd.setCursor(0,1)
    lux = round(lux,1)
    lcd.message("L:"+str(lux))
    humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
    if humidity is not None and temperature is not None:
        humidity = round(humidity,2)
        print "humidity is " + str(humidity)
        lcd.setCursor(0,0)
        lcd.message("H:" + str(humidity))
    else:
        print 'Failed to get reading. Try again!'
コード例 #20
0
ファイル: lcd.py プロジェクト: CoderDojoMinho/raspberry
DURATION = 30
START_POSITION = 14 # Have the text scroll left. Adjust for LCD size
current_time = lambda: int(round(time.time()))
start_time = current_time()

msg = 'CODERDOJO\nMINHO'
split = msg.split('\n')

position = START_POSITION
max_len = max(len(split[0]), len(split[1])) 

lcd = CharLCD(pin_rs=2, pin_e=4, pins_db=[3, 14, 25, 24])
lcd.clear()
lcd.begin(16,2)
lcd.setCursor(14,0)
lcd.message(split[0])
lcd.setCursor(14,1)
lcd.message(split[1])


while current_time() < start_time + DURATION:
  lcd.DisplayLeft()
  position = (position + 1) % max_len
  time.sleep(.3)

for x in range(position, START_POSITION + max_len):
  lcd.DisplayLeft()
  time.sleep(.3)

lcd.clear()