• No results found

State Detection 36

In document Firefly Primer 1006 (Page 36-50)

Firefly > Utility > State Detection

Used when you want to detect when something has switched from LOW to HIGH (0 or 1) or vice versa. For more information see: http://arduino.cc/en/Tutorial/ButtonStateChange

Description of Component Input/Output Parameters

Input parameters:

V (Integer) Incoming value to test.

M (Integer) Modulo value to determine the number of state changes before a switch is made.

Output parameters:

S (Integer) Current State C (Integer) Counter TRY IT OUT:

1. Build the Button Circuit illustrated below. Make sure the button is connected to digital Pin 2 as pictured.

2. Construct the Firefly components as they are illustrated above. When you press the button the LED (hard-wired to Pin 13) on your Arduino board should turn ON and OFF.

2.26 Stop Watch

Firefly > Utility > Stop Watch

Time in milliseconds since the data was updated.

Description of Component Input/Output Parameters

Input parameters:

D (Generic Data) Data to be updated.

Output parameters:

T (Number) Time in milliseconds since the data was updated.

FPS (Integer) Approximate frames per second. Note: Takes the average of last five fps values.

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

Boolean Switch - Toggle a switch between TRUE / FALSE. (True outputs a 0; False outputs a 1)

Params > Special > Boolean Switch

Boolean Switch Description

A switch is a special interface object that allows for quick setting of individual Boolean values. You can toggle a Switch through the Menu, or by double-clicking it. Note that switches only have output grips.

Number Slider - output a specific range of numbers by sliding a dial left and right

Params > Special > Number Slider

Number Slider Description

A slider is a special interface object that allows for quick setting of individual numeric values. You can change the values and properties through the menu, or by double-clicking a slider object. Sliders can be made longer or shorter by dragging the right-most edge left or right. Note that sliders only have output grips.

Value Tracker - Track a collection of numeric values over time

Value Tracker Description

The Value Tracker allows you to visualize incoming sensor data coming from your APins and DPins. If you right-click on the Value Tracker component you can set the Period (width of the graph - from 1 second to 1 hour), and you can set the Update time (this works best if you keep the default setting of “Smooth 25ms”). This is a very handy tool to use when you are trying understand how your sensors are performing side-by-side.

Params > Special > Value Tracker

Remap Numbers - Remap numbers into a new numeric domain

Remap Numbers Description

This component allows to you remap incoming analog sensor data (usually 0-1023) to any numeric domain (for LEDs this is usually 0 To 255, or for servos this is usually 0 To 180).

Input parameters:

V (Number) Values to remap

S (Domain) Optional source domain.

T (Domain) Target domain Output parameters:

R (Number) Remapped numbers.

Math > Domain > Remap Numbers

Analog values will be variable and

continuous ranging from 0 to 1023

Digital values will spike from 0 to 1

Panel - output parameters of components, or input parameters into a component (text or numbers).

Params > Special > Panel

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 - Timers are objects which fire update events at specified intervals. In the image below it is used to fire (like a bang) the UNO Read component every 1 millisecond (it reads the sensor values every 1/1000 of a second.)

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.

Special > Domain > Timer

Timer

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

Introduction

For this first Firefly tutorial you will utilize the three most basic Firefly components: Open Port, Uno Read and Uno Write. To begin with - your Arduino board’s USB cable should be connected to your computer and the green “power” light should on. The “Firefly DUEM Firmata” should also be uploaded to you board. Next you will place these three Firefly components into your Grasshopper workspace, then you will prepare them to both read and write data over the USB serial port.

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

3.1 - Tutorial: Basic Reading and Writing 3.0 FIREFLY TUTORIALS

Step 1: Preparing the Arduino Breadboard Circuit

a. LED - Connect the long leg of an LED to Digital Pin 13, and connect the short leg to the second-to-last pin maked GND. Note that Pin 13 has a built-in resistor. If you attach to any other pin you must use a resistor.

b. STANDARD SERVO - Connect a Standard Servo to Digital Pin 9. Note that this pin is marked PWM (Pulse Width Modulation). The standard Firefly build allows you to control servos on Digital Pins 9,10,11 only.

c. LED (PWM) - Connect the long leg off the LED to a resistor and Digital Pin 3, and the other to GND.

d. PHOTORESISTOR - Use a Photoresistor and a 10K resistor to construct the circuit pictured above. Connect the SIG (signal) to any of your Analog In pins. The circuit above uses Analog Pin 1.

a. LED

Step 1: Preparing Open Port

a. Drag the Open Port component to the Grasshopper workspace

b. Add a Boolean Toggle [A] to the “Open” input. When you double-click the Boolean Toggle you will activate (True) or deactivate (False) Firefly’s ability to communicate with your Arduino.

