Physical Computing · Week 7

Lab: Two-Way (Duplex) Serial Communication Using An Arduino and P5.js

Preparing my breadboard: Connected my Arduino Nano, ADXL335 accelerometer, soldered my sensor board to the pins, and added a push button to power and ground

Sending multiple serial data using punctuation: Programmed the microcontroller to read the pushbutton and two axes of the accelerometer (X and Y) in Arduino sketch

Set Up of Code in Arduino for Two Way Communication

Receiving the data in p5.js: Following the instructions, I set up my p5.js code accordingly through adding in the various parts of code provided

Set Up of Code in p5.js for Two Way Communication

Mapping my sensor value: After running my code in p5.js my circle wasn’t visible and I struggled a little to figure out why. After checking my code thoroughly, I figured out the it was probably due to me using the default sensor values provided and thus I tried console logging my serial data to figure out the range of my sensor

Troubleshooting and Mapping My Sensor Values Due to Empty Black Screen

After this, I was then able to get my circle to appear on my canvas and move it around through tilting my accelerometer and making it disappear by pressing on my push button.

Flow control — call and response (handshaking): Adding in handshaking to code above in Arduino as sometimes can run into the problem of the sender sending faster than the receiver can receive

Flow Control by Adding to and Slightly Adjusting the Punctuation Code Above

When I run my sketch, I was able to see the word “hello” in my serial monitor and was able to get a string of sensor values after typing in a character in the output box.

Flow control — modifying my p5.js sketch: Following the instructions, I made changes to the serialEvent( ) function in my p5.js sketch. Since I already have the serial.write(‘x’) lines in already, I didn’t have to add in those

Modifying My serialEvent( ) function in p5.js

By adding in handshaking, my Arduino in now only sending when the p5.js is ready to receive, which helps it better manage the serial communication.

Project 2 Idea

For my project 2, I am interested in making a game controller for a game similar to the digital interface of music rhythm games. Currently, my idea is to have a paddle on the bottom for it to catch the falling shapes and and either control the paddle with the keys A and D (from the WASD gaming layout) or the left and right arrow keys. I am also thinking of using LEDs as my serial output, programming various colors of LEDs to light up accordingly as the falling objects hit my paddle. Bellow are some inspirations from the web:

I might consider implementing the use of my APDS9960 color and gesture sensor to add in an additional component to my game controller if I see fit after understanding this sensor better through working on next week’s lab, or modify my idea as I work depending on my execution ability and process.

Note: I have also finished updating my week 6 blog post on labs from the previous week as well.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s