def getI2C(self): if self.i2c == None: self.i2c = machine.I2C(scl=machine.Pin(5, machine.Pin.OUT, machine.Pin.PULL_UP), sda=machine.Pin(4, machine.Pin.OUT, machine.Pin.PULL_UP)) self.dht12sensor = dht12.DHT12(self.i2c) self.bmp180 = BMP180(self.i2c) self.bmp180.oversample_sett = 2 self.bmp180.baseline = 101325 # self.envData['LIGHT_LEVEL'] = bh1750fvi.sample(self.i2c) self.envData['BMP_TEMPERATURE'] = self.bmp180.temperature self.envData['BMP_PRESSURE'] = (self.bmp180.pressure) / 100
#import webrepl #webrepl.start() gc.collect() import time import ssd1306 from machine import I2C, Pin, PWM import dht12 import neopixel i2c = I2C(-1, Pin(5), Pin(4)) display = ssd1306.SSD1306_I2C(64, 48, i2c) sensor = dht12.DHT12() button = Pin(0) def polsador(): return not(button.value()) freqs = {'do' : 523, 're' : 587, 'mi' : 669, 'fa' : 698, 'sol' : 784, 'la' : 880, 'si' : 988} def toca(nota): beeper = PWM(Pin(14), freq=freqs[nota], duty=512) time.sleep(0.5) beeper.deinit() led = neopixel.NeoPixel(Pin(15, Pin.OUT), 7)
import dht12,machine,oled,time,gc,urequests from machine import I2C,Pin # from umqtt.simple import MQTTClient i2c = I2C(scl=Pin(13),sda=Pin(5)) d = dht12.DHT12(i2c) # thingspeakChannelId = "224710" # <--- replace with your Thingspeak Channel ID # thingspeakChannelWriteapi = "QEAXQACRL1LZHN46" # <--- replace with your Thingspeak Write API Key # # myMqttClient = "my-mqtt-client" # can be anything unique # thingspeakIoUrl = "mqtt.thingspeak.com" # c = MQTTClient(myMqttClient, thingspeakIoUrl, 1883) # uses unsecure TCP connection # c.connect() while True: d.measure() oled.clear() oled.text(str(gc.mem_free()),0,8) oled.text('Temp '+str(d.temperature()),0,24) oled.text('Humid '+str(d.humidity()),0,40) urequests.post('http://api.thingspeak.com/update?api_key=QEAXQACRL1LZHN46&field1='+str(d.temperature())) gc.collect() time.sleep(1) # credentials = "channels/{:s}/publish/{:s}".format(thingspeakChannelId, thingspeakChannelWriteapi) # payload = "field1={:.1f}&field2={:d}\n".format(d.temperature(), gc.mem_free()) # c.publish(credentials, payload) # # time.sleep(5) # # c.disconnect()
import dht12 from machine import I2C, Pin i2c = I2C(scl=Pin(5), sda=Pin(4)) sensor = dht12.DHT12(i2c) sensor.measure() print(sensor.temperature()) print(sensor.humidity())
import json import time import struct from machine import Pin, I2C, SPI, Timer import sdcard import dht12 import sht30 binary_struct = b"<I4f" binary_struct_len = struct.calcsize(binary_struct) i2c = I2C(scl=Pin(5), sda=Pin(4)) dht_sens = dht12.DHT12(i2c) sht_sens = sht30.SHT30(i2c) sd = sdcard.SDCard(SPI(1), Pin(15)) assert sd.csd_version == 2 buffer_4096 = bytearray(512) pointer = 0 buffer_cursor = 0 # in lba size units SD_LBA_SIZE = const(512) last_measurements = None last_measurements_time = 0 measurements_store_time_limit_sec = 2.5 def _get_measures(): global last_measurements_time, last_measurements