My pyramid controller is almost identical to my sphere controller. The difference in shape means that each side feels a little like a preset, and its easier to have an intuition about rotation and orientation compared to a sphere. The code is slightly different as it doesn't adjust brightness; this looks better in my opinion. The code and model files can be found here: https://github.com/little-scale/Music-Sphere-Controller alongside a Max patch that makes it easy to get the data from the pyramid. The board will transmit x y and z data streams for acceleration, gyroscope and magnetometer. The acceleration values determine the colour of the onboard LED. Printing in white or clear PLA makes the colour shine through nicely.
I needed a way to switch cameras without using my hands.
I connected a simple on / off foot switch from a music keyboard to a Teensy, and I added a Wiznet Wiz820io to the SPI port. I then used AtemOSC to receive network OSC messages from the Teensy to auto transition between camera shots.
Connecting the WizNet 820io is as follows: • Wiznet 820io GND, GND, GND are connected to Teensy GND • Wiznet 820io 3.3V, 3.3V are connected to Teensy 3.3V
• Wiznet 820io PWDN is connected to Teensy 3.3V
• Wiznet 820io nRESET is connected to Teensy digital pin 9 • Wiznet 820io nSS is connected to Teensy digital pin10 • Wiznet 820io MOSI is connected to Teensy digital pin11 • Wiznet 820io MISO is connected to Teensy digital pin12 • Wiznet 820io SCLK is connected to Teensy digital pin 13
As long as the IP address of the computer running the switching software is correct in the Arduino sketch, then atemOSC should see the incoming messages for control. The ATEM Mini Pro needs to be on the same network as the computer and the foot switch.
Overview
DC motors rotate when a voltage is applied across the terminals. The speed of the motor is related to the voltage.
When using a microcontroller to control a DC motor a PWM (or pulse width modulated) signal is used. The Teensy forms a pulse wave, whereby the duty cycle is proportional to the average, equivalent over time. The duty cycle refers to the percentage of the waveform that the pulse wave is high as opposed to low.
A PWM output with a duty cycle of 50% will result in an average of half the voltage of the digital pin, a duty cycle of 25% in one quarter and so on. More information can be found about PWM signals here.
For instance, given a 3V digital pin with a PWM wave of 50%, this would provide the equivalent voltage of 1.5V over time. Thus, the digital PWM outputs on a Teensy can change the speed of a DC motor, not just turn it off and on.
The default frequency for PWM signals on the Teensy 3.6 is 488.28 Hz. Digital outputs 2, 3, 4, 5, 6, 7, 8, 9, 10, 14, 16, 17, 20, 21, 22, 23, 29, 30, 35, 36, 37, 38 are all PWM-capable pins. More information about the PWM functionality of the Teensy can be found here.
When using a PWM signal to control a motor, a certain amount of current is needed to power the motor. The outputs of the Teensy cannot provide sufficient current for the DC motor, and attempting to do so may damage the Teensy.
Instead, a Darlington transistor array in a convenient chip form can manage power source, current and control input and act as mediator between the teensy, the USB power and the DC motor. Note that anything more heavy duty than a very light motor will require an external power supply.
The Darlington transistor array comes packaged in an 8-channel version (ULN2803AN) and 7-channel version (ULN2003AN). In both cases, multiple channels can be combined to control larger motors. Each channel can provide up to 500mA of current, if a sufficient power supply is used.
In the example shown below, a single channel of a ULN2803AN is used to drive a single DC motor using 3V from the Teensy USB power supply.
Hardware Setup
Ground from the Teensy is connected to pin 9 of the ULN2803AN. 3V from the Teensy is connected to pin 10 of the ULN2803AN. Digital pin 2 of the Teensy is connected to pin 1 of the ULN2803AN. Pin 18 of the ULN2803AN is connected to one terminal of the motor. 3V from the Teensy is connected to the other terminal of the motor.
Software Setup
To control the motor, make sure that the motor is connected to a PWM-capable pin. Digital outputs 2, 3, 4, 5, 6, 7, 8, 9, 10, 14, 16, 17, 20, 21, 22, 23, 29, 30, 35, 36, 37, 38 are all PWM-capable pins.
Use analogWrite(pin, value) to set the speed of the motor. The pin is the pin number. The value is a range of 0 - 255.
There is no need to set the pin as an output pin in setup().
Example 1 - Turning the DC Motor On and Off
The motor is turned on and off.
Summary
DC motors can be easily controlled via analogWrite(), however they require additional hardware to work. Combined with MIDI control, there can be used in projects of various types.
Overview
A servo motor is a physical actuator that usually rotates for half a circle or less, or moves forwards and backwards by a set amount. Arduino add-on includes a servo library, which can be used to easily control a servo motor.
A simple, lightweight servo motor can be connected and powered by the Teensy 3.6. Note that anything more heavy duty than a very light motor will require an external power supply.
A servo motor has a control input, which expects a pulse wave with a duty cycle of around 1 - 2 ms and a period length of 20 ms. The duty cycle determines the angle or position of the servo. A duty cycle of 1 ms sets the minimum rotation or position. A duty cycle of 2 ms sets the maximum rotation or position.
Hardware Setup
The servo motor has three connections. Black or brown is usually ground, and should be connected to Teensy ground. Red is usually the positive power terminal, and should be connected to Teensy 3.3V. Orange or yellow is usually the control input, and should be connected to a Teensy digital pin, in this case pin 0.
Note that if a more heavy-duty servo motor is used, an external power supply is required. In this case, the ground of the motor, teensy and power supply should be connected. The positive terminal of the power supply should be connected to the positive terminal of the servo. The control input should be connected to a Teensy digital pin.
Software Setup
The servo library must be included at the start of the code. A servo object with a unique name can then be created by using the Servo structure.
The servo object can then be attached to a digital pin of the Teensy. This can be any digital pin. Two optional arguments as part of attaching the pin set the minimum and maximum duty cycle time periods in microseconds. A suggestion is to start with 1000 microseconds and 2000 microseconds, and adjust from there.
To control the servo motor, the write command is used with the Servo object. The value is in degrees, from 0 - 180.
Example 1 - Rotating the Servo
In this example, a servo is connected to the Teensy. The servo is then simply rotated and delayed on loop via the servo library.
Example 2 - Controlling the Servo via MIDI
In this example, the servo is controlled via a MIDI control message on channel 1, controller 1. The range of 0 - 127 is mapped to 0 - 180 degrees.
Overview
A rotary encoder uses digital encoding of pulses in either a clockwise or counter-clockwise direction to determine relative location. This particular rotary encoded includes a push button as part of the shaft.
This example shows how to connect a single, simple rotary encoder, and use the output as a MIDI controller.
Hardware
This particular encoder has five pins. The group of three pins on one side is the encoder. The group of two pins on the other side is the
For the group of three encoder pins, connect the right hand pin to a digital pin on the Teensy. In this case, pin 2 has been chosen. Connect the left hand pin to a digital pin on the Teensy. In this case, pin 3 has been chosen. Connect the middle of the three pins to ground.
These particular pins have been selected because they support interrupts on the Teensy LC. Refer to the Teensy pinouts to see possible pins, labelled INT. Note that Teensy 3.1 and 3.2 support interrupts on all digital pins.
For the group of two button pins, connect one pin to a digital pin on the Teensy and the other pin to ground.
The code uses the encoder library, which is included with the Teensyduino install. The encoder is mapped to MIDI CC #1 channel 1, and is constrained to 0 - 127. The button is mapped to MIDI CC#2 channel 1.
High resolution MIDI improves the resolution of continuous controller messages from 7 bits (0 - 127) to 14 bits (0 - 16383) by pairing together certain controller numbers. Controllers 0 - 31 for the high byte are paired with controllers 32 - 63 for the low byte.
This is an example of using the Teensy LC, along the analogReadResolution() function to read an analog value of 12 bits, scaled to 14 bits, and then sent as a high resolution MIDI message sent via MIDI CC 32 paired with MIDI CC 0.
Tilt switches are straightforward to connect to Teensy. One leg goes to a digital pin, and the other leg goes to ground. The internal pull resistor should be used with the digital pin. When the tilt switch is switched on, the digital pin will read LOW. When the tilt switch is switched off, the digital pin will read HIGH.
Overview
Here's how to build a very cheap eight pot MIDI controller. This is easily expandable to sixteen pots.
Hardware
The required hardware include eight pots (10k linear), Teensy (2.0, 3.1, 3.2 or LC will work just fine), 4067 multiplexer, two breadboards and breadboard jumper wires.
Put the Teensy and the 4067 multiplexer on the breadboards. Connect ground from the Teensy to gnd and en on the 4067. Connect 3.3V or 5V from the Teensy to VCC on the 4067. Connect Teensy pins 0, 1, 2 and 3 to 4067 pins S0, S1, S2 and S3 respectively for the address bus pins. Connect sig from the 4067 to analog input 0 on the Teensy. Pinout for the Teensy can be found here.
Connect the outside leg of each pot to ground. Connect the other outside leg of each pot to 3.3V or 5V. Connect the middle leg of each pot to the input channels of the multiplexer, from 0 - 7.
Up to sixteen pots can be connected to the 4067 multiplexer. Additionally multiplexers can be added for more than sixteen pots.
Code
An example Arduino sketch can be downloaded here. Please note that the correct board must be selected. The USB type must be set to MIDI.
Usage
The Teensy will show up as a MIDI device automatically. Pots 1 - 8 are mapped to MIDI CC controller numbers 0 - 7 on MIDI channel 1.
I made a simple YES / NO swipe interface using a Teensy and two Ping distance sensors.
The ping signal pin is connected to pins 7 and 8 (for the YES and NO Pings respectively).
There are values in the code that set the min, max and time-based parameters for when a swipe is recognised as being a swipe.
They are:
long distance_min = 800; // change to set minimum swipe range distance
long distance_max = 2200; // change to set maximum swipe range distance
int swipe_reactivity = 2; // change to set swipe reactivity in time
int swipe_delay = 1000; // change to set delay after positive swipe is read
The YES swipe is transmitted by a Serial port message at 9600 baud saying "swipe yes", as well as a USB MIDI control change message of channel 1, controller 1 and value 127.
The YES swipe is transmitted by a Serial port message at 9600 baud
saying "swipe no", as well as a USB MIDI control change message of
channel 1, controller 2 and value 127.
An example Max patch which differentiates these values is as follows:
This is a simple example of using an infrared distance sensor as a MIDI controller. The hardware setup is simple - analog out to analog input on the Teensy, ground to ground and 5V to 5V.
I want the wireless link to appear as a native MIDI USB device
I want the wireless link to be sturdy
I want the wireless link to be made up of off-the-shelf components that can be sourced in Australia
Here is a simple solution and proof of concept that fulfills these conditions. The idea is that a USB 'dongle' is connected to the computer. Let's call this the base receiver. A second device reads data from a pot. Let's call this the node transmitter.
Wireless communication is handled by a par of XBee modules. This project is designed to run using XBee modules straight out of the packet - i.e. no configuration is necessary.
As it has been stated, this project is more of a proof-of-concept to show how easy and simply it is to set up something like this. Keep in mind that (1) many sensors etc can be attached to the node transmitter (2) more than one node transmitter can be used and (3) speeds can be increased via configuring the XBee modules.
Usage
As presented here, potentiometer data will be sent using MIDI channel 1 and controller 1. This data should appear on the Teensy USB MIDI device, which can interface directly with Ableton Live etc.