Hi all,
I have a feeling this is a rather frequent problem, but no amount of searching on these forums or the googles gives me an answer. I'm not a total Arduino or Processing noob, but my limits are showing here.
I'm trying to have bidirection communication between an Arduino and a Processing sketch eventually, sending a compass reading to Processing (eventually over XBees) and Processing sending a PWM value back as well as a couple digital HIGH/LOW settings for motor direction control. I'm trying to get a motor to align things with North.
My code, based on the example "PhysicalPixel" sketch, code I've altered is in red:
const int ledPin = 13; // the pin that the LED is attached to
[color=red]String[/color] incomingByte; // a variable to read incoming serial data into
void setup() {
// initialize serial communication:
Serial.begin(9600);
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
}
void loop() {
// see if there's incoming serial data:
if (Serial.available() > 0) {
// read the the serial buffer:
[color=red]incomingByte = Serial.read();[/color]
Serial.println(incomingByte);
// if it's "High", turn on the LED:
if (incomingByte == "H[color=red]igh[/color]") {
digitalWrite(ledPin, HIGH);
}
// if it's "Low" turn off the LED:
if (incomingByte == "L[color=red]ow[/color]") {
digitalWrite(ledPin, LOW);
}
}
}
To keep things simple for now I'm just using the Arduino IDE serial monitor to watch the serial coming in, and to manually type "High" or "Low". As you may have guessed by now I'm receiving
72
105
103
104
10
in the serial monitor, which is obviously the ASCII codes for "High" - each letter, plus newline.
Any hints or places anyone can send me to get this solved. I have a feeling it's something simple but I can't track it down.
Thanks in advance