Notice: Array to string conversion in /var/www/wiki.sourcebinder.org/includes/Setup.php on line 304

Warning: Parameter 1 to Language::getMagic() expected to be a reference, value given in /var/www/wiki.sourcebinder.org/includes/StubObject.php on line 58
Arduino mac - SourceBinder Wiki

Arduino mac

From SourceBinder Wiki

Jump to: navigation, search

Contents

In order to be able to use Arduino with Sourcebinder you need the following things:

  • An Arduino board and the Arduino IDE installed on your computer. Note: For this tutorial the IDE version 22 has been used. All sensors/actuators will be connected to the Arduino.
  • Firmata installed on your Arduino. Firmata will pass along the measured values of the sensors/actuators to the serial connection of the Arduino. Via its USB connection, your computer ultimately receives the data.
  • A serial proxy for the communication between the Arduino and a Flash Application. This proxy basically takes the data from the serial port on your computer and hands it over to Flash applications.
  • A flash policy file to let Sourcebinder communicate with the serial proxy via a socket connection. Since Sourcebinder is not a local application on your computer, this policy file is needed to allow Flash to access specific ports, in order to exchange information with the serial proxy.


Now, that you know what you need, let’s get started:

  1. Download Arduino IDE from the Arduino homepage and install it on your computer.
  2. Open the Firmata software inside the Arduino environment. You can find it under: File -> Examples -> Firmata -> StandardFirmata
  3. File:FirmataSketch.png

  4. Search for the „Firmata.begin“ command within the opened Frimata program code and either change the value within the brackets (not recommended!!!) or write it down somewhere. We will need this value again at a later stage (it will be called #FIRMATA)!
  5. File:FirmataCode.png

  6. Connect the Arduino to your computer and upload the program to it (NOTE: If you are using Arduino UNO you MUST have the Arduino connected to the computer before you start the Arduino IDE). In order to be able to upload the program you need to select the serial port your Arduino is connected to:
  7. File:SerialPort.png

  8. There you will find two entries for the Arduino. One starts with “tty.” and another with “cu.” Inside the Arduino IDE select the tty port, but write down the cu one, since we will need it later (it will be called #SERIALPORT)!
  9. Now, to the serial proxy. Go to the as3glue Project page and download the “arduino as3 glue bundle”. When finished open the extracted folder.
  10. Within the serproxy subfolder you will find the “serproxy.cfg” file.
    • Open it and look for the line “comm_baud=” and replace the value after it (if needed) to the previously noted value #FIRMATA.
    • Find the “serial_device1=” line and put in #SERIALPORT (it will look something like this: “/dev/cu.usbserial-XXXXXXXX”)
    • Here is a example for the cfg file:
    # Config file for serproxy
    # See serproxy's README file for documentation
    
    # Transform newlines coming from the serial port into nils
    # true (e.g. if using Flash) or false
    newlines_to_nils=true
    
    # Comm ports used
    comm_ports=1,2,3,4
    
    # Default settings
    comm_baud=57600
    comm_databits=8
    comm_stopbits=1
    comm_parity=none
    
    # add my serial device - the magic happens here, change the identifier to wathever it is inside
    # your Arduino menu -> Tools -> Serial Ports
    serial_device1=/dev/cu.usbserial-A6008m3d
    
    # Idle time out in seconds
    timeout=300
    
    # Port 1 settings (ttyS0)
    net_port1=5331
    
  11. Now, we check if everything is working so far. First, go to the serproxy subfolder and start the serprxoy executable. Then, go to the “monitor” subfolder of the as3glue folder and open the monitor application. If everything is ok, you should see the measured values on the Arduino in this application.
  12. File:AS3Monitor.png

  13. Now to the Flash policy file. For background information on the topic relate to: Adobe.
    To setup the policy file we will follow this tutorial
    • Download and extract the sample file “flashpolicyd_v0.6.zip” from Adobe.
    • Open the “flashpolicy.xml” file and change the content to the following:
    • <?xml version="1.0"?>
      <!DOCTYPE cross-domain-policy SYSTEM "/xml/dtds/cross-domain-policy.dtd">
      <cross-domain-policy> 
          <site-control permitted-cross-domain-policies="master-only"/>
          <allow-access-from domain="sourcebinder.org" to-ports="1000-20000" />
      </cross-domain-policy>
      
  14. Congrats! Everything is setup and you are ready to start!


To start working with Arduino and Sourcebinder do the following:

  1. Open a terminal session and go the “standalone” subfolder from the flashpolicy folder. There execute the following command:
    sudo ./flashpolicyd.py --file ../flashpolicy.xml --port 843
    
    Note: Keep in mind, that this command assumes, that the python script file (.py) is in the standalone folder and the xml file is one hierarchy level up in the folder structure.
  2. Find the as3glue folder and go into the serproxy subfolder and start the serproxy executable.
  3. Open Sourcebinder.org (do NOT open the webpage or any other program which uses the serial port of the Arduino before steps 1 and 2!!) and choose an Arduino sketch.
  4. Enjoy ☺


Possible Pitfalls/Errors:

  • Sourcebinder states “socket connected” and immediately after that “socket closed”

    This could mean, that either some other application is using the socket or the socket is still locked by the system from a previous use. Most of the time a computer restart should help to free the socket again. Please make also sure, that you start everything in the order given above.

  • Sourcebinder keeps stating “connecting…”

    Have you started the flashpolicy script?

  • Personal tools