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
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
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
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
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
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.