This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from machine import SoftI2C, Pin | |
from ssd1306 import SSD1306_I2C | |
from time import sleep | |
from mpu6050 import Accel | |
i2c = SoftI2C(sda=Pin(13), scl=Pin(14)) | |
display = SSD1306_I2C(128, 64, i2c, addr=0x3C) | |
i2c2 = SoftI2C(sda=Pin(22), scl=Pin(32)) # SDA=Y11, SCL=Y12 | |
accelerometer = Accel(i2c2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from time import sleep_us, ticks_us | |
class HCSR04(): | |
def __init__(self,trig,echo): | |
self.trig=trig | |
self.echo=echo | |
def getDistance(self): | |
distance=0 | |
self.trig.value(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BMP280_I2C_ADDR = const(0x76) | |
class BMP280(): | |
def __init__(self, i2c): | |
self.i2c = i2c | |
self.dig_T1 = self.get2Reg(0x88) | |
self.dig_T2 = self.short(self.get2Reg(0x8A)) | |
self.dig_T3 = self.short(self.get2Reg(0x8C)) | |
self.dig_P1 = self.get2Reg(0x8E) | |
self.dig_P2 = self.short(self.get2Reg(0x90)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from machine import Pin, SoftI2C, ADC | |
from ssd1306 import SSD1306_I2C | |
from time import sleep | |
i2c = SoftI2C(sda=Pin(13), scl=Pin(14)) | |
display = SSD1306_I2C(128, 64, i2c, addr=0x3C) | |
waterLevel = ADC(Pin(32)) | |
waterLevel.atten(ADC.ATTN_11DB) # 150mV - 2450mV |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from machine import Pin, SoftI2C, ADC | |
from ssd1306 import SSD1306_I2C | |
from time import sleep | |
i2c = SoftI2C(sda=Pin(13), scl=Pin(14)) | |
display = SSD1306_I2C(128, 64, i2c, addr=0x3C) | |
soil = ADC(Pin(32)) | |
soil.atten(ADC.ATTN_11DB) # 150mV - 2450mV |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from machine import Pin, SoftI2C, ADC | |
from ssd1306 import SSD1306_I2C | |
from time import sleep | |
i2c = SoftI2C(sda=Pin(13), scl=Pin(14)) | |
display = SSD1306_I2C(128, 64, i2c, addr=0x3C) | |
light = ADC(Pin(32)) | |
light.atten(ADC.ATTN_11DB) # 150mV - 2450mV |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from machine import SoftI2C, Pin | |
from ssd1306 import SSD1306_I2C | |
from time import sleep | |
i2c = SoftI2C(sda=Pin(13), scl=Pin(14)) | |
display = SSD1306_I2C(128, 64, i2c, addr=0x3C) | |
pir = Pin(22, Pin.IN, Pin.PULL_UP) | |
display.fill(0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from machine import Pin, SoftI2C | |
from ssd1306 import SSD1306_I2C | |
from dht import DHT11 | |
from time import sleep | |
i2c = SoftI2C(sda=Pin(13), scl=Pin(14)) | |
display = SSD1306_I2C(128, 64, i2c, addr=0x3C) | |
dt = DHT11(Pin(27)) | |
sleep(2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from machine import Pin, SoftI2C | |
from ssd1306 import SSD1306_I2C | |
from onewire import OneWire | |
from ds18x20 import DS18X20 | |
from time import sleep | |
i2c = SoftI2C(sda=Pin(13), scl=Pin(14)) | |
display = SSD1306_I2C(128, 64, i2c, addr=0x3c) | |
ds = DS18X20(OneWire(Pin(4))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from machine import UART | |
uart = UART(2, baudrate=115200, tx=32, rx=22) # TX : Y12, RX : Y11 | |
uart.write('Hello DeviceMart!') | |
while True: | |
if uart.any(): | |
text = uart.read(64) | |
print(text) |