Arduino Workshop 5 - Communication
In this workshop we will look at communication using an Arduino. This could be communication with software on your computer/tablet/phone, the internet, other microcontrollers, other IoT (Internet of Things) enabled devices, micro location beacons, or even your car electronics. Before we get too carried away, we need to first look at 'Serial' communication.
The Circuit
Exercise 1 - Speaking to the Computer from Arduino
We will be using the graphical media based programming environment 'Max MSP' from Cycling74 for this exercise. Go to the download page to get an appropriate version, if you are on Windows you will also need Quicktime for the video stuff. There is a full trial version, but you can still run patches if it has expired, you just can't save.
- Paste the following code into the Arduino IDE and upload it. Then download this Max patch, open it and follow the instructions inside.
/*This sketch will send the values from a potentiometer * and a button out via serial. We will be using the * graphical media based programming environment 'Max MSP' * by Cycling74 https://cycling74.com/ to interpret the * values and control things with them. Likewise, in the * next exercise, we will communicate with the Arduino from * Max too, to control our RGB LED. * * Max is available as a free trial, but the provided patches * will run anyway even if your trial has finished (though you * will not be able to save). * * Luke Wodbury 14 January 2016 */ void setup(){ // create serial buffer, i.e. enable serial communication Serial.begin(9600); } void loop(){ //create an integer variable called 'pot' and store //the reading from pin Analog 0 in it int pot = analogRead(0); //create an integer variable called 'button' and store //the reading from pin Digital 2 in it int button = digitalRead(2); // write values to serial buffer //print the word 'pot' and a space Serial.print("pot "); //print the value of the pot variable followed by a line break (println) Serial.println(pot); //print the word 'button' and a space Serial.print("button "); //print the value of the pot variable followed by a line break (println) Serial.println(button); }