Pages: 1 [2]   Go Down
Author Topic: Can't read Atlas Scientific colour detector  (Read 4322 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 16
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

changing that shows this

Code:
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
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 16
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 220
Posts: 13846
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


added 2 extra lines
Code:
#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
Logged

Rob Tillaart

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

0
Offline Offline
Newbie
*
Karma: 0
Posts: 16
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I just updated your code

Code:
#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:
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>
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 308
Posts: 26474
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You should not be using a signed type for the print.
Try a "(unsigned char)" cast.
Logged

"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.

0
Offline Offline
Newbie
*
Karma: 0
Posts: 16
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks

this give me this...

Code:
#include <SoftwareSerial.h>

SoftwareSerial mySerial(2, 3); 

void setup() 
{
  Serial.begin(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())
  {
    unsigned char c = mySerial.read(); // <------------ added unsigned char
    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
   

  }
      delay(1000);
}


I also added a delay just to see what I was getting from the sensor in one loop. the resulting data is somelike like:

Code:
<51>

10 seconds of running the serial monitor, i get something like:

Code:
b,Start color sensor
<49><56><44>
<177><147><148><152><156><134><49>
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 220
Posts: 13846
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

<49><56><44> is in ascii 183 which looks like a very valid value

<177><147><148><152><156><134><49> are non sensical ...

I don't understand the output.. think...
Logged

Rob Tillaart

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

Offline Offline
Faraday Member
**
Karma: 62
Posts: 3077
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Try changing the color and see what happens.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 16
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hmm,

not getting a difference when putting into a completely black area (0,0,0)

I did notice tho, when I removed the sensor from the arduino I still continue to receive readings... that cant be good right?
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 16
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

did a quick test with the default code for serial communication and tested against a black surface and got a reading of (0,0,0) so sensor seems to be responding correctly... but then entering the code above I dont receive any 0's 
Logged

Offline Offline
Faraday Member
**
Karma: 62
Posts: 3077
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I don't think you can actually assume that you should get  0,0,0  from a "black" surface.   Not unless you can exclude the light from the sensor element entirely.

It's a concern that you appear to still get readings from the sensor after you unplug it !
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 220
Posts: 13846
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


maybe you have swapped TX and RX ? can you check?
Logged

Rob Tillaart

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

Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorry for bumping the post and thanks for checking, but I am having the same problem with atlas ENV-RGB color sensor, I tried the code provided from the manufacturer websitehttps://www.atlas-scientific.com/product_pages/sensors/env-rgb.html and it did not work, also I tried all of the codes provided in this post and the last one seems working somehow:

Code:
#include <SoftwareSerial.h>

SoftwareSerial mySerial(1, 0);  

void setup()  
{
  Serial.begin(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())
  {
    unsigned char c = mySerial.read(); // <------------ added unsigned char
    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
    

  }
      delay(300);
}


The above code gave me:

Code:
Start color sensor
<255><97><114><116><32><99><111><108><111><114><32><115><101><110><115><111><114><13>
<10><60><50><53><53><62><60><57><55><62><60><49><49><52><62><60><49><49><54><62><60><51><50><62><60><57><57><62><60><49><49><49><62><60><49><48><56><62><60><49><49><49><62><60><49><49><52><62><60><51><50><62><60><49><49><53><62><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60><60>

I keep getting these values whether the sensor is connected or not..and every time I get the same exact values..

Can someone explain or help please (I am using both UNO R3 and Mega 2560)

this is my first post, but I've been around this forum for quite some time : )

Thanks!
« Last Edit: March 07, 2013, 10:50:49 am by tamem_max » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I've been using this sensor with a Diecimila and come to the same conclusion: the sample code provided by Atlas doesn't work. My current theory is that it's a timing issue with SoftwareSerial; there's data coming in but it's not ASCII.

I have the sensor working using the hardware Serial, but that means that you can't simultaneously communicate with the PC. For some applications that's fine. Code for this:
Code:
//Connections:
//Sensor green wire (sensor RX) to pin 0 (board RX)
//Sensor white wire (sensor TX) to pin 1 (board TX)


char sensorstring[30];

void setup() {
    Serial.begin(38400);
    strcpy(sensorstring, "");
    pinMode(13, OUTPUT); //LED
}


void loop() {
    while (Serial.available()) {
        //read from the sensor and watch out for a carriage return indicating
        //the end of the reading
        char inchar = (char)Serial.read();
        strncat(sensorstring, (char *) &inchar, 1);
        if (inchar == '\r') {
            //Sensor format: something like RR,GGG,B\r or RRR,GGG,BBB,*\r
            //i.e. we don't know in advance how many ASCII characters are in
            //each reading, or even how many commas.
            //Assumption: the sensor is in its default mode, providing continuous
            //readings in mode 1
           
            char rstring[4];
            char *rstart = strtok(sensorstring, ",");
            strncpy(rstring, rstart, 4);
            int red = atoi(rstring);

            char gstring[4];
            char *gstart = strtok(NULL, ",");
            strncpy(gstring, gstart, 4);
            int green = atoi(gstring);

            char bstring[4];
            char *bstart = strtok(NULL, ",\r");
            strncpy(bstring, bstart, 4);
            int blue = atoi(bstring);

            // now do something interesting with the data
           
           
            strcpy(sensorstring, "");
           
            //flash the LED to show success
            digitalWrite(13, HIGH);
            delay(100);
            digitalWrite(13, LOW);
        }
    }
}


Thanks phil88 for that trick: the empty sketch allows the sensor data to pass straight through the Arduino to the PC so you can check that the sensor is working and responding to commands. Note that RX and TX have to be swapped while you do this: i.e. white wire on pin 0, green wire on pin 1. Like phil88, I found that the Serial Monitor doesn't reproduce the carriage return regardless of what you set in the drop-down, but it is being sent.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hi all,

i'm trying to use the env-rgb sensor with an arduino uno.  has anyone used the shield with the sensor and uno?  http://www.atlas-scientific.com/_files/arduino_shield.pdf?RQPN=1-1337543-0  the site says it helps with the debugging phase. 

i'm trying to use the sensor to read rgb continuously when submerged in cups with food coloring. 

the main issue i'm facing is receiving the error messag: avrdude: stk500_getsync(): not in sync: resp=0x00, which i've read means that my board is not communicating with arduino well.  i've tried disconnecting all the pins, the usb, resetting the board, closing and reopening arduino but nothing seems to work.  while i receive this error message, when i open the serial reader, there is some text, "x" and "o" type characters in a horizontal line with some spacing.

has anyone successfully used this sensor with arduino uno or used the shield successfully?  any help is much appreciated. 

thank you,
prentiss
Logged

Pages: 1 [2]   Go Up
Jump to: