#hardware platform:FireBeetle-ESP32 from machine import Pin, I2C import time i2c = I2C(scl=Pin(22), sda=Pin(21), freq=10000) #create I2C object,init Pin and frequency b = bytearray("dfrobot") #create a array i2c.writeto_mem(0x50, 0, b, addrsize=16) #Write b to the slave specified by 0x50 starting #from the memory address specified by 0, The addrsize is 16 time.sleep(0.1) print( i2c.readfrom_mem(0x50, 0, 7, addrsize=16) ) #Read 7 bytes from the slave specified by 0x50 starting from the memory address specified by 0. #The addrsize specifies the address size in bits. Returns a bytes object with the data read.
''' 实验名称:光敏传感器 版本:v1.0 日期:2019.8 作者:01Studio 【www.01Studio.org】 说明:通过光敏传感器对外界环境光照强度测量并显示。 ''' #导入相关模块 from machine import Pin, I2C, ADC, Timer from ssd1306 import SSD1306_I2C #初始化相关模块 i2c = I2C(sda=Pin(13), scl=Pin(14)) oled = SSD1306_I2C(128, 64, i2c, addr=0x3c) #初始化ADC,Pin=36,11DB衰减,测量电压0-3.3V Light = ADC(Pin(32)) Light.atten(ADC.ATTN_11DB) #中断回调函数 def fun(tim): oled.fill(0) # 清屏显示黑色背景 oled.text('01Studio', 0, 0) # 首行显示01Studio oled.text('Light test:', 0, 15) # 次行显示实验名称 value = Light.read() #获取ADC数值
def do_menu(): global module_name """ btnLeft = Pin(12, Pin.IN, Pin.PULL_UP) btnRight = Pin(13, Pin.IN, Pin.PULL_UP) btnUp = Pin(14, Pin.IN, Pin.PULL_UP) btnDown = Pin(2, Pin.IN, Pin.PULL_UP) """ btnLeft = Pin(13, Pin.IN, Pin.PULL_UP) btnRight = Pin(14, Pin.IN, Pin.PULL_UP) btnUp = Pin(15, Pin.IN, Pin.PULL_UP) btnDown = Pin(18, Pin.IN, Pin.PULL_UP) import ssd1306 # configure oled display I2C SSD1306 i2c = I2C(-1, Pin(5), Pin(4)) # SCL, SDA display = ssd1306.SSD1306_I2C(128, 64, i2c) SKIP_NAMES = ("boot", "main", "menu") files = [item[0] for item in os.ilistdir(".") if item[1] == 0x8000] # print("Files: %r" % files) module_names = [ filename.rsplit(".", 1)[0] for filename in files if (filename.endswith(".py") or filename.endswith(".mpy")) and not filename.startswith("_") ] module_names = [ module_name for module_name in module_names if not module_name in SKIP_NAMES ] module_names.sort() tot_file = len(module_names) tot_rows = const(5) screen_pos = 0 file_pos = 0 launched = False while not launched: gc.collect() display.fill(0) display.text(sys.platform + " " + str(gc.mem_free()), 5, 0, 1) i = 0 for j in range(file_pos, min(file_pos + tot_rows, tot_file)): current_row = 12 + 10 * i if i == screen_pos: display.fill_rect(5, current_row, 118, 10, 1) display.text(str(j) + " " + module_names[j], 5, current_row, 0) else: display.fill_rect(5, current_row, 118, 10, 0) display.text(str(j) + " " + module_names[j], 5, current_row, 1) i += 1 if pressed(btnUp): if screen_pos > 0: screen_pos -= 1 else: if file_pos > 0: file_pos = max(0, file_pos - tot_rows) screen_pos = tot_rows - 1 if pressed(btnDown): if screen_pos < min(tot_file - file_pos - 1, tot_rows - 1): screen_pos = min(tot_file - 1, screen_pos + 1) else: if file_pos + tot_rows < tot_file: file_pos = min(tot_file, file_pos + tot_rows) screen_pos = 0 if pressed(btnRight): display.fill(0) display.text("launching ", 5, 20, 1) display.text(module_names[file_pos + screen_pos], 5, 40, 1) display.show() sleep_ms(1000) module_name = module_names[file_pos + screen_pos] return True if pressed(btnLeft): launched = True display.fill(0) display.text("exited ", 5, 24, 1) display.show() return False display.show()
#This is the class file for the LIS3DH Accelerometer import machine import time from machine import Pin, I2C i2c = I2C(scl=Pin(5), sda=Pin(4), freq=100000) #REGISTER ADDRESESS OUT_X_L = 0x28 OUT_X_H = 0x29 OUT_Y_L = 0x2A OUT_Y_H = 0x2B OUT_Z_L = 0x2C OUT_Z_H = 0x2D CTRL_REG1 = 0x20 CTRL_REG4 = 0x23 #CONFIGURATION BYTES CONFIG1 = 0x27 CONFIG4 = 0x00 class lis3dh: # Class Constructor and Configuration def __init__(self, i2c, i2cAddress): self.i2c = i2c self.i2cAddress = i2cAddress self.i2c.writeto_mem(self.i2cAddress, CTRL_REG1, bytearray([CONFIG1])) self.i2c.writeto_mem(self.i2cAddress, CTRL_REG4, bytearray([CONFIG4])) time.sleep(0.5)
tp = [None, None, None, None] calibrate = [1000, 1000, 1000, 1000] # init value - will be lower margin = const(-30) # margin between no touch and touch LEDS = const(48) segment_wait = const(30) last_state = [None, None, None, None] rings = [{0, 11}, {12, 23}, {24, 35}, {36, 47}] RED = (128, 0, 0) GREEN = (0, 32, 0) BLUE = (0, 0, 32) np = NeoPixel(Pin(neo_pin), LEDS) for i in range(4): tp[i] = TouchPad(Pin(touch_pins[i])) i2c = I2C(0, scl=Pin(22), sda=Pin(21), freq=400000) lcd = LCD2004(i2c, addr=39) # take many readings to get an average of no touch readings def do_calibrate(t_channel, np): cycles = 48 cul = 0 for i in range(cycles): cul += t_channel.read() if i < LEDS: np[i] = BLUE np.write() uasyncio.sleep_ms(segment_wait) uasyncio.sleep_ms(800) # just so wee can see all the LEDs lit up return int(cul / cycles)
# copy this to shell on pico import urtc from machine import Pin, I2C sdapin = Pin(14) sclpin = Pin(15) i2c = I2C(1, sda=sdapin, scl=sclpin, freq=400000) rtc = urtc.DS3231(i2c) # year, month, day, day of week (mon = 0), hour, min, sec rtc.datetime([2021, 6, 7, 0, 15, 54, 00])
# history: # V1.1 add oled draw function,add buzz.freq(). by tangliufeng # V1.2 add servo/ui class,by tangliufeng from machine import I2C, PWM, Pin, ADC, TouchPad, UART from ssd1106 import SSD1106_I2C import esp, math, time, network,audio import ustruct, array, ujson from neopixel import NeoPixel from esp import dht_readinto from time import sleep_ms, sleep_us, sleep from framebuf import FrameBuffer import motion_mpu6050 from mpython_classroom_kit_driver import BS8112A,Es8388 i2c = I2C(scl=Pin(Pin.P19), sda=Pin(Pin.P20), freq=400000) bs8112a = BS8112A(i2c) es8388 = Es8388(i2c) class Font(object): def __init__(self, font_address=0x400000): self.font_address = font_address buffer = bytearray(18) esp.flash_read(self.font_address, buffer) self.header, \ self.height, \ self.width, \ self.baseline, \ self.x_height, \
from machine import I2C, Pin, reset from time import sleep_ms import uctypes bus = I2C(scl=Pin(5), sda=Pin(2), freq=100000) def send_raw_data(chipid, buf): chip_addr = 0x74 + chipid try: bus.writeto(chip_addr, buf) except: print('Erorr durring write on I2C bus...') def get_raw_data(chipid, buf): send_raw_data(chipid, buf) sleep_ms(10) chip_addr = 0x74 + chipid buf = bytearray(b'\x00' * 35) try: bus.readfrom_into(chip_addr, buf) #from ubinascii import hexlify #print ('\nMCP39F521 returns following data:') #print (hexlify(buf, b":"))
from machine import I2C import time import sht31 i2c = I2C(0, I2C.MASTER, baudrate=100000) s31 = sht31.SHT31(i2c) while (True): data = s31.get_temp_humi(celsius=True) print(data) time.sleep(1)
def _config(self): #Relay self.relay_setup() #MQTT from mqttse import MQTTClient self.mqtt = MQTTClient(client_id) # "local1": "192.168.100.240", # "local2": "192.168.254.1", # "eclipse": "iot.eclipse.org" self.mqtt.server = "192.168.100.240" self.mqtt.set_callback(self.mqtt_sub_cb) self.mqtt.set_topic("status", "status") self.mqtt.set_topic("services", "services") self.mqtt.set_topic("sw1_set", "sw1/set") self.mqtt.set_topic("sw1_state", "sw1/state") self.mqtt.set_topic("sw2_set", "sw2/set") self.mqtt.set_topic("sw2_state", "sw2/state") #i2c # esp32i2cPins = {'sda': 23, 'scl': 22} # sclPin = esp32i2cPins['scl'] # sdaPin = esp32i2cPins['sda'] i2c = I2C(scl=Pin(22), sda=Pin(23)) #si7021 from si7021 import SI7021 self.s_si = SI7021(i2c) self.s_si.read_delay = 30 self.s_si.sensor_detect() self.s_si.start() self.mqtt.set_topic("si_t", "si/temperature") self.mqtt.set_topic("si_h", "si/humidity") self.s_si.set_callback(self.s_si_cb) #bmp180 from bmp180 import BMP180 self.s_bmp = BMP180(i2c) self.s_bmp.read_delay = 30 self.s_bmp.sensor_detect() self.s_bmp.start() self.mqtt.set_topic("bmp_t", "bmp/temperature") self.mqtt.set_topic("bmp_h", "bmp/pressure") self.mqtt.set_topic("bmp_a", "bmp/altitude") self.s_bmp.set_callback(self.s_bmp_cb) #http from httpse import HTTPSE from httpse.route_system import SystemHandler from httpse.route_led import LedHandler _routeHandlers = [] _routeHandlers.append(SystemHandler().route_handler) _routeHandlers.append(LedHandler(relay=self.sw_1).route_handler) self.http = HTTPSE(route_handlers=_routeHandlers)
import machine, onewire, ds18x20, json #display ,0 hh:mm 25.4C xxxx #display ,1 W:ok*R12#RG v3.9 #display ,1 W:no*R12 v3.9 # Create new modem object on the right Pins modem = SIM800L.Modem(MODEM_PWKEY_PIN=4, MODEM_RST_PIN=5, MODEM_POWER_ON_PIN=23, MODEM_TX_PIN=16, MODEM_RX_PIN=17) # ESP32 Pin Layout led = Pin(2, Pin.OUT, value=0) # BlueLed Pin i2c = I2C(-1, sda=Pin(18), scl=Pin(19), freq=400000) # i2c Pin lcd = ulcd1602.LCD1602(i2c) # LCD1602 OBJ ds_pin = machine.Pin(13) # DS18b20 Pin ds_sensor = ds18x20.DS18X20(onewire.OneWire(ds_pin)) # DS18B20 OBJ # rutinas SMS def smsreporte(): #21:10/21.6*C/21 Riegos/Agua0OK..!/TDS:1200/SD23Bs print('ST') lcd.puts("#ST", 8, 1) #data2send = [] #data2send.append(hr[0]) #data2send.append(':') #data2send[2] = hr[1] #data2send.append('/')
import gc import random import ssd1306 from machine import I2C # sensor data + url url_base='http://mosspig.club/?public_key=834c74e03901cd1702c0a3060803f767&private_key=bfe468dc77b5530d65319b67cc39cdbc' temp=23.3 moisture=18.2 url_full=url_base+'&temp='+str(temp)+'&moisture='+str(moisture) print(url_full) i2c = I2C(-1, Pin(14), Pin(2)) oled = ssd1306.SSD1306_I2C(128, 64, i2c) oled.fill(0) oled.text("Sleeping for 10 sec ...",0,0) oled.show() time.sleep(10) oled.fill(0) oled.text("Starting post ...",0,0) oled.show() baudrate=9600 #baudrate=57600
MicroPython with the ESP32 https://techexplorations.com ''' from machine import Pin, I2C, Timer, ADC from LCD1602 import LCD1602 from time import sleep from random import * from dht11 import * led_onboard = Pin(25, Pin.OUT) dht11 = DHT(18) sda = Pin(6) scl = Pin(7) i2c = I2C(1, sda=sda, scl=scl, freq=400000) print("I2C addresses found: ", i2c.scan()) lcd = LCD1602(i2c, 2, 16) light = ADC(0) timer = Timer() lcd.print("Starting...") sleep(1) lcd.clear() def read_sensor_isr(timer):
#while 1: # client.check_msg() if __name__ == "__main__": '''do_connect() a = crypt.CryptAes() print(a.iv) print(a.verify_hmac("fdsiufhisuf")) on.loads(a))) ''' client_int = None client = None do_connect() AES = crypt.CryptAes(b'2222' * 4, b'four' * 4) demo = False AES.G_LED = PWM(Pin(21), freq=100, duty=0) AES.R_LED = Pin(27, Pin.OUT, value=0) onboard = Pin(13, Pin.OUT, value=0) button1 = Pin(12, Pin.IN, Pin.PULL_DOWN) button2 = Pin(14, Pin.IN, Pin.PULL_DOWN) button1.irq(trigger=Pin.IRQ_RISING, handler=button_interrupt_1) button2.irq(trigger=Pin.IRQ_RISING, handler=button_interrupt_2) i2c = I2C(scl=Pin(22), sda=Pin(23), freq=400000) wait = True
from machine import I2C, Pin, SPI, UART import uos import time import sdcard import ssd1306 Pin(21, Pin.OUT, value=0) # Pantalla oled rst = Pin(16, Pin.OUT) rst.value(1) scl = Pin(15, Pin.OUT, Pin.PULL_UP) sda = Pin(4, Pin.OUT, Pin.PULL_UP) #i2c = I2C(scl=scl, sda=sda, freq=450000) i2c = I2C(scl=scl, sda=sda, freq=400000) oled = ssd1306.SSD1306_I2C(128, 64, i2c, addr=0x3c) oled.fill(0) oled.text('Iniciando', 0, 0) oled.show() # inicializacion modulo SD Pin(18, Pin.OUT, value=1) #para desactivar LoRa spi = SPI(sck=Pin(23), miso=Pin(14), mosi=Pin(12)) done = 0 while done < 128: try: sd = sdcard.SDCard(spi, Pin(2, Pin.OUT)) vfs = uos.VfsFat(sd) uos.mount(vfs, "/")
#7.2 from machine import Pin from machine import ADC from machine import I2C from ssd1306 import SSD1306_I2C import NeoPixelLib import time sw1 = Pin(33, Pin.IN) sw2 = Pin(32, Pin.IN) adc1 = ADC(Pin(34)) adc1.atten(ADC.ATTN_11DB) i2cbus = I2C(scl=Pin(22), sda=Pin(21), freq=400000) oled = SSD1306_I2C(128, 64, i2cbus) np = NeoPixelLib.NeoPixel(Pin(12), 3) red = (255, 0, 0) green = (0, 255, 0) blue = (0, 0, 255) yell = (255, 255, 0) count1 = 0 count2 = 0 def intrsw2(e): time.sleep_ms(50) if sw2.value() == 0: global count2 count2 += 1
import gc import micropython from machine import I2C, Pin, Timer from gnssl76l import GNSSL76L from micropyGPS import MicropyGPS micropython.alloc_emergency_exception_buf(100) i2c = I2C(scl=Pin(26), sda=Pin(25)) receiver = GNSSL76L(i2c) gps = MicropyGPS() def read_receiver(timer): for sentence in receiver.sentences(): # MicropyGPS wants data char by char. # This is quite inefficient. for char in sentence: gps.update(chr(char)) print(gps.latitude) print(gps.longitude) print(gps.speed) print(gc.mem_free()) timer_0 = Timer(0) timer_0.init(period=1000, mode=Timer.PERIODIC, callback=read_receiver)
led.value(1) time.sleep(1) import network wlan = network.WLAN(network.STA_IF) wlan.active(True) led = Pin(2, Pin.OUT) Temp = 0 import dht import machine dht11 = dht.DHT11(machine.Pin(4)) from machine import Pin, I2C import ssd1306 from time import sleep i2c = I2C(-1, scl=Pin(22), sda=Pin(21)) oled_width = 128 oled_height = 64 oled = ssd1306.SSD1306_I2C(oled_width, oled_height, i2c) oled.fill(0) oled.text(str('IoT Test'), 10 , 10) oled.show() sleep(0.5) if not wlan.isconnected(): oled.fill(0) oled.text(str('Conectando..'), 5 , 10) oled.show() wlan.connect('Embebidos', '12345678') while not wlan.isconnected():
* CCS811 - Air Quality Sensor Breakout - VOC and eCO2. * BME280 - Temperature, Atmospherique Pressure, Relative Humidity See https://github.com/mchobby/esp8266-upy/tree/master/modenv for more information Author(s): * Meurisse D for MC Hobby sprl """ import time import ccs811 import bme280 from machine import I2C i2c = I2C(2) ccs811 = ccs811.CCS811(i2c) bme = bme280.BME280(i2c=i2c) # Check if the sensor returns an error if ccs811.check_error: print("An error occured!") print("ERROR_ID = %s" % ccs811.error_id.as_text) while True: time.sleep(0.100) # Wait for the sensor to be ready while not ccs811.data_ready: time.sleep(0.100) while True:
Simple endless loop ''' import utime from machine import I2C, Pin from mpu9250 import MPU9250 from ssd1306 import SSD1306_I2C SDA0 = Pin(8) # GPI0 8 is Pin 11 SCL0 = Pin(9) # GPIO 9 is Pin 12 SDA1 = Pin(26) SCL1 = Pin(27) WIDTH = 128 # oled display width HEIGHT = 64 # oled display height i2c0 = I2C(0, scl=SCL0, sda=SDA0) sensor = MPU9250(i2c0) i2c1 = I2C(1, sda=SDA1, scl=SCL1) oled = SSD1306_I2C(WIDTH, HEIGHT, i2c1) print("MPU9250 id: " + hex(sensor.whoami)) while True: accel = "A {:.1f} {:.1f} {:.1f}".format(*sensor.acceleration) gyro = "G {:.1f} {:.1f} {:.1f}".format(*sensor.gyro) mag = "M {: .0f} {: .0f} {: .0f}".format(*sensor.magnetic) temp = "Celcius: {:.1f}".format(sensor.temperature) print(accel) print(gyro) print(mag)
def __init__(self, scl_pin=5, sda_pin=4, delta_temp=0.0, delta_hum=0.0, i2c_address=DEFAULT_I2C_ADDRESS): self.i2c = I2C(scl=Pin(scl_pin), sda=Pin(sda_pin)) self.i2c_addr = i2c_address self.set_delta(delta_temp, delta_hum) time.sleep_ms(50)
# Complete project details at https://RandomNerdTutorials.com from machine import Pin, I2C import ssd1306 from time import sleep # ESP32 Pin assignment i2c = I2C(-1, scl=Pin(5), sda=Pin(4)) # ESP8266 Pin assignment #i2c = I2C(-1, scl=Pin(5), sda=Pin(4)) oled_width = 128 oled_height = 64 oled = ssd1306.SSD1306_I2C(oled_width, oled_height, i2c) oled.text('..................', 0, 0) oled.text('................:)', 0, 10) oled.text('..............:)..', 0, 20) i = 0 while True: if i > 50: i = 0 oled.show() itext = "^~^~str(i)~^~^" oled.text(itext, 0, 30) i += 1
from machine import Pin, I2C import MAX31855 import time i2c = I2C(scl=Pin(22), sda=Pin(21), freq=10000) max31855 = MAX31855.MAX31855(i2c) while True: if (max31855.scan() == True): #detect i2c device temp = max31855.readCelsius() #Read Celsius print("Temperature:%s C" % temp) else: #No I2C was detected. print("No I2C devices!") time.sleep(1)
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ from pca9536 import PCA9536 from machine import Pin, I2C from time import sleep # Create the I2C bus accordingly to your plateform. # Pyboard: SDA on Y9, SCL on Y10. See NCD wiring on https://github.com/mchobby/pyboard-driver/tree/master/NCD # Default bus Freq 400000 = 400 Khz is to high. # So reduce it to 100 Khz. Do not hesitate to test with 10 KHz (10000) i2c = I2C(2, freq=100000) # Feather ESP8266 & Wemos D1: sda=4, scl=5. # i2c = I2C( sda=Pin(4), scl=Pin(5) ) # ESP8266-EVB # i2c = I2C( sda=Pin(6), scl=Pin(5) ) pca = PCA9536(i2c) # Set IO0 to Input - Hardware pull-up activat on all Pin by default pca.setup(0, Pin.IN) # Set IO1 to Input - Hardware pull-up activat on all Pin by default # Read's result will be False when pin is HIGH (not connected to ground) # Read's result will be True when pin is LOW (connected to ground) pca.setup(1, Pin.IN) # Set IO3 to Output
''' 实验名称:I2C总线(OLED显示屏) 版本:v1.0 日期:2019.12 作者:01Studio 实验内容:学习使用MicroPython的I2C总线通讯编程和OLED显示屏的使用。 ''' from machine import I2C from ssd1306k import SSD1306 #定义I2C接口和OLED对象 i2c = I2C(I2C.I2C0, mode=I2C.MODE_MASTER, scl=27, sda=28) oled = SSD1306(i2c, addr=0x3c) #清屏,0x00(白屏),0xff(黑屏) oled.fill(0) #显示字符。参数格式为(str,x,y),其中x范围是0-127,y范围是0-7(共8行) oled.text("Hello World!", 0, 0) #写入第 0 行内容 oled.text("MicroPython", 0, 2) #写入第 2 行内容 oled.text("By 01Studio", 0, 5) #写入第 5 行内容
import ustruct from machine import I2C, Pin import time i2c = I2C(scl=Pin(5),sda=Pin(4)) # freq=100000 A = const(0) # Motor A B = const(1) # Motor B BRAKE = const(0) CCW = const(1) CW = const(2) STOP = const(3) STANDBY = const(4) leftSensor = Pin(12,Pin.IN) # D6 左輪感測器 rightSensor = Pin(16,Pin.IN) # D0 右輪感測器 flagL = 0 # 左輪狀態 flagR = 0 # 右輪狀態 valL = 0 # 左輪脈衝值 valR = 0 # 右輪脈衝值 speedL = 0 # 左輪速度 speedR = 0 # 右輪速度 class Motor: def __init__(self, address=0x30, freq=1000, standbyPin=None): self.i2c = i2c
def run_code(): getDataFromAPI() # get weatherData from the API storeDataFromAPI() # store and organize data from the API in a variable displayTextToLCD() # display the text to the LCD screen scrollText() # continuously move the LCD screen to the left. weatherAttributes = ['city_name','wind_spd', 'temp','precip'] # create an array of weatherAttributes that will match the data from the API weatherCondition = ['null','null','null','null'] # create an array of weatherConditions weatherTitles = ['City:', ' Wind(m/s):', ' Temp:', ' Rain:'] # create an array of weatherTitles that will be shown on the LCD screen deviceAddress = 40 # the address for the NHD-0216K3Z LCD is 40 displayLength = 40 # the maximum display length for the LCD is 40s i2c = I2C(scl=Pin(5), sda = Pin(4), freq = 50000) # initialize the I2C pin with where D1-GPIO5 is SCL and D2-GPIO4 is SDA, and the SCL frequency is 50 kHz (Max for the LCD is 100kHz) #i2c.scan() # scan for available I2C devices url = "https://weatherbit-v1-mashape.p.rapidapi.com/current?lang=en&lon=-114.0719&lat=51.0447" # API URL headers = { # API Headers 'x-rapidapi-host': "weatherbit-v1-mashape.p.rapidapi.com", 'x-rapidapi-key': "8623950a6dmsh625496159b93e42p1733c9jsnb2cd9bd0654a" } #print('we here')
""" Pi4IoT -> https://www.youtube.com/pi4iot draw symbol on the ssd1306 display """ import ssd1306 import machine import sys from machine import I2C, Pin i2c = I2C(sda=Pin(4), scl=Pin(5)) display = ssd1306.SSD1306_I2C(128, 64, i2c) display.fill(0) battery_emty = [ '00001111111111111111111111', '00001000000000000000000001', '11111000000000000000000001', '10000000000000000000000001', '10000000000000000000000001', '10000000000000000000000001', '10000000000000000000000001', '10000000000000000000000001', '11111000000000000000000001', '00001000000000000000000001', '00001111111111111111111111'] battery_full = [ '00001111111111111111111111', '00001000000000000000000001', '11111001111001111001111001',
from machine import I2C from machine import Pin from machine import RTC from time import sleep from time import sleep_ms from time import ticks_ms from esp8266_i2c_lcd import I2cLcd import network import dht import urequests import WorldClock p0 = Pin(4, Pin.OUT) p1 = Pin(17, Pin.OUT) d = dht.DHT11(Pin(16)) i2c = I2C(scl=Pin(22), sda=Pin(21), freq=400000) lcd = I2cLcd(i2c, 0x27, 2, 16) lcd.backlight_off() lcd.clear() # FUNCION PARA LEER DHT11 def readTemperature(): print("Iniciando lectura de temperatura y humedad") data = [0, 0] try: d.measure() t = d.temperature() h = d.humidity() print("La temperatura es de " + str(t) + "ºC\n y la humedad del " + str(h) + "%.") data[0] = t
# Make a rainbow color cycle on the trackball # # See GitHub: https://github.com/mchobby/esp8266-upy/tree/master/trackball from machine import I2C from trackball import Trackball import time i2c = I2C(2) # Y9=scl, Y10=sda or Pyboard-Uno-R3 (I2C over pin 13) trackball = Trackball(i2c) def hsv_to_rgb(h, s, v): if s == 0.0: return v, v, v i = int(h * 6.0) # XXX assume int() truncates! f = (h * 6.0) - i p = v * (1.0 - s) q = v * (1.0 - s * f) t = v * (1.0 - s * (1.0 - f)) i = i % 6 if i == 0: return v, t, p if i == 1: return q, v, p if i == 2: return p, v, t if i == 3: return p, q, v if i == 4: return t, p, v