Last edited 02/08/2009
This was originally posted on the TeamPaulC blog, that blog entry will not be updated, but this page will be updated as required.
There are quite a few posts about getting communicating between an Arduino and Flash, but none that put it ALL in one place, so here's a quick tutorial. :)
Setup two way communications between an Arduino Duemilanove and an Adobe AIR application written in FLEX. We will setup a photocell and two LEDs. The Arduino will sample the photocell every 2 seconds and send the results to the Flash application. The Flash application will graph the data from the Arduino and have three buttons that will toggle the LEDs on the Arduino and turn them both off. Useless, but it shows that it works. :) The protocol is SUPER basic, but again, its proof of concept.
Connect one end of an orange LED to pin 10 of your Arduino the other to ground via the proper sized resistor.
Connect one end of a red LED to pin 12 of your Arduino the other to ground via the proper sized resistor. If you aren't sure of the proper resistor size you can use this calculator, or just use 120 ohms
Connect a photocell (Radio Shack 276-1657) to pin 5 of your Arduino like this:
Adobe AIR applications do not have access to the local machines serial port, so we will setup a proxy to proxy requests to and from the serial port to a TCP port on the local machine.
Download serial proxy and unzip it to a folder.
Edit the file serproxy.cfg and make sure that you have a line for the serial port that your Arduino is using. My Arduino is on com6 so I have the line
that means that any software trying to connect to my computer on TCP port 5336 will be proxied through to com6. You can get your serial port from the Arduino software menu "Tools", "Serial Port".
Keep in mind, that if you are monitoring your serial port in the Arduino software, then serialproxy wont work.
Make sure that serialproxy is runing.
Load the Arduino code into your Arduino.
Compile and run the Flex AIR code.
I apologize for the non Arduino code in the sample, but I like to do some things with the native AVR C code. Well, its all native AVR C code, Arduino just has nicely packaged libraries.
If you don't have AVR035.h, here it is:
If AVR035.h confuses you, then read this:
When you run the AIR application you should see a graph at the bottom that is graphing your photocell data live as well as a text area at the top with the raw data and three buttons for manipulating the LEDs. Turn a light off and on and note changes. But remember that we are only sampling the photocell every 2 seconds.
Yes, its a contrived project, but it shows bidirectional communication between an Arduino and an AIR application.
I accidentally left the AIR application running all night, and predictably "bad things" happened. The transactions array had no limit so it grew all night long. I updated the FLEX code above and added a variable "maxItems" which I have defaulted to 100.