Get readings from Grove CO2 sensor [SOLVED]

@tlintved, this sensor is 5v powered and has a UART so you will need to connect the sensor to the Photon this way (assuimg Photon is USB powered):

Photon   Sensor
---------------
Vin      power
GND      GND
RX       TX
TX       RX

This uses the Serial1 port of the Photon versus the SoftwareSerial of the sample code on the sensor’s wiki. The code needs to be adapted slightly:

#define DEBUG 0
 
const unsigned char cmd_get_sensor[] =
{
    0xff, 0x01, 0x86, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x79
};
unsigned char dataRevice[9];
int temperature;
int CO2PPM;
 
void setup()
{
    Serial1.begin(9600);    // Sensor uses Serial1 on Photon
    Serial.begin(115200);  // This is the USB serial port on the Photon
    Serial.println("get a 'g', begin to read from sensor!");
    Serial.println("********************************************************");
    Serial.println();
}
 
void loop()
{
    if(dataRecieve())
    {
        Serial.print("Temperature: ");
        Serial.print(temperature);
        Serial.print("  CO2: ");
        Serial.print(CO2PPM);
        Serial.println("");
    }
    delay(1000);
}
 
bool dataRecieve(void)
{
    byte data[9];
    int i = 0;
 
    //transmit command data
    for(i=0; i<sizeof(cmd_get_sensor); i++)
    {
        Serial1.write(cmd_get_sensor[i]);
    }
    delay(10);
    //begin reveiceing data
    if(Serial1.available())
    {
        while(Serial1.available())
        {
            for(int i=0;i<9; i++)
            {
                data[i] = Serial1.read();
            }
        }
    }
 
#if DEBUG
    for(int j=0; j<9; j++)
    {
        Serial.print(data[j]);
        Serial.print(" ");
    }
    Serial.println("");
#endif
 
    if((i != 9) || (1 + (0xFF ^ (byte)(data[1] + data[2] + data[3]
    + data[4] + data[5] + data[6] + data[7]))) != data[8])
    {
        return false;
    }
    CO2PPM = (int)data[2] * 256 + (int)data[3];
    temperature = (int)data[4] - 40;
 
    return true;
}

:smiley: