Connect with us

I2C ESP8266 Arduino Bad Reading

Discussion in 'Microcontrollers, Programming and IoT' started by martik123, Feb 13, 2017.

Scroll to continue with content
  1. martik123

    martik123

    1
    0
    Feb 13, 2017
    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);
    }
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-