Thanks for that,
ive just tried verify this and get the following error:
'NewSoftSerial' does not name a type.
im running 1.0.3
Cheers,
Phil
Thanks for that,
ive just tried verify this and get the following error:
'NewSoftSerial' does not name a type.
im running 1.0.3
Cheers,
Phil
Use "SoftwareSerial" instead.
I'm sorry I joined.
Members from IP (range) xx.xxx.xxx.xx
IP address Display name
xx.xxx.xxx.xx Summersgill, summersgillb
So sorry, you joined twice?
Sorry, retry
#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(c);
if (c == ',') Serial.println(); // split the R G and B
if (c == 13) Serial.println(); // extra newline
}
}
thanks for that,
I open up the serial monitor and get this...
͹ÙL
(values change when i close and re-open the monitor) for example:
Ô»Ðó
ݽùÌ
that looks like some ascii code very promising (said the optimist)
#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(c, DEC); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<< line changed
if (c == ',') Serial.println(); // split the R G and B
if (c == 13) Serial.println(); // extra newline
}
}
can you give it a try?
cool,
im getting a new reading roughly every second now...
ɵÁ\?Ð?p?aà°?ÁY`1?aÿ?ðÉÜp?aàÐ?£p?#à°???¡p?#øÐÅ?£p?#àðÉ??!p?øÌùñ 0?apÀ̹±?á cøÐÅ?£p?#à°?ÁK°cà?Ùpcà
There are coming to much bytes, could also be a loose wire(!)
Have you try alternative baud rates?
9600, 19200, 38400 (already tested), 115200?
Thanks, robtillaart. I tried your code, too, but I still don't get anything back.
ah yes, that makes sense then sensor runs at 38400,
changing that shows this
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
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.
added 2 extra lines
#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
I just updated your 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
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>
You should not be using a signed type for the print.
Try a "(unsigned char)" cast.
Thanks
this give me this...
#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:
<51>
10 seconds of running the serial monitor, i get something like:
b,Start color sensor
<49><56><44>
<177><147><148><152><156><134><49>
<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...
Try changing the color and see what happens.
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?
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
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 !
maybe you have swapped TX and RX ? can you check?