Hi all,
I have started this thread a bit unprepared - now I am back with more data better structure.
Step 1: check if communication with sensor works
I have used a USB to Serial device to connect to the sensor. The software to communicate between PC and sensor over serial is HTerm 0.8.1 beta.
The documentation says, to send 11 01 01 ED in Hex to the sensor, to get an answer with the sensor values.
This actually also happens.
As shown in the screenshot I receive in total 24 “characters” in Hex.
The red circle of the screenshot represents the oxygen value (I need this value as integer).
The blue circle of the screenshot represents the gas flow value (I need this value as integer).
This is an example of the supplier manual, how they calculate the values:
For example: a measurement result for the flow: 5L / min, O2 concentration: 94.8%. Then the returned result (O2) = 94.8% = 0x03B4
(Hexadecimal), (FLOW) = 5.0 L / min = 0x0032 (hexadecimal), the returned data is "16 09 01 03 B4 00 32 00 D2 00 00 25"
Conclusion:
The sensor behaves as detailed in the manual.
Step 2: try to connect to the sensor with an Arduino.
I have used this simple sketch to receive the sensor data with an Arduino and instantly repeat it over an soft serial to the PC.
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX
void setup() {
mySerial.begin(9600); // Serial to send stuff to PC.
Serial.begin(9600); // Serial to communicate with sensor.
}
void loop() {
// Query the sensor data.
Serial.write(0x11);
Serial.write(0x01);
Serial.write(0x01);
Serial.write(0xED);
// Wait for the sensor to answer.
delay(10);
// Read the answer from the sensor.
while (Serial.available()) {
// Send the received data to PC.
mySerial.write(Serial.read());
}
delay(1000);
}
It worked fine.
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX
void setup() {
mySerial.begin(9600); // Serial to send stuff to PC.
Serial.begin(9600); // Serial to communicate with sensor.
}
void loop() {
// Query the sensor data.
Serial.write(0x11);
Serial.write(0x01);
Serial.write(0x01);
Serial.write(0xED);
delay(10);
// Read the answer from the sensor.
int i = 0;
while (Serial.available()) {
// Send the received data to PC.
mySerial.write(Serial.read());
i = i + 1;
}
mySerial.println("{" + String(i) + "}");
delay(1000);
}
Just to be sure I checked next how often the while loop iterates, respectively how many bytes it receives – and it is 12 bytes – so everything is fine and dandy so far.
Step 3: convert the received data.
I have generated a byte array reading[11], which should contain the 12 byte sent by the sensor.
Instead of repeating the data to the softserial, I write the data to the byte array.
After the data was received I try to convert the byte array, which contains the hex values to integer, and there the problems start.
The oxygen value of 00 CD HEX should be 205 decimal, which means 20.5% oxygen, which is the atmospheric content of O2 – so the sensor is delivering the correct value only my math is failing.
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX
byte reading[11]; // byte array where the Serial readings are stored.
int oxigen_concentration; // Sensor value 1;
int flow_rate; // Sensor value 2;
void setup() {
mySerial.begin(9600); // Serial to send stuff to PC.
Serial.begin(9600); // Serial to communicate with sensor.
}
void loop() {
// Query the sensor data.
Serial.write(0x11);
Serial.write(0x01);
Serial.write(0x01);
Serial.write(0xED);
delay(10);
// Read the answer from the sensor.
int i = 0;
while (Serial.available()) {
reading[i] = Serial.read();
i = i + 1;
}
oxigen_concentration = reading[3] * 256 + reading[4];
flow_rate = reading[5] * 256 + reading[6];
mySerial.println(oxigen_concentration);
mySerial.println(flow_rate);
delay(1000);
}
The output is complete garbage...
Thanks a lot for your help.
