Even with the power of a real ATmega328P microcontroller running at 16MHz, the 32Kb of memory space on an Arduino is not enough for larger projects. It would be great if we can harness the power of our PC to do the complex processing while the Arduino can be the platform for the sensors and motor controls. In this configuration, you can do much more, the only draw back is you do need to keep your PC tethered, by USB or Wifi. For some applications this is fine and preferred. In those cases, Firmata is one solution you can use to make this very simple.
In essence it turns the arduino into a conduit device that passes through commands and reports pin states. Using the Processing platform, you can interface the Arduino via Serial bus and exposed API provided by the Firmata system. Firmata takes the leg work out of designing a custom software protocol layer any application will need to interface between the Arduino and PC, it does it for you.
Copy the following engineering notebook template to your notebook and answer the questions as you work through the procedure below.
Firmata is a generic protocol for communicating with microcontrollers from software on a host computer. It is intended to work with any host computer software package. Begin by installing the general Firmata control code onto your arduino processor.
1. Connect the Arduino board to the PC and open up the Arduino software.
2. Upload the sketch StandardFirmata from Examples/Firmata. (Dont forget to have your COM port set in Tools->Ports in the Arduino IDE.)
3. Pin 13 has a surface mounted LED to test this code, just like the example Blink code. We will use this feature to test the Firmata connection.
Now we set up the processing environment:
1. First you need to Install the Processing Arduino Firmata library. Sketch->Import Library->Add Library
2. Search arduino and install the Arduino Firmata Library
3.Run the following code in Processing:
In some cases, on some computers, the COM port selection will not work. One reason for this issue is that a computer will recognize multiple ports and the line of code: " arduino = new Arduino(this, Arduino.list()[0], 57600); " assumes the first instance of the COM port is the one with the arduino when it is not. To resolve this issues open Arduino IDE and look to see what port has the arduino. (Tools -> Port: COMX (Arduino Uno) where X = the # port that has the arduino communication established.)
Change the arduino communication line in the Processing Code to match the port #.
arduino = new Arduino(this, Arduino.list()[0], 57600); -> arduino = new Arduino(this, "COM12", 57600);
*Note that you will need to update the port manually each time you connect a different arduino or use a different computer.
Create a Circuit for Your Controller
Once you have established communication between the computer and the Arduino, Build your controller circuit:
Lastly, review the example code for getting the Face Avatar to move with the arduino.
DO THIS IN YOUR PROCESSING CODE
Replace The If keyPressed section with arduino code in your game:
Lasty, run your code and press the buttons to see the avitar move.
Capture your work in your engineering notebook.