SlideShare a Scribd company logo
Getting Started with Firefly
The City University of New York
Architectural Technology Dept.
written by Anthony Gonzalez
GettingStartedwithFirefly
2
Introduction
Firefly is a suite of software tools written for the
Grasshopper plug-in that enable you to drive
parametric values through sensor data via an Arduino
microcontroller. In addition to slaving parameters of a
GrasshopperdefinitiontothatofanArduino-connected
sensor (or creating a mathematical relationship
between a sensor measurement and a controlled
parameter), Firefly also enables parameters to behave
as outputs that drive actuation (eg. motors, LEDS,
etc.). Thus, using Firefly, there is potential for two-way
communication where not only can you determine the
state of external physical conditions and use that data
to construct and/or manipulate responsive virtual
models, you can also use those same virtual models
and their parameters as outputs that control the state
of responsive physical environments.
The Firefly Installation files are available at http://
www.fireflyexperiments.com/download
GettingStartedwithFirefly
3
Preparing for Firefly Communication
Assuming you have already installed the Arduino
IDE and your Arduino board is currently connected
to your workstation, you must now upload the Firefly
Firmata sketch to the Arduino board. Firmata is what
is described as a “generic protocol for communicating
with microcontrollers from software on a host
computer.” In other words, by uploading the Firefly
Firmata sketch you are essentially embedding a
prewritten program onto the Arduino board that allows
Firefly to both read from and write to the Arduino’s pins.
Once uploaded, you can move away from the Arduino
IDE and create all programmatic behavior through the
visual programming language of Grasshopper.
The Firefly Firmata is available at http://www.
fireflyexperiments.com/download
GettingStartedwithFirefly
4
The Firefly Toolbar
Fig. 1 shows the Firefly toolbar as it is in Grasshopper.
As you can see, Firefly actually adds more functionality
to Grasshopper than just Arduino communication.
As seen in Fig. 1, Firefly provides components to
interface with audio input, send & receive data over a
network, and even open up a webcam feed. However,
the components we are concerned about here are
in the panel to the far left (shows in Fig. 2). These
are components specifically related to your Arduino
microcontroller (ignore the Wii object). Depending on
the model of Arduino board you are using, the most
important component to become familiar with is
either the UNO or MEGA component along with its two
variations: READ and WRITE.
Fig. 1 -Firefly Toolbar
Fig. 2 -Firefly Toolbar
GettingStartedwithFirefly
5
The Virtual Arduino
The functionality of the physical Arduino board
(specific pins behaving as either INPUTS or OUTPUTS)
is virtually represented within Firefly as two separate
components (as shown in Fig. 3 & Fig. 4).
Through this simple binary implementation, Firefly
has already designated which pins on the Arduino
board can behave as INPUTS (those assigned to
the ‘Read’ component) and those pins which can
behave as OUTPUTS (those assigned to the ‘Write’
component). While this limits a certain amount of
flexibility in choosing which pins behave in which
manner (like when coding in the Arduino IDE), with
this “hard-coded” approach conflict is averted and the
extra step of assigning behavior to the specific pins
you plan to use is eliminated. Notice in the ‘Read’
object, all six analog pins are available to read, which
makes perfect sense since analog pins are meant
for sensing (measuring voltage) and even in the
Arduino IDE voltage values other than HIGH or LOW
cannot actually be written to analog pins. In addition
to interfacing with analog pins, the ‘Read’ component
interfaces with three digital pins: DPin2, DPin4, and
DPin7. Now look at the ‘Write” component and notice
the absence of analog pins (perfectly legitimate)
and the inclusion of nine digital pins: DPin3, DPin5,
DPin6, DPin8, DPin9, DPin10, DPin11, DPin12, and
DPin13. Digital pins 2, 4, 7 are excluded from the
‘Write’ component because they have already been
designated by Firefly as INPUTS (by their inclusion in
the ‘Read’ component). When wiring, make sure to
note that digital pins 0 and 1 are reserved for serial
communication and are not represented in either the
‘Read’ or ‘Write’ components.
Fig. 3 -Uno Read Component Fig. 4 -Uno Write Component
GettingStartedwithFirefly
6
Reading & Writing to Pins
While the ‘Read’ and “Write’ components are
critical to interfacing with the Arduino board, in
turn, these components depend on other smaller
components in order to operate properly. Before any
kind of communication can take place between the
Arduino board and Grasshopper (or any other piece
of software) a serial port must be opened for that
communication to take place.
The ‘Open Port’ component (shown in Fig. 5)
establishes and opens a port over which
communication will take place between the Arduino
board and Grasshopper. This component requires
three input parameters: Open, Port, and Baud. Open
accepts a “Boolean” value (True or False) which is
easiest to interface with using the “Boolean Toggle”
parameter (under Params > Special) while Port and
Baud accept “Integer” parameters (under Params >
Primitive). The significance of each parameter is self
explanatory: the “Boolean” opens and closes the
connection respectively, the Port “Integer” tells the
component which communication port the Arduino
board is actually connected to, and the Baud “Integer”
tells the port at what transmission speed to operate
(this rate must match the rate defined in the Firefly
Firmata sketch which by default is 115200). The
number assigned to the communication port used by
your Arduino board can be determined in two different
ways: using the Device Manager or through Firefly’s
“Ports Available” component (shown in Fig. 6).
Fig. 5 -Open Port Component Fig. 6 -Ports Available Component
GettingStartedwithFirefly
7
Reading & Writing
Uno Read
Once you have determined the correct port number,
have entered that number into the “Integer”
parameter connected to the “Open Port” component,
and have set the Open property of that component
to True, you are now ready to begin communicating
with the Arduino board. Let’s look at the “Uno Read”
component again (shown in Fig. 7).
Although you have already established and opened a
port over which communication between the Arduino
board and Grasshopper can take place, both the
“Uno Read” and “Uno Write” components require a
clear directive to actually begin utilizing that open
port. This directive is defined through two required
input parameters: Start and Port. The Start input
expects a “Boolean” value and the Port input expects
an “Integer” value (naturally, the corresponding port
number of the line of communication you have already
opened in the “Open Port” component). In addition to
initializing the “Uno Read” component, you must also
define how often to check for updated values from the
Arduino board. This is accomplished by connecting a
“Timer” object directly to the “Uno Read” component.
The “Timer” object sends pulses at a set interval (in
this case every 20ms) to the “Uno Read” component,
which essentially command the component to retrieve
new values for each of the Arduino board’s input pins.
Now let’s set our “Boolean Toggle” to True and connect
some text panels to our component outputs for some
feedback and… you’re now reading values from our
Arduino board’s input pins (as shown in Fig. 8).
Fig. 7 -Uno Read Component Fig. 8 -Uno Read Component
GettingStartedwithFirefly
8
Reading & Writing
Uno write
Using the “Uno Read” component you’ve now used
Firefly as an input to retrieve data from the Arduino
board’s output pins. With this data, you can drive
any parameter of your Grasshopper definition in any
manner that you desire. The counterpart to “Uno
Read” is the “Uno Write” component (shown in Fig. 9)
which allows you to use Firefly as an output that can
send data to the Arduino board’s input pins.
If you remember how to initialize and begin sending
pulses to the “Uno Read” component, then you’ll have
no trouble getting the “Uno Write” component up and
running. Notice the two input parameters Start and
Port as well as the “Timer” object connected directly
to the “Uno Write” component. The obvious difference
here is the number of inputs available, which
correspond to the pins you can control on the Arduino
board from Grasshopper. Each digital pin input
parameter (eg. DPin13) expects either a “Boolean”
or “Integer” value. As in most if not all programming
languages, True evaluates to 1, False evaluates to
0, and vice versa. In addition, any non-zero integer
evaluates to True.
Taking a closer look at the input parameters of “Uno
Write” you’ll notice a small variation on specific digital
pins, specifically the tilde (~). The tilde defines pins
that can be used for either digital input (0 or 1 / false
or true) or PWM (pulse width modulation). In brief,
PWM uses square waves to simulate analog values
by modulating the time the signal is high by the time
the signal is low. These pins can accept integers other
than 0 or 1 and are great for fading LED’s, controlling
motors, etc. By right-clicking the input parameters you
can set how each digital pin should behave (shown in
Fig. 10).
The Out output parameter is included here in order
to demonstrate that the “Uno Write” component
continually writes data to all of the Arduino board’s
input pins regardless of whether you are actually
changing one or all of the “Uno Write” input
parameters.
Fig. 9 -Uno Write Component
Fig. 10 -Set Pin to PWM

