Hi,
I've been trying to get a project involving co2-measurements going, but I seem to be stuck at what odd to be the most basic stuff.
I had no problems going through all the tutorials, and the fastspi_led2 library(will be part of the project eventually),
but this serial stuff just gets me stuck.
--------------
What I have is a Teensy 3.0 and a SenseAir K-30 module.
G0 (k30) goes to the common ground (GND) of the Teensy, and G+ (k30) gets power from Vin (Teensy).
Rxd (k30) goes to 9 (Teensy) and Txd (k30) goes to 10 (Teensy).
[I am using the UART Terminal on the k30.]
----------------------------
Now to the problem:
I get no response.
I tried using the Arduino example (see K30_basic example below), but 'while(!K_30_Serial.available())' got stuck in an infinite loop.
Then I went to try the kSeries.h from their example #2, but it does not support Teensy 3.0.
Now I figured that since that while-loop got stuck I should try work with a purely simplified code to try get contact with the module and went with something very simple (see Very_simple example below).
Nothing here either, the counter runs, but it can not seem to find the module.
Then I tried with a simple SoftwareSerial example (see simple_softwareSerial below).
Nothing here either.
Finally I changed pins and tried analogRead, and now the module at least said hello to me.
Not like that is going to help much though!
------------------------------------------
So the question is, what am I doing wrong
(I have thought of shifting the RxD and TxD signals from the k30 module down to 3.3V before they hit the Teensy,
but for the time beeing I am hoping for any usable output from the module before I expand stuff.
--------------------------------------------------------
Arduino example using SoftwareSerial.:
http://www.co2meters.com/Documentation/AppNotes/AN126-K3x-sensor-arduino-uart.pdf
K-30 datasheet.:
http://co2meters.com/Documentation/Datasheets/DS30-01%20-%20K30.pdf
Offical product sheet.:
http://www.senseair.se/wp-content/uploads/2012/02/PSP110_k30.pdf
kSeries.h from co2meter.:
http://www.co2meters.com/Documentation/AppNotes/AN126-K3x-sensor-arduino-uart.zip
K30_basic example:
Very_simple example.:
Simple_softwareSerial example.:
I am using Arduino IDE v1.0.5 with Teensy Loader v1.15 under WinXP.
I've been trying to get a project involving co2-measurements going, but I seem to be stuck at what odd to be the most basic stuff.
I had no problems going through all the tutorials, and the fastspi_led2 library(will be part of the project eventually),
but this serial stuff just gets me stuck.
--------------
What I have is a Teensy 3.0 and a SenseAir K-30 module.
G0 (k30) goes to the common ground (GND) of the Teensy, and G+ (k30) gets power from Vin (Teensy).
Rxd (k30) goes to 9 (Teensy) and Txd (k30) goes to 10 (Teensy).
[I am using the UART Terminal on the k30.]
----------------------------
Now to the problem:
I get no response.
I tried using the Arduino example (see K30_basic example below), but 'while(!K_30_Serial.available())' got stuck in an infinite loop.
Then I went to try the kSeries.h from their example #2, but it does not support Teensy 3.0.
Now I figured that since that while-loop got stuck I should try work with a purely simplified code to try get contact with the module and went with something very simple (see Very_simple example below).
Nothing here either, the counter runs, but it can not seem to find the module.
Then I tried with a simple SoftwareSerial example (see simple_softwareSerial below).
Nothing here either.
Finally I changed pins and tried analogRead, and now the module at least said hello to me.
Not like that is going to help much though!
------------------------------------------
So the question is, what am I doing wrong
(I have thought of shifting the RxD and TxD signals from the k30 module down to 3.3V before they hit the Teensy,
but for the time beeing I am hoping for any usable output from the module before I expand stuff.
--------------------------------------------------------
Arduino example using SoftwareSerial.:
http://www.co2meters.com/Documentation/AppNotes/AN126-K3x-sensor-arduino-uart.pdf
K-30 datasheet.:
http://co2meters.com/Documentation/Datasheets/DS30-01%20-%20K30.pdf
Offical product sheet.:
http://www.senseair.se/wp-content/uploads/2012/02/PSP110_k30.pdf
kSeries.h from co2meter.:
http://www.co2meters.com/Documentation/AppNotes/AN126-K3x-sensor-arduino-uart.zip
K30_basic example:
Code:
/*
Basic Arduino example for K-Series sensor
Created by Jason Berger
Co2meter.com
*/
#include "SoftwareSerial.h"
SoftwareSerial K_30_Serial(9,10); //Sets up a virtual serial port
//Using pin 9 for Rx and pin 10 for Tx, because it is Serial2 on the Teensy
byte readCO2[] = {0xFE, 0X44, 0X00, 0X08, 0X02, 0X9F, 0X25}; //Command packet to read Co2 (see app note)
byte response[] = {0,0,0,0,0,0,0}; //create an array to store the response
//multiplier for value. default is 1. set to 3 for K-30 3% and 10 for K-33 ICB
int valMultiplier = 1;
void setup()
{
// put your setup code here, to run once:
Serial.begin(9600); //Opens the main serial port to communicate with the computer
K_30_Serial.begin(9600); //Opens the virtual serial port with a baud of 9600
}
void loop()
{
sendRequest(readCO2);
unsigned long valCO2 = getValue(response);
Serial.print("Co2 ppm = ");
Serial.println(valCO2);
delay(2000);
}
void sendRequest(byte packet[])
{
while(!K_30_Serial.available()) //keep sending request until we start to get a response
{
K_30_Serial.write(readCO2,7);
delay(50);
}
int timeout=0; //set a timeoute counter
while(K_30_Serial.available() < 7 ) //Wait to get a 7 byte response
{
timeout++;
if(timeout > 10) //if it takes to long there was probably an error
{
while(K_30_Serial.available()) //flush whatever we have
K_30_Serial.read();
break; //exit and try again
}
delay(50);
}
for (int i=0; i < 7; i++)
{
response[i] = K_30_Serial.read();
}
}
unsigned long getValue(byte packet[])
{
int high = packet[3]; //high byte for value is 4th byte in packet in the packet
int low = packet[4]; //low byte for value is 5th byte in the packet
unsigned long val = high*256 + low; //Combine high byte and low byte with this formula to get value
return val* valMultiplier;
}
Very_simple example.:
Code:
int counter = 0;
void setup() {
Serial.begin(38400);
Serial2.begin(9600);
}
void loop() {
Serial.println(counter); //only checking if the loop is running
counter++;
if (Serial2.available() > 0) {
Serial.print("Found the device!");
}
delay(1000);
}
Simple_softwareSerial example.:
Code:
#include "SoftwareSerial.h"
SoftwareSerial k30(9,10);
int counter = 0;
void setup() {
Serial.begin(38400);
k30.begin(9600);
}
void loop() {
Serial.println(counter); //only checking if the loop is running
counter++;
if (k30.available() > 0) {
Serial.print("Found the device!");
}
delay(1000);
}
I am using Arduino IDE v1.0.5 with Teensy Loader v1.15 under WinXP.
