Ejemplo n.º 1
0
def test_main():
    #Test function for verifying basic functionality
    print("Running test_main")
    i2c = I2C(0, sda=machine.Pin(0), scl=machine.Pin(1), freq=400000)
    lcd = I2cLcd(i2c, I2C_ADDR, I2C_NUM_ROWS, I2C_NUM_COLS)
    lcd.putstr("It Works!")
    utime.sleep(2)
    lcd.clear()
    count = 0
    while True:
        lcd.clear()
        time = utime.localtime()
        lcd.putstr(
            "{year:>04d}/{month:>02d}/{day:>02d} {HH:>02d}:{MM:>02d}:{SS:>02d}"
            .format(year=time[0],
                    month=time[1],
                    day=time[2],
                    HH=time[3],
                    MM=time[4],
                    SS=time[5]))
        if count % 10 == 0:
            print("Turning cursor on")
            lcd.show_cursor()
        if count % 10 == 1:
            print("Turning cursor off")
            lcd.hide_cursor()
        if count % 10 == 2:
            print("Turning blink cursor on")
            lcd.blink_cursor_on()
        if count % 10 == 3:
            print("Turning blink cursor off")
            lcd.blink_cursor_off()
        if count % 10 == 4:
            print("Turning backlight off")
            lcd.backlight_off()
        if count % 10 == 5:
            print("Turning backlight on")
            lcd.backlight_on()
        if count % 10 == 6:
            print("Turning display off")
            lcd.display_off()
        if count % 10 == 7:
            print("Turning display on")
            lcd.display_on()
        if count % 10 == 8:
            print("Filling display")
            lcd.clear()
            string = ""
            for x in range(32, 32 + I2C_NUM_ROWS * I2C_NUM_COLS):
                string += chr(x)
            lcd.putstr(string)
        count += 1
        utime.sleep(2)
from machine import Pin,I2C
from lcd_api import LcdApi
from pico_i2c_lcd import I2cLcd

import utime

sda=machine.Pin(12)
scl=machine.Pin(13)

i2c=machine.I2C(0,sda=sda, scl=scl, freq=400000) # I2C channel 0, pins, 400kHz max
i2c.scan()
print("I2C Address       : "+hex(i2c.scan()[0]).upper()) # Display device address
print("I2C Configuration : "+str(i2c))                   # Display I2C config

lcd = I2cLcd(i2c, I2C_ADDR, I2C_NUM_ROWS, I2C_NUM_COLS)
lcd.clear()

data = []
address = 64

# The status register must be read and then just the valid control bits changed
i2c.writeto(address, b'\xE7')    # Read user register
data = i2c.readfrom(address, 1)  # Get the 1 byte result
##print ("Status register = " '{:08b}'.format(data[0])) # print as a 8 bit binary with leading zeros

if data[0] & (1<<6):
    print ("Supply voltage is under 2.25V")
else:
    print ("Supply voltage is over 2.25V")
Ejemplo n.º 3
0
#m = (5500-4000)/(40-30) = 150
#x = (y-2500)/150 + 20

from lcd_api import LcdApi
from pico_i2c_lcd import I2cLcd
from machine import ADC, Pin, I2C
import time

NUM_ROWS = 2
NUM_COLS = 16
SDA = Pin(0)
SCL = Pin(1)
i2c = I2C(0, sda=SDA, scl=SCL, freq=400000)
#print(i2c.scan())
I2C_ADDR = 0x27
LCD = I2cLcd(i2c, I2C_ADDR, NUM_ROWS, NUM_COLS)

SENSOR_TEMP = ADC(4)
CONVERSION_FACTOR = 3.3 / 65535

ANEMOMETRO = ADC(0)


def main():
    run = True

    while run:
        temp_reading = SENSOR_TEMP.read_u16() * CONVERSION_FACTOR
        temperature = round(37 - (temp_reading - 0.706) / 0.001721, 2)
        LCD.clear()
        LCD.move_to(0, 0)
Ejemplo n.º 4
0
from machine import Pin
import utime as time
from pico_i2c_lcd import I2cLcd
from machine import I2C
from dht import DHT11, InvalidChecksum

i2c = I2C(id=1,scl=Pin(27),sda=Pin(26),freq=100000)
lcd = I2cLcd(i2c, 0x27, 2, 16)

while True:
    time.sleep(1)
    pin = Pin(15, Pin.OUT, Pin.PULL_DOWN)
    sensor = DHT11(pin)
    t  = (sensor.temperature)
    h = (sensor.humidity)
    print("Temperature: {}".format(sensor.temperature))
    print("Humidity: {}".format(sensor.humidity))
    
    time.sleep(1)
    lcd.clear()
    lcd.move_to(0,0)
    lcd.putstr('Temp :')
    lcd.move_to(7,0)
    lcd.putstr(str(t)+" C")
    lcd.move_to(0,1)
    lcd.putstr('Humi :')
    lcd.move_to(7,1)
    lcd.putstr(str(h)+" %")
Ejemplo n.º 5
0
from pico_i2c_lcd import I2cLcd
from machine import I2C
from machine import Pin
import utime as time

i2c = I2C(id=1,scl=Pin(27),sda=Pin(26),freq=100000)
lcd = I2cLcd(i2c, 0x27, 2, 16) # LCD 16x2

while True:
    lcd.move_to(0,0)
    lcd.putstr('Hello World')
Ejemplo n.º 6
0
from pico_i2c_lcd import I2cLcd
from machine import I2C
from machine import Pin
import utime as time

i2c = I2C(id=0, scl=Pin(1), sda=Pin(0), freq=100000)
lcd = I2cLcd(i2c, 0x27, 4, 20)  # LCD 16x2

lcd.putstr('Hello World')
Ejemplo n.º 7
0
from machine import I2C, Pin
from urtc import DS1307
import utime
from pico_i2c_lcd import I2cLcd

i2c_lcd = I2C(id=1,scl=Pin(27),sda=Pin(26),freq=100000)

lcd = I2cLcd(i2c_lcd, 0x27, 2, 16)

i2c_rtc = I2C(0,scl = Pin(1),sda = Pin(0),freq = 400000)
result = I2C.scan(i2c_rtc)
rtc = DS1307(i2c_rtc)

while True:
    (year,month,date,day,hour,minute,second,p1)=rtc.datetime()
    lcd.clear()
    lcd.move_to(0,0)
    lcd.putstr("Time:")
    lcd.move_to(6,0)
    lcd.putstr(str(hour) + ":" + str(minute) + ":" + str(second))
    lcd.move_to(0,1)
    lcd.putstr("Date:")
    lcd.move_to(6,1)
    lcd.putstr(str(date) + "/" + str(month) + "/" + str(year))
    utime.sleep(1)