In this week’s lesson, we were introduced to Arduino Mega 2560. It is a microcontroller board which has 54 digital input/output pins and 16 analog inputs. It is very easy to use – simply connect it to a computer with a USB cable – plug and play.
In order to allow interaction between MAX and Arduino, a library called Maxuino was also installed. Before we could start tinkering with anything, there were some configurations to be done:
- In Arduino 3, select the right board and port used. (Tools -> board -> Arduino Mega 2560 ; Tools ->port -> usbmodem.??.tty
- Open up the Standard Firmata under Examples and upload it into the board
Then get a copy of SparkFun Inventor’s Kit for Arduino and get started!
Yi Xiang and I grouped together and we had fun connecting up the wires and components. I found that it is easier to follow the schematic diagram than the illustration. In our exercise, we used a photoresistor (as analog input), a LED (as digital output), a 330 ohms resistor, a 10k ohms resistor, and some jumper wires. The connection is shown in the diagram below:
After opening up Maxuino-gui, update the board and port used. Then we tested the input and output of Arduino in Maxuino patch with GUI. The GUI is very useful in letting us to control and observe the arduino’s input and output in real time. To program this exercise, the patch was modified as shown in the figure below:
Basically this is how it works:
- The program takes in the input value from the photoresistor (which change its resistance according to light intensity)
- The input value is compared with a certain value (e.g. 0.5)
- When the value exceeds 0.5, it will trigger the ouput to go to “on” state (LED connected to that output pin will light up)
- At the same time, the input values are also converted to larger number using “scale”. The converted values are fed into “mtof” and “cycle~” to produce a sinusoidal wave. Finally a speaker is connected to output the sound waves. Therefore, the photoresistor has a direct effect on the sound wave produced.
- Later on, we modified it to allow the control of movie playback using the photoresistor.
Overall, it was a fun lesson!