Cozir sensor co2 UART arduino uno


bonjour,

je souhaite me faire une petite station météo et j'ai trouvé ce superbe capteur pour réaliser ma station.
co2 cozir : http://www.gassensing.co.uk/product/cozir-ambient/

cependant, je ne parviens pas à envoyer des commandes pour changer le mode de fonctionnement ou tout
simplement pour afficher une température. j'ai trouvé un exemple qui fait exactement ce que je souhaite (http://www.co2meters.com/documentation/appnotes/an128-%20cozir_arduino.pdf ) mais je ne comprend pas pourquoi
je n'arrive pas à envoye rune simple commande.
je me semble pourtant que lorsque je créé une liaison série (uart) vers le capteur ("softwareserial myserial(10, 11); // rx, tx")
il me suffit juste d'écrire ensuite : myserial.print("k 0\r\n"); pour changer de mode.
ou bien myserial.print("t\r\n") pour demander la température.
mais cela ne change rien.
quelqu'un aurait il une solution à me proposer ou même un bout de piste à suivre. cela fait une semaine que j'essaye mais sans succès.

merci d'avance.


voici mon code:

quote


//**********************************************************************************
#include <softwareserial.h>
softwareserial myserial(10,11); // rx, tx

//*****************variables*******************************************************

string val= ""; //holds string of value
double co2 = 0; // holds actual value
double multiplier = 10; //each range of sensor has different value.
// up to 2% =1
// up to 65% = 10
//up to 100% = 100;
uint8_t buffer[25];
uint8_t ind =0;

//********************************************************************************

void setup()
{
serial.begin(9600);
delay(300);
//start serial connection with host
myserial.begin(9600);
//start serial connection with sensor
delay(300);
myserial.print("k 0\r\n"); // doesn't work !!! problem
}

//*******************************************************************************

void loop()
{
//cozir sensors ship from the factory in streaming mode
//so we read incoming bytes into a buffer until we get '0x0a' which is the ascii value for new-line

buffer[ind] = myserial.read();
ind++;

myserial.print("k 0\r\n"); // doesn't work !!!
myserial.print("k <cr><lf>"); // doesn't work !!!


report(); //once '0x0a' report in buffer
}

//*******************************function*********************************************

void report()
{
//cycle through the buffer and send out each byte including the final linefeed
/*
each packet in the stream looks like "z 00400 z 00360"
'z' lets us know its a co2 reading. the first number is the filtered value
and the number after the 'z' is the raw value.
we are really only interested in the filtered value
*/
for(int i=0; < ind+1; i++)
{

if((buffer != 0x0a) && (buffer != 0x0d))
val += buffer-48; 
// we subtract 48 to get to the actual numerical value
// example the character '9' has an ascii value of 57. [57-48=9]

}
}
co2 = (multiplier * val.toint()); //now multiply value factor specific ot sensor. see the

serial.print( "co2 = ");
serial.print(co2);
serial.println(" ppm");
ind=0; //reset buffer index overwrite previous packet
val=""; //reset value string
}



Arduino Forum > International > Français (Moderators: jfs, Snootlab) > Cozir sensor co2 UART arduino uno


arduino

Comments

Popular posts from this blog

opencv3, tbb and rasp pi 2 - Raspberry Pi Forums

small ethernet problem - Raspberry Pi Forums

Multithumb configuration params not working? - Joomla! Forum - community, help and support