Hmmmm, I'm still trying to find out where the problem is.... I've tried cutting the code down so that it does the bare minimum to display the data required but I don't think it's right? I have also inserted a sample counter to see when the crash happens but my noobness can't even get that right!!! it counts 1,2,3,10,11,12,13,20 :-(
Yikes
#include <LCD4Bit_mod.h>
LCD4Bit_mod lcd = LCD4Bit_mod(2);
#include <Wire.h>
#define address 0x31
#define delayC 2000
#define baudrate 9600
char co_str[10];
char sam_str[4];
int sam;
int co;
const int data_bytes = 7;
byte data_buffer [data_bytes];
void setup()
{
Wire.begin();
Serial.begin(baudrate);
lcd.init();
lcd.clear();
lcd.printIn("Value");
}
void loop()
{
Wire.beginTransmission(address);
Wire.send('R');
Wire.endTransmission();
delay(2);
Wire.requestFrom(address, data_bytes);
while (!Wire.available ());
for (int i = 0; i < data_bytes; ++i)
data_buffer [i] = Wire.receive();
for (int i=0;i<7;i++)
{
byte c = data_buffer [i];
if (i==1) co = c;
if (i==2) co = (co << 8) | c;
}
lcd.cursorTo(2, 0);
lcd.printIn(itoa(co,co_str,10));
lcd.cursorTo(2, 5);
lcd.printIn("ppm");
sam = (sam++);
lcd.cursorTo(2, 10);
lcd.printIn(itoa(sam,sam_str,4));
delay(delayC);
}