Professional Documents
Culture Documents
006
CONNECTING ARDUINO + GRASSHOPPER + MORE
BY
FIREFLY PRIMER
JASON KELLY JOHNSON AND ANDREW PAYNE
Firefly Primer - Version 1.006 By Jason Kelly Johnson and Andrew Payne Copyright 2011 All Rights Reserved For use with Grasshopper (build 0.80050 or higher) Last Modified: August 15, 2011 10:08 PM Downloads, Primer Updates and Firefly Forum: www.fireflyexperiments.com
Ideas
The apparent veil between the organic and the manufactured has crumpled What should we call that common soul between the organic communities we know of as organisms and ecologies, and their manufactured counterparts of robots, corporations, economies, and computer circuits? I call those examples, both made and born, vivisystems for the lifelikeness each kind of system holds. -Kevin Kelly, Out of Control If architects designed a building like a body, it would have a system of bones and muscles and tendons and a brain that knows how to respond. If a building could change its posture, tighten its muscles and brace itself against the wind, its structural mass could literally be cut in half. -Guy Nordenson, Princeton University / Nordenson and Associates We foresee the possibility that most (if not all) architectural space will become responsive and be animated through intelligent kinetic capacities. Each space will have a series of sensors which allow the occupational patterns within the space to be registered and fed back into the intelligent responsive structures. This can operate on many scales and levels. I think what emerges is a new era within architecture, or between architecture and some other disciplines -Patrick Schumacher (from an interview conducted by Alessandra Belia on 10 Feb 2004) First we build the tools, and then they build us. -Marshall McLuhan
Images: Kuka fabrication robot, Aegis Wall, MIT Senseable Cities Lab, Makerbot personal fabricator, Usman Haque, Future Cities Lab
Table of Contents
Section Contents Page
INTRODUCTION
Table of Contents
03
07 08 09
1.0 2.0
Rhino, Grasshopper, Firefly (.gha) Install Arduino, Blink, Firefly Firmata (.pde) Upload
08 11
13 14 15 17 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 32 33 34 35 36 37 38
2.10 2.11 2.12 2.13 2.14 2.15 2.16 2.17 2.18 2.19 2.20 2.21 2.22 2.23 2.24 2.25 2.26 2.27 3.1 3.2 4.1 4.2 4.3
3.0
FIREFLY TUTORIALS
40
40 44
4.0
Hardware Suppliers and Related Software Recommended Web Resources Recommended Books and Readings
ADDITIONAL RESOURCES
48 48 49
47
1.0
GETTING STARTED
Prerequisites
In order to begin working with Firefly, youll want to make sure you have the following software installed on your computer: Rhinoceros 4.0 (or 5.0 WIP beta) http://www.rhino3d.com/download.htm Service Release 8 (for Rhino) http://download.rhino3d.com/en/Rhino/4.0/sr/download/ Grasshopper (version 0.8 or higher) http://download.rhino3d.com/Grasshopper/1.0/wip/download/ Arduino IDE (Integrated Development Environment) http://arduino.cc/en/Main/Software
Download and unzip the Firefly Build 1.006.zip folder: http://www.fireflyexperiments.com/download/ The first thing well want to do is to copy and paste the Firefly.gha and Firefly_X.gha files (found inside the Firefly zip file) and the libTUIO.dll file into the proper Grasshopper Directory. First, launch Rhino and type the word Grasshopper in the command line. This will launch the GH editor. Click on File>Special Folders> Components Folder. Delete any older versions of Firefly (either older .gha files or the libTUIO.dll) if they are already installed on your computer. Next, open the Firefly Installation folder (in the .zip file you just downloaded) and copy all three files (Firefly. gha, Firefly_X.gha, and libTUIO.dll) into the Components Folder that was opened from within Rhino. Note: All three of these files have to be copy/pasted into that directory for Firefly to run properly. This process only has to be done once! Make sure to remove any prior Firefly installation files (if you are upgrading from an earlier release and had the build files stored in this folder). If you had installed an earlier version of Firefly and you had placed the build files in the C:\Program Files (x86)\ Rhinoceros 4.0\Plug-ins\Grasshopper\Components directory... please remove them! Now, Restart Rhino and Grasshopper - This time when you launch Grasshopper, you should see a new Firefly tab at the top of the Grasshopper Editor. Congratulations! Youve now installed the Firefly toolbar.
Firefly Tab
Note: If you are having problems getting Firefly to load properly in Rhino 5.0 beta, try the following steps: Open the Special Components folder (where we just copied the 3 files) and right-click on each file and select Properties. Under the General tab, check the box to Unblock the file. Do this for each of the three files. Now, Restart Rhino and Grasshopper
Firefly Primer - Version 1.006 - Page 8
Step 02. Arduino 0022 Software + Install the Drivers + Blink your Arduino Board
Download the latest version: http://www.arduino.cc/en/Main/Software * If you are using a Mac OSX we recommend that you install Arduino 0022 on the Windows side.
Follow these instructions closely and complete steps #1-6: http://arduino.cc/en/Guide/Windows A few seconds after the upload finishes, you should see the pin 13 (L) LED on the board start to blink (in orange). If it does, congratulations! Your Arduino is up-and-running!
USB
Blink Me !!!
Note: If you are having Arduino installation problems visit: http://arduino.cc/en/Guide/Troubleshooting ///////////////////////////////////////////////////////
Download the latest Firefly Firmata: http://www.fireflyexperiments.com/download/ Copy/Paste the folder named Firefly_UNO_Firmata into your Arduino Sketchbook folder: My Documents\Arduino or Username\Documents\Arduino Note: The first time you run the Arduino software, it will automatically create a directory for your Sketchbook. You can view or change the location of the sketchbook location with the File > Preferences dialog. The sketches in your sketchbook can be opened from the File > Sketchbook menu or from the Open button on the toolbar.
a. Launch the Arduino 0022 Application b. Open the Firefly Firmata sketch: File > Sketchbook > Firefly_UNO_Firmata.pde c. Select your Board: Tools > Board > Arduino Uno (w/ ATmega 328) (or whatever board you are using) d. Select your Serial Port: Tools > Serial Port > COM# (choose one that is available; remember the Port #)
Upload Button
e. Upload the Program: Simply click the Upload button. Wait a few seconds - you should see the RX and TX LEDS on the board flashing. If the upload is successful, the message Done uploading. will appear in the status bar. You will keep the USB connected to the Arduino - this is how Firefly will communicate with the sensors, motors and LEDS connected to the board. Congratulations - your Arduino board is now ready to communicate with Grasshopper / Firefly!!!
Firefly Primer - Version 1.006 - Page 9
WinAVR is now required to be installed in order to use the new Upload to I/O Board component in Firefly. WinAVR is an suite of open source software development tools that includes avr-gcc (compiler) and avrdude (programmer) among other things. To install the latest version of WinAVR: Go to: http://sourceforge.net/projects/winavr/files/WinAVR/ Click on the folder called 20100110 and download the file WinAVR-20100110-install.exe Run the executable and follow the instructions.
Your now set to start playing around with Firefly. Launch Rhino, and type the word Grasshopper into the command prompt to launch the Grasshopper Editor. Open one of the example files located in the Grasshopper Examples folder (inside the zip file) and begin exploring the connection between the physical and virtual worlds!
1.1
An amazing set of example files has been put together by Andy Payne in collaboration with Gil Akos and Ronnie Parsons. The files are located in the Firefly Build 1.006.zip folder: http://www.fireflyexperiments.com/download/ These example files are a great way to jump start the learning process.
2.0
I/O Boards
PORTS
COM Ports Available - Check to see which COM Ports are currently available Open Port - open the serial port, set the port number and the baud rate
OSC + UDP
OSC Listener - receives data from a specified UDP port [New to 1.006!] OSC Sender - sends messages over a UDP port to a specified IP address [New to 1.006!] UDP Listener - opens a UDP port and listens for any incoming messages. [New to 1.006!] UDP Sender - sends any string to a specified IP address on the network [New to 1.006!]
OTHER INPUTS
Pachube Read - Read a file from a Pachube Internet feed (www.pachube.com) ReacTIVision - connects to an open source, cross-platform computer vision framework Wii Nunchuck - read all sensor values from a Wii Nunchuck XML Search - Search an XML file (web or a local directory) for a specific element tag [New to 1.006!]
UTILITY
Binary Blink - oscillates 0s and 1s based on an incoming pattern of integers Buffer - Store the last number of values based on the buffer domain Constrain Values - constrains a number to specific numeric range Data Log- create a log for incoming data Fader One-Way - fade between one value to another based on a time interval Fader Two-Way - fade between a min and max value based on fade in /out Playback - the playback component will retrieve values from a text file (.txt, .csv, and .dat) Smoothing - Smooth (or average) an incoming value Wave - creates a sinusoidal waveform output State Detection - detect a switch from LOW to HIGH (0 or 1) or vice versa [New to 1.006!] Stop Watch - time in milliseconds since the data was updated. [New to 1.006!]
2.1
2.2
Uno Read
A
Firefly > Boards > Uno Read
The FireFly Uno Read component will read values for all corresponding digital and analog pins on the Arduino Uno, Duemilanove, Diecimilla, or Lillypad board. Use the GH_Timer component (Parameters/Special/Timer) to update the sensor values in real-time. Note: This component is meant to be used in tandem with the FireFly Uno Arduino Firmata program (a .pde file) which can be downloaded from the Firefly website at: www.fireflyexperiments.com
2.3
Uno Write
A
Firefly > Boards > Uno Write
The FireFly Uno Write component will write values for all corresponding digital pins on an Arduino Uno, Duemilanove, Diecimilla, or Lillypad board. Note: This component is meant to be used in tandem with the FireFly Uno Arduino Firmata Sketch (a .pde file). Note: If the Port has been opened, double-click on the Start toggle to set it to True and start writing values to the Arduino. The Firefly Firmata sketch has been completely re-written to make the Write process more fluid. For example, you can now control a servo on any of the digital pins. The pins that have the tilde (~) symbol represent the digital pins on the Arduino board that have Pulse Width Modulation (PWM: 0-255) capabilities. To set the type of pin control, simply right-click on any input and set the status to either Digital (HIGH/LOW or 0/1), PWM (0-255), or Servo (0-180). If you right-click on the Uno Write components DPins 11,6,5 and 3 you will see the PWM option (between Digital and Servo) in the drop down menu. In the current build Pins 10,9 are not PWM. Let me know if this works for you. [A] Port: This should match the Port number that you first established in the Open Port component
status is set then the integer (0) will send a LOW value and a (1) will send a HIGH value. If the PWM status is set then any value between 0-255 can be used to analogWrite to the specified pin. If the Servo status is set then any value between 0-180 can be used to for servo positioning. DPin5~ (Integer) Integer to write to Digital Pin 5. Right-click on the input to set the input status (Digital, PWM, Servo). If the Digital status is set then the integer (0) will send a LOW value and a (1) will send a HIGH value. If the PWM status is set then any value between 0-255 can be used to analogWrite to the specified pin. If the Servo status is set then any value between 0-180 can be used to for servo positioning. DPin3~ (Integer) Integer to write to Digital Pin 3. Right-click on the input to set the input status (Digital, PWM, Servo). If the Digital status is set then the integer (0) will send a LOW value and a (1) will send a HIGH value. If the PWM status is set then any value between 0-255 can be used to analogWrite to the specified pin. If the Servo status is set then any value between 0-180 can be used to for servo positioning. Port (Integer) The Port Number has to be the same Serial Port assigned in the Arduino Sketch. You can find which COM port you are using by clicking on the Tools>Serial Port button on the Arduino IDE.
Output parameters:
Out (String) Returns the string that will be sent to the Arduino board. The Arduino sketch that accompanies this component will split this string up and send the values to the appropriate pins. Msg (String) Current status of Serial Port
Pin13 LED
5V Volt Regulator Power Jack Power Pins Arduino Uno Overview Analog Input Pins
The Arduino Uno (released in 2010) is a microcontroller board based on the ATmega328 chip. It has 14 digital input/output pins (of which 6 can be used as PWM outputs), 6 analog inputs, a 16 MHz crystal oscillator, a USB connection, a power jack, an ICSP header, and a reset button. It contains everything needed to support the microcontroller; simply connect it to a computer with a USB cable or power it with a AC-to-DC adapter or battery to get started. The Uno is the latest in a series of USB Arduino boards; for a comparison with previous versions, see the index of Arduino boards. For more info: http://arduino.cc/en/Main/ArduinoBoardUno
Firefly Primer - Version 1.006 - Page 16
2.4 / 2.5
2.6
2.7
2.8
Code Generator
2.9
Click to upload the Arduino Code Firefly > Boards > Upload I/O
This component will attempt to upload any Arduino sketch to your I/O Board. VIDEO: Andy has created a great video illustrating how it works: http://www.fireflyexperiments.com/videos/arduino-code-generator-upload-to-io-board.html If the Arduino sketch file path is valid (can be from the Code Generator), you can click on the arrow icon to upload the sketch to the board. Alot of stuff happens behind the scenes, but it should create a dynamic MakeFile and convert the .pde file into a .cpp (C++) file and then into .hex code (machine readable code for the microcontroller). NOTE: WinAVR is required to be installed in order for the Upload to I/O Board component to work properly. WinAVR (pronounced whenever) is a free suite of executable, open source software development tools which includes avr-gcc (compiler), avrdude (programmer), among other things. You can download the latest version of WinAVR at: http://winavr.sourceforge.net/index.html
2.10
2.11
2.12
Pachube Read
2.13
Reactivision Listener
2.14
Wii Nunchuck
2.15
XML Search
2.16
Binary Blink
Binary Blink is one of the simplest ways to confirm that Firefly and the Arduino board are communicating correctly. In the image (right) the long leg (+) of an LED is inserted into Pin13 and the short leg (-) is inserted into GND. Firefly Primer - Version 1.006 - Page 28
2.17
Buffer
2.18
Constrain
2.19
Data Log
2.20 / 2.21
2.22
Playback
2.23
Smoothing
A
2.24
Wave
2.25
State Detection
2.26
Stop Watch
2.27
Additional Components
Additional Components [Boolean, Number Slider, Value Tracker, Remap, Panel, Timer]
These additional components are not Firefly specific components but you will use them quite often. They come pre-packaged as a part of the standard Grasshopper build. You will utilize many of these components when you use Firefly so it is critical that you know where to find them and how to incorporate them into your projects. This is a just a sampling of what we consider to be the most important for beginning users - as you get more advanced you will certainly begin to incorporate many more into your projects. If there are components or custom clusters that you invent and you think they should be included in the next Firefly Primer - please leave us a comment on the Firefly website: www.fireflyexperiments.com
Analog values will be variable and continuous ranging from 0 to 1023 Digital values will spike from 0 to 1
Panel Description
Panels can receive their information from elsewhere. If you plug an output parameter into a Panel, you can see the contents of that parameter in real-time. All data in Grasshopper can be viewed in this way.
Timer
Timer Description
Timers are object which fire update events at specified intervals. This process is reasonably dangerous since updates might occur when you do not expect them, so please be careful when using them, and only use a timer when you have no other option. Remarks: Timer intervals are specified in milliseconds. Right-click on the Timer component and then select Interval. If you type in 1 then this will set the timer to 1 millisecond (very fast). 500 ms equals 1/2 second, and 1000 ms equals 1 second etc.
3.0
FIREFLY TUTORIALS
In order to complete these tutorials you must have successfully followed all the steps outlined in the first section of this Primer: 1.0 Getting Started > Installation. Download the tutorial support files at: http://www.fireflyexperiments.com
Steps 1 will cover building the actual circuit using an Arduino Board, breadboard, Servo, LEDs Steps 2-4 will cover the process of setting GH/Firefly Open Port, Read and Write Steps 5 will cover linking your GH/Firefly sketch to specific geometry
b. STANDARD SERVO
SIG GND +
a. LED
c. LED (PWM)
GND 5V
+ 1K 10 K GND
USB
d. PHOTORESISTOR
5V
GND
SIG
READ A B PORT
WRITE
E G F
Above - The Uno Write Component (see description on the next page)
Firefly Primer - Version 1.006 - Page 42
B A D E
Figure 1. The Rhino modeling window (left) and Grasshopper Interface (right)
My Settings
Preparing the Pachube Read Component Step 1. Setup a pachube account and find your API Key
In order to begin monitoring various sensor feeds from pachube.com, you will first need to create an account. Begin by going to the URL: http://www.pachube.com and click on the Sign Up link at the top of the page. After providing a unique user name, e-mail address, and password you will be directed back to the pachube home page. When logged in, you will notice a grey menu bar at the top of the page with various links to manage your account. On the far right hand side of this menu, you will find a link to manage My Settings. After clicking on this link, you will be directed to your account settings page where you will find your API Key. Some Pachube API methods dont require authentication (primarily those involving syndication and those that contain no real-time data, for example 24-hour history CSV and graphs). This enables them to be used in thirdparty websites or mashups that require public access. However, most real time data methods do require a Pachube API key. Your API Key is your personal identification code that will be required to access many real-time feeds on pachube. Note: Since your API Key is your personal identifier on pachube, it is crucial that you keep this code private. Do not share this information with others and make sure you do not share Grasshopper files which may contain your key inside the document. Now that we have setup an account, drag and drop a Text Panel onto the canvas. Copy and paste your API Key (from your account settings) into the Text Panel. Connect the output of this Text Panel to the API Key input node of the Pachube Read component.
URL: retrieves the real-time value of that datastream alone. We can add the extension .xml or .csv to this URL address to isolate the current value of a single sensor data stream. History: quick view of the last 24 hours of data in 15-minute increments, CSV format, no timestamps (total of 96 datapoints). This URL address can only be accessed by adding the .csv file extension. Archive: complete datastream history in 15-minute increments, CSV format, includes timestamps. This URL address can only be accessed by adding the .csv file extension. PNG graph: HTML code snippet for embedding a configurable PNG graph of the datastream. Currently the PNG graphs cannot be imported into Grasshopper. Zoom graph: HTML code snippet for embedding a zoomable graph of the last 30 days of data. Currently the Zoom graph cannot be imported into Grasshopper.
This example and several others are covered in a very thorough example file 20110625_Firefly_07_Pachube. gh available in the Download section here: www.fireflyexperiments.com. The example file covers several additional steps not shown here including how to connect the Pachube Read component to geometry in Grasshopper.
4.00
4.1
ADDITIONAL RESOURCES
Hardware Suppliers and Related Software
LITTLE BITS OF EVERYTHING Adafruit [Based in NYC - Arduinos, Sensors, Wireless, DIY Central, great range of things ...] Jameco [outside SF in Belmont, CA - Huge selection of Electronics; Great mail order too] RobotShop [Huge selection of robot-based electronics, SMAs, Motors, Sensors] Al Lashers Electronics [Located in Berkeley, CA -1734 University Ave (510)843-5915] Electronics Plus [San Rafael, CA - (415) 457-0466] Frys [1077 East Arques Ave. Sunnyvale, CA, 408.617.1300 - also in Palo Alto, San Jose and more] Marlin P. Jones [Huge Supplier including Power Supplies, LED, Connectors, etc] Digikey [Major Electronics Supplier with an huge catalog] SuperBrightLEDS.com [Single LEDs or multiple strings, all types, good quality] Servocity [Great Selection of Servos and Supplies] ARDUINO + GENERAL ELECTRONICS SUPPLIERS Arduino [mothership: great links to everything Arduino] Sparkfun [custom Arduino shields, sensors, hardware, kits ...] MakerShed [sensors, hardware, kits ...] LiquidWare [lots of everything] SENSORS Acroname [Sharp IR Sensor Source - we use the GP2Y0A02YK] Making Things [Great range of Sensors - highly recommend] Sparkfun Sensors [many flavours] Sensor Kit by Sparkfun LadyAda [Bits and Pieces; Sensors and Arduinos and much more] SHAPE MEMORY ALLOY Dynalloy [maker of Flexinol - located in Tustin, CA] Images Scientific Instruments [large selection of nitinol and flexinol based products] Miga Motors [large selection of SMA driven servos and actuators] POWER SUPPLIES PowerSupplyOne [Huge Selection of Power Supplies] GOOD ARDUINO BASED STARTER KITS + Mid-Range > Arduino Starter Pack or equal [includes Arduino Uno, Protoboard, and a good selection of starter components] + High-End Recommended > Arduino Experimentation Kit v1.0 or equal [includes Arduino Uno, Prototyping bundles, and a great selection of starter components] Other misc. tools that you might consider purchasing: a soldering iron and solder, wire strippers, helping hands, digital multimeter, etc. Here is a great link for info on the best tools to purchase. [Note: These are working lists. Please e-mail us a related links and well consider adding them to our lists]
Firefly Primer - Version 1.006 - Page 47
4.2
LEDS
LED Circuitry Tutorial: http://www.theledlight.com/ledcircuits.html LED Calculator: http://www.led-calculator.com/ Instructables http://www.instructables.com/ Lady Ada Tutorials http://www.adafruit.com/index.php?main_page=tutorials SERVOS Hacking Servos for continuous rotation: http://www.seattlerobotics.org/guide/servohack.html
4.3
Grasshopper Home [plug-in for Rhino; Created by David Rutten and augmented by many others] Kangaroo [Physics Engine for simulating materials] Geometry Gym [Geometry toolkit] ModeLab Tools [Many helpful GH tools ] Geco [connect GH with Ecotect] Weaverbird [smoothing, modifying and preparing meshes] Finches / Local Code (GIS tools): http://www.grasshopper3d.com/group/localcodecomponents For a complete list visit: http://www.grasshopper3d.com/page/addons-for-grasshopper
Arduino Related
Arduino [obviously, but this is a key software especially to hack the Firefly Firmata!] Processing [Arduino is based on Processing by Casey Reas and Ben Fry] Modkit [Drag and Drop programming for Arduino]
Ubimash [Uses UDP to publish and subscribe to server data; used with GC and others] NetLabToolkit [Tools for tangible interaction using Arduino / Flash Widgets] Fritzing [Draw, Visualize and Output Circuits Diagrams; Arduino to Breadboard - highly recommended]
Machine Vision
Python
Python Interpreter for GH: http://www.grasshopper3d.com/forum/topics/python-interpreter-test-drive Python GH Research by Walter Kim: http://abstractnonsen.se/cca/ag_s11/ [Note: These are working lists. Please e-mail us a related links and well consider adding them to our lists]
4.4
Fox, Michael and Kemp, Miles. Interactive Architecture. Princeton Architectural Press, 2009. (Amazon) Nobel, Joshua. Programming Interactivity: A Designers Guide to Processing, Arduino, and Openframeworks. OReilly Media, 2009. (Amazon) Platt, Charles. Make: Electronics (Learning Through Discovery Series). Make Publishers, 2009. (Amazon) Banzi, Massimo. Getting Started with Arduino. Make Publishers, 2008. (Amazon) Reas and Fry. Processing - Programming Handbook for Designers. MIT Press. (Amazon) Igoe and OSullivan. Physical Computing: Sensing and Controlling the Physical World with Computers. Course Tech CPR. (Amazon) Igoe, Tom. Making Things Talk. OReilly Press. (Amazon)
Cover graphic courtesy of Future Cities Lab - The Aurora Project (JK. Johnson/N. Gattegno with special thanks to C. Norman/T. Kelley)