In this project we will be integrating an accelerometer to measure movement in three dimensions with our Werkstatt using an Arduino microcontroller. An accelerometer is a device that measures acceleration in three dimensions and outputs a corresponding voltage.
1 x Breadboard
1 x ADXL335 Accelerometer
1 x Arduino Microcontroller
Please download hi res images and Fritzing files for this project HERE.
For this mod we will be using an Arduino Uno micro controller. The Arduino is based around the ATMEL series of micro processor IC's, and is a very versatile tool across multiple disciplines. Refer to Figure 1 for a closer look at the exact digital and analog I/O configuration for the Arduino. For more information regarding the Arduino please visit arduino.cc
Figure 1. Arduino UNO
We will also be using an accelerometer breakout board from SparkFun. The ADXL335 is a very common cost efficient accelerometer. An accelerometer is a device that measures acceleration in three dimensions (X, Y, Z) and outputs a corresponding voltage. The three dimensions of space are based on a Cartesian coordinate system with origin set at an upright and flat accelerometer position.
Other accelerometers would work with this project as well but the V+ requirements may vary. Our ADXL335 needs a power regulated 3.3V+, we can pull this from our Arduino's 3.3V power rail. First lets run our power jumper and ensure that our ADXL335, Arduino, and Werkstatt all share a common ground.
Run a 3.3V+ power jumper from the Arduino and share ground between the Werkstatt, Arduino, and Accelerometer.
Run signal jumpers from the X, Y, and Z pins on our Accelerometer. These send an analog signal based on position so we will need to run these into our Arduino's analog inputs to ensure accurate readings. Since the ADXL335 sends a true analog signal it is possible to power through a voltage divider from the Werkstatt and run this mod without the Arduino. However, without the Arduino we loose a larger V+ spread and with it the expressivity of the mod.
Now that our Arduino is wired to accept the ADXL335 signal we need to send control voltages to our Werkstatt. In the above configuration only HIGH/LOW control signals would be sent due to PWM nature of Arduino digital outputs. If we want a true analog control voltage we would need to create a low-pass filter exactly like the one we built for our Arpeggiator/Sequencer mod. The figure below is an example of a low-pass RC filter using a 10kΩ resistor and 2.2uF capacitor.
Now that our ADXL335 is wired into the Arduino we are ready to upload our code.
Please download the Arduino code for this project HERE.
We will need to upload our code to the Arduino for this mod to work properly. To upload simply plug your Arduino into your computer, open accelerometer .pde in the Arduino IDE, select which functions we want to control our Werkstatt, and press upload. As long as the moog_werkstatt library is in the IDE's path, the code will compile and upload.
First we will see in the the sketch that our accelerometer class is called and named with input arguments that set the three analog inputs for ADXL335 data capture. The included accelerometer.pde sketch has two functions we can experiment with and these are defined as n_axis and n_pulse. The variable n changes as we select what dimension we want to call to manipulate our control voltage.
N_axis functions are scalable one to one mappings of incoming accelerometer data. Input arguments for this function are as follows; (PWM out pin, minimum output PWM, maximum output PWM). Functions of this type need to be run through a low pass filter for the best results as discussed earlier.
N_pulse functions send digital on/off pulses at specific MS intervals based on captured sensor data. Input arguments for functions of this type are as follows; (digital out pin, minimum output MS, maximum output MS).