12 Replies Latest reply on Jul 18, 2014 6:39 AM by conor100

    A CO2 sensor that is compatible with galileo?

    conor100

      Hi Guys,

       

      Would anybody know of a CO2 sensor that is compatible with Galileo?

       

      I've tried a k-30 sensor but it depends on the softwareserial library.

       

      CO2 Meter - CO2 sensor for OEM applications. Quantity pricing. In stock - Sensor by Senseair

       

      Many thanks

      Conor

      sesnor

        • 1. Re: A CO2 sensor that is compatible with galileo?
          JPMontero_Intel

          Hi conor100

          As far as I know the softwareSerial library is not implemented yet, take a look at this post https://communities.intel.com/thread/47898 . Regarding the Sensor I've seen a couple of CO sensors that have an analog output, but I don’t know any CO2 sensor, if I find one that might work for the Galileo I’ll post it here.
          Regards,
          JPMontero_Intel

          • 2. Re: A CO2 sensor that is compatible with galileo?
            JPMontero_Intel

            Hi conor100

            I was looking into the sensor you’ve tried, and in the datasheet http://co2meters.com/Documentation/Datasheets/DS30-01%20-%20K30.pdf on page 5, says the sensor have 2 analog outputs and include the relation between voltage and ppm on table 2. In that way you won’t have problem with any library. I hope it works for you.

            Regards
            JPMontero_Intel

            • 3. Re: A CO2 sensor that is compatible with galileo?
              conor100

              Hi JPMontero_Intel,

               

              Thanks for your helpful suggestion and for looking into it, much appreciated. I have not purchased this sensor yet but will post how I get on when I purchase it.

               

              Cheers

              • 4. Re: A CO2 sensor that is compatible with galileo?
                conor100

                Hi JP,

                 

                I was looking at this sensor again and it appears to SoftwareSerial library, according to this document http://www.co2meters.com/Documentation/AppNotes/AN126-K3x-sensor-arduino-uart.pdf

                 

                I'm relatively new to Arduino, would you know what the sketch would look like for the analogue inputs? I think I will buy it.

                 

                Thanks

                C

                • 5. Re: A CO2 sensor that is compatible with galileo?
                  JPMontero_Intel

                  Hi conor100

                   

                   

                  It would look just like the example AnalogInput included in the Arduino IDE, but with a few modifications. As far as I understand from the datasheet there are two analog outputs the first one have an output between 0.0 and 4.0VDC and a correspondence from 0 to 2000 ppm CO2, with a resolution of 10mV. The other output gives from 1 to 5VDC with the same correspondence of CO2 and a resolution of 5mV. This means that if you connect the OUT2 to analog output and you receive 1024 (this corresponds to 5V because of the resolution of the ADC) by using the sketch AnalogInput the sensor would be getting 2000 ppm CO2. And just in case, you can find this sketch in File > Examples > 03.Analog > AnalogInput. You just need to add the conversion from voltage to ppm CO2, depending on output of the sensor.

                  Regards,
                  JPMontero_Intel

                  • 6. Re: A CO2 sensor that is compatible with galileo?
                    conor100

                    Thanks JP

                     

                    Regards

                    Conor

                    • 7. Re: A CO2 sensor that is compatible with galileo?
                      flummer

                      Hi Conor,

                       

                      The PDF you linked to with an Arduino example uses the SoftwareSerial library, but that's just because they want to use the regular hardware UART to output data to the computer.

                       

                      On the Galileo board, the hardware serial pins (digital pin 0 and pin 1) isn't the same as the serial output to the computer, so you can simply use the hardware one.

                       

                      The code needs to be changed a little bit, but it's not complicated, can almost be done with "search and replace".

                       

                      /Thomas

                      • 8. Re: Re: A CO2 sensor that is compatible with galileo?
                        Tim2

                        Hi all,

                         

                        I am also interested in the K30 CO2 sensor. It seems that you can connect this sensor via UART or I2C.

                         

                        I2C: http://cdn.shopify.com/s/files/1/0019/5952/files/Senseair-Arduino.pdf?1264294173

                         

                        UART: http://www.co2meters.com/Documentation/AppNotes/AN126-K3x-sensor-arduino-uart.pdf

                         

                        JPMontero_Intel the Galileo has the software.serial library and the wire library so I would of thought that the code in both of these documents would work as is?

                         

                        I'm new to using the board, it would be helpful if I knew if before I purchase the sensor, $100+ dollars

                         

                        Thanks

                        Tim

                        • 9. Re: A CO2 sensor that is compatible with galileo?
                          flummer

                          Hi Tim,

                           

                          The software.serial library can NOT be used with the Intel Galileo, but the serial port configuration on the Galileo board is a bit different, so in some cases, you won't need the software.serial library, but can use the hardwired serial ports instead.

                           

                          The primary scenario is communicating with a sensor over a serial connection and at the same time sending serial data to the computer.

                           

                          The Arduino UNO only has one hardware serial port (connected both via USB connection to the computer and to pin 0 and 1).

                           

                          The Galileo board has two separate serial connections for that, one on pin 0 and 1 and another (virtual) serial port for communicating to the computer. (There is also a third one, but that is normally used for terminal access).

                           

                          I hope this clears it up a bit!

                           

                          /Thomas

                          • 10. Re: Re: A CO2 sensor that is compatible with galileo?
                            conor100

                            Hi Thomas,

                             

                            I'm afraid that I don't follow you. I'm a complete newbie to Arduino. When you say just "search and replace" would you explaining a little further please? Would be very helpful.

                             

                            Thanks

                            Conor

                             

                             

                            /*
                            Basic Arduino example for K-Series sensor
                            Created by Jason Berger
                            Co2meter.com
                            */
                            
                            #include "SoftwareSerial.h"
                            
                            SoftwareSerial K_30_Serial(12,13); //Sets up a virtual serial port
                            //Using pin 12 for Rx and pin 13 for Tx
                            
                            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;
                            }
                            
                            • 11. Re: Re: Re: A CO2 sensor that is compatible with galileo?
                              flummer

                              Hi Conor,

                               

                              "Search and Replace" is a feature in most text editing programs that substitutes all occurrences of one text string with another, normally used with large files with many occurrences, since it's tedious and sometimes error prone to go through the file manually and change stuff.

                               

                              But I have done it manually with the example code you included (it was only a few occurrences) and included the edited version for Intel Galileo below:

                               

                              Instead of connecting the sensor to pin 12 and pin 13, you will need to use pin 0 and pin 1 respectively.

                               

                              If you compare the files, you will see that I have replaced "K_30_Serial" with "Serial1" and changed the initialization a little bit, that's it.

                               

                              /*
                              Basic Galileo example for K-Series sensor
                              Created by Jason Berger
                              Co2meter.com
                              
                              Edited by Thomas Flummer for use with Intel Galileo
                              hackmeister.dk
                              */ 
                              
                              //Uses the hardware serial port instead of SoftwareSerial
                              //Using pin 0 for Rx and pin 1 for Tx 
                              
                              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 
                              Serial1.begin(9600); //Opens the hardware 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(!Serial1.available()) //keep sending request until we start to get a response 
                              { 
                              Serial1.write(readCO2,7); 
                              delay(50); 
                              } 
                              
                              int timeout=0; //set a timeoute counter 
                              while(Serial1.available() < 7 ) //Wait to get a 7 byte response 
                              { 
                              timeout++; 
                              if(timeout > 10) //if it takes to long there was probably an error 
                              { 
                              while(Serial1.available()) //flush whatever we have 
                              Serial1.read(); 
                              
                              break; //exit and try again 
                              } 
                              delay(50); 
                              } 
                              
                              for (int i=0; i < 7; i++) 
                              { 
                              response[i] = Serial1.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; 
                              } 
                              

                               

                              I hope it works!

                               

                              /Thomas

                              • 12. Re: A CO2 sensor that is compatible with galileo?
                                conor100

                                Thanks for taking the time to explain that Thomas. It was very helpful to see. I understand now.

                                 

                                Conor