Incorporate the Touch Board to your Processing project
Learn how to use the Touch Board with Processing
Processing is a fantastic tool to help you quickly build projects. We have written a Processing example sketch, with which you can use to communicate with the Touch Board. You can use this sketch to send data (if an electrode has been touched or not) to your Processing application. To download the Processing sketch, head over to our GitHub repo and follow the instruction on how to add the sketch to the Processing sketchbook. If you haven’t downloaded Processing yet, you can download it on the Processing website.
Step 1 Set up the Touch Board
Before you get started, you need to first set up the Touch Board. You can do this by following the Touch Board set-up tutorial.
We are going to use the “DataSteam.ino” sketch. First, open the sketch in File->Examples->MPR121->Examples in the Arduino IDE and upload it to your Touch Board. Also, note the Touch Board’s serial ID by having a look at the bottom right corner of the Arduino IDE. In our case, the ID of the board is “/dev/cu.usbmodemFD131”. You will need this information later.
Step 2 Check Datastream
If you now open the Serial Monitor, you should see a stream of numbers. You can find the Serial Monitor in the top right corner of the Arduino IDE. Whenever you uncheck “autoscroll” you get a glimpse of the incoming data. The data is a repeating set of values, with one of them being TOUCH. If you touch one of the electrodes, you can see that the electrode’s respective TOUCH value changed from a 0 to a 1. This is the raw data that we are going to use in Processing.
Step 3 Run the Processing sketch
Now it’s time to work in the Processing sketch. First, open the sketch in Processing and have a look at line 31. In there, you can find the variable “Serial.list()”. You might need to change the number in the square brackets, so that it matches the one on the Touch Board. To do so, run the code for the first time. In the console window, you should see a list of incoming serial ports, including the Touch Board’s. The board’s port list position is what you need to include in the brackets in line 31. Note that the counting starts at 0, so if the Touch Board’s port is the second one, you need to have a 1 in the brackets.
So for example, in the right image, you can see that the ports are /dev/cu.Bluetooth-Incoming-Port, /dev/cu.usbmodemFD131, /dev/tty.Bluetooth-Incoming-Port and /dev/tty.usbmodemFD131. The Touch Board’s port is the second one, so we know that we need to have “Serial.list()” in line 31. Stop the code from running, change the variable accordingly and hit run again.
Step 4 Touch the electrodes
If everything is set correctly and you touch the electrodes, it should inform you which electrode has been touched in Processing. That’s it! You are free to use this example code for your project.