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 0x70, which is the correct address, indicated on the datasheet for the sensor.

After I tried to read values from the sensor with command 0b00001001 (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, 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 doesn't work. Binary is the proper way I assume.

My Output:

Bytes Available: 32 
Data read: 00000000000000000000000000000000


#include <Wire.h>

int miscadr = 0b1110000;

void setup() {

void loop() {
  Wire.beginTransmission(miscadr); //Start bit
  Wire.write(0b00001001); //Asking for registry 9
  Wire.requestFrom(miscadr, 100);
  Serial.print("Bytes Available: ");
  Serial.print("Data read: ");
  while(Wire.available()!=0) {
  • I'm not familiar with NodeMCU, but normally, you'll need to send I2C addr with r/w bit, so something like 0b00010010 or 0b00010011 (for read or write). You should print any statuses available (no ACK from slave etc.) to help you debug. – domen Feb 13 '17 at 11:51
  • Thank you domen for the reply. You are correct about that, I read the datasheet once again. The last bit sent in 0b0000100_1_ is there for stating it is a read command. So what I said about this being 0x9 isnt correct, but the command sent is according to what the datasheet says. Let me know if you have other suggestions, appreciated! – Martik Feb 13 '17 at 19:30
  • Have you got an oscilloscope/logic analyser/voltmeter? It would be good to have some idea what's happening on clock and data lines. Also have you got a very simple I2C device just to see your HW setup is fine? Temperature sensors are usually simple and work with no config. (Although the sensor you're using looks simple as well) – domen Feb 13 '17 at 20:44
  • I just ordered an oscilloscope! Seems as if it can be useful.. Anyhow, I tried a Bosch Pressure Sensor, BP280, and it gave me perfect readings. So HW seems to be correct. – Martik Feb 14 '17 at 21:43
  • "I request 100 bytes just to make sure to get everything, but I receive only 32 back". Wire buffer is 32 bytes long. Wire.available() > 0 doesn't means you have 100 bytes to read; you have to read-accumulate bytes until you read all 100. – user31481 Nov 15 '17 at 19:34

Which VOC sensor is it ? I like to see the datasheet myself. My crystal ball tells me it is a MiCS-VZ-86/89. When the i2c scanner finds address 0x7, then you should use 0x7. In your sketch the miscadr is now 0x70.

The read and write bit is taken care of by the Wire library. You could print the return value of Wire.endTransmission and Wire.requestFrom. The Wire.endTransmission returns an error and the Wire.requestFrom returns the number of read bytes. Those return values can tell if the I2C transaction was wrong.

There is no need for a while-loop to wait for data after the Wire.requestFrom. You can remove that first while statement.

You can not request 100 bytes. The Wire library has a buffer of 32 bytes.

When you use the term "address", please use "i2c address" or "register address".

The Wire.requestFrom reads bytes from the Slave (the VOC sensor), but the sensor can not stop the I2C transaction after 6 bytes. The Master (the ESP8266) should set the number of bytes to read. If you need only 6 bytes, then you should read only 6 bytes.

| improve this answer | |
  • Thank you very much for the reply! The i2c adress of the MiCS-VZ-89TE(great crystal ball you have btw!) is 0x70, not 0x7 as I wrote. So the code was right on that part. Serial.print for endTransmission returns 0, and for requestFrom returns 7. Still, all I get is a bunch of 0s in return from the sensor! Cannot figure out the reason for this. I have changed the pullup resistors to 4.7kohm also, without any difference.. Any more suggestions what I can try? Thank you! – Martik Feb 18 '17 at 11:05
  • Zero errors from Wire.endTransmission means you are communicating with the sensor. Request 6 bytes and see what happens. – Jot Feb 18 '17 at 14:33
  • I only receive 0s, 32bytes or 6bytes requested.. Scratching my head here! – Martik Feb 18 '17 at 15:00
  • 1
    On this page sgxsensortech.com/sensor-selector/#prod_4569 under the tab "Application notes" I selected the I2C application note. It says that you need to send 6 bytes, and you will receive 7 bytes. Older versions of that sensor require only the command 0x09, but according to the datasheets the MiCS-VZ-89TE always requires those 6 bytes. The Upgrade Guide appliction note shows a short CRC calculation function. – Jot Feb 19 '17 at 11:31
  • @Martik I am late to the party and you might have fixed your issue by now. If it helps I wrote a lib for the MiCS-VZ-89TE, I have it working on the EPS8266-01 github.com/HGrabas/MICS-VZ-89TE – vrleboss Dec 11 '17 at 3:43

If your ESP8266 device NodeMCU is not using the Arduino ESP8266 Library standard pins for I2C ( SDA=2, SCL=14) then you must change the Wire.begin() statement to Wire.begin(SDA, SCL) inserting your values for the SDA and SCL pins. See this note for another ESP breakout (Sparkfun) Arduino ESP8266 Wire

| improve this answer | |
  • Thank you for the reply! It didnt do any difference though. I did get a respons from the sensor on what adress it is on, and other sensors works good. So the pin output should be properly configured for the i2c. Let me know if you have other suggestions! Thank you. – Martik Feb 18 '17 at 11:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.