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.

Teensy 3.6 Basics: Sending Serial Data

Overview
There are a number of ways that the Teensy can communicate with a computer or other device. A serial connection can be used via USB, and provides an easy way to troubleshoot hardware and debug code, as the Teensy can send human-readable information to the computer for feedback. The Arduino IDE can open up a serial connection, and receive data from the Teensy via the Serial Monitor.

There are some downsides, too. Idiosyncrasies regarding serial data and connections may cause some confusion. For example, only one piece of computer software can actively communicate with a given serial-based connection at a time, as opposed to USB MIDI data - where multiple pieces of computer software can send and received data from the one device.

Data types also play a role in usability, as each data value in a serial message is 8-bit, and can represent either an ASCII code (and therefore an alphanumeric symbol) so as to be human-readable, or an integer from 0 - 255 so as to be treated as a data value. This will be expanded on with examples below.






Hardware Setup
The initial hardware setup is simply the Teensy connected via USB to a computer.







Software Setup
A serial connection makes use of a series of Serial-based functions. A serial connection also has a pre-determined speed, which is set as part of the sketch as one of a number of possible baud rates, or data transfer speeds.

A suggested baud rate for USB connections is 57600, however it may be useful to go beyond this.

Possible rates include: 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 38400, 57600, or 115200. All of these are given in bits per second.

To open a Serial connection, the function Serial.begin(57600); is required in the setup function. Serial.print(), Serial.println() and Serial.write() can all be used to send data from the Teensy to the computer.

Serial.print() will send the contents as ASCII character codes, so that the Arduino IDE can display them as human-readable numbers, letters and symbols. However, this will never add a line break.

Serial.println() will send the contents as ASCII character codes, so that the Arduino IDE can display them as human-readable numbers, letters and symbols and also add a line break immediately after the message.

Serial.write() will send the contents as a data value from 0 - 255, so that the data can be used directly in other software such as Max, PD or Processing.

To open the Serial Monitor in the Arduino IDE, select Serial Monitor under the Tools menu or use command shift m.







Example 1 - Printing to the Serial Monitor
In this example, the aim is to simply print the word "Hello" to the Serial Monitor from the Teensy every second. The serial port is opened with a rate of 57600. The Serial.println(); function is used to print the word "Hello" as a new line in the Serial Monitor.


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








Example 2 - Print Variable to the Serial Monitor
In this example, the aim is to print a variable to the Serial Monitor from the Teensy. In this case, a for loop is used to increase a value i by one every loop. This value can then be used. Note how this combines static text, the Serial.print() function, variables and the Serial.println function.



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







Example 3 - Print Value of Potentiometer to the Serial Monitor
In this example, the aim is to read the value of an analog input to which a potentiometer is connected. The value of the potentiometer is printed to the Serial Monitor.











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






Example 4 - Use Serial Write with Max
In this example, Serial.write() is used instead of Serial.print(). This means that values are sent from the Teensy in the data range 0 - 255. Max can then receive these values as integers that can be visually displayed using a multislider object.

Note the use of analogReadResolution(8) - setting the range to 8-bits - to keep the values within a range of 0 - 255. The serial object is used in Max to receive the data, and the data is timed using the metro object.







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









Summary
The serial connection can be used to help troubleshoot and test Arduino sketches on the Teensy. Depending on how the output data is to be used, Serial.print(), Serial.println() or Serial.write() may be used.