# How do I read the UART communication protocol from a datasheet?

**URL:** <https://forum.arduino.cc/t/how-do-i-read-the-uart-communication-protocol-from-a-datasheet/1216110>\
**Category:** Networking, Protocols, and Devices\
**Created:** [January 26, 2024, 9:05am UTC](https://forum.arduino.cc/t/how-do-i-read-the-uart-communication-protocol-from-a-datasheet/1216110 "2024-01-26T09:05:12Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![reallynotonsteam](https://avatars.discourse-cdn.com/v4/letter/r/958977/32.png) [@reallynotonsteam](https://forum.arduino.cc/u/reallynotonsteam)\
**Post date:** [January 26, 2024, 9:05am UTC](https://forum.arduino.cc/t/how-do-i-read-the-uart-communication-protocol-from-a-datasheet/1216110/1 "2024-01-26T09:05:12Z")

</div>

Hello everyone,  
I am trying to connect a more exotic sensor to my Arduino. It is a VOC sensor: PS1-VOC-10-MOD. There is no library for this sensor but a detailed datasheet. The sensor is connected with TX and RX. (next to VCC and GND)  
However, the data sheet only contains commands in "HEX" format. How can I use these to obtain the measurement data?

The datasheet can be found here: [DS-0423-PS1&PS4-VOC-10-MOD (cdistore.com)](https://sgx.cdistore.com/datasheets/sgx/ds-0423-ps1ps4-voc-10-mod.pdf)

Can anyone help finding the right direction?

---

<div class="post-metadata">

**Author:** ![bobcousins](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/bobcousins/32/221530_2.png) [@bobcousins](https://forum.arduino.cc/u/bobcousins)\
**Post date:** [January 26, 2024, 9:13am UTC](https://forum.arduino.cc/t/how-do-i-read-the-uart-communication-protocol-from-a-datasheet/1216110/2 "2024-01-26T09:13:42Z")

</div>

Build the command in a byte buffer, then use `Serial.write(buf, len)`

---

<div class="post-metadata">

**Author:** ![horace](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/horace/32/1014299_2.png) [@horace](https://forum.arduino.cc/u/horace)\
**Post date:** [January 26, 2024, 9:15am UTC](https://forum.arduino.cc/t/how-do-i-read-the-uart-communication-protocol-from-a-datasheet/1216110/3 "2024-01-26T09:15:46Z")

</div>

have a read of [Arduino serial basics](https://forum.arduino.cc/t/serial-input-basics-updated/382007) - in particular the later examples

what Arduino are you planning to use?

---

<div class="post-metadata">

**Author:** ![jim-p](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jim-p/32/922840_2.png) [@jim-p](https://forum.arduino.cc/u/jim-p)\
**Post date:** [January 26, 2024, 9:18am UTC](https://forum.arduino.cc/t/how-do-i-read-the-uart-communication-protocol-from-a-datasheet/1216110/4 "2024-01-26T09:18:45Z")

</div>

@reallynotonsteam  
Which Arduino are you using?

---

<div class="post-metadata">

**Author:** ![reallynotonsteam](https://avatars.discourse-cdn.com/v4/letter/r/958977/32.png) [@reallynotonsteam](https://forum.arduino.cc/u/reallynotonsteam)\
**Post date:** [January 26, 2024, 9:31am UTC](https://forum.arduino.cc/t/how-do-i-read-the-uart-communication-protocol-from-a-datasheet/1216110/5 "2024-01-26T09:31:04Z")

</div>

Thank you very much for your quick answers.

I'm going to use an Arduino UNO R3

I'll have a look at the serial basics tutorial and i have seen similiar problems in this forum that have been solved with a byte buffer.

I have another fundamental question. If you look at the "Command 5" data sheet, there are a number of bits. "_Start bit_", "_Retain_", "_Parity_" and "_Command_". I think I have understood the basics of transferring such data, I just don't understand whether I also have to insert these retain bits in the "Serial.Write();" command

I would also like to know whether the "returned value" is available as HEX or how I can interpret this data.

---

<div class="post-metadata">

**Author:** ![horace](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/horace/32/1014299_2.png) [@horace](https://forum.arduino.cc/u/horace)\
**Post date:** [January 26, 2024, 9:38am UTC](https://forum.arduino.cc/t/how-do-i-read-the-uart-communication-protocol-from-a-datasheet/1216110/6 "2024-01-26T09:38:55Z")

</div>

> [@reallynotonsteam](#):
>
> I'm going to use an Arduino UNO R3

recommend you use [AltSiftSerial](https://www.arduino.cc/reference/en/libraries/altsoftserial/) it can simultaneously transmit and receive.  
the sensor serial uses  
_Baud rate: 9600 Data bits: 8 bits Stop bits: 1 bit_  
which should work OK to [write()](https://www.arduino.cc/reference/en/language/functions/communication/serial/write/) byte buffer of specified length

---

<div class="post-metadata">

**Author:** ![reallynotonsteam](https://avatars.discourse-cdn.com/v4/letter/r/958977/32.png) [@reallynotonsteam](https://forum.arduino.cc/u/reallynotonsteam)\
**Post date:** [January 26, 2024, 9:51am UTC](https://forum.arduino.cc/t/how-do-i-read-the-uart-communication-protocol-from-a-datasheet/1216110/7 "2024-01-26T09:51:06Z")

</div>

Does this give me any advantages, even though the sensor is supposed to measure every five seconds in the fastest case?

Apart from that, the use of this library seems to be very similar

---

<div class="post-metadata">

**Author:** ![GolamMostafa](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/golammostafa/32/239011_2.png) [@GolamMostafa](https://forum.arduino.cc/u/GolamMostafa)\
**Post date:** [January 26, 2024, 9:57am UTC](https://forum.arduino.cc/t/how-do-i-read-the-uart-communication-protocol-from-a-datasheet/1216110/8 "2024-01-26T09:57:10Z")

</div>

If I would be in your place, I would learn the programming of the sensor with the help of the Forum for which I would need the following equipment:  
**1.** Arduino UNO (5 Volt logic device)  
**2.** Level Shifter (Fig-1)  
 ![LevelShifterPictureGreen](https://europe1.discourse-cdn.com/arduino/original/4X/4/6/3/463e5b3974ee98a7873d4d9ed3468bd911d15adb.png)  
Figure-1:

**3.** At least two sensors (3.3V logic device; could be powered from 3.3V or 5V)  
**4.** Make connection as per Fig-2:

 ![gasModule](https://europe1.discourse-cdn.com/arduino/original/4X/5/7/a/57a4265cbe893e3a6a487c05dfe83fd149fe15ed.png)  
Figure-2:

**5.** Study the data sheets of the Sensor and pick up a command which when transferred to the sensor returns known values. This is to validate that Arduino UNO is communicating correctly with the Sensor Module.

**6.** Now, learn on trial-and-erros basis about which command to be issued to acquire measurement signal from Sensor Module.

---

<div class="post-metadata">

**Author:** ![jim-p](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jim-p/32/922840_2.png) [@jim-p](https://forum.arduino.cc/u/jim-p)\
**Post date:** [January 26, 2024, 10:01am UTC](https://forum.arduino.cc/t/how-do-i-read-the-uart-communication-protocol-from-a-datasheet/1216110/9 "2024-01-26T10:01:21Z")

</div>

@reallynotonsteam  
It may have been translated from Polish to English and some of the terminology didn't come out quite right.  
Retain just means you need to transmit those bytes.  
In some places they use the term bit but should have been byte.  
Parity bit is actually a checksum byte  
It look like all data is HEX

---

<div class="post-metadata">

**Author:** ![GolamMostafa](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/golammostafa/32/239011_2.png) [@GolamMostafa](https://forum.arduino.cc/u/GolamMostafa)\
**Post date:** [January 26, 2024, 10:03am UTC](https://forum.arduino.cc/t/how-do-i-read-the-uart-communication-protocol-from-a-datasheet/1216110/10 "2024-01-26T10:03:47Z")

</div>

Thank you! I had been thinking in your line.

---

<div class="post-metadata">

**Author:** ![reallynotonsteam](https://avatars.discourse-cdn.com/v4/letter/r/958977/32.png) [@reallynotonsteam](https://forum.arduino.cc/u/reallynotonsteam)\
**Post date:** [January 26, 2024, 10:12am UTC](https://forum.arduino.cc/t/how-do-i-read-the-uart-communication-protocol-from-a-datasheet/1216110/11 "2024-01-26T10:12:25Z")

</div>

**Thank you very much for your commitment and for your input.**  
I am willing to work into the topic and learn a lot, as it is for a project work as part of my studies. I'm still a bit overwhelmed at the moment, as my previous hobby experience is limited to simple sensors with libraries.

> [@jim-p](#):
>
> It may have been translated from Polish to English and some of the terminology didn't come out quite right.

Thanks for this hint, it helps me to understand the data sheet better.

> [@GolamMostafa](#):
>
> If I would be in your place, I would learn the programming of the sensor with the help of the Forum for which I would need the following equipment:

Thank you for your detailed input. Working with a level shifter is completely new to me and I will familiarise myself with the subject. But I'm very interested in it! Is it possible to write your own library for it this way?

I'm still figuring it out, but I'm trying my hand at the first lines of code with the byte buffer. In this context, I would like to get in touch with you later!

---

<div class="post-metadata">

**Author:** ![GolamMostafa](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/golammostafa/32/239011_2.png) [@GolamMostafa](https://forum.arduino.cc/u/GolamMostafa)\
**Post date:** [January 26, 2024, 10:22am UTC](https://forum.arduino.cc/t/how-do-i-read-the-uart-communication-protocol-from-a-datasheet/1216110/12 "2024-01-26T10:22:40Z")

</div>

If you don't use level shifter, there is a good chance that either one of the boards or both boards will be damaged due to differenet operating logic.

The information given in the data sheet are good enough (no need of Librray which in fact contains functions written by others) to compute gas concentration from data received from Sensor provided that the information are well understood for valid interpretation.

---

<div class="post-metadata">

**Author:** ![b707](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/b707/32/854321_2.png) [@b707](https://forum.arduino.cc/u/b707)\
**Post date:** [January 26, 2024, 10:33am UTC](https://forum.arduino.cc/t/how-do-i-read-the-uart-communication-protocol-from-a-datasheet/1216110/13 "2024-01-26T10:33:26Z")

</div>

> [@GolamMostafa](#):
>
> f you don't use level shifter, there is a good chance that either one of the boards or both boards will be damaged due to differenet operating logic.

According the datasheet the sensor's voltage range is 3.3 - 5.5v, so I don't think that OP will need a level shifter

---

<div class="post-metadata">

**Author:** ![GolamMostafa](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/golammostafa/32/239011_2.png) [@GolamMostafa](https://forum.arduino.cc/u/GolamMostafa)\
**Post date:** [January 26, 2024, 10:39am UTC](https://forum.arduino.cc/t/how-do-i-read-the-uart-communication-protocol-from-a-datasheet/1216110/14 "2024-01-26T10:39:09Z")

</div>

> [@b707](#):
>
> According the datasheet the sensor's voltage range is 3.3 - 5.5v, so I don't think that OP will need a level shifter

From the following excerpt (Fig-1) of the data sheets, I understand that:  
Supply voltage for the VCC-pin: 3.3V to 5V  
TX/RX Logic level are: 3.3V

 ![gasModuleDataSheets](https://europe1.discourse-cdn.com/arduino/original/4X/3/d/1/3d11f0e605b82e9775436fc4faf124537d7a5fe9.png)  
Figure-1:

---

<div class="post-metadata">

**Author:** ![reallynotonsteam](https://avatars.discourse-cdn.com/v4/letter/r/958977/32.png) [@reallynotonsteam](https://forum.arduino.cc/u/reallynotonsteam)\
**Post date:** [January 26, 2024, 10:45am UTC](https://forum.arduino.cc/t/how-do-i-read-the-uart-communication-protocol-from-a-datasheet/1216110/15 "2024-01-26T10:45:59Z")

</div>

hi

```arduino
int sensorValueCalculated; //Datasheet gives a formula for this: (Gas concentration value = high gas concentration *256 + low gas concentration)
byte buf[] = { 0xFF, 0x01, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00, 0x79 };

void setup() {
  Serial.begin(9600);
  Serial.println("<Arduino is ready>");
}

void loop() {

  while (Serial.available() > 0) {

    Serial.write(buf, 9);
    CalculatingGasConcentration(Serial.read()); //reading the returned value and giving it to the calculating function
  }
}

//Function for calculating the gas concentration. Im not sure about the data type of the returned value
int CalculatingGasConcentration(int sensorValueHEX[9]) {
  int highGasConcentration = sensorValueHEX[3];
  int lowGasConcentration = sensorValueHEX[4];

  return sensorValueCalculated = highGasConcentration * 256 + lowGasConcentration;
}

```

I tried my hand at the first lines.  
I used Command 5 from the data sheet. Have I understood the function of the byte buffer correctly?  
The returned value is also a hexadecimal number and the data sheet states that this must be converted. Is there an elegant solution for this in the Arduino programme?

Also, the datasheet says:

 ![image](https://europe1.discourse-cdn.com/arduino/original/4X/e/4/9/e49669078a7106a5d0081f303f784c71b18c3318.png)

How should I understand this?

---

<div class="post-metadata">

**Author:** ![GolamMostafa](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/golammostafa/32/239011_2.png) [@GolamMostafa](https://forum.arduino.cc/u/GolamMostafa)\
**Post date:** [January 26, 2024, 10:49am UTC](https://forum.arduino.cc/t/how-do-i-read-the-uart-communication-protocol-from-a-datasheet/1216110/16 "2024-01-26T10:49:27Z")

</div>

Do you have the equipment as listed in post 8 in order to test your sketch of post #15?

If yes, then it is worth for me to work on your sketch/code; else, I will wait till you get those.

---

<div class="post-metadata">

**Author:** ![reallynotonsteam](https://avatars.discourse-cdn.com/v4/letter/r/958977/32.png) [@reallynotonsteam](https://forum.arduino.cc/u/reallynotonsteam)\
**Post date:** [January 26, 2024, 10:55am UTC](https://forum.arduino.cc/t/how-do-i-read-the-uart-communication-protocol-from-a-datasheet/1216110/17 "2024-01-26T10:55:40Z")

</div>

> [@GolamMostafa](#):
>
> Do you have the equipment as listed in post 8 in order to test your sketch of post #15?

It was ordered yesterday, but it will probably take until the end of next week for it to be delivered. Until then I want to learn the basics.

I can understand that you don't want to invest the time in my sketch without hardware  
But so far I would like to thank you for your time.

---

<div class="post-metadata">

**Author:** ![GolamMostafa](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/golammostafa/32/239011_2.png) [@GolamMostafa](https://forum.arduino.cc/u/GolamMostafa)\
**Post date:** [January 26, 2024, 11:03am UTC](https://forum.arduino.cc/t/how-do-i-read-the-uart-communication-protocol-from-a-datasheet/1216110/18 "2024-01-26T11:03:57Z")

</div>

If you have two UNOs, then you can connect them together using SUART port; where, the sender UNO (UNO-2) can be programmed to simulate your sensor and this way the meanings of the command bytes of the data sheets could be understood.

---

<div class="post-metadata">

**Author:** ![jim-p](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jim-p/32/922840_2.png) [@jim-p](https://forum.arduino.cc/u/jim-p)\
**Post date:** [January 26, 2024, 11:20am UTC](https://forum.arduino.cc/t/how-do-i-read-the-uart-communication-protocol-from-a-datasheet/1216110/19 "2024-01-26T11:20:56Z")

</div>

> [@reallynotonsteam](#):
>
> I tried my hand at the first lines.

At this point, I think your time would best be spent on learning how to do serial communications on the UNO. Don't worry about the gas sensor just yet.

---

<div class="post-metadata">

**Author:** ![b707](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/b707/32/854321_2.png) [@b707](https://forum.arduino.cc/u/b707)\
**Post date:** [January 26, 2024, 11:34am UTC](https://forum.arduino.cc/t/how-do-i-read-the-uart-communication-protocol-from-a-datasheet/1216110/20 "2024-01-26T11:34:40Z")

</div>

> [@reallynotonsteam](#):
>
> Have I understood the function of the byte buffer correctly?

No, your code is not correct. You send a 9 bytes command and read only one byte in return while the sensor output is more.

It is better to read something about Serial first, as @jim-p suggested.

[Next page](https://forum.arduino.cc/t/how-do-i-read-the-uart-communication-protocol-from-a-datasheet/1216110.md?page=2)
