Serial Communication

For this project, the aim was to get Serial Communication from Arduino to P5.js and P5.js to Arduino. There were three things to check for this assignment: get two analog inputs from the Arduino and send the values to P5.js, create something interactive using the analog values, then send values from P5.js to Arduino to get some sort of output.

What I had planned for this project did not turn out like I wanted.

There are two potentiometers in the breadboard, a slider and a regular potentiomter. In P5.js, the goal of the interaction is to get a circle into a hole. The two potentiometers send values from the Arduino into P5.js. Where P5.js reads and uses the values to control the ball. One slider controls the y-axis of the ball, while the other controls the x-axis of the ball. In P5.js draw loop, there is a if statement. The if statement does two things: it changes the background color to green, and it sends two values to Arduino. Once the circle/ball is inside the hole, the values are sent to Arduino to turn the two LEDs on.

GitHub Link to Arduino Code: https://gist.github.com/feve1752/481335266d868d70244f93cb56de2db6

P5.js sketch: https://editor.p5js.org/framirez1998/sketches/cIN-6noro

Vinmeo video: https://vimeo.com/327201558

What I had planned for the project, the circle hole thing would have levels. Each time a circle/ball would make it into a hole, a new hole would appear with a different size. After a certain number of holes appear, the game would reset turning the second LED ON. That got complicated real quick in terms of programming in the P5.js side. I realized, not only did it complicated but the code got messy too. I should have created functions for certain events to clean up the code. That in the end did not work out so well.

Things I considered. Sometimes, for some reason, the Arduino and P5.js did not sync with each other very well. There would be delays in the values that the P5.js would receive. Making the circle appear to not move or move very slowly then rapidly. Also, when building my breadboard, the wires are in the way of the potentiometers. If I touched the wires, this would cause changes in values. Making the circle move back and forth or, even, jump from one spot to the other. When building something better, those are somethings to keep in mind.

Leave a comment

Design a site like this with WordPress.com
Get started
search previous next tag category expand menu location phone mail time cart zoom edit close