World’s cheapest SCADA device: source code

This is the source code (as of May 27, 2008) for the Parallax BasicStamp Recording light meter.  I apologize for the formatting, but in the exciting new world of Office 2007, there is *literally* no way to edit the HTML that Google or Help know about, so I can’t use the  <pre></pre> tag.

' {$STAMP BS2}
' {$PBASIC 2.5}

index VAR Nib

wStrength VAR Word
wCount VAR Word

soundTime VAR Word
bCmd VAR Byte

'  generic tmp variable
iTmp VAR Word
wTmp VAR Word

'  '
' ''' Number of values to store in EEPROM
'  '
wMaxValuesToStore VAR Word
wMaxValuesToStore = 200
wCurrEntvalueLocation VAR Word
wStoredValuesCount VAR Word
wStoredValuescount = 0

'  '
' ''' How long to wait (milliseconds) for command input before resuming the main loop
'  '
wCommandDelay VAR Word
wCommandDelay = 3000

OUTH = %00000000
DIRH = %11111111

'  Commands that can be sent to the application
'  returns a fixed length buffer with known contents


'   ''
' ''''''
' ''''''
'   ''

  GOSUB getRCTime
  GOSUB getCommand
  GOSUB Delay
  GOSUB updateDisplay


  DEBUG "ResetStart",CR

  '  Make sure history memory ring buffer is set to a value that lets us later distinguish it from zero (0)
  DEBUG "Starting",CR
  DEBUG "Will save ", DEC wMaxValuesToStore, " values in EEPROM",CR

  DEBUG "Initializing history ring buffer",CR
  FOR iTmp = 0 TO ((wMaxValuesToStore -1) * 2) STEP 2
    'DEBUG DEC iTmp, "."
  DEBUG "Finished initializing history ring buffer",CR
  wCount = 0
  wStrength = 0
  FOR iTmp = 0 TO ((wMaxValuesToStore -1) * 2) STEP 2
    WRITE iTmp, Word 0
  wStoredValuesCount = 0
  DEBUG "ResetFinish",CR


  'DEBUG "cmd> "
'  SERIN 16,  84,getCommandBadData, 5000,getCommandTimeout, [WAITSTR cmdBuffer9]
  SERIN 16,  84, wCommandDelay, getCommandTimeout, [DEC1 bCmd]
  'SERIN 16,  84, [DEC bCmd]
  GOSUB processCommand

  'DEBUG "Got command: ", DEC bCmd, CR


    '  reset
      GOSUB Reset

    '  send current value
      DEBUG "", DEC5 wStrength, "", CR

    '  send last N values
      DEBUG "" ,CR
      DEBUG TAB, "", DEC wMaxValuesToStore, "",CR
      DEBUG TAB, "", DEC wStoredValuesCount, "", CR
      DEBUG TAB, "", DEC (wCurrentValueLocation / 2), "",CR
      DEBUG TAB, "", DEC wCommandDelay, "", CR

'      FOR iTmp = 0 TO ((wMaxValuesToStore -1) * 2) STEP 2
      FOR iTmp = 0 TO ((wStoredValuesCount *2 ) + 1) STEP 2
        READ iTmp, Word wTmp
        DEBUG TAB,"", CR
        DEBUG TAB, TAB,"", DEC iTmp, "", CR
        DEBUG TAB, "", CR
        wtmp = 0

      DEBUG "", CR

      DEBUG "Sleeping", CR
      SLEEP 1

      DEBUG "deadbeef0",CR

      'DEBUG DEC wCurrentValueLocation,"->",DEC wStrength,CR

      'DEBUG "Received NOOP command", CR
'      NAP 0
      DEBUG 0, CR

      'DEBUG "Received unknown command", CR



  'DEBUG "Got bad command", CR
  DEBUG "CommandError", CR

  'DEBUG "No command received" ,CR
'     DEBUG DEC wCurrentValueLocation,"->",DEC wStrength,CR
      'DEBUG DEC wStrength,CR


  '  These next 3 lines are the actual application.  How long is it taking for a charged cap to drop to 0?
  HIGH 2   '  arbitrary short time to charge the cap (from the training example)
  PAUSE 3  '  arbitrary short time to let it "leak" down to zero (from the training example)
  RCTIME 2, 1, wStrength

  soundTime = wStrength * 3

  'DEBUG  "Raw strength: ", DEC wStrength ,CR
  '22wStrength = wStrength * wStrength

  wCurrentValueLocation = (wcount // wMaxValuesToStore) * 2
  WRITE wCurrentValueLocation, Word wStrength
  wStoredValuesCount = (wStoredValuesCount + 1) MAX wMaxValuesToStore

  wCount = wCount + 1

'  DEBUG "", DEC5 wStrength, "", CR

' DEBUG CLS, DEC5 sStrength, " soundTime: ", DEC5 soundTime
' FREQOUT 5,  soundTime MAX 250 , ABS (soundTime - 2640)


  PAUSE  wStrength MAX 250

  IF index = 6 THEN index = 0
  LOOKUP index, [ %01000000,
    %00100000 ], OUTH

  index = index + 1

The world’s cheapest SCADA device?

As part of my learning about CygNet, SCADA, and the exciting world of Real World Data, I decided to build a SCADA-enabled device from scratch.

I wanted something that could be reconfigured to support any sort of sensor, was very small, and that didn’t require soldering.  A little bit of research (and by research I mean shopping) turned up the venerable BasicStamp:

It’s just about the simplest embedded system possible.  A processor with a built-in Basic (the language) interpreter, 16 I/O lines, a serial port, and a small breadboard for components.

For $80, you can pick up a version at Radio Shack that includes a complete training program.   (, or you can buy just the boards for anywhere from $10-$40 on eBay or the Parallax store.

I spent a little over a week going through the training and ended up with a photocell-based light meter that output readings on the serial port, and stored a small number of recent readings in its onboard EEPROM.  I hadn’t read a circuit diagram in about 30 years, so that was fun.

Useful tidbit:  the web has lots of resistor value calculators


Doug had already created a serial-device EIE for the Davis Vantage weather station, so it was a matter of hours for him to add a new “general” message that would allow communications with arbitrary devices


The protocol is blindingly simple. Send a number (really a single byte with the ASCII code for a numeral) from 0-n, and the device sends back data and/or takes some action. The current command set:

  • 0 (48/0x30) – reset the device. Clear the ring buffer and all counters and restart the program
  • 1 (49/0x31) – return the most recent reading
  • 2 (50/0x32) – return all readings
  • 3 (51/0x33) – sleep (turn off power to the device for N seconds, where N is currently hardcoded)
  • 4 (52/0x34 – return a known diagnostic string (“deadbeef”). Why that word? It’s the default register & memory settings for the RS/6000 plus it’s all in hex. I didn’t say the commands made sense.
  • 254 – used in early testing

Example: Send “1” -> Receive “NNNNN” where N is a numeral

There is no way I could have gotten this running without help from everyone, but especially Doug, Pete, Sheri, and Derek.

NoiseTube – cell phones for ubiquitous noise pollution monitoring

Hey, world, we told you so, although we were a little more advanced in our design and concepts. 🙂



Turn your mobile phone into an environmental sensor and participate to the monitoring of noise pollution

Noise pollution is a serious problem in many cities. NoiseTube is a research project about a new participative approach for monitoring noise pollution involving the general public. Our goal is to extend the current usage of mobile phones by turning them into noise sensors enabling each citizen to measure his own exposure in his everyday environment. Furthermore each user could also participate to the creation of a collective map of noise pollution by sharing automatically his geolocalized measures with the community.

By installing our free application on your GPS equipped phone, you will be able to measure the level of noise in dB(A) (with a precision a bit lower than a sound level meter), and contribute to the collective noise mapping by annotating it (tagging, subjective level of annoyance) and sending this geolocalized information automatically to the NoiseTube server by internet (GPRS).

IPv6 SCADA system for energy use monitoring

generic sensor node –

Arch Rock products and technology enable new wireless sensor applications to be developed in familiar environments, delivered on a wide range of embedded hardware platforms, and integrated with the enterprise. Drawing together three major advancements: industry standard IP-based, multi-hop mesh networking, powerful embedded systems and flexible web services computing architectures, Arch Rock has not only created the foundation to network the physical world, but has now delivered a comprehensive product suite based upon that foundation – Arch Rock Energy Optimizer™ – to help meet the challenge of Green House Gas reduction.

I can’t find anything that says they’re actually producing and selling this technology, which seems odd for a company that’s gotten $15M in venture funding.

They’re doing IPv6 over Zigbee, basically, which is what 802.15.4 is


Tired of toy and/or antique languages when dealing with SCADA?  Weep no more, cousins, for TinyCLR has your number.  It’s available with/as two kinds of boards, one compatible with Arduino pin-outs, and the other with Parallax BasicStamps.  They’re dirt-cheap, too, on the order of $100-$150.

Sample I/O devices:  Wii controller, metal detector, reflective sensor, variable potentiometer, Bluetooth (cool – we could talk to the Blackberry this way), MP3 player (as a shield board), accelerometer, IR remote emitter/detector, motor controllers

If we do another round of Cygnipede this year, I’d suggest we build it around these devices.

Welcome to TinyCLR.

Your guide to embedded systems.

Jump start your first .NET Micro Framework project with
the C# Language in minutes!

FEZ Domino and FEZ Mini are very small (open source) boards targeted for beginners. They are based on the USBizi chipset and all it’s features. FEZ offers many peripherals, such as USB host and SD interface, not available with hobbyist-targeted boards. Even though FEZ is targeted for beginners, it’s also a low-cost starting point for professionals wanting to explore NETMF (.NET Micro Framework).
FEZ stands for "Freakin’ Easy!"
FEZ offers many features not found in Arduino, BASIC STAMP and others:

  1. Based on Microsoft’s .NET Micro Framework.


Generic Serial Driver for Windows 7 Sensor and Location Platform

The Generic Serial Driver lets you use Arduino and similar microcontroller boards with the Windows 7 Sensor and Location Platform. You’ll be able to create your own combination of firmware and physical sensors. It’s developed in C++ and Arduino.

Their sensor protocol:


Invention: Inexpensive absolute rotary (or positional) encoder

Traditional rotary encoders are expensive and too good for my hobbyist/research needs.  The cheapest I’ve found are about $300, plus the several hundred dollars it costs us to set up an account and buy one.  For many applications it would be very, very helpful to not have to give the system hints about where its “arms” and “legs” are via a generally tedious and time-consuming zeroing procedure (I’m looking at you, Meade Telescopes.)

Using an encoding ring similar to my example (below), use a Parallax ColorPAL and pre-calibrated tables (E.g. R:0 G:0 B:0 = 0 Degrees) you could drop the cost signficantly, especially when you consider that a Parallax BasicStamp could also be used for other control/sensing activities at the same time.  To make this simpler to program, although more expensive, you could print separate Red, Green, and Blue rings where the differentiating factor is the value (black<->white).

The sensed area doesn’t have to be a ring if you use colors, but could be any shape, which might be interesting for sensing X-Y positions.



The ColorPAL is a miniature color and light sensor which, through its RGB LED, doubles as a color generator. For sensing color, the ColorPAL uses its LED to illuminate a sample, one color component at a time, along with a broad-spectrum light-to-voltage converter to measure the light reflected back. The amount of light reflected from the sample under illumination from each red, green, and blue LED can be used to determine the sample’s color.




Invention: pseudo 3-D visual control cues on accelerometer-equipped display devices

Which is a fancy way of saying tablet or mobile phone.  This is so simple that it’s probably been done.

Image an on-screen control like a button object.  Typically I’d use a bit of a false drop-shadow to give the illusion of 3D.  With a phone that can sense movement, though, you could vary the position of the drop shadow in response to changes in position.  With devices that support ambient light sensors, you could also vary the strength of the shadow.

Imagine a UI with a single, “3D” button in the middle of the screen, with the device being held level.  The in-UI light source is coming from directly above the button, which is to say roughly where the user’s head is IRL.  As the device it tilted right (right side down, left side up), a simulated shadow is displayed on the right side of the button, growing longer as the tilt angle increases.  If you wanted to get gnarly about it, you could also begin to foreshorten the button image itself.

I whipped up a demo of how this works, deliberately exaggerating the side-to-side movement of the light source.  Take it from me, even a fast laptop makes a sucky render farm.  If, for some reason, you want the source for this, it’s a Blender file: http://gutenberg.vsi.dom/wp-content/uploads/2010/04/3d-button-shadow.blend.

Note: Depending on your version of Quicktime, your settings therefore, and the phase of Jupiter’s odd-numbered moons, you may have to single/double/context click the movie to get it to play.  You may have to wait for a month with two blue moons and then sacrifice an insurance sales rep to get it to play.  In case it’s not playing, you can download/watch it from here: http://gutenberg.vsi.dom/wp-content/uploads/2010/04/



Huh.  I’ve been Googling for something on this but am not having any luck.  This seems incredibly obvious.  What am I missing?