Firmware Design

Final Project for Principles of Engineering

All of the Arduino IDE firmware code was compiled into a single script. This reflected our goal of a compact and polished project goal, as we attempted to minimize the number of Arduinos we needed in the system. With all the code compiled into a single Arduino, it is easy to observe how all the code runs in parallel.

At the beginning of the Arduino code, we initialize settings and libraries we will use. We initialize the adafruit motor library, which allows to use motor shields for the Arduino uno effectively, and initialize each of our 8 motors and set their initial speed.

Further initialization include LED interaction setups, and defining LED function definitions for later. Each LED is hooked to 3 digital pins, and the mixture of RGB of each LED defined the final color the LED was. LED functions down below included input triggered patterns and so forth.

The final initialization relates to the photodiode and accelerometer, the electrical components on the protoboard. For these components, the variables that will be used to store counters (for counting the number of knocks) and the read values from the accelerometer and the photodiode initialized.

Further initialization include LED interaction setups, and defining LED function definitions for later. Each LED is hooked to 3 digital pins, and the mixture of RGB of each LED defined the final color the LED was. LED functions down below included input triggered patterns and so forth.

AFter the initialization is complete, the Arduino code is set up. In the setup process, the motor speeds initialized above are applied, and the motors are now given their initial speeds. Also, the LED pins are grouped together for flexibility and simplification in commanding.

After all the variables are initialized, the code enters the main void loop. In this loop, there are two main interactions. The first main function of the main loop is the knock sensing. For the knocking, if a knock didn’t happen for over a certain period of time, we reset the knock counter to zero, as we only want consecutive knocks to register as “knocks”. When the counter registers one knock, LED toggling happens, and if it registers two knocks, it toggles a serial interaction with the raspberry pi.

The serial communication initially occurs with a self written “serial flush” function. Sometimes, due to us attempting two way communication between the Arduino and the Pi, there is unwanted noise and echo in the serial terminal. The serial flush function resets the serial terminal so that these noises do not hinder the communication process.

The switch-cases after the two major functions are different states the desktop companion is in. These states are accessed by the different inputs and interactions. Different cases equate to different emotions of the kinetic sculpture, and it will output different types of LED patterns and make different faces on the screen attached to the sculpture. Each of the LED pattern commands are linked here, in our github repository.