Week 4: 3D Printing and Coding Galore

This week, we've made several large strides to achieving our goal of making a self-playing bass. Our challenge for this week was to begin going beyond just strumming, and achieve some methodology of controlling pitch (i.e. fretting). Here is what we were able to achieve:

Code

This week we began our github repository for the code that controls our Teensy. It can be found here: https://github.com/emanespino/ENGR103-Self-Play-Bass

We basically created the basis of how the code will work for the self-playing bass based off of the template that we were given at the start of the class for interacting with the Teensy microcontroller.

Major points of interest in the code are:


This is the strumNote function. It takes an integer as a parameter to determine which pin to trigger. It utilizes two built-in functions, digitalWrite and digitalRead. The latter, digitalRead, is simply a function that, given a pin number in the form of integer, returns either a 0 or 1 depending on whether or not LOW or HIGH power is currently being sent to that pin. Likewise, the digitalWrite function takes a pin number and a value to be written to that pin, either 0 or 1. When a note is to be strummed, all this function needs is a string number. It takes that integer, and writes to the pin it specifies to the value opposite of what it currently reads. In short, it flips the value for that pin when that pin is specified. Physically, this command either turns on or off power to a solenoid, the result of which being an extension of a pick or a retraction. This creates an upstroke or a downstroke on the string that is specified.


The triggerFrets function is a little more complex when compared to the strumNote function. Again, it takes an integer parameter that translates to a fret that needs to be pressed. The digitalWrite function is used again to trigger different power levels for the pins in question. There is a constant array seen in this function, FRETS, which is a list of the pins that correspond to the pins that trigger fretting. If a fret needs to be pressed down, the code first lifts up all the solenoids that come after that fret. From there, if the fret is not the open string, the fret is then pressed down by a solenoid. 



This is still an evolving portion of the code, but what we have here is the logic used to determine the frets that are pressed and the strings that are strummed based on the MIDI data received by the Teensy. This bass will be able to play the range of MIDI notes from 16-36, therefore all our ranges are based off of this. There are only 5 frets that can be played, so when a note is received, the code subtracts a 1 and does a modulus operation on the data so that it fits the range of [0-4]. Once the fretting is completed, the code must determine which string to play. This is done by subtracting 1 from the note, dividing it by 5, and then subtracting to normalize the data to begin at 0. This assures that the first 5 notes are played by the first string, the second 5 notes are played by the second string, and so on and so forth. 

3D Printing

Another big portion of what was worked on this week were 3D parts. We did a lot of printing and testing for strumming, and for fretting. Here are the results thus far:

For strumming, we 3D printed several iterations of a structure for how we wished to approach strumming. Here is what we ultimately landed on for this week: 

Strumming structure

It works fairly well, however, the solenoid does heat up with extended use. Time will tell if the design will need to be further worked.

Another component that we spent a lot of time on was the part used to actually fret the guitar. This week, our goal was to show that we could change the pitch of our instrument. We went through a lot of design iterations, until we came up with this structure: 

Half of the fretting structure

Actual printed structure

It's not perfect, and we plan to continue to revise it for the next week, but it achieves the goal of changing the pitch of the bass guitar. 

Comments