Close

Python Example

A project log for D1 Mini Analog Shield

Add 12 analog pins to the D1 Mini ESP8266 board

dehipudeʃhipu 02/19/2018 at 21:460 Comments

The same example in MicroPython for the ESP8266:

import machine

def read_channel(i2c, channel):
    if not 0 <= channel <= 11:
        raise ValueError()
    data = i2c.readfrom_mem(0x35, 0x61 | (channel << 1), 2)
    return ((data[0] & 0x0f) << 8) | data[1]

i2c = machine.I2C(-1, sda=machine.Pin(4), scl=machine.Pin(5))
while True:
    print(read_channel(i2c, 0))

Discussions