The ARDUINO is great for catching input, and FLASH is very convenient for designers to work with. Combining the two is not difficult at all, although there are some details which could be complicated. Or so we thought....indeed sometimes it works, but switching from XP to MAC OS for instance requires the right port setting, and still the serial data, from the analog ARDUINO pins comes in erratically, also changing from the ATmega168 to the ATmega2328 board does seem to change the way the serial data come in.
Using a Socket in FLASH or using an XML Socket differs too...
So there are a few problem areas:
- the config file for Serproxy, which is the port number in the MAC OS case?
- the FLASH socket, XML or not?
- the serial data coming in, sometimes something seems to be skipped, do we have to use a checksum?
There are several links in the Arduino docs explaining what to use and how:
http://www.arduino.cc/playground/Interfacing/FlashPersonally I use simply the Serial lib from the Arduino, Serproxy and a socket in FLASH.
You have to configure the serproxy.cfg, that it uses the right com port. Then you have the two way communication. (Tinkerproxy is only one way.)
Setting the serproxy config file is explained here:
http://protolab.pbworks.com/TutorialFlashSetupEspecially for the MACOS fans...
The digital pins work fine, being only true or false.
So you start the arduino script, just talking into the serial port:
like Serial.println (digitalRead(pinNumber));
Serproxy is started, it says waiting for clients...
Then in FLASH you use:
import flash.net.Socket;
you add an eventlistener:
arduinoSocket = new Socket("localhost",5331);
arduinoSocket.addEventListener(Event.CLOSE, closeHandler); arduinoSocket.addEventListener(ProgressEvent.SOCKET_DATA, socketDataHandler);
and you read the data:
var nb : uint = arduinoSocket.bytesAvailable;
var bytes:ByteArray = new ByteArray();
var input:String = String(arduinoSocket.readShort( ));
//or like this
//var input:String = String(arduinoSocket.readBytes( bytes, 0, 5));
the reading of the HIGH or LOW is simple and reliable, but the potmeter on an analog port is more complex, due to the bits being sent through the Serial port which have to be caught in the right way.
basic flash script (will be improved shortly)Using the analog pins ( a potentiometer or a flex sensor) gives more problems.
You have to experiment with the bytes coming in.
We had the arduino flash connections running on XP using serproxy in no time.
On the other hand we had trouble getting it running on MAC OS. The problem was the comport naming. Apparently normally ARDUINO software choses /dev/tty.usbserial-*, but for Serproxy you need the /dev/cu.usbserial-*
so using this serproxy.cfg:
# Config file for serproxy
# Do not Transform newlines coming from the serial port into nils
newlines_to_nils=true
# Comm ports used
comm_ports=3
# Default settings
comm_baud=9600
comm_databits=8
comm_stopbits=1
comm_parity=none
# Idle time out in seconds
timeout=300
# Settings for COM3
serial_device3=/dev/cu.usbserial-A7006vzH
net_port3=5333
we got it right. Also why is this called port 3? We found that out using Tinkerproxy, which showed this port number, but the list of ports in the terminal gave no clue about this number.
Anyway, now it works on both operating systems....
Well this was what we thought, but experimenting with our own and scripts of other found on the internet, with different ARDUINO boards, with XMLSocket and the plain "Socket" class, we still have erratic data coming in the FLASH part, skipping things etc.
(If you open the serial window in the ARDUINO IDE then the data come in fine.)
Evidently more experience and or knowledge of what is going on is needed.