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