def print_temps_start(self, samp_max=1000, interval=5): sleep_microsec = int(1000 * interval) pause_microsec = 1000 i2c = I2C(scl=Pin(p_I2Cscl_lbl), sda=Pin(p_I2Csda_lbl)) try: lcd = I2cLcd(i2c, 0x27, 2, 16) lcdF = 1 except: lcdF = 0 sample_num = 1 # Start sample number at 0 so we can count the number of samples we take while sample_num <= samp_max: # This will repeat in a loop, until we terminate with a ctrl-c self.ds.convert_temp() # Obtain a temperature reading sleep_ms(pause_microsec) # Sleep for 1 sec print("Sample: ", sample_num, ',', self.ds.read_temp(self.roms[0]), ' C') # print the sample number and temperature print( "\n" ) # Print a line of space between temp readings so it is easier to read if lcdF == 1: lcd.clear() # Sleep for 1 sec lcd.putstr("Sample: " + str(sample_num) + "\nTemp: " + str(round(self.ds.read_temp(self.roms[0]), 2)) + " C") sleep_ms( max(sleep_microsec - pause_microsec, 0) ) # Wait 5 sec, before repeating the loop and taking another reading sample_num += 1 # Increment the sample number for each reading if lcdF == 1: lcd.clear() lcd.putstr("Done!") sleep_ms(2000) lcd.clear()
def test_main(): """Test function for verifying basic functionality.""" print("Running test_main") i2c = I2C(scl=Pin(5), sda=Pin(4), freq=400000) lcd = I2cLcd(i2c, DEFAULT_I2C_ADDR, 2, 16) lcd.putstr("It Works!\nSecond Line") sleep_ms(1000) lcd.clear() count = 0 lcd.clear() # Don't call clear often as it causes screen flash. while True: lcd.move_to(0, 0) t = localtime() # name = '{:04d}_{:02d}_{:02d}_{:02d}_{:02d}_{:02d}'.format(t[0], t[1], t[2], t[3], t[4], t[5]) time = '{:04d}_{:02d}_{:02d}\n{:02d}_{:02d}_{:02d}'.format( t[0], t[1], t[2], t[3], t[4], t[5]) lcd.putstr(time) sleep_ms(50) count += 1 global motion if motion: print('Motion detected! Interrupt caused by:', interrupt_pin) relay.value(1) sleep_ms(500) motion = False relay.value(0)
def setup(temps, sm): i2c = machine.I2C(0, scl=machine.Pin(22), sda=machine.Pin(21)) lcd = I2cLcd(i2c, 39, 2, 16) lcd.clear() r = RotaryIRQ(18, 19, 0, 10, False) menu = ep_lcd_menu.menu_rot_enc(menu_config_file="menu.json", display_type="1602", display=lcd, rotary=r, button_pin=5) menu.display_funcs = { "print_T_Oven": lambda: "{:.2f} C".format(temps("T_Oven")), "print_T_TankU": lambda: "{:.2f} C".format(temps("T_TankU")), "print_T_TankL": lambda: "{:.2f} C".format(temps("T_TankL")), "print_state": lambda: "{}".format(sm.state), "print_cpu_temp": lambda: "{:.2f} C".format((esp32.raw_temperature() - 32) * 5 / 9), "print_ram": lambda: "{:.1f}/{:.1f}kB".format(gc.mem_free() / 1024, (gc.mem_alloc( ) + gc.mem_free()) / 1024), } menu.load() menu.render() return menu
def test_main(): """Test function for verifying basic functionality.""" print("Running test_main") i2c = I2C(scl=Pin(5), sda=Pin(4), freq=400000) lcd = I2cLcd(i2c, DEFAULT_I2C_ADDR, 2, 16) lcd.putstr("It Works!\nSecond Line") sleep_ms(3000) lcd.clear() count = 0 while True: lcd.move_to(0, 0) lcd.putstr("%7d" % (ticks_ms() // 1000)) sleep_ms(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()
def print_light_start(self,samp_max=1000,interval=5): sleep_microsec=int(1000*interval) pause_microsec=1000 i2c = I2C(scl=Pin(p_I2Cscl_lbl),sda=Pin(p_I2Csda_lbl)) try: lcd = I2cLcd(i2c, 0x27,2,16) lcdF = 1 except: lcdF = 0 sample_num=1 # Start sample number at 0 so we can count the number of samples we take while sample_num <= samp_max: # This will repeat in a loop, until we terminate with a ctrl-c full, ir, lux = self.sensor.light() # Obtain a distance reading sleep_ms(pause_microsec) # Sleep for 1 sec print("Sample: ",sample_num, ', full: ',str(full),' ir: ',str(ir)) # print the sample number and distance print("\n") # Print a line of space between temp readings so it is easier to read if lcdF ==1: lcd.clear() # Sleep for 1 sec lcd.putstr("# "+str(sample_num)+': '+str(round(lux,1))+' lux\n('+str(full)+','+str(ir)+')') sleep_ms(max(sleep_microsec-pause_microsec,0)) # Wait 5 sec, before repeating the loop and taking another reading sample_num+=1 # Increment the sample number for each reading if lcdF == 1: lcd.clear() lcd.putstr("Done!") sleep_ms(2000) lcd.clear()
def print_GPSs_start(self,samp_max=1000,interval=5): sleep_microsec=int(1000*interval) pause_microsec=1000 i2c = I2C(scl=Pin(p_I2Cscl_lbl),sda=Pin(p_I2Csda_lbl)) try: lcd = I2cLcd(i2c, 0x27,2,16) lcdF = 1 except: lcdF = 0 sample_num=1 # Start sample number at 0 so we can count the number of samples we take while sample_num <= samp_max: # This will repeat in a loop, until we terminate with a ctrl-c (date,timestamp,dec_lat,dec_long) = self.print_GPS(display=False) print("Sample: ",sample_num,', ',date,', ',timestamp,', ',dec_lat,', ',dec_long) # print the sample number and temperature print("\n") # Print a line of space between temp readings so it is easier to read if lcdF ==1: lcd.clear() # Sleep for 1 sec GPSstr3='#{} {},{}'.format(sample_num,dec_lat,dec_long) lcd.putstr(GPSstr3) #lcd.putstr("Sample: "+str(sample_num)+"\nTemp: "+str(round(self.ds.read_GPS(self.roms[0]),2))+" C") sleep_ms(max(sleep_microsec-pause_microsec,0)) # Wait 5 sec, before repeating the loop and taking another reading sample_num+=1 # Increment the sample number for each reading if lcdF == 1: lcd.clear() lcd.putstr("Done!") sleep_ms(2000) lcd.clear()
def test_main(): """Test function for verifying basic functionality.""" print("Running test_main") i2c = I2C(scl=scl, sda=sda, freq=400000) scan = i2c.scan() addr = scan[0] lcd = I2cLcd(i2c, addr, 2, 16) lcd.putstr("It Works!\nSecond Line")
def onDisplay(topic, msg): i2c = I2C(scl=Pin(5), sda=Pin(4), freq=100000) #i2c.scan() lcd = I2cLcd(i2c,63, 2, 16) lcd.clear() lcd.putstr(msg.decode('ascii')) time.sleep(5) lcd.clear()
def main(): global sensor # use a global variable to fix global vs. local namespace issues activeNames, activeFuncs, sensors = [[] for i in range(3)] # Lists for when we are going to use multiple sensors sensorFuncs = {'light': 'light', 'distance': 'dist', 'temperature': 'temp', 'GPS': 'GPS'} for sensr in ['GPS','distance','light','temperature']: # lets try talking to all the sensors try: activeName = sensr activeFunc = sensorFuncs[sensr] exec('import read_'+activeFunc) sensor = eval('read_'+activeFunc+'.read_'+activeFunc+'()') sleep(1) print('success: queuing sensor driver ',activeFunc) exec('sTest = sensor.test_'+activeFunc+'()') if sTest: activeNames.append(activeName) activeFuncs.append(activeFunc) sensors.append(sensor) print('success: able to make measurement using ',activeFunc) else: print('Error: unable to connect to ',activeFunc, ' sensor') except: print('Error: sensor driver ',activeFunc,' was requested but failed to load') if asFlag ==1: activeList = [s for s in [item for item in dir(active_sensors) if not item.startswith("__")] if eval('active_sensors.'+s) == 1] activeNamesMeasure = [k for k in activeList if (k inactive Names) and (k in activeList)] # check which from the active list work activeIndex = [activeNames.index(k) for k in activeNamesMeasure] # get the index of the active & good sensors activeFuncs = [activeFuncs[k] for k in activeIndex] # use the index to get the good and active funcs sensors = [sensors[k] for k in activeIndex] # get the good and active sensor objects else: # if no active_sensors, use all the sensors found and the original lists as above activeNamesMeasure = activeNames try: i2c = I2C(scl=Pin(p_I2Cscl_lbl),sda=Pin(p_I2Csda_lbl)) lcd = I2cLcd(i2c, 0x27,2,16) lcd.clear() lcd.scrollstr('Found the following sensors: '+', '.join(activeNames)) lcd.clear() lcd.scrollstr('Preparing to measure: '+', '.join(activeNamesMeasure)) lcd.clear() lcd.putstr("Ready!\n"+chr(0)+'Listo!') i=0 while True: first = button.value() sleep(0.01) second = button.value() if first and not second: sensor=sensors[i] exec('sensor.print_'+activeFuncs[i]+'()') i = (i+1) % len(activeNamesMeasure) elif not first and second: pass except Exception as e: print_exception(e) print('LCD not registered...')
def print_light(self): i2c = I2C(scl=Pin(p_I2Cscl_lbl),sda=Pin(p_I2Csda_lbl)) try: lcd = I2cLcd(i2c, 0x27,2,16) lcdF = 1 except: lcdF = 0 full, ir, lux = self.sensor.light() print('full: ',str(full),' ir: ',str(ir)) if lcdF == 1: lcd.clear() # Sleep for 1 sec lcd.putstr(str(round(lux,1))+' lux\n('+str(full)+','+str(ir)+')')
def print_GPS(self,display=True, pr=1): i2c = I2C(scl=Pin(p_I2Cscl_lbl),sda=Pin(p_I2Csda_lbl)) try: lcd = I2cLcd(i2c, 0x27,2,16) lcdF = 1 except: lcdF = 0 # Create a loop to obtain several sentences from the GPS, to make sure # all relevant fields in the parser are populated with recent data sentence_count = 0 while True: if uartGPS.any(): stat = self.my_gps.update(chr(uartGPS.readchar())) if stat: print(stat) stat = None sentence_count += 1 if sentence_count == self.num_sentences: # have necessary fixes, output data and return # calculate decimal lat and long dec_lat=self.my_gps.latitude[0]+self.my_gps.latitude[1]/60 if self.my_gps.latitude[2]=="S": # correction for southern hemisphere dec_lat=-dec_lat dec_long=self.my_gps.longitude[0]+self.my_gps.longitude[1]/60 if self.my_gps.longitude[2]=="W": # correction for western hemisphere dec_long=-dec_long if not display: # if False, return GPS data instead of displaying it return (self.my_gps.date,self.my_gps.timestamp,dec_lat,dec_long) #print('UTC Timestamp:', self.my_gps.timestamp) #print('Date:', self.my_gps.date_string('long')) #print('Latitude:', self.my_gps.latitude_string()) #print('Longitude:', self.my_gps.longitude_string()) #print('Altitude:', self.my_gps.altitude)#_string()) #print('Speed:', self.my_gps.speed_string()) #print('Compass direction:', self.my_gps.compass_direction()) #print('Course:', self.my_gps.course)#_string()) #print('Horizontal Dilution of Precision:', self.my_gps.hdop) #print() GPSstr='GPS: {}-{}-{} {}:{}:{} {},{}'.format(self.my_gps.date[0],self.my_gps.date[1],self.my_gps.date[2], \ self.my_gps.timestamp[0],self.my_gps.timestamp[1],self.my_gps.timestamp[2], \ dec_lat,dec_long) print(GPSstr) #print('GPS: {} {} {} {}'.format(self.my_gps.timestamp,self.my_gps.date,self.my_gps.latitude,self.my_gps.longitude)) if lcdF == 1 & pr==1: lcd.clear() # Sleep for 1 sec #GPSstr2='GPS: {}:{}:{} {},{}'.format(self.my_gps.timestamp[0],self.my_gps.timestamp[1], \ # self.my_gps.timestamp[2],dec_lat,dec_long) GPSstr2='GPS: {},\n {}'.format(dec_lat,dec_long) lcd.putstr(GPSstr2) #lcd.putstr('GPS: {} {} {} {}'.format(self.my_gps.timestamp,self.my_gps.date,dec_lat,dec_long)) break;
def print_dist(self): i2c = I2C(scl=Pin(p_I2Cscl_lbl), sda=Pin(p_I2Csda_lbl)) try: lcd = I2cLcd(i2c, 0x27, 2, 16) lcdF = 1 except: lcdF = 0 dist = self.sensor.distance() print(str(dist) + " cm") if lcdF == 1: lcd.clear() # Sleep for 1 sec lcd.putstr(str(dist) + " cm")
def scroll(long_string): i2c = I2C(scl=Pin(5), sda=Pin(4), freq=400000) lcd = I2cLcd(i2c, 0x3F, 2, 16) framebuffer1 = 'Message:' sleep_ms(2000) lcd.clear() # long_string = 'This string is too long to fit 1 1 Hello!' for i in range(len(long_string) - 16 + 1): framebuffer = (framebuffer1 + '\n' + long_string[i:i + 16]) lcd.clear() lcd.putstr(framebuffer) sleep_ms(300) lcd.clear()
def mess(long_string): i2c = I2C(scl=Pin(5), sda=Pin(4), freq=400000) lcd = I2cLcd(i2c, 0x3F, 2, 16) lcd.putstr(" New\n Message:") framebuffer1 = 'Message:' sleep_ms(2000) lcd.clear() framebuffer = (framebuffer1 + '\n' + long_string) lcd.putstr(framebuffer) for i in range(len(long_string) - 16 + 1): lcd.clear() framebuffer = (framebuffer1 + '\n' + long_string[i:i + 16]) lcd.putstr(framebuffer) sleep_ms(300)
def __init__(self, size_x=20, size_y=4): self.size_x = size_x self.size_y = size_y lcd = I2cLcd(I2C(0, scl=Pin(18), sda=Pin(19), freq=I2C_FREQ), 0x27, 4, 20) lcd.clear() lcd.backlight_on() self.lcd = lcd self.throttle_max = 1 self.throttle_min = 255 self.phase_amps_max = 10 self.phase_amps_max = 10 self._spinner = self._spinner_iter() self._draw_count = 0 self._braking = 0
def hardware_setup(): lcd_address = 0x27 lcd_cols = 40 lcd_row = 4 # Set up LCD i2c = I2C(scl=Pin(5), sda=Pin(2), freq=100000) lcd = I2cLcd(i2c, 0x27, 4, 40) lcd.clear() # set up DHT11 dht_sensor = dht.DHT11(machine.Pin(27)) # Set up c02 c02_sensor = c02.C02_sensor(36) # Set up pm2.2 pm25_sensor = pm25.PM25_sensor(25, 26) return (lcd, dht_sensor, c02_sensor, pm25_sensor)
def lcd_paint(): I2C_FREQ = 400000 lcd = I2cLcd(I2C(0, scl=Pin(18), sda=Pin(19), freq=I2C_FREQ), 0x27, 4, 20) lcd.clear() lcd.backlight_on() start = time.ticks_ms() for n in range(200): lcd.move_to(0, 0) lcd.putstr("x" * 20) lcd.move_to(0, 1) lcd.putstr("x" * 20) lcd.move_to(0, 2) lcd.putstr("x" * 20) lcd.move_to(0, 3) lcd.putstr("{}".format(n)) elapsed = time.ticks_diff(time.ticks_ms(), start) / 1000 print("{}".format(elapsed))
def write_to_lcd(msg=["Hello LCD"]): from machine import I2C scl = machine.Pin(2) sda = machine.Pin(5) i2c = I2C(scl=scl, sda=sda, freq=400000) # find out the address of the device devices = i2c.scan() if len(devices) == 0: print("no i2c device") else: print("i2c devices found: ", len(devices)) for device in devices: print("Decimal address: ", device, " | Hexa address: ", hex(device)) lcd = I2cLcd(i2c, 0x3f, 4, 20) lcd.putstr("\n".join(msg))
def main(): freq = 0 i2c = I2C(scl=Pin(5), sda=Pin(4), freq=100000) adc = ADC(0) lcd = I2cLcd(i2c, 0x27, 2, 16) lcd.putstr("starting\nproject") time.sleep(2) lcd.clear() s = socket.socket() ai = socket.getaddrinfo("0.0.0.0", 80) addr = ai[0][-1] s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) s.bind(addr) s.listen(5) lcd.putstr("Listening:80\n") ''' while True: res = s.accept() client_sock = res[0] client_addr = res[1] print("Client address:", client_addr) lcd.putstr("%s" % client_addr[0]) print("Client socket:", client_sock) client_stream = client_sock while True: data = input() print("to send data", data) client_stream.write(data) client_stream.close() ''' while True: conn, addr = s.accept() print('Connected by', addr) while True: lcd.clear() freq = int(input()) val = adc.read_u16() lcd.putstr("%s\n%s" % (val, freq)) print('data', val) try: conn.sendall(("%s,%s\r\n" % (val, freq)).encode()) except Exception as e: print('exception', e) break time.sleep_ms(20)
def setup(): i2c = machine.I2C(0, scl=machine.Pin(22), sda=machine.Pin(21)) lcd = I2cLcd(i2c, 39, 2, 16) lcd.clear() r = RotaryIRQ(18, 19, 0, 10, False) menu = ep_lcd_menu.menu_rot_enc(menu_config_file="menu.json", display_type="1602", display=lcd, rotary=r, button_pin=5) menu.load() menu.render() return menu
def print_temp(self): i2c = I2C(scl=Pin(p_I2Cscl_lbl), sda=Pin(p_I2Csda_lbl)) try: lcd = I2cLcd(i2c, 0x27, 2, 16) lcdF = 1 except: lcdF = 0 self.ds.convert_temp( ) # Obtain temp readings from each of those sensors sleep_ms( 750 ) # Sleep for 750 ms, to give the sensors enough time to report their temperature readings print("Temp: ", self.ds.read_temp(self.roms[0]), ' C') if lcdF == 1: lcd.clear() # Sleep for 1 sec lcd.putstr("Temp: " + str(round(self.ds.read_temp(self.roms[0]), 2)) + " C")
def __init__(self): self.lcd = None self.lcd_light = True self.servo = None self.servo_pin = None self.display = None self.adc = None self.button = None self.thermometer = None if int(utils.get_config("servo_pin", -1)) > -1: self.servo_pin = Pin(int(utils.get_config("servo_pin", 4))) self.servo = PWM(self.servo_pin, freq=50) self.servo.duty(20) self.servo.duty( utils.map_temp_to_servo( int(utils.get_config("piec_temperatura", 40)))) del self.servo if int(utils.get_config("lcd_sda_pin", -1)) > -1: from esp8266_i2c_lcd import I2cLcd self.i2c = SoftI2C(scl=Pin(int(utils.get_config("lcd_scl_pin", -1))), sda=Pin(int(utils.get_config("lcd_sda_pin", -1))), freq=100000) self.lcd = I2cLcd(self.i2c, 0x27, 2, 16) self.lcd_wifi_chars(self.lcd) self.lcd.hide_cursor() self.lcd.clear() if int(utils.get_config("button_pin", -1)) > -1: self.button = Pin(int(utils.get_config("button_pin", 5)), Pin.IN, Pin.PULL_UP) if int(utils.get_config("adc_pin", -1)) > -1: if sys.platform == "esp8266": self.adc = ADC(int(utils.get_config("adc_pin", 0))) elif sys.platform == "esp32": self.adc = ADC(Pin(int(utils.get_config("adc_pin", 2)))) self.adc.atten(ADC.ATTN_11DB) self.adc.width(ADC.WIDTH_10BIT) if int(utils.get_config("thermometer_pin", -1)) > -1: import sensors self.thermometer = sensors.Sensory()
def test_main(): """Test function for verifying basic functionality.""" print("Running test_main") i2c = I2C(scl=Pin(4), sda=Pin(5), freq=400000) lcd = I2cLcd(i2c, DEFAULT_I2C_ADDR, 4, 20) lcd.clear() lcd.putstr( "1234567890123456789\n2234567890123456789\n3234567890123456789\n4234567890123456789" ) sleep_ms(1000) lcd.clear() lcd.move_to(0, 0) lcd.putstr("12345678901234567890") lcd.move_to(0, 1) lcd.putstr("22345678901234567890") lcd.move_to(0, 2) lcd.putstr("32345678901234567890") lcd.move_to(0, 3) lcd.putstr("42345678901234567890")
def __init__(self, name, sda=None, scl=None, width=16, height=2, addr=0x27): self.present = False self.last_text = "" self.char_width = width self.char_height = height self.display_buffer = bytearray(b" " * width * height) self.back_buffer = bytearray(b" " * width * height) self.x = 0 self.y = 0 if type(sda) is I2C: i2c = sda else: i2c = I2C(sda=sda, scl=scl) # test if lcd is responding try: self.dp = I2cLcd(i2c, addr, height, width) self.dp.clear() self.clear() self.hide_cursor() self.println("iot.ulno.net") except OSError: print("lcd not found") else: self.present = True Device.__init__(self, name, i2c, setters={"set": self.evaluate}, report_change=False) self.getters[""] = self.value
def __init__(self): self.temps = ['-', '-'] self.status = 'OFF' self.on = self.status self.DEFAULT_I2C_ADDR = 0x3f self.i2c = I2C(scl=Pin(13), sda=Pin(27), freq=400000) self.lcd = I2cLcd(self.i2c, self.DEFAULT_I2C_ADDR, 2, 16) self.aste = [0xe, 0xa, 0xe, 0x0, 0x0, 0x0, 0x0, 0x0] self.lcd.custom_char(0, bytearray(self.aste)) self.lcd.clear() self.lcd.move_to(0, 0) self.lcd.putstr("in ") self.lcd.putstr(self.temps[0]) self.lcd.putchar(chr(0)) self.lcd.putstr("C") self.lcd.move_to(0, 1) self.lcd.putstr("out ") self.lcd.putstr(self.temps[1]) self.lcd.putchar(chr(0)) self.lcd.putstr("C") self.lcd.move_to(13, 0) self.lcd.putstr(self.on) loop = asyncio.get_event_loop() loop.create_task(self.run())
from machine import Pin, I2C from time import sleep import dht from esp8266_i2c_lcd import I2cLcd i2c = I2C(scl=Pin(5), sda=Pin(4), freq=400000) lcd = I2cLcd(i2c, 0x27, 2, 16) d = dht.DHT11(Pin(0)) while 1: lcd.hide_cursor() lcd.putstr("**Pitias Home**\nTemp & Humidity") # 16 characters sleep(1) lcd.clear() sleep(2) d.measure() lcd.putstr("Temperature :") lcd.putstr(str(d.temperature())) # eg. 23 (°C) lcd.putstr("C") sleep(1) lcd.putstr("Humidity :") lcd.putstr(str(d.humidity())) # eg. 41 (% RH) lcd.putstr("% RH") sleep(4) lcd.clear()
def __init__(self): self.i2c = I2C(scl=Pin(5), sda=Pin(4), freq=400000) self.lcd = I2cLcd(self.i2c, addr, 2, 16)
import time from machine import Pin,I2C from esp8266_i2c_lcd import I2cLcd DEFAULT_I2C_ADDR = 0x27 i2c = I2C(scl=Pin(018), sda=Pin(05), freq=400000) lcd = I2cLcd(i2c, DEFAULT_I2C_ADDR, 2, 16) a='' b='' c='' d=0 r1=[1,2,3,'a'] r2=[4,5,6,'b'] r3=[7,8,9,'c'] r4=['*',0,'#','d'] dx={'a':'+','b':'-','c':'x','d':'/'} zx='' m=False while 1: o1=Pin(26,Pin.OUT) o2=Pin(25,Pin.OUT) o3=Pin(33,Pin.OUT) o4=Pin(32,Pin.OUT) v1=Pin(13,Pin.IN,Pin.PULL_UP) v2=Pin(12,Pin.IN,Pin.PULL_UP) v3=Pin(14,Pin.IN,Pin.PULL_UP) v4=Pin(27,Pin.IN,Pin.PULL_UP) if not v1.value()&v2.value()&v3.value()&v4.value(): if v1.value()==0: v1o=Pin(13,Pin.OUT) o1=Pin(26,Pin.IN,Pin.PULL_UP) o2=Pin(25,Pin.IN,Pin.PULL_UP)
# Meteo basic import machine,bme280 from machine import I2C from esp8266_i2c_lcd import I2cLcd from ntptime import settime settime() ## Ajusta el tiempo rtc = machine.RTC() i2c = machine.I2C(scl=machine.Pin(5), sda=machine.Pin(4)) i2c.scan() ## [63, 118] bme = bme280.BME280(i2c=i2c) lcd = I2cLcd(i2c, 63, 2, 16) lcd.move_to(0, 0) lcd.putstr(bme.values[0]) lcd.move_to(0, 1) lcd.putstr(bme.values[1]) lcd.move_to(10, 0) lcd.putstr(bme.values[2]) (year, month, mday, hour, minute, second, weekday, yearday) = utime.localtime() lcd.move_to(10,1) if hour < 10 : lcd.putsrt('0') lcd.putsrt(':')
#Importaciones para Wifi try: import usocket as socket except: import socket from machine import Pin import network from time import sleep # para pantalla lcd from machine import I2C, Pin from esp8266_i2c_lcd import I2cLcd temp = I2C(scl=Pin(5), sda=Pin(4), freq=400000) lcd = I2cLcd(temp, 0x27, 2, 16) lcd.backlight_off() lcd.clear() import esp esp.osdebug(None) import gc gc.collect() ssid = 'TIGO-8A6E' password = '******' station = network.WLAN(network.STA_IF) station.active(True) station.connect(ssid, password)