TUSIC
  • Home
  • Process
    • Sprint One
    • Sprint Two
    • Sprint Three
    • Final Sprint
  • Budget
  • Systems
    • Mechanical
    • Electrical
    • Software
  • The Team
  • Blog
  • Home
  • Process
    • Sprint One
    • Sprint Two
    • Sprint Three
    • Final Sprint
  • Budget
  • Systems
    • Mechanical
    • Electrical
    • Software
  • The Team
  • Blog

Software

Overview

The software for this project was used to enable a hands-free turning method.  It consists of two modes: calibration and live-run.  In the calibration, the number of beats that have been played is actively updated, and a "beat count" is recorded when a pedal is pressed.   In live-mode, the beats are counted and a page is turned whenever a "beat count" is reached.  This software relies on open communication between Python code (run off a computer) and an Arduino. 
Calibration Mode
Picture
User initiates calibration mode by holding down the button.  Arduino
​signals python to start listening for and counting beats.
Picture
User taps the button to turn the page.  Arduino signals python to
​remember the beat count at this moment.
Picture
User holds down the button again, indicating the piece is over.
Vertical Divider
Live-Mode
Picture
User presses and holds down the button to begin live-mode. Python begins counting beats, as in calibration mode.
Picture
Python tells Arduino when to turn the page based off of the beat count found in calibration mode.

Arduino Code

The Arduino is responsible for operating the motors as well as taking input from the pedal.  The servo motor is run using the built-in servo library, and the pedal is coded in the same manner as a typical button.  Originally, the stepper motors were run from a built-in stepper library, but this library was unable to run multiple stepper motors at the same time.  Instead, we rewrote this code to manually turn the coils in the stepper motors on and off.  More information on this process can be found in our Electrical Systems page.

Along with integrating the pedal and motors, Arduino code was also used to communicate with the Python beat-detection code.  This communication occurs via the serial monitor.  When the button is pressed in calibration mode, a "turn" message is printed onto the serial monitor.  The Arduino also monitors whether the button was tapped or held down, as this results in different actions.  To do this, the difference between the time at which the button was pressed and the time that it was released is found.  If the time difference is greater than a certain threshold, then the Arduino will register the action as a "held button." 
Code for Stepper Motor

Python Code

​We have two different python scripts: calibration and live playing beat detection.  The calibration code waits for a long press from the pedal to start recording the music. It keeps track of the beat count, and every time the pedal is pressed, the page is turned and the beat count is stored.  When the pedal is long pressed again, the recording stops and the beat count corresponding to each page turn is saved to a text file.  The illustration below depicts this calibration process. 
Picture

Full Code

To see the full implementation of our code, go to our GitHub repository.
GitHub Repository with Code
Create a free web site with Weebly