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?
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.
recommend you use AltSiftSerial 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() byte buffer of specified length
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)
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:
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.
@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
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.
Thanks for this hint, it helps me to understand the data sheet better.
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!
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.
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?
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.
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.