I have a gas sensor whose datasheet is attached:

Now it says that UART communication is needed (P2P) where it (module) waits for Data Frame before tx the data frame to host which I need.

All i know is that I can send start bit in I2C but how shall I proceed. Also if I have multiple sensors how shall I connect them to ESP-32?

  • UART is used for rs232 type communication ... it is not I2C – jsotola Aug 18 '19 at 7:40
  • Datasheet says sensor waits for bytes before sending, show shall I proceed with the coding. I could not receive data values. – Raj Aug 18 '19 at 7:45
  • Step 1: Send the correct data bytes. Step 2: Receive the data from the module. Step 3: Profit. – Majenko Aug 18 '19 at 10:56

First, you need to be communicating by UART, not I2C. That means using Serial or some similar object (On ESP32 you can define your own on whatever pins you want). However, the datasheet omits one vital piece of information: the baud rate it communicates at - so you will have to guess that and try various different standard baud rates until you find the one that works.

Then you have to send the "Give me the data" instruction. The module then responds with the data.

For example (untested):

HardwareSerial mySerial(1);

#define PIN_RX 21
#define PIN_TX 22

void setup() {
    mySerial.begin(9600, SERIAL_8N1, PIN_RX, PIN_TX); // This is the one you need to guess since the DS omits it...

void setup() {

    // Once a second send the request to get the data

    static uint32_t ts = millis();
    if (millis() - ts > 1000) { // Once a second
        ts = millis();
        // "Give me the data"

    // When 10 or more bytes have arrived then assume that they are correctly
    // framed and print them.  Really it should read one byte at a time and
    // look for the correct start sequence of 0x42 0x4d 0x08 and read only
    // from there, but this will server for demonstration purposes.

    if (mySerial.available() >= 10) { // We expect 10 bytes returned
        uint8_t packet[10];
        mySerial.readBytes(packet, 10);
        Serial.print("ID:   ");
        Serial.print("UNIT: ");
        Serial.print("VH:   ");
        Serial.print("DHH:  ");
        Serial.print("DLL:  ");
        Serial.print("LRCH: ");
        Serial.print("LRCL:   ");
  • Thanks. Well it helped a lot. – Raj Aug 22 '19 at 9:55

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.