More Related Content

PDF
arduino
PDF
What is arduino
PDF
Microcontroladores: Programación en C para microcontroladores con AVR Butterf...
PPT
General Talk on Pointers
KEY
Intro to Arduino
PDF
Notes1
PPTX
PPTX
Introduction to the Arduino
arduino
What is arduino
Microcontroladores: Programación en C para microcontroladores con AVR Butterf...
General Talk on Pointers
Intro to Arduino
Notes1
Introduction to the Arduino

What's hot (20)

PDF
Intro to Arduino Revision #2
PDF
Ardx experimenters-guide-web
PPTX
Arduino Foundations
PDF
Arduino Workshop Day 2 - Advance Arduino & DIY
PDF
IRJET- Smart Gloves to Convert Sign Languages to Vocal Output
PDF
Arduino Workshop Day 1 - Basic Arduino
PPTX
Programming with arduino
PPT
Physical prototyping lab1-input_output (2)
PPTX
Arduino course
PPT
C++ Pointers And References
PDF
아두이노 Digital/Analog IO
PPTX
Arduino for beginners- Introduction to Arduino (presentation) - codewithgauri
PDF
Pointer in c++ part1
PPTX
Keyboard interrupt
DOCX
Interfacing to
PPTX
Arduino Workshop
PDF
Lily pad dev_handout
PPTX
Intro to Python Programming Language
PDF
Intro to Arduino Revision #2
Ardx experimenters-guide-web
Arduino Foundations
Arduino Workshop Day 2 - Advance Arduino & DIY
IRJET- Smart Gloves to Convert Sign Languages to Vocal Output
Arduino Workshop Day 1 - Basic Arduino
Programming with arduino
Physical prototyping lab1-input_output (2)
Arduino course
C++ Pointers And References
아두이노 Digital/Analog IO
Arduino for beginners- Introduction to Arduino (presentation) - codewithgauri
Pointer in c++ part1
Keyboard interrupt
Interfacing to
Arduino Workshop
Lily pad dev_handout
Intro to Python Programming Language
Ad

