top of page
  • Writer's picturemoawling

serial inputs! call backs! faces!! woohoO!

This week, we're learning about serial communication, a process where data is sent at bits at a time. This process allows for longer-distance communication and helps mediate synchronization difficulties. I dedicated my time this week to develop a better understanding of how serial communication is established through software. I also killed some time messing around trying to draw faces with a potentiometer, which definitely absolutely benefited my understanding of the process.

I'll mostly be focusing on this lab for this blog post, "Serial Input to p5.js"

The goal of this lab was to establish serial communication between a microcontroller and computer, utilizing a potentiometer as a form of input. This involved physical electric components, a computer, p5 js editor, and the P5.serialcontrol application.

The Physical Electric Components:

I started with setting up my breadboard! This lab would be using a potentiometer as a sensor, after looking over the code for the assignment, I made sure to connect the potentiometer to the pin specified in the code which was A0, a pin for analog input. This pin is located four pins down on the left of the Arduino Nano 33.

Image Description: A small breadboard with an Arduino Nano, potentiometer, and several black, red, and yellow wires. The red wires represent power, the black wires are coded for ground, and the yellow wire represents input.

The potentiometer has three pins total, I used its middle pin to connect it to my microcontroller (the Arduino), and used the other two pins to power and ground it.

I then programmed the microcontroller, which is a necessary step in establishing the input, serial communications, and controlling the rate of the transfer of data.

(this code is copy+pasted directly from the lab assignment, the comments are in blue text)

void setup() {
 Serial.begin(9600); // initialize serial communications
void loop() {
 int potentiometer = analogRead(A0);                  // read the input pin
 int mappedPot = map(potentiometer, 0, 1023, 0, 255); // remap the potentiometer value to fit in 1 byte
 Serial.write(mappedPot);                             // print it out the serial port
 delay(1);                                            // slight delay to stabilize the ADC

From my understanding of this code and serial communication (which could be entirely wrong), determining characteristics like the size of input data or the delay can affect how our information will be displayed through p5js. I'm curious if determining the potentiometer value may affect how we should program the delay. buT that'S a questiON for LATER yEAHHH


All of the setup required to establish serial communication was the most intriguing aspect of this lab and I can't wait to share what I only understand 5% of.

This lab required us to install the P5.js Serialport Library and the P5.serialcontroll App.

35 views0 comments

Recent Posts

See All WHEE

bottom of page