I2C A/D circuit PCF8591 OK with UNO & ESP6266-12E but not ESP8266-01

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);
}

I'm sure this code doesn't compile for the UNO, as there is not two parameter version of Wire.begin() for the AVR platform.

Please post pictures of the wiring for the two ESP types, if you get 255 it seems that you don't have the wiring correctly (you get 0xFF if not device is connected at all).

After further consideration that there could be a problem with the 01 using the i2c lines (SDA & SCL) I used the identical 01 and connected the same 3.3V, GND, SDA & SCL lines to a OLED and with suitable code to see if the OLED would work OK in i2c mode and it did perfectly.

I then used my oscilloscope to monitor the SDA & SCL lines which worked perfectly sitting high and pulsing low on data & clock pulses driving the OLED to display correctly.

Now reconnecting the PCF8591 to the SDA & SCL similar data pulsed were found when driving the ADC from a UNO or 12E but with the 01 the clock line just stays high.

Bottom line is I don't need to use a 01 and a 12E will provide more functionality with the project I'm developing so using the 01 is going into the 'too hard' bin.

Following is some code I plagiarized and adapted for testing PCF8591 with arduino code, may be of interest to others.

// Filename: PCF8591_analogReadWrite.ino Refer to:GitHub - xreef/PCF8591_library: Library to use pcf8591 i2c analog IC with Arduino, Raspberry Pi Pico and rp2040 boards, esp32, SMT32 and ESP8266. Can read analog value and write analog value with only 2 wire.
// Wiring to i2C
// Uno A5 (SCL) wires to PCF8591 pin 10 or (ESP8266-01 pin GPIO'2')but ESP01 not working
// Uno A4 (SDA) wires to PCF8591 pin 9 or (ESP8266-01 pin GPIO'0')but ESP01 not working
// ESP8266-12E SCL wires to D1 pin GPIO'5' - tested to work OK
// ESP8266-12E SDA wires to D2 pin GPIO'4' - tested to work OK

#include "Arduino.h"
#include "PCF8591.h"
#define PCF8591_I2C_ADDRESS 0x48

PCF8591 pcf8591(PCF8591_I2C_ADDRESS);

void setup()
{
Serial.begin(115200);
pcf8591.begin();
}

void loop()
{
PCF8591::AnalogInput ai = pcf8591.analogReadAll();

Serial.println("Will now show value on the 4 A/I points ");
Serial.print(ai.ain0);
Serial.print(" - ");
Serial.print(ai.ain1);
Serial.print(" - ");
Serial.print(ai.ain2);
Serial.print(" - ");
Serial.print(ai.ain3);
Serial.println(" the last input ain3 was the onboard pot");

delay(2000);

int ana = pcf8591.analogRead(AIN0);
Serial.print("AIN0 --> ");
Serial.println(ana);

ana = pcf8591.analogRead(AIN1);
Serial.print("AIN1 --> ");
Serial.println(ana);

ana = pcf8591.analogRead(AIN2);
Serial.print("AIN2 --> ");
Serial.println(ana);

ana = pcf8591.analogRead(AIN3);
Serial.print("AIN3 --> ");
Serial.println(ana);
delay(3000);
Serial.println(" ");
Serial.println("Will now output to A/O point 3 ramping voltages from low-mid-high ");
Serial.println(" ");
pcf8591.analogWrite(0);
delay(3000);
pcf8591.analogWrite(128);
delay(3000);
pcf8591.analogWrite(255);
delay(3000);
}

Doesn't the PCF8591 need the last bit to be a 1 for the read configuration?
0x90 is 1001000 (write) but the read address is 10010001 (0x91)
From the Data sheet: "write operation is 0x90, read operation is 0x91,"
So therefore it should be
#define PCF8591 (0x91 >> 1)
But there in lies the problem - won't this bitshift the far right bit into oblivion?
I've started another topic about this but added this to an old post in case (as I did) a search leads to this post.

#define PCF8591 (0x91 >> 1)
But there in lies the problem - won't this bitshift the far right bit into oblivion?

The Wire library is handling the read/write bit, you just have to provide the address (0x48 in this case).

The original i2c library in Arduino frame work for ESP8266 is buggy. Replace it with this. It is fully compatible, but do not have new slave mode.

The original i2c library in Arduino frame work for ESP8266 is buggy.

A short explanation of what exactly the error in the original driver is may be beneficial.