Maker Pro
Maker Pro

I2C ESP8266 Arduino Bad Reading

I have a NodeMCU, which I program with the Arduino IDE. I have connected a VOC sensor to pins D1, D2, which are the SLC/SDA pins for NodeMCU. They have pull-up resistor at 4,3kohm to 3.3V.

First I used I2C scanner code, provided by Arduino, and got a response that I have the sensor connected at address 0x7, which is the correct address, indicated on the datasheet for the sensor.

After I tried to read values from the sensor at 0x9 (provided in the datasheet also), I only get 0s as output! Probably something weird in the coding, perhaps someone could assist me in what I am doing wrong here?

In the code, I request 100 bytes just to make sure to get everything, I receive 32 back.

My Output:

Start
Bytes Available: 32
Data read: 00000000000000000000000000000000

Code:

#include <Wire.h>

int miscadr = 0b1110000;

void setup() {
Serial.begin(115200);
Wire.begin();
delay(100);
}

void loop() {
Serial.println();
Serial.print("Start");
Serial.println();
Wire.beginTransmission(miscadr); //Start bit
Wire.write(0b00001001); //Asking for registry 9
Wire.endTransmission();
Wire.requestFrom(miscadr, 100);
Serial.print("Bytes Available: ");
while(Wire.available()==0);
Serial.print(Wire.available());
Serial.println();
Serial.print("Data read: ");
while(Wire.available()!=0) {
Serial.print(Wire.read());
}
Serial.println();
delay(2000);
}
 
Top