Just had a sensor delivered to eventually do a air quality project, currently working on another project at the moment. All the sketches i have tried involve other bits of equipment like wifi, or a display of some sorts. As i'm still quite new to all of this me chopping bits out of the sketch isn't working as i hoped. Hoping someone might know of a sketch where i can view the working through serial monitor in the ide?
Regards
Ok my need to find something final came up trumps at 0230, thanks to the good old Russians. If anyone else is looking for a simple test sketch this is it. Note that the TX & RX go to analog 0&1.
В последнее время популярны гаджеты, показывающие уровень CO 2 , равно как и статьи, рассказывающие как монитор CO 2 можно превратить в подключенный к компьютеру датчик. Я хочу показать решение задачи...
rx en tx on a0,a1 5v ,gnd
#include <SoftwareSerial.h>;
SoftwareSerial mySerial(A0, A1); // connect also co2sensor-ardunoUno17 with Tx-A0,Rx-A1,Vin-5v,GND-GND ,Old bootloader in my case
byte cmd[9] = {0xFF,0x01,0x86,0x00,0x00,0x00,0x00,0x00,0x79};
unsigned char response[9];
void setup() {
Serial.begin(9600);
mySerial.begin(9600);
}
void loop()
{
mySerial.write(cmd, 9);
memset(response, 0, 9);
mySerial.readBytes(response, 9);
int i;
byte crc = 0;
for (i = 1; i < 8; i++) crc+=response[i];
crc = 255 - crc;
crc++;
if ( !(response[0] == 0xFF && response[1] == 0x86 && response[8] == crc) ) {
Serial.println("CRC error: " + String(crc) + " / "+ String(response[8]));
} else {
unsigned int responseHigh = (unsigned int) response[2];
unsigned int responseLow = (unsigned int) response[3];
unsigned int ppm = (256*responseHigh) + responseLow;
Serial.println(ppm);
}
delay(10000);
}
hammy
March 31, 2020, 11:40am
4
The idea is to write code and learn from it ! Saves you a couple of years ??
hammy:
The idea is to write code and learn from it ! Saves you a couple of years ??
When the trolls have to self isolate and have nothing else better to do.
fritssluijter:
rx en tx on a0,a1 5v ,gnd
#include <SoftwareSerial.h>;
SoftwareSerial mySerial(A0, A1); // connect also co2sensor-ardunoUno17 with Tx-A0,Rx-A1,Vin-5v,GND-GND ,Old bootloader in my case
byte cmd[9] = {0xFF,0x01,0x86,0x00,0x00,0x00,0x00,0x00,0x79};
unsigned char response[9];
void setup() {
Serial.begin(9600);
mySerial.begin(9600);
}
void loop()
{
mySerial.write(cmd, 9);
memset(response, 0, 9);
mySerial.readBytes(response, 9);
int i;
byte crc = 0;
for (i = 1; i < 8; i++) crc+=response[i];
crc = 255 - crc;
crc++;
if ( !(response[0] == 0xFF && response[1] == 0x86 && response[8] == crc) ) {
Serial.println("CRC error: " + String(crc) + " / "+ String(response[8]));
} else {
unsigned int responseHigh = (unsigned int) response[2];
unsigned int responseLow = (unsigned int) response[3];
unsigned int ppm = (256*responseHigh) + responseLow;
Serial.println(ppm);
}
delay(10000);
}
Thank you, I did find a sketch a few years ago after creating the thread, never did get around to posting it. Just a link.
Regards