Show Posts
Pages: 1 ... 12 13 [14] 15 16 ... 19
196  Forum 2005-2010 (read only) / Interfacing / Re: Serial read from sensor on: November 02, 2009, 06:33:30 am
WORKING :-)

The issue was the delay - changed from 2 to 50.

It would still be good to try and ask Arduino to wait until data is available before printing anything - just not quite sure if this is poss and how?

Thanks for all the help - it is very much appreciated.
197  Forum 2005-2010 (read only) / Interfacing / Re: Serial read from sensor on: November 01, 2009, 05:50:05 pm
Hmmm, I'm starting to wonder if this is a timming issue?  Is it possible to get arduino to wait until the bytes are delivered from the sensor before continuing? - the sensor transmits evey 3 seconds.
198  Forum 2005-2010 (read only) / Interfacing / Re: Serial read from sensor on: November 01, 2009, 04:15:15 pm
Hi Paul, its the Arduino that crashes (or at lease that's what appears to be happening - the display stops updating but the sensor LED keeps blinking as expected).  Now with the loop counter working I can see that the crash has happened after the following counts:

61,32,10,56,33,10,56,47,11,101,34

I thought a pattern was emerging but I don't think so now.
199  Forum 2005-2010 (read only) / Interfacing / Re: Serial read from sensor on: November 01, 2009, 02:11:50 pm
Thanks Paul, it all makes perfect sense now :-) - I can see when the crash is happening now - at 96 loops this time !!
200  Forum 2005-2010 (read only) / Interfacing / Re: Serial read from sensor on: November 01, 2009, 01:41:40 pm
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

Code:
#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);

}
201  Forum 2005-2010 (read only) / Interfacing / Re: Serial read from sensor on: October 30, 2009, 09:28:20 am
Printing to the serial window rather than the LCD also produces a crash - first try after 35 samples, second time after 49 samples.  The sensor is still blinking away though.
202  Forum 2005-2010 (read only) / Interfacing / Re: Serial read from sensor on: October 30, 2009, 08:44:21 am
Hmmm - this routine has been running happily for an hour or so - that's with the sensor connected.  Not sure what to do next?

Code:
#include <LCD4Bit_mod.h>
LCD4Bit_mod lcd = LCD4Bit_mod(2);

#define address 0x31

#define delayC 1000

char co_str[10];

void setup()
{
  
  lcd.init();
  lcd.clear();
  lcd.printIn("test");
}

void loop()
{
  
  for (int co=0; co >= 0; co++){
  
  lcd.cursorTo(2, 0);
  lcd.printIn(itoa((long)co,co_str,10));
  lcd.printIn(" number  ");
  delay(delayC);
  }
}
203  Forum 2005-2010 (read only) / Interfacing / Re: Serial read from sensor on: October 30, 2009, 05:40:43 am
Thanks AWOL - will give it a try.
204  Forum 2005-2010 (read only) / Interfacing / Re: Serial read from sensor on: October 30, 2009, 05:32:16 am
ahhh... new problem !!!  It's all working very nicely printing out to an LCD but..... after a few short minutes it seems to crash - ie it all looks the same but the value remains the same (even when I know it should be changing)  Any ideas what could be going on?

The code used is:

Code:
#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];

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();
  
  getI2Cdata();

  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((long)co,co_str,10));
  lcd.printIn(" ppm  ");
  delay(delayC);
}

void getI2Cdata()
{
  delay(2);
  Wire.requestFrom(address, data_bytes);
  while (!Wire.available ());
  for (int i = 0; i < data_bytes; ++i) {
  data_buffer [i] = Wire.receive();
  }
}
  
205  Forum 2005-2010 (read only) / Interfacing / Re: Serial read from sensor on: October 29, 2009, 06:51:54 am
Well, GOD MEMBER is about right - you have fixed it - very, very much appreciated.

Thanks for your input on this and sorry for my lack of skill - I now know a little more :-)

Cheers
206  Forum 2005-2010 (read only) / Interfacing / Re: Serial read from sensor on: October 29, 2009, 06:27:17 am
Hi Awol,

Thanks for the advice - I substituted your code into the script but I'm getting errors beyond my ability.  It will be my lack of syntax/knowledge !!  Would you be up for patching it into the original code?
207  Forum 2005-2010 (read only) / Interfacing / Re: Serial read from sensor on: October 28, 2009, 05:06:25 pm
Ideally I would get I2C working :-)  I am using 4K7 pullups to 5V and analog pins 4 & 5.  The code below (written by another helpful soul)returns a result but the bytes returned are all 8's with a PPM: 2056 !!!

IE:
CO PPM: 2056
Data received:8,8,8,8,8,8,8,


Code:
#include <Wire.h>
//wire library

#define address 0x31
//address of the sensor

#define delayC 5000
//delay count in ms

#define baudrate 9600
//baudrate for communication

void setup()
{
  Wire.begin();
  Serial.begin(baudrate);
}

void loop()
{
  //Serial.print("CO PPM: ");
  
  int co=0;

  Wire.beginTransmission(address);
  // start the transmission
  
  Wire.send('R');
    
  Wire.endTransmission();
  //end the transmission
  
 /// Wire.requestFrom(address, 7);
  
  // format
  // 1) Configuration 0x08
  // 2) CO (high byte?)
  // 3) CO (low byte?)
  // 4) reserved
  // 5) reserved
  // 6) reserved
  // 7) reserved
  
  Serial.print ("Data received:");
  for (int i=0;i<7;i++)
  {
    byte c;
    c = getI2Cchar();
    Serial.print(c,HEX);
    Serial.print(',');
    if (i==1) co = c;
    if (i==2) co = (co << 8) | c;
  }
  Serial.println("");
  Serial.print("CO PPM: ");
  Serial.println(co);

  delay(delayC);
}

byte getI2Cchar()
{
  delay(2); // delay 2mS
  Wire.requestFrom(address, 1);
  return (Wire.receive());
}
208  Forum 2005-2010 (read only) / Interfacing / Re: Serial read from sensor on: October 28, 2009, 04:37:20 pm
Hi Groove,

OKAY - that would explain a lot - it looks like I am back to headscratching (well scrathced already) with I2C then or buying a MEGA?
209  Forum 2005-2010 (read only) / Interfacing / Re: Serial read from sensor on: October 28, 2009, 04:33:19 pm
Hi Andy,

Your right - at this stage I just want to 'see' the output, eventually printing to an LCD and finally data logging.

The sensor is pre-production so not too much info available to share - it does output to both I2C & UART.

Thanks for the serial expalination - I'm clear now - would also expalin why I couldn't upload with the sensor connected!
210  Forum 2005-2010 (read only) / Interfacing / Re: Serial read from sensor on: October 28, 2009, 04:28:23 pm
Hmmm, you could be right - I looked at this too: http://arduiniana.org/libraries/NewSoftSerial/ max BAUD being 28800 - does it have to be exactly the same to work?

The data sheet say this:

UART
38400bps, 8bit, No parity, 1 stop bit
TTL Level Voltage 3.0~4.5V
Pages: 1 ... 12 13 [14] 15 16 ... 19