Wednesday, March 29, 2017

readChange Library for Arduino

The readChange library for Arduino allows the user to read an analog input, and then detect and respond to change. 

Download the library with examples here: https://github.com/little-scale/readChange

To give an example of use - the value of a potentiometer connected to an analog input should be read, compared against a previously-read value. The data should be sent via a serial connection to the Arduino IDE Serial Monitor, but only when the value of the potentiometer has changed. 

To install this library, download the .zip file and move the decompressed folder to Documents/Arduino/libraries/.

The library can be used in a sketch by including it at the top of the code: 

#include

The library contains a parameterised constructor called readChange, which can be used to create instances of objects by name. When creating the instance, the readChange constructor takes one argument, which is the analog input pin that should be attached. 

For example, placing the following line before setup() will create a new readChange object named "pot1", which will read the input of analog input pin 0:

readChange pot1(0);

Each readChange object can then use three functions - update(), change() and read(). 

The update() function should be called regularly - for example, once every loop(). This will update the readChange instance by reading the current value from the analog input pin that was attached during instance creation: 

pot1.update(); 

If the value of the analog input has changed, then the change() function will return true. Used in conjunction with an if statement, this can be used to detect and respond to changes in the analog input value. 

pot1.change(); 

The read() function will return the current value of the analog input. 

pot1.read(); 

In the context of an example, the above functions could be used as follows: 




Tuesday, March 28, 2017

Soldering the Header Pins on a Teensy




Notes:

  • The long side of the header pins should go into the breadboard, with the shorter side sticking up through the Teensy. 
  • Heat up the the metal junction of a connection between two things using the soldering iron- in this case, the metal pad encircling a pin hole on the teensy, and the individual pin showing through
  • If a junction has been heated up enough, solder will simply flow onto the metal area and solidify once the soldering iron has been removed
  • Be conservative in terms of solder use - err on the side of caution 
  • Clean the soldering iron every now and then between solder points

Monday, March 27, 2017

Teensy 3.6 Basics: Sending Pitchbends

Overview
The Teensy can send many types of MIDI data of USB, including pitchbends. MIDI pitchbend data has a resolution of 14 bits, which covers the range of 0 - 16383. This is far higher than continuous controller data, which has a range of 0 - 127 with 7 bits.

As such, the pitchbend messages are useful when requiring a higher degree of control.





Hardware Setup
In this example, a potentiometer is connected to analog input 0. A push button is connected to digital pin 32.









Example 1 - Sending Pitchbend Data
In this example, the pitchbend value is sent based on the potentiometer and the push button sends note on / note off messages.

Note the use of analogReadResolution to set the range to 14 bits (0 - 16383), and analogReadAveraging to smooth out the data values by averaging 32 samples.

The pitchbend function, usbMIDI.sendPitchBend() takes the argument of value and channel, where value is an int in the range of 0 - 16383.






Download here: http://milkcrate.com.au/_other/downloads/arduino/teensy_3_6_basics/Sending_Pitchbends_Example_1/









Summary
If a higher resolution of MIDI control is required, sending pitch bend data may be a suitable solution.

Teensy 3.6 Basics: Sending MIDI Continuous Control

Overview
The Teensy can send MIDI data over USB. This include sending MIDI note on and note off events. Built-in functions make sending MIDI data simple. A summary of Teensy MIDI message types that can be sent over USB can be found here.




Hardware Setup
A potentiometer is connected to 3.3V, ground and analog input 0.









Software Setup
The analogRead() function is used to measure a voltage at an analog input. The analogReadResolution() function is used to set the range of the reading value to 0 - 127. The usbMIDI.sendControlChange() function is used to send a MIDI continuous control message via USB.

The order of arguments for the usbMIDI.sendControlChange() are control number, control value, MIDI channel.

The DAW that receives the controller data must be set up to see the Teensy as a control input.







Example 1 - Sending the Value of One Potentiometer as a Continuous Control Message
In this example, the aim is to read the value of a potentiometer and, if the value has changed compared to the previous reading, send the new value as a MIDI control message.





Download here: http://milkcrate.com.au/_other/downloads/arduino/teensy_3_6_basics/Sending_MIDI_Continuous_Control_Example_1/







Example 2 - Sending the Value of Two Potentiometers as Continuous Control Messages
In this example, the aim is to read the value of two potentiometers and, if a value has changed compared to the previous reading, send the new value as a MIDI control message. The two potentiometers are completely separate.







Download here: http://milkcrate.com.au/_other/downloads/arduino/teensy_3_6_basics/Sending_MIDI_Continuous_Control_Example_2/





Summary
The Teensy can easily send continuous controller messages using the USB MIDI functions.

Teensy 3.6 Basics: Sending MIDI Notes

Overview
The Teensy can send MIDI data over USB. This include sending MIDI note on and note off events. Built-in functions make sending MIDI data simple. A summary of Teensy MIDI message types that can be sent over USB can be found here.





Hardware Setup
In the first example, the hardware used is a single push button connected to a digital pin.





Software Setup
The Bounce2 library is used to read the state changes of the button. usbMIDI.sendNoteOn() and usbMIDI.sendNoteOff() are used to send the MIDI data over USB.

A MIDI variant of the USB type sub menu under the Tools menu must be selected before uploading the sketch to the Teensy.

The digital pin is setup to be an input pin with a pullup resistor to avoid erroneous digital reads.






Example 1 - Sending a MIDI Note from One Push Button
In this example, a single push button is used to send a MIDI note. When the button is pressed, a note on event is sent via USB. When the button is depressed, a note off event is sent via USB. Note the format of the usbMIDI.sendNoteOn() function in terms of arguments is note, velocity, channel. These arguments can be substituted with static values, variables.

Download here: http://milkcrate.com.au/_other/downloads/arduino/teensy_3_6_basics/Sending_MIDI_Notes_Example_1/





Example 2 - Sending MIDI Notes from Two Push Buttons
In this example, two push buttons are used to send two MIDI notes. When a button is pressed, a note on event is sent via USB. When a button is depressed, a note off event is sent via USB. The setup can hold more than one note at once.






Download here: http://milkcrate.com.au/_other/downloads/arduino/teensy_3_6_basics/Sending_MIDI_Notes_Example_2/







Summary
The Teensy can easily send note on and note offs using the usbMIDI.sendNoteOn() and usbMIDI.sendNoteOff functions.