Hi all,
I was about to post this question, and then figured out how to fix it. I wanted to post it anyways, with the solution, so that it might help others. I do have two unanswered question at the end of the post.
Original question:
I'm trying to get the Tweak the Logo project to work but I've hit a snag. The logo remains red, and nothing is printed to the Processing console.
I'm using a Mac with Catalina OS.
This is my Arduino code:
void setup() {
Serial.begin(9600);
}
void loop() {
Serial.write(analogRead(A0) / 4);
delay(1);
}
And this is my Processing code:
import processing.serial.*;
Serial myPort;
PImage logo;
int bgcolor = 0;
void setup() {
size(1, 1);
surface.setResizable(true);
colorMode(HSB, 255);
logo = loadImage("http://www.arduino.cc/arduino_logo.png");
surface.setSize(logo.width, logo.height);
println("Available serial ports:");
println(Serial.list());
myPort = new Serial(this, Serial.list()[0], 9600);
}
void draw() {
if ( myPort.available() > 0) {
bgcolor = myPort.read();
println(bgcolor);
}
background(bgcolor, 255, 255);
image(logo, 0, 0);
}
This is what Processing reports as my available ports:
/dev/cu.Bluetooth-Incoming-Port /dev/cu.MALS /dev/cu.SOC /dev/cu.usbmodem141301 /dev/tty.Bluetooth-Incoming-Port /dev/tty.MALS /dev/tty.SOC /dev/tty.usbmodem141301
Behaviour:
The processing sketch shows a red logo. Nothing is printed to the console, and the logo colour never changes--it's always red.
If I open the Arduino serial monitor, this is what I see: when I rotate the dial, I get question marks output to the serial monitor for half of the arc, and for the other half I get characters that change as I rotate the pot.
I've looked at messages from others on the forum, and nothing I've found has helped, including:
- Changing the if to while in the Processing sketch
- Changing Serial.write to Serial.print or Serial.println
- Changing the [0] in myPort = new Serial(this, Serial.list()[0], 9600); to a [1]
- Changing the delay to 33 in the Arduino sketch
Solution:
To cover all my bases, I tried [2], and [3] instead of [0] here: myPort = new Serial(this, Serial.list()[0], 9600);. The [3] ended up working: it got me a different colour than red. However, when I moved it, nothing changed. That made me think that the 'if' did in fact need to change to 'while' in the Processing code. Those two changes made the code work.
Unanswered questions:
-
Does anyone know why the correct port is [3] (the fourth port), when the Processing sketch only prints two ports in the list of available ports?
-
Why does the Arduino output question marks to the serial monitor for half of the potentiometer's arc?
Thanks so much!