Similar to Getting Started With Firefly (20)

PPTX
Fund. of IoT LAB - CO 252.pptx
PPTX
Electronz_Chapter_14.pptx
PPTX
Presentation of online Internship Program on Arduino completed at INTERNSHALA
PDF
Arduino day 2019
PPTX
arduino uno
PDF
Arduino-workshop.computer engineering.pdf
PDF
Arduino: Arduino starter kit
PPTX
arduino uno.pptx
PPTX
Ch_2_8,9,10.pptx
DOCX
Arduino and Circuits.docx
PDF
Arduino electronics cookbook
PPT
Introduction to Arduino 16822775 (2).ppt
PPTX
Fun with arduino
PDF
Digital home automation with arduino bluetooth
PPTX
After COMPUTING THIS IS FOR COMPUTER SCIENTISTS.pptx
PDF
Arduino comic v0004
PDF
Arduino Comic-Jody Culkin-2011
PPTX
Lecture 7
PDF
Arduino workshop sensors
PDF
Ardublock tutorial
Fund. of IoT LAB - CO 252.pptx
Electronz_Chapter_14.pptx
Presentation of online Internship Program on Arduino completed at INTERNSHALA
Arduino day 2019
arduino uno
Arduino-workshop.computer engineering.pdf
Arduino: Arduino starter kit
arduino uno.pptx
Ch_2_8,9,10.pptx
Arduino and Circuits.docx
Arduino electronics cookbook
Introduction to Arduino 16822775 (2).ppt
Fun with arduino
Digital home automation with arduino bluetooth
After COMPUTING THIS IS FOR COMPUTER SCIENTISTS.pptx
Arduino comic v0004
Arduino Comic-Jody Culkin-2011
Lecture 7
Arduino workshop sensors
Ardublock tutorial
Ad

More from NYCCTfab (20)

PDF
Fusion 360 Tutorial
PDF
Citytech HTML/CSS Guide
PDF
Ultimaker 2+
PDF
Robot Studio
PDF
Roland Primer 3D Scanner
PDF
Lighting with Photoshop
PDF
Fusion 360 Tutorial
PDF
Architectural diagrams
PDF
Advanced Techniques in Photoshop
PDF
Adobe Premiere Pro
PDF
VRay Lighting for Rhino
PDF
Adobe Illustrator CC 2018
PDF
Silicone Mold Primer
PDF
Presentation Board Layout
PDF
CPD Dental Cam Primer
PDF
Temperature and Light Logger (UA-002-64)
PDF
Telaire CO2 Sensor (Tel-7001)
PDF
UX90-002 Light & Occupancy Logger
PDF
Light Meter (LM-120)
PDF
Temperature and Relative Humidity Ext
Fusion 360 Tutorial
Citytech HTML/CSS Guide
Ultimaker 2+
Robot Studio
Roland Primer 3D Scanner
Lighting with Photoshop
Fusion 360 Tutorial
Architectural diagrams
Advanced Techniques in Photoshop
Adobe Premiere Pro
VRay Lighting for Rhino
Adobe Illustrator CC 2018
Silicone Mold Primer
Presentation Board Layout
CPD Dental Cam Primer
Temperature and Light Logger (UA-002-64)
Telaire CO2 Sensor (Tel-7001)
UX90-002 Light & Occupancy Logger
Light Meter (LM-120)
Temperature and Relative Humidity Ext

Recently uploaded (20)

PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Empathic Computing: Creating Shared Understanding
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Machine learning based COVID-19 study performance prediction
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
Big Data Technologies - Introduction.pptx
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
Spectroscopy.pptx food analysis technology
PDF
Approach and Philosophy of On baking technology
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPT
Teaching material agriculture food technology
Chapter 3 Spatial Domain Image Processing.pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Empathic Computing: Creating Shared Understanding
The Rise and Fall of 3GPP – Time for a Sabbatical?
Machine learning based COVID-19 study performance prediction
Programs and apps: productivity, graphics, security and other tools
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Agricultural_Statistics_at_a_Glance_2022_0.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
Diabetes mellitus diagnosis method based random forest with bat algorithm
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Big Data Technologies - Introduction.pptx
Digital-Transformation-Roadmap-for-Companies.pptx
20250228 LYD VKU AI Blended-Learning.pptx
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Spectral efficient network and resource selection model in 5G networks
Spectroscopy.pptx food analysis technology
Approach and Philosophy of On baking technology
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Teaching material agriculture food technology

Getting Started With Firefly

  • 1. Getting Started with Firefly The City University of New York Architectural Technology Dept. written by Anthony Gonzalez
  • 2. GettingStartedwithFirefly 2 Introduction Firefly is a suite of software tools written for the Grasshopper plug-in that enable you to drive parametric values through sensor data via an Arduino microcontroller. In addition to slaving parameters of a GrasshopperdefinitiontothatofanArduino-connected sensor (or creating a mathematical relationship between a sensor measurement and a controlled parameter), Firefly also enables parameters to behave as outputs that drive actuation (eg. motors, LEDS, etc.). Thus, using Firefly, there is potential for two-way communication where not only can you determine the state of external physical conditions and use that data to construct and/or manipulate responsive virtual models, you can also use those same virtual models and their parameters as outputs that control the state of responsive physical environments. The Firefly Installation files are available at http:// www.fireflyexperiments.com/download
  • 3. GettingStartedwithFirefly 3 Preparing for Firefly Communication Assuming you have already installed the Arduino IDE and your Arduino board is currently connected to your workstation, you must now upload the Firefly Firmata sketch to the Arduino board. Firmata is what is described as a “generic protocol for communicating with microcontrollers from software on a host computer.” In other words, by uploading the Firefly Firmata sketch you are essentially embedding a prewritten program onto the Arduino board that allows Firefly to both read from and write to the Arduino’s pins. Once uploaded, you can move away from the Arduino IDE and create all programmatic behavior through the visual programming language of Grasshopper. The Firefly Firmata is available at http://www. fireflyexperiments.com/download
  • 4. GettingStartedwithFirefly 4 The Firefly Toolbar Fig. 1 shows the Firefly toolbar as it is in Grasshopper. As you can see, Firefly actually adds more functionality to Grasshopper than just Arduino communication. As seen in Fig. 1, Firefly provides components to interface with audio input, send & receive data over a network, and even open up a webcam feed. However, the components we are concerned about here are in the panel to the far left (shows in Fig. 2). These are components specifically related to your Arduino microcontroller (ignore the Wii object). Depending on the model of Arduino board you are using, the most important component to become familiar with is either the UNO or MEGA component along with its two variations: READ and WRITE. Fig. 1 -Firefly Toolbar Fig. 2 -Firefly Toolbar
  • 5. GettingStartedwithFirefly 5 The Virtual Arduino The functionality of the physical Arduino board (specific pins behaving as either INPUTS or OUTPUTS) is virtually represented within Firefly as two separate components (as shown in Fig. 3 & Fig. 4). Through this simple binary implementation, Firefly has already designated which pins on the Arduino board can behave as INPUTS (those assigned to the ‘Read’ component) and those pins which can behave as OUTPUTS (those assigned to the ‘Write’ component). While this limits a certain amount of flexibility in choosing which pins behave in which manner (like when coding in the Arduino IDE), with this “hard-coded” approach conflict is averted and the extra step of assigning behavior to the specific pins you plan to use is eliminated. Notice in the ‘Read’ object, all six analog pins are available to read, which makes perfect sense since analog pins are meant for sensing (measuring voltage) and even in the Arduino IDE voltage values other than HIGH or LOW cannot actually be written to analog pins. In addition to interfacing with analog pins, the ‘Read’ component interfaces with three digital pins: DPin2, DPin4, and DPin7. Now look at the ‘Write” component and notice the absence of analog pins (perfectly legitimate) and the inclusion of nine digital pins: DPin3, DPin5, DPin6, DPin8, DPin9, DPin10, DPin11, DPin12, and DPin13. Digital pins 2, 4, 7 are excluded from the ‘Write’ component because they have already been designated by Firefly as INPUTS (by their inclusion in the ‘Read’ component). When wiring, make sure to note that digital pins 0 and 1 are reserved for serial communication and are not represented in either the ‘Read’ or ‘Write’ components. Fig. 3 -Uno Read Component Fig. 4 -Uno Write Component
  • 6. GettingStartedwithFirefly 6 Reading & Writing to Pins While the ‘Read’ and “Write’ components are critical to interfacing with the Arduino board, in turn, these components depend on other smaller components in order to operate properly. Before any kind of communication can take place between the Arduino board and Grasshopper (or any other piece of software) a serial port must be opened for that communication to take place. The ‘Open Port’ component (shown in Fig. 5) establishes and opens a port over which communication will take place between the Arduino board and Grasshopper. This component requires three input parameters: Open, Port, and Baud. Open accepts a “Boolean” value (True or False) which is easiest to interface with using the “Boolean Toggle” parameter (under Params > Special) while Port and Baud accept “Integer” parameters (under Params > Primitive). The significance of each parameter is self explanatory: the “Boolean” opens and closes the connection respectively, the Port “Integer” tells the component which communication port the Arduino board is actually connected to, and the Baud “Integer” tells the port at what transmission speed to operate (this rate must match the rate defined in the Firefly Firmata sketch which by default is 115200). The number assigned to the communication port used by your Arduino board can be determined in two different ways: using the Device Manager or through Firefly’s “Ports Available” component (shown in Fig. 6). Fig. 5 -Open Port Component Fig. 6 -Ports Available Component
  • 7. GettingStartedwithFirefly 7 Reading & Writing Uno Read Once you have determined the correct port number, have entered that number into the “Integer” parameter connected to the “Open Port” component, and have set the Open property of that component to True, you are now ready to begin communicating with the Arduino board. Let’s look at the “Uno Read” component again (shown in Fig. 7). Although you have already established and opened a port over which communication between the Arduino board and Grasshopper can take place, both the “Uno Read” and “Uno Write” components require a clear directive to actually begin utilizing that open port. This directive is defined through two required input parameters: Start and Port. The Start input expects a “Boolean” value and the Port input expects an “Integer” value (naturally, the corresponding port number of the line of communication you have already opened in the “Open Port” component). In addition to initializing the “Uno Read” component, you must also define how often to check for updated values from the Arduino board. This is accomplished by connecting a “Timer” object directly to the “Uno Read” component. The “Timer” object sends pulses at a set interval (in this case every 20ms) to the “Uno Read” component, which essentially command the component to retrieve new values for each of the Arduino board’s input pins. Now let’s set our “Boolean Toggle” to True and connect some text panels to our component outputs for some feedback and… you’re now reading values from our Arduino board’s input pins (as shown in Fig. 8). Fig. 7 -Uno Read Component Fig. 8 -Uno Read Component
  • 8. GettingStartedwithFirefly 8 Reading & Writing Uno write Using the “Uno Read” component you’ve now used Firefly as an input to retrieve data from the Arduino board’s output pins. With this data, you can drive any parameter of your Grasshopper definition in any manner that you desire. The counterpart to “Uno Read” is the “Uno Write” component (shown in Fig. 9) which allows you to use Firefly as an output that can send data to the Arduino board’s input pins. If you remember how to initialize and begin sending pulses to the “Uno Read” component, then you’ll have no trouble getting the “Uno Write” component up and running. Notice the two input parameters Start and Port as well as the “Timer” object connected directly to the “Uno Write” component. The obvious difference here is the number of inputs available, which correspond to the pins you can control on the Arduino board from Grasshopper. Each digital pin input parameter (eg. DPin13) expects either a “Boolean” or “Integer” value. As in most if not all programming languages, True evaluates to 1, False evaluates to 0, and vice versa. In addition, any non-zero integer evaluates to True. Taking a closer look at the input parameters of “Uno Write” you’ll notice a small variation on specific digital pins, specifically the tilde (~). The tilde defines pins that can be used for either digital input (0 or 1 / false or true) or PWM (pulse width modulation). In brief, PWM uses square waves to simulate analog values by modulating the time the signal is high by the time the signal is low. These pins can accept integers other than 0 or 1 and are great for fading LED’s, controlling motors, etc. By right-clicking the input parameters you can set how each digital pin should behave (shown in Fig. 10). The Out output parameter is included here in order to demonstrate that the “Uno Write” component continually writes data to all of the Arduino board’s input pins regardless of whether you are actually changing one or all of the “Uno Write” input parameters. Fig. 9 -Uno Write Component Fig. 10 -Set Pin to PWM