Clara Casas Castedo & Miguel Sánchez de León Peque
2019-01-17
NodeMCU pin | Magnetic sensor pin |
---|---|
D1 (GPIO5) | SDA (P2.10) |
D2 (GPIO4) | SCL (P2.11) |
3V3 | 3V3 (P1.0) |
GND | GND |
from machine import I2C
from machine import Pin
i2c = I2C(scl=Pin(5), sda=Pin(4), freq=400000)
devices = i2c.scan()
address = devices[0]
i2c.writeto(address, b'123') # Write 3 bytes
i2c.readfrom(address, 4) # Read 4 bytes
i2c.readfrom_mem(address, 8, 3) # Read 3 bytes at address 8
i2c.writeto_mem(address, 2, b'\x10') # Write 1 byte at address 2