Week 14 - Interfacing
For this week, the task was fairly easy. I began by thinking about using tkinter, but ultimately decided against it beause I figured something else would be better for what I wanted to do, so I tried processing instead. On [Mrs. Morrow's site] she has videos that I followed to create some simple graphics. This was fairly intuitive as I had some previous experience with designing some things using javascript on Khan Academy. Essentially there are many different commands to draw different shapes, as well as the coordinates where they are placed. After I had a basic understanding of what you could do in processing, I asked Chat GPT to write me a program in processing that reads a value from a button on an rp2040 pico and reads out "button on" when pressed and "button off" when not pressed
. In return for this, ChatGPT spit out this code -
`` import processing.serial.*;
Serial myPort; // Serial port object boolean buttonState = false; // Variable to store button state
void setup() { String portName = Serial.list()[0]; // Change index if needed myPort = new Serial(this, portName, 9600); }
void draw() { if (myPort.available() > 0) { char inByte = myPort.readChar(); if (inByte == '1') { buttonState = true; } else if (inByte == '0') { buttonState = false; } }
background(255); textSize(24); textAlign(CENTER, CENTER);
if (buttonState) { fill(0, 255, 0); // Green color when button is pressed text("Button On", width / 2, height / 2); } else { fill(255, 0, 0); // Red color when button is released text("Button Off", width / 2, height / 2); } }
void keyPressed() { if (key == 'q' || key == 'Q') { myPort.stop(); // Stop reading from the serial port exit(); // Quit the application } } ``
I couldn't get this code to run for a little bit until I figured out that I had to change String portName = Serial.list()[0]; // Change index if needed
to String portName = "COM35"; // Change index if needed
or to whatever port I was using. I tried to run this and I got no error, but I realized that nothing was working. I asked chatGPT what was wrong, and it told me that I had to still upload some basic serial write code to the Pico I was using. Once I did this, I was able to get it to work!
Group site
This week we compared different infrastructures to each other for interfacing, here is the link to the group site