I'm trying to provide analog inputs on a ESP8266-01 using a 4 channels I2C circuit PCF8591. Code installs & runs but Serial Monitor not showing expected data just 255 , 255 , 255 , 255 which is obviously end of scale with these 8 bit analog inputs.
Circuit is just using 3.3V & GND with SLA on ESP8266-01 pin GPIO'2' and for SDA GPIO'0' and when I substitute the 01 with a UNO or ESP8266-12E all works as expected.
The PCF8591 module I'm using has on-board analog sensors like thermistor & a pot. http://arduinolearning.com/code/arduino-pcf8591-example.php
Has anyone experienced this before ??? Is the wire.h compatible with ESP6266 although it works fine with the 12E.
Any comments appreciated, code follows:
// This works fine with UNO and a ESP8266-12E BUT not sofar with ESP8266-01
// http://arduinolearning.com/code/arduino-pcf8591-example.php
#include "Wire.h"
#define PCF8591 (0x90 >> 1)
// this is the same as 48 as x90 counts the LSB of the 8 bit address but the
// rightshift 1 removes the LSB again making it 0x48
byte adcvalue0, adcvalue1, adcvalue2, adcvalue3;
void setup()
{
Wire.pins(0,2);// just to make sure
Wire.begin(0,2);// the SDA and SCL
Serial.begin(9600);
}
void loop()
{
Wire.beginTransmission(PCF8591); // Begin a transmission to the I2C slave device with the given address.
Wire.write(0x04); // Writes data from a slave device in response to a request from a master
// where Wire.write(value) and value: a value to send as a single byte
Wire.endTransmission();
Wire.requestFrom(PCF8591, 5); // Used by the master to request bytes from a slave device. The bytes may
// then be retrieved with the available() and read() functions.
// following are the 5 bytes requested
adcvalue0=Wire.read(); // the 1st byte transmitted in anread cycle contains
// the conversion result code of the previous read cycle
adcvalue0=Wire.read();
adcvalue1=Wire.read();
adcvalue2=Wire.read();
adcvalue3=Wire.read();
Serial.print(adcvalue0);
Serial.print(" ,");
Serial.print(adcvalue1);
Serial.print(" ,");
Serial.print(adcvalue2);
Serial.print(" ,");
Serial.print(adcvalue3);
Serial.println();
delay(1000);
}