Go Down

Topic: Can't read Atlas Scientific colour detector (Read 4 times) previous topic - next topic

phil88

ah yes, that makes sense then sensor runs at 38400,

changing that shows this

Code: [Select]
b,Start color sensor
495253-84494853-84494857-115495250-84494850-84494854-115495253-84494853-844948-75-115495253-84494853-84494853-115545344
-76-105-108-103-104-122544944
-108-99-106-102-102-122

phil88

what is unusual,

I can only start the readings when I pull out the 5v and ground and reinsert into the arduino. The sensor also works without the 5v wire.

robtillaart


added 2 extra lines
Code: [Select]
#include <SoftwareSerial.h>

SoftwareSerial mySerial(2, 3); 

void setup() 
{
  Serial.begin(115200);
  Serial.println("Start color sensor");

  // set the data rate for the NewSoftSerial port
  mySerial.begin(38400);
  mySerial.print('C');
}

void loop()
{
  if (mySerial.available())
  {
    char c = mySerial.read();
    Serial.print("<");  // <<<<<<<<<<<<<<<<<<<<<<<<<<<<< line added
    Serial.print(c, DEC); 
    Serial.print(">"); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<< line added
    if (c == ',') Serial.println(); // split the R G and B
    if (c == 13) Serial.println(); // extra newline
  }
}


please give it a try
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

phil88

I just updated your code

Code: [Select]
#include <SoftwareSerial.h>

SoftwareSerial mySerial(2, 3); 

void setup() 
{
  Serial.begin(38400); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<< changed to 38400
  Serial.println("Start color sensor");

  // set the data rate for the NewSoftSerial port
  mySerial.begin(38400);
  mySerial.print('C');
}

void loop()
{
  if (mySerial.available())
  {
    char c = mySerial.read();
    Serial.print("<");
    Serial.print(c, DEC); 
    Serial.print(">");
    if (c == ',') Serial.println(); // split the R G and B
    if (c == 13) Serial.println(); // extra newline
  }
}


That gives me this

Code: [Select]
b,¡¡¤%¥¡%%%Start color sensor
<52><51><44>
<-77><-108><-106><-103><-102><-122><50><53><44>
<-79><-107><-106><-104><-103><-122><50><53><44>
<-78><-111><-108><-103><-104><-122><50><53><44>
<-78><-103><-106><-103><-104><-122><50><49><44>
<-79><-104><-108><-104><-100><-122><50><52><44>
<-79><-103><-106><-102><-103><-122><52><51><44>
<-77><-111><-106><-103><-102><-122><52><48><44>
<-78><-104><-106><-103><-103><-122><49><48><44>
<-79><-104><-106><-102><-103><-122><51><50><44>
<-78><-104><-106><-103><-103><-122>

AWOL

You should not be using a signed type for the print.
Try a "(unsigned char)" cast.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Go Up