def __init__(self, scl, sda, address, width, height): import esp8266_i2c_lcd as i2c_lcd self.i2c = machine.I2C( scl=machine.Pin(scl), sda=machine.Pin(sda), freq=400000, ) self.lcd = i2c_lcd.I2cLcd( self.i2c, address, height, width, )
import usocket as socket import utime as time import ubinascii as binascii import ccs811 import bme280 import esp8266_i2c_lcd from machine import I2C, Pin time.sleep(3) i2c = I2C(scl=Pin(2), sda=Pin(4), freq=100000) bme = bme280.BME280(i2c=i2c) ccs = ccs811.CCS811(i2c) lcd = esp8266_i2c_lcd.I2cLcd(i2c, 39, 2, 16) sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) address = ("0.0.0.0", 2003) delay_time = 5 def get_time(): lc = binascii.hexlify(i2c.readfrom_mem(104, 0x00, 7)) lt = (2000 + int(lc[12:14]), int(lc[10:12]), int(lc[8:10]), int(lc[4:6]), int(lc[2:4]), int(lc[0:2]), int(lc[6:8]), 0) return time.mktime(lt) + 946674000 while True: time.sleep(delay_time) lcd.clear() lcd.move_to(2, 0) lcd.putstr('Temperature') lcd.move_to(4, 1)
mySensorBaseAvg = 270 ##REMEMBER TO SET TO ACTUAL VALUE! for x in range(9): mySensorArray1[x] = mySensorBaseAvg for x in range(9): mySensorArray2[x] = mySensorBaseAvg for x in range(9): mySensorArray3[x] = mySensorBaseAvg for x in range(9): mySensorArray4[x] = mySensorBaseAvg for x in range(9): mySensorArray5[x] = mySensorBaseAvg i2c = I2C(scl=Pin(21), sda=Pin(22), freq=400000) lcd = esp8266_i2c_lcd.I2cLcd(i2c, 0x27, 4, 20) lcd.move_to(0, 0) lcd.putstr("Base avg:" + str(mySensorBaseAvg)) sleep_ms(2000) def cycleValues(pickSensor): for x in range(9): pickSensor[x] = pickSensor[x + 1] def connectWifi(ssid, passwd): #function to connect to the Web global wlan #declare a WLAN object lcd.move_to(0, 0) #move LCD cursor to top left corner lcd.putstr("Connect to WLAN") #write the string to the LCD wlan = network.WLAN(network.STA_IF) #create a wlan object wlan.active(True) #Activate the network interface
Course: MicroPython with the ESP32 https://techexplorations.com ''' from machine import I2C, Pin import esp8266_i2c_lcd as esp8266_lcd from time import sleep #DEFAULT_I2C_ADDR = 0x27 i2c = I2C(0) # Using hardware I2C channel 0 lcd = esp8266_lcd.I2cLcd(i2c, esp8266_lcd.DEFAULT_I2C_ADDR, 2, 16) lcd.clear() counter = 0 while True: lcd.move_to(0, 0) lcd.putstr("2x16 LCD demo") lcd.move_to(0, 1) counter = counter + 1 lcd.putstr("Counter: %d" % (counter)) print("Counter: %d" % (counter)) sleep(1)
from machine import I2C, Pin, DAC, PWM import esp8266_i2c_lcd from hcsr04 import HCSR04 import network import socket import random import urequests import machine import json try: #Then, we create some variables and settings sensor = HCSR04(trigger_pin=16, echo_pin=23) #ultrasound sensor implementation i2c = I2C(scl=Pin(21), sda=Pin(22), freq=400000) #settings for LCD lcd = esp8266_i2c_lcd.I2cLcd(i2c, 0x27, 4, 20) #LCD implementation led = Pin(17, Pin.OUT) #create LED object from pin2,Set Pin2 to output myDelay = 50 #define the length of the norse dot - this guides all timing myAdVar = 0 #define the variable that picks the random message #this sets up the array of letters from which the morse code index is found myMorseLetterString = "abdcefghijklmnopqrstuvwxyz.,01234567890!" #this sets up the array of morse code characters myMorseList = [ ".-", "-...", ".-.-", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", ".-", "..-", ".--", "-..-", "-.--", "--..", ".-.-.-", "--..--", "-----", ".----", "..---", "...--", "....-", ".....", "-....", "--...", "---..", "----.", "------", "-.-.--" ] #this sets up the array of advertising messages myAdsList = [