Sending Data from Hardware

For this example, we will be using a PiTFT send touch data from the Raspberry Pi. You could use this same method to send data from a wide range of sensors, but to keep things simpler, we will be focusing on the PiTFT touch data.

For this example you will need to have followed one of our PiTFT touchscreen installation guides, such as the guide for the 3.5" touchscreen. Once you have successfully installed the PiTFT touchscreen, you will be ready to continue.

Installing the Dependencies

First, run the following command to install the build dependencies.

Download: file
sudo apt-get install evtest tslib libts-bin libts-dev libcairo2-dev

Then, cd into the pitft folder located in the osc-examples folder on your Pi and run npm install to install the node.js dependencies.

Starting the Node.js Sine Script

The first script will take X & Y touch coordinates, and convert them into MIDI pitch and velocity values. These values will then be sent as OSC messages to Max, and used to control the frequency and amplitude of a sine wave. Enter the following command to start the script after you have installed the dependencies.

Download: file
$ node sine.js

Sine Wave Example

I will be using Max again for this example, but you can use the pitft_sine example in Pure Data or ChucK to follow along if you use those environments. To get started, open the pitft_sine example, and point the example at the IP address of your Pi as we have done for the previous examples. Press the connect /pitft connect button in Max to connect the patch to the Pi. If everything works as expected, your PiTFT will turn bright blue.

You can then drag your finger along the PiTFT to control the pitch and volume of the sine wave. Dragging your finger from left to right will change pitch, and dragging from top to bottom will control volume.

The source for the node script that transforms the touch data to OSC messages can be found in the osc-examples GitHub repository.

Sample Trigger Example

You can use the same process to start the sample trigger patch. First start the sample.js script on the Pi, which can be found in the pitft examples folder.

Download: file
$ node sample.js

Then, open the pitft_sample example in Max, Pure Data or Chuck on your computer and replace the IP with the IP of your Pi as we have done in the previous examples. Then, click the button in the upper right to load the samples. You should see the names displayed on your PiTFT as shown in the video.

You can click on the sounds to trigger them in Max, and you can change the loaded clips by dragging new files into Max. The filenames will be automatically updated on the PiTFT.

The source for the node script that builds the UI and transforms the touch data to OSC messages can be found in the osc-examples GitHub repository.

Modifying the Node Examples

If you need to modify the Node.js examples to fit your needs, your best resource will be the documentation for the osc-min library.

Feedback

Hopefully this guide has helped you get started with basic communication between a remote device and your favorite audio/visual programming environment. If you have any questions, please feel free to leave feedback. We'd love to hear your thoughts!

This guide was first published on Mar 26, 2015. It was last updated on Mar 26, 2015. This page (Sending Data from Hardware) was last updated on Nov 23, 2015.