Serial IMU Output to p5.js Lab to Personal Project

I decided to work on this lab as a way to prepare for the sketch I am going to do for this weeks assignment.

Programming the Microcontroller went well until I added the Madgwick library. For some reason even after deleting and adding the file to Arduino it kept giving me an error saying the file was private. I ended up re-downloading Arduino and the Madgwick folder and it was able to read the code.

Then when it came time to add serial handshaking I received an error saying “amp;” was not defined. I did not understand this and noticed in the code provided for the lab there was an error.

if (IMU.accelerationAvailable() & amp; & amp; IMU.gyroscopeAvailable())

I made the simple change and it started reading the gyroscope.

if (IMU.accelerationAvailable() && IMU.gyroscopeAvailable())

Moving the data to p5.js was successful.

I am going to use this as a base to control a past p5 sketch I’ve done.

My original sketch

What I wanted to change is how the car is moved. Instead of pressing keys you move the Arduino left or right to activate the song and motion. The first step was to get the sensors reading within the original sketch.

Then I wanted to replace the key functions with the Gyroscope reader.

I got the reader to print out which direction it is going instead of the coordinates.

I got the Arduino sketch and p5.js to communicate the directions

This is as far as I was able to go until I ran into a road block. I got p5 to receive the sensors information but unable to link the actions of the cars to the sensors.

Update:

Got it to work for short moments and wanted to try it without the delay to see if it helped but then I started getting this error:

Update 2:

I tried switching from the Gyroscope to Accelerometer and the readings were more consistent but the translation from the sensor to the p5 sketch was still unsteady.

Current code that is not working.

Previous
Previous

Final Project Drafts

Next
Next

Two-Way (Duplex) Serial Communication