Sending data to arduino
in
Integration and Hardware
•
2 years ago
Hello,
I've written a simpe arduino program that listens to serial port and waits for data.
The data is a 9 digit number, each 3 digits are one of the RGB values to color the LED's acordingly.
When i upload the code to arduino and test it via serial monitor it works like a charm.
Now i'm trying to pass the data from a processing code instead of serial monitor.
And all i get is my led's flashing for a milisecond and nothing else.
Any ideas what i'm doing wrong here?
Arduino code
Processing code
I've written a simpe arduino program that listens to serial port and waits for data.
The data is a 9 digit number, each 3 digits are one of the RGB values to color the LED's acordingly.
When i upload the code to arduino and test it via serial monitor it works like a charm.
Now i'm trying to pass the data from a processing code instead of serial monitor.
And all i get is my led's flashing for a milisecond and nothing else.
Any ideas what i'm doing wrong here?
Arduino code
- int analogPinR = 9;
int analogPinG = 10;
int analogPinB = 11;
//the buffer
int RGB[9];
//VALUES OF Red green and blue
int R=0;
int G=0;
int B=0;
void setup()
{
Serial.begin(9600);
}
void loop(){
if(Serial.available()==9){
for(int i =0;i<9;i++){
RGB[i]=Serial.read() - '0';
}
//get the data from the integer array
R= RGB[0]*100+RGB[1]*10+RGB[2];
G= RGB[3]*100+RGB[4]*10+RGB[5];
B= RGB[6]*100+RGB[7]*10+RGB[8];
}
//light the leds
analogWrite(analogPinR, R);
analogWrite(analogPinG, G);
analogWrite(analogPinB, B);
}
Processing code
- import processing.serial.*;
Serial port;
void setup() {
port = new Serial(this, Serial.list()[1], 9600); - port.write(000255000);
}
2