Strange results from Arduino through Serial
in
Integration and Hardware
•
1 year ago
I'm trying to use Processing to display sensor values from my Arduino.
The serial monitor gives the correct values, but Processing gives two (sometimes three) incorrect digits.
Here's my Arduino code:
The serial monitor gives the correct values, but Processing gives two (sometimes three) incorrect digits.
Here's my Arduino code:
- void setup() {
- Serial.begin(9600);
- }
- void loop() {
- float brightness = analogRead(A0);
- brightness = brightness / 1023 * 255; //make sure that it's under 255 so it's only one byte...
- //maybe it's a stupid idea, but I'm no expert.
- Serial.println(byte(round(brightness)));
- }
Processing code:
- import processing.serial.*;
- Serial bob; //I've named my robot bob... so sue me.
- int light;
- void setup() {
- bob = new Serial(this, "COM3", 9600);
- }
- void draw() {
- if (bob.available() > 0) {
- light = int(bob.read());
- println(light);
- }
- }
2