I need to porting the Library for the K33 CO2 Sensor written by KinaSmith to the Electron.
This library works great with our Arduino based dataloggers
I think I’m close, but my problem is rewriting a function in Co2Meter_K33.cpp that includes a function called "wakeSensor().
I need some advice on how to repeat this I2C maneuver in the Electron. I did some research on this but I could use some pointers.
Thanks in advance.
///////////////////////////////////////////////////////////////////
// Function : void wakeSensor()
// Executes : Sends wakeup commands to K33 sensors.
// Note : THIS COMMAND MUST BE MODIFIED FOR THE SPECIFIC AVR YOU ARE USING
// THE REGISTERS ARE HARD‐CODED
/////////////////////////////////////////////////////////////////
void Co2Meter_K33::wakeSensor() {
// This command serves as a wakeup to the CO2 sensor, for K33‐ELG/BLG Sensors Only
// You'll have the look up the registers for your specific device, but the idea here is simple:
// 1. Disabled the I2C engine on the AVR
// 2. Set the Data Direction register to output on the SDA line
// 3. Toggle the line low for ~1ms to wake the micro up. Enable I2C Engine
// 4. Wake a millisecond.
TWCR &= ~(1 << 2); // Disable I2C Engine
DDRC |= (1 << 4); // Set pin to output mode
PORTC &= ~(1 << 4); // Pull pin low
delay(1);
PORTC |= (1 << 4); // Pull pin high again
TWCR |= (1 << 2); // I2C is now enabled
delay(1);
}
Wire.end(); // Turn off the I2C bus so GPIO (pins D0 and D1) can be used
pinMode(D0, OUTPUT); // Set SDA (D0) to output
digitalWrite(D0, LOW); // Toggle the pin low for 1ms then HIGH again
delay(1);
digitalWrite(D0, HIGH);
Wire.begin(devAddr); // restart the I2C bus with the device's address
We are using it at a research site where the soil and groundwater have been contaminated with hydrocarbons (old gas refinery). We cover the soil surface with plastic or a chamber and monitor the buildup of CO2 in the headspace as a measure of underground microbial respiration - a proxy for the hydrocarbon degradation rate.