AnalogIn

Read values from a microcontroller analog input, or other continuous sources

The AnalogIn connects to the analog inputs of a microcontroller and other systems and can process the incoming values. AnalogIn will receive and display the values coming from an actual sensor attached to the selected port on the microcontroller (e.g. Arduino port zero), or from software such as OSC or hubFeed. Once processed, the values are sent to one or more other widgets.

The default range for analog inputs on most microcontrollers is 0 – 1023, which can be scaled any range desired by setting the min and max numbers.

AnalogIn has a fader knob which can be dragged by the user to simulate the values of a sensor coming in, making it possible to test the project without external hardware/software hooked up.

On Screen Features

  • connect – A button in the top right corner, when on, reads data from the sensor at the selected port. When off, drag the slider knob to set the output value. The off mode is useful for when you don’t have the sensor and/or microcontroller hooked up, but still want to test what would happen.
  • range management – The following settings allow you to control the ranges of both input and output for the widget. On the input, the floor and ceiling adjust the range of input values the widget listens to. The min and max set the range of output values the widget creates from the input values.
    • floor – The lowest raw input value processed. Note that the range within CEILING and FLOOR will be scaled to the MAX and MIN values. So if ceiling is set to 800, floor is set to 200, max is set to 100 and min is set to 0, the values from 800 to 200 will be scaled from 100 to 0. Can also be set to a negative number for sources such as OSC that may have negative values.
    • ceiling – The highest raw input value processed. Values higher than this value are ignored. Useful if your application uses a limited range of the sensor. Can also be used to extend beyond the normal 1023 maximum range.
    • min – Sets the lowest value output. The lowest input value (after ceiling and floor) is scaled to this value
    • max – Sets the highest value output. The highest input value (after ceiling and floor) is scaled to this value
  • smooth – When on, performs a median filter on the raw sensor readings so that the processed values are less jittery. This is helpful because many sensors produce rough readings that change more than you want. Adjust the smoothingBufferSize parameter for more or less smoothing.
  • ease – When on, performs a real-time easing function on the input so that the output follows the input in a smooth, seemingly natural motion that’s similar to how a real physical object would move, exhibiting momentum and reacting to friction.
  • invert – Makes a high raw value produce a low output value and visa versa. Useful for reversing the effect of a sensor

The raw values coming from the controller are displayed at the top, “in” section of the widget, and the values sent to the next widget after any processing the AnalogIn widget performs are shown at the bottom of the widget in the “out” section.

Parameters

  • Screenshot_7_6_14__3_12_PMcontroller – Determines where the input values come from – Device options are: Arduino, Xbee, iotnREST, OSC, accelerometer (mobile devices), mic, inputSource (values come from widget named in inputSource param), hubFeed (see the hubfeed Tutorial for more info), serial (any device that can connect to your computer via USB/Serial input can send numbers – see the serial tutorial)
  • controllerInputNum – Sets the analog input port on the controller – starts at 0 to use the first port on the controller. When using an inputSource such as OSC that may have multiple values, this number sets the argument used. E.g. in /acceleration/xyz 0.1 0.2 0.3, setting controllerInputNum to 2 would get the third argument for the Z value of 0.3.
  • controllerIP – Sets the IP address used to communicate with OSC or iotnREST.
  • controllerPort – Sets the IP Port used to communicate with OSC
  • easeAmount – Controls the amount of easing that’s applied if the ease button is ON. Higher numbers increase momentum.
  • hubFeedName – The name of the Hub feed to listen to. The hubFeed controller option allows the application to accept input from any arbitrary source that sends a feed to the Hub. See also the AnalogOut for sending a hub feed, and the HubFeed tutorial.
  • inputSource – Used if “inputSource” is selected in the CONTROLLER parameter, to get values from another widget this name.
  • invisible: If set to “true” or checked, the widget will disappear when the Flash movie is run – NOTE: you can make all the widgets invisible interactively when the Flash moving is running simply by pressing the backslash key “\”.
  • multiplier – This number is multiplied with the raw input number from the controller, if set to OSC, hubFeed, or accelerometer. Many OSC devices and software provide fractional values from 0-1. To work with other toolkit widgets, these numbers should be scaled up to an integer range, e.g. by setting multiplier to 1023.
  • remoteHubIP – This sets the IP address of the Hub where the widget will get input values from a microcontroller. Normally this would be 127.0.0.1 for the Hub running locally. But set this to the IP address of another computer running a HUB, e.g. to access devices connected to that computer. Note that even if you are using a remote Hub, the Hub application must also be running locally on the same machine as the widgets.
  • sampleRate – The number of times per second the microcontroller port is queried for its value.
  • serialPort – For widgets set to communicate with an Arduino or XBee, the USB serial port name that the device is connected to. On the Mac, you can leave the default (/dev/cu.usb*) if only one device is hooked up. On the PC, replace this with the COM port used, e.g. COM7. For more detailed info on how to set this parameter, see the common features for all widgets discussion here.
  • smoothAmount – The size of the buffer for the smoothing. The larger the number, the more smooth the processed values will be, but the processed values output will have a longer delay from the actual sensor data.
  • urlString – This text is used for iotnREST and OSC inputs. For iotnREST, this is the URL sent to the remote device. For OSC, this is the OSC message that AnalogIn will listen for (e.g. “/slider/1” will listen for the message from iPhone app OSCemote’s first slider).
  • xbeeRemoteID – When using the Xbees, use this number to indicate which remote Xbee you wish to communicate with. (note, this is a decimal number, when configureing the XBee in XCTU the ID number you enter there is in hexedecimal).

Tutorials

Working with OSC

AnalogIn can receive OSC messages from any device, and will read the a value after the main OSC string if the string matches what’s specified in oscString. It will multiply this value by the multiplier specified in the widget parameters. So for example, if you use the iPhone app OSCemote, the Sliders send a message such as:

/slider/1 0.3

In this case, you would set the oscString parameter to “/slider/1”, and the multiplier to 1023. AnalogIn will then convert the numbers OSCemote sends (which are between 0 and 1), and convert them to the full range of the widget (0-1023).

For more information, see the OSC tutorial.

Code Interface

The below examples assume an AnalogIn widget with an instance name of “input0”

multiInput

AnalogIn can accept multiple values from the OSC, hubFeed and accelerometer controllers. The main interface and output of AnalogIn only pays attention to the value correlating to the controllerInputNum setting – e.g. if set to 0, the first value is used, if set to 3 the fourth value is used. But all values can be accessed via this code interface.

Examples of this would be accessing the x,y,z values from the accelerometer of an iPhone. Rather than setting up three separate AnalogIn widgets, only one is needed, and the three values can be accessed in code via the following method. Another example would be getting all of the joints in a skeleton sent by the Kinect.

input0.multiInput = processInput; // process multiple values from AnalogIn with an instance name of input0

// function to process multiple values
function processInput(... args) { // args is an array that will contain all the values
   for(var i:int=0; i<args.length; i++) { // get each value in order
      trace(args[i]);
   }
}

connectWidget()

Causes the widget to connect to the controller, the same result as using the connect button.

input0.connectWidget();

disconnectWidget()

Causes the widget to connect to the controller, the same result as using the connect button.

input0.disconnectWidget();

Last modified July 6th, 2014