i2c reading returns 0s
Posted: Sun Feb 12, 2017 8:32 am
I have a nodemcu which I program via Arduino IDE. I have connected a VOC sensor to pin D1,D2 which is the SLC/SDA pins for nodemcu. They have pull-up resistor at 4,3kohm to 3.3V.
First I use i2c scanner code provided by arduino and get a response that I have the sensor connected at address 0x7, which is the correct address comparing to the datasheet for the sensor.
After I try to read values from the sensor at 0x9 (provided in the datasheet also). However I only get 0´s as output!! Probably something weird in the coding, perhaps someone could assist me in what I do wrong here?
In the code I request 100 bytes just to make sure to get everything, but I receive only 32 back. The datasheet says it should be 6 bytes on address 0x9. And I have tried hex and dec form but that doesnt work. Binary is the proper way I assume.
My Output:
Code:
First I use i2c scanner code provided by arduino and get a response that I have the sensor connected at address 0x7, which is the correct address comparing to the datasheet for the sensor.
After I try to read values from the sensor at 0x9 (provided in the datasheet also). However I only get 0´s as output!! Probably something weird in the coding, perhaps someone could assist me in what I do wrong here?
In the code I request 100 bytes just to make sure to get everything, but I receive only 32 back. The datasheet says it should be 6 bytes on address 0x9. And I have tried hex and dec form but that doesnt work. Binary is the proper way I assume.
My Output:
Code: Select all
Start
Bytes Available: 32
Data read: 00000000000000000000000000000000
Code:
Code: Select all
#include <Wire.h>
int miscadr = 0b1110000;
//int miscadr = 0x7;
//int miscadr = 7;
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.write(0x9); //Asking for registry 9
//Wire.write(9); //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);
}