-
Arduino to Processing to Flash
This is a demo/workshop to get your data from your Arduino board to your Flash application using a Processing sketch as the middleware. Since AS3 doesn’t directly interact with your computer’s local hardware including the serial port, a middleware, or a reflective broadcaster is needed to pick up the data from the serial port and broadcast it else where that higher level runtime like Flash can access. In most cases, especially with Flash, that else where is a socket server, and we are going to create this server with Processing. There are other applications out there that helps you do the same thing too.
This demo consist of three parts, however, once the data gets through the serial port from Arduino board to your laptop, it is pretty much up for grab by any applications, OF, MAXMSP, C#, Objective C, Python, Zinc … etc, that has the ability to access local serial port. Data will be sent from your Arduino character by character in ASCII code. On the computer end, it will see a data stream coming, ASCII by ASCII, however, it won’t be able to tell where is the beginning or the end of a particular set of data if we don’t define one for it.
Therefore, we need to set up an end ASCII code for the data set we are sending, so our Processing sketch knows that in between every two end ASCII codes is a complete data set. We will take advantage of a build-in command in Arduino to save some works for us. When uses the command “server.println(data)” in Arduino, it will add two extra ASCII codes, 10 and 13, at the end of your data. These two extra ASCII codes stand for “Newline” (10) and “Pointer returns to the header”(13), which is a perfect identifier for Processing to determine the end of a data set. In between every 1013 there is the completely data set.
Fun starts here:
Hook up your Arduino board to your computer with a USB cable, install USB driver that come with the software, and program your Arduino for serial communication as usual, see picture below. For the purpose of this demo, we are not setting up any sensor, you should already have something set up on your Arduino board that you desperately want to get it to your computer. Just read the pin on your Arduino board, digital or Analogue, and Serial.println the data, and you are good to go.
This is what’s in the Arduino program:
You can also print them in many different format, but no matter what format you are sending, it will be ASCII coded. Which means it will chop up your data, and send character by character in its ASCII code form. Upload you program and open the serial monitor, you should see random number flowing through the 9600 bps channel. After you done, completely exit the Arduino software, and open up Processing. It is crucial that you exit Arduino software completely because it will cause a port conflict with Processing if you don’t.This is what’s in the Processing sketch:
If you decide to use Processing as your visual solution, you don’t have to implement the server part of this sketch. The data will be read one character at a time in its ASCII code form, so we need to concatenate them back to what it was. Because we set up NEWLINE (ASCII code: 10) as the end byte, we concatenate whatever that is in between the two end byte, with the right bps on both ends, we should be getting a complete data set from the serial port. At the every end of the sketch, we write the complete data to the XMLsocket server where Flash will pick them up.This is what’s in the Flash document.as:
Make sure you plug in your Arduino before running Processing, and run you Flash application the last, it has to be done in this order.
Multiple input values:
If you have more than just one data that you want to send at any given time, ex. you have five buttons on your Arduino board and you want to send all of them to your laptop. You have to set up an standard divider so when Processing or Flash read the data set, they can split the set into individual ones. To make this happen, we will use “Serial.print(data)” to send each individual value and a divider in between and we use “Serial.println(data)” to send the last value. The difference between “Serial.print(data)” and “Serial.println(data)” is that the “Serial.print(data)” doesn’t send out the extra two ASCII codes. The Arduino code should look similar to this: (I use “,” as my divider)
Serial.print(value1);
Serial.print(“,”);
Serial.print(value2);
Serial.print(“,”);
Serial.print(value3);
Serial.print(“,”);
Serial.print(value4);
Serial.print(“,”);
Serial.println(value5);And Processing receives it, the string will look like this:
value1,value2,value3,value4,value5
just split them using split(data, divider you defined); and you get yourself a array with all five data.
27 Oct 2009 / admin / 0
Categories: Experiements
iBot – an iphone robot made with Arduino and photocells SMALLab: Data Emulator DATAMUX
Pages
Categories
Archives
- June 2016
- April 2016
- March 2016
- February 2016
- July 2015
- June 2015
- May 2015
- April 2015
- March 2015
- February 2015
- January 2015
- December 2014
- June 2014
- May 2014
- February 2014
- December 2013
- November 2013
- October 2013
- September 2013
- August 2013
- June 2013
- May 2013
- April 2013
- March 2013
- February 2013
- January 2013
- December 2012
- November 2012
- October 2012
- May 2012
- April 2012
- March 2012
- December 2011
- August 2011
- February 2011
- December 2010
- October 2010
- July 2010
- June 2010
- April 2010
- March 2010
- February 2010
- December 2009
- November 2009
- October 2009
- September 2009
- August 2009
- July 2009
- April 2009
- March 2009
- November 2008
- October 2008
- August 2008
- June 2008
- May 2008
- April 2008
- December 2007
- October 2007
- August 2007
- July 2007
- May 2007
- April 2007
- March 2007
- February 2007
- November 2006
- October 2006
- September 2006
- March 2006
- February 2004
- August 2003
- September 2001