Close

Arduino 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 19:260 Comments

This is an example Arduino sketch that keeps reading from channel 0 and printing the result on the serial console.

#include <Wire.h>


#define ADC_I2C_ADDRESS 0x35


uint16_t readChannel(uint8_t channel) {
    if (channel >= 12) {
        return 0;
    }
    Wire.beginTransmission(ADC_I2C_ADDRESS);
    Wire.write((channel << 1) | 0x61);
    Wire.endTransmission(false);
    Wire.requestFrom(ADC_I2C_ADDRESS, 2);
    uint8_t high = Wire.read();
    return ((high & 0x0f) << 8) | Wire.read();
}

void setup() {
    Wire.begin();
    Serial.begin(9600);
}

void loop() {
    Serial.print(readChannel(0));
}

Discussions