def main():
    """Main function."""

    print("main_test(): start")

    micropython.alloc_emergency_exception_buf(100)

    ## Create the LCD instance.
    i2c = I2C(1, I2C.MASTER)
    lcd = I2cLcd(i2c, 0x27, 4, 20)

    ## Create the keypad instance.
    keypad = Keypad_uasyncio(queue_size=4, start=True)

    ## Get a handle to the asyncio event loop.
    loop = asyncio.get_event_loop()

    ## Add the keypad scanning and keypad watcher coroutines.
    loop.create_task(keypad.scan_coro())
    loop.create_task(keypad_lcd_task(lcd=lcd, keypad=keypad))

    ## Start running the coroutines
    loop.run_forever()

    print("main_test(): end")
示例#2
0
def test_main():
    """Test function for verifying basic functionality."""
    print("Running test_main")
    i2c = I2C(1, I2C.MASTER)
    lcd = I2cLcd(i2c, 0x27, 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()
示例#3
0
import time
from pyb import Pin, I2C, ADC
import dht

from pyb_i2c_lcd import I2cLcd
from PH_Monitor import PH_Monitor

LCD_ADDRESS = 0x27

pump_1 = Pin('Y9', mode=Pin.OUT_PP)
pump_2 = Pin('Y10', mode=Pin.OUT_PP)

button_pin = ADC('X11')
ph_pin = ADC('X7')

d_temp_humid = dht.DHT22(Pin('X6'))

i2c = I2C(1, I2C.MASTER)
lcd = I2cLcd(i2c, LCD_ADDRESS, 2, 16)

ph_monitor = PH_Monitor(ph_pin, button_pin, pump_1, pump_2, d_temp_humid, lcd)

ph_monitor.loop()
# main.py -- put your code here!
import pyb  # Clase que contiene la conf de la pyboard
import dht  # Clase que contiene la conf del sensor DHT11
from pyb import I2C, delay, millis  # importa conf de I2C , delay, millis
from lcd_api import LcdApi  # Clase que contiene las funciones del LCD
from pyb_i2c_lcd import I2cLcd  # Clase que contiene la conf del LCD con conversor I2C

DEFAULT_I2C_ADDR = 0x27  # Direccion por defecto del LCD 0x27 se puede cambiar con jumpers desde 0x20 a 0x27
PX1 = pyb.Pin(
    pyb.Pin.board.X1,
    pyb.Pin.IN)  # Conectar DHT11 al pin X1 configurando este como entrada
d = dht.DHT11(PX1)  # instantacion del pin X1 en el sensor DHT11
i2c = I2C(1, I2C.MASTER
          )  # Crea un puerto llamado i2c en el I2C numero 1 de la pyb_i2c_lcd
lcd = I2cLcd(
    i2c, DEFAULT_I2C_ADDR, 2,
    16)  # Instantacion del i2c a un display lcd 16x2 en la direccion 0x27
#lcd.move_to(0, 0)
#lcd.putstr("%7d" % (millis() // 1000))
while True:
    d.measure()  # actualiza mediciones desde el DHT11
    DT = d.temperature(
    )  # eg. 23 (°C)							# guarda en DT la temperatura en grados celcuis medida como entero
    DH = d.humidity(
    )  # eg. 41 (% RH)							# guarda en DH la humedad relativa en % de humedad medida cmo entero
    print("la temperatura es:", DT, "y  la humedad:",
          DH)  # imprime en el terminal serial el texto
    lcd.move_to(0, 0)  # ubica display en la columna 0 fila 0 el cursor
    lcd.putstr("Temperatura = %d" % DT)  # imprime texto en el display
    lcd.move_to(0, 1)  # ubica display en la columna 0 fila 1 el cursor
    lcd.putstr("Humedad = %d" % DH)  # imprime texto en el display
示例#5
0
## SETUP PWM
# Pulse width modulation
pwm_pin = Pin('Y4')
tim = Timer(4, freq=100)
ch = tim.channel(4, Timer.PWM, pin=pwm_pin)
ch.pulse_width_percent(0)

## SETUP FAN CONTROL

fans_pin = Pin('Y3', mode=Pin.OUT_PP)
fans_pin.low()

## SETUP LCD
lcd_address = 0x3F
i2c = I2C(1, I2C.MASTER)
lcd = I2cLcd(i2c, lcd_address, 2, 16)

## SETUP RELAY
# Also not currently in use, but doesn't do any harm.
relay_1 = Pin('X11', mode=Pin.OUT_PP)
relay_2 = Pin('X12', mode=Pin.OUT_PP)

## SETUP STATE MACHINE
alta = ALTA(ptd, inner, ch, ldr_pin, lcd, fans_pin, relay_1, relay_2)

filepath = 'data/'

# WRITE ANY CODE YOU WANT TO EXECUTE ON TURNING THE PYBOARD ON HERE

#alta.linear_experiment(filepath)