c. Set the Serial Port Number (this should match the “Available Ports” # - see Section 2.1 for details). We recommend using a Text Panel [B] (Params > Special > Text Panel) to input your port COM#.

d. Close/Toggle your Boolean to (False) for now. You will open it after you get everything else set up.

Step 2: Preparing Uno Read

a. Drag the Uno Read component to the Grasshopper workspace

b. Add a Boolean Toggle to the “Start” and “Timer” inputs. When you double-click the Boolean Toggle you will activate (True) or deactivate (False) this components ability to communicate with your Serial Port / Arduino.

c. Create and connect Text Panels (Params > Special > Panel) to each of the “Read” [D] parameters (APin0 through DPin 7) and the Msg panel on the right side of the component. This will allow you to read the values coming from sensors connected to the Arduino. In later steps we will connect these directly to specific param-eters within a Grasshopper model to dynamically control geometries, spatial relationships, etc.

Above - The Uno Write Component (see description on the next page)

PORT

Step 3: Preparing Uno Write

a. Drag the Uno Write component to the Grasshopper workspace

b. Add a Boolean Toggle to the “Start” input. When you double-click the Boolean Toggle you will activate (True) or deactivate (False) communication with your Serial Port / Arduino.

c. Create and connect Text Panels (Params > Special > Panel) to the Out and Msg [J] parameters. The Out parameter is essentially a diagnostic tool that allows you to see what data is actually being sent through the Serial Port to the Arduino board. This string of comma-seperated numbers is then separated in the Arduino Firmata (.pde) sketch and is used to control specific Arduino pins.

d. Add three unique Number Sliders to all the components on the left side of the component. Refer to the diagram above to locate these three slider types:

[E] 0-1 Slider (Slider Type: Integer; Lower Value: 0 and Upper Value: 1) [F] Servo Slider (Slider Type: Integer; Lower Value: 0 and Upper Value: 179) [G] LED Slider (Slider Type: Integer; Lower Value: 0 and Upper Value: 255)

Note on DPins marked with a star* [H]: The DPin11*, DPin10*, DPin9*, DPin6*, DPin5*, Dpin3* parameters have a “PWM” option (Pulse Width Modulation). If you right click over the DPin parameter text you will see an option to select PWM [I]. If PWM is selected, Pins 5,6,7 can be used to fade LEDS, and Pins 9,10,11 can control Servo Motors. These PWM pins correspond to the PWM pins indicated on the Arduino Uno board. If the PWM button is not checked, then the integer (0) will send a LOW value and a (1) will send a HIGH value. If the PWM button is checked, then any PWM value between 0-255 can be sent to the specified pin.

Step 4: Connect Firefly to points in the Rhino File

The example (below) creates a real-time 3D map of your Analog Inputs and draws a line across them. We first connect the 6 outputs from the Uno Read component to the Z input of a Point component [A]. We then use a Series Component to input (0,5,10,15,20,25) into the Y input [B]. A Pline [C] is used to connect these points and create a dynamically updating line in space. We then add another corresponding Point component. These points will be fixed to ground plane. Again, we use the Series Component to input (0,5,10,15,20,25) into the Y input [D]. The final step is to connect both sets of points with vertical lines [E].

Figure 1. The Rhino modeling window (left) and Grasshopper Interface (right)

C

B A C

D E

E

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 ac-count. 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 don’t 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 third-party 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 identifica-tion 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.

3.2 - Tutorial: Pachube Read

My Settings

Step 2. Find a Pachube feed

There are several different methods for accessing the thousands of live real-time sensor feeds that are updated to the pachube servers every minute. Map View allows users to find a feed based on geolocation. Tags are color coded based on categories: agriculture, buildings, devices, energy, environment, transport, and other.

List View gives users a text based version of all online feeds. Finally, Cloud View provides a list of all feed tags and scales the text of each tag based on the number of occurrences of each tag (larger fonts indicate the greater number of occurrences of a given tag). We can also Search Feeds or Tags by using the search box at the top of the page.

For this tutorial, we will use a feed created by the National Wind Technology Center in Denver, CO. Type the following web address into your browser: http://www.pachube.com/feeds/1197 . The readings that are dis-played are derived from instruments mounted on or near an 82 meter (270 foot) meteorological tower located at 39° 54’ 38.34” N and 105° 14’ 5.28” W (datum WGS84) with its base at an elevation of 1855 meters (6085 feet) above mean sea level.

Each feed’s page (e.g. http://www.pachube.com/feeds/1197) lists three URLs for accessing real-time data in various formats: CSV, JSON & EEML (an XML format). The XML file format contains the most descriptive infor-mation about a sensor feed (including metadata), while the CSV format contains the least. Note: The Grass-hopper Pachube Read component can only access XML or CSV file formats.

By retrieving data from one of these URLs you will access the remote environment’s most recent datastream values and metadata (up to a resolution of 5 seconds) and can use this data to control, trigger, modulate or otherwise affect your device, building, environment, actuator, etc.

Each feed page has a data stream link labeled ‘embed, history, triggers’ which reveal a drawer with a number of URLs and code snippets:

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.

Step 3. Setting up a Pachube Read Component in 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 ADDITIONAL RESOURCES

4.1 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]

Fry’s [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 we’ll consider adding them to our lists]

4.3 Related Software Projects

Grasshopper and GH Plug-in Related

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]

General Related Projects

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

ReACTivision: http://reactivision.sourceforge.net/

Kinect / Grasshopper Research Group: http://ghkinect.blogspot.com

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/

4.2 Related Tech Links

Hacking Servos for continuous rotation: http://www.seattlerobotics.org/guide/servohack.html

[Note: These are working lists. Please e-mail us a related links and we’ll consider adding them to our lists]

4.4 Related Books and Reading

Fox, Michael and Kemp, Miles. Interactive Architecture. Princeton Architectural Press, 2009. (Amazon)

Nobel, Joshua. Programming Interactivity: A Designer’s Guide to Processing, Arduino, and Openframeworks.

O’Reilly 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 O’Sullivan. Physical Computing: Sensing and Controlling the Physical World with Computers. Course Tech CPR. (Amazon)

Igoe, Tom. Making Things Talk. O’Reilly Press. (Amazon)

Image courtesy of modelab.nu/

ver graphic courtesy of Future Cities Lab - The Aurora Project ttegno with special thanks to C. Norman/T. Kelley)

In document Firefly Primer 1006 (Page 36-50)

Related documents