From the specs I've seen, this should do a basic capture. Give it a try
#include <NewSoftSerial.h>
NewSoftSerial 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.write('C');
}
void loop()
{
char c;
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
}
}
#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
}
}
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
}
}
#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
}
}
#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
}
}
#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>
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