Unidata float and capacitance water level gages

note on SDI-12 protocol

(c) 1998 , 2002 EME Systems, Berkeley CA U.S.A.
 <stamp index> <home>

Contents (updated 11/13/2010)

Unidata float & beaded cable depth gage, models 6509, 6532, 6541


We use the following BS2 subroutine to read data from the HSIO (High Speed I/O, serial data interface) of the model 6531 depth gage manufactured by Unidata of Australia. This professional (US$500) instrument uses a float and counterweight on a beaded line to measure depths of up to 49 meters with a resolution of 0.75 millimeter. Other instruments from Unidata use this same protocol.

Unidata America, Lake Oswego Oregon: 503-697-3570
Unidata Australia, Willeton: +61.9.457.1499
Unidata Europe, Manchester UK: +

The U6531 is wired to the logger using three of the digital i/o lines. One an active high select line that initializes and enables the data transfer. It is sometimes called the "scan sync" line. The second line puts out a regular series of pulses to clock the serial data transfer, and the third line carries the actual serial data. Here in the BS2 routine, two BS2 pins are outputs: uss_ is the active high "scan sync", and uclk_ is the data clock. One BS2 pin, Udata_ is configured as an input.

uss_   con 12   ' pin to activate the serial interface
uclk_ con 13 ' pin to clock the serial interface
udata_ con 14 ' pin to receive data from sensor
result var word

high uss_ ' activate the sensor
pause 9 ' delay for settling
shiftin udata_,uclk_,lsbpre,[udata\16] ' grab the data
low uss_ ' deactivate the sensor
debug dec result,cr ' show the result
nap 6 ' wait a bit
goto U6541 ' do it again

The data is returned in the word variable, result.

Two or more U6531 can be chained together using the same select, clock and data lines. The devices are wired in a daisy-chain, with the data out line of #2 connected to the data input (called "serial link") line of #1 in the daisy chain. The select lines and clock lines of both are connected in parallel. To read the data, the uss_ line is brought low, and then the data from is clocked out in succession: the first 16 clock pulses get data from the 1st one, the next 16 pulses get data from the second one.

Here is an example with two U6531. This particular routine gets data from one or the other, depending on the value of the variable ADch when the subroutine is called.

uss_    con 12   ' pin to activate the serial interface
uclk_ con 13 ' pin to clock the serial interface
udata_ con 14 ' pin to receive data from sensor
result1 var word
result2 var word

high uss_
pause 9
shiftin udata_,uclk_,lsbpre,[result1\16]
shiftin udata_,uclk_,lsbpre,[result2\16]
low us_
debug dec result1,tab,dec result2,cr ' show the result
nap 6 ' wait a bit
goto U6541X2 ' do it again

There is a limit as to how long the cable from the logger to the SDI-12 device can be. It is the capacitance of the cable in conjunction with the clock and data drive impedances that limit the slew rate of signals on the cable. Think of it as a 16000 hertz square wave. The Stamp always clocks the shiftin command at about 16000 hertz. Limit cables to 30 feet or less and use low-capacitance cable. If the reading is in error, try the following routine that runs slower.

The old Unidata model 6509 does not respond to the fast clock signal. The shifin command does not work well on long cables. Here is a bit-banged routine that moves the data much more slowly. I recommend this routine also any time any model of gage is attached to a long cable.

uss_   con 12     ' pin to activate the serial interface
uclk_ con 13 ' pin to clock the serial interface
udata_ var in14 ' pin to receive data from sensor, note this is now an alias variable
result var word
ix var nib ' for count of bits sent/received

high uss_ ' activate the sensor
low uclk_
pause 9 ' delay for settling
for ix=0 to 16
pulsout uclk_,8000 ' an 8 millisecond clock pulse
low uss_ ' deactivate the sensor
debug dec result,cr ' show the result
nap 6 ' wait a bit
goto U6541 ' do it again

The syntax, result.bit0(ix) referes to bit number "ix" of the word, "result". The ".bit0" tells the interpreter that the index is referring to a bit offset from bit0 of "result".

The instruments require a pullup resistor on the clock or data line.


Unidata model 6521 capacitive depth gage


The Unidata capacitive gage generates a voltage proportional to depth of water. The instrument is solidly constructed, but please read the notes below about its calibration and performance. The full scale output as calibrated at the factory is 2.56 volts. This is a simple analog voltage, that is read by the OWL2 analog inputs.

Inspect the interior of each probe to be sure that packing material is not stuck inside (i.e., plastic peanuts). Also check to be sure that there is no potting compound deposited on the central sense wire. If necessary, follow the disassembly instructions and clean the central wire.

For best results, check the calibration of each instrument as it comes from the factory, and also after a period of deployement. You will need a vessel long enough to immerse the probe. A long PVC pipe with an end cap can serve this purpose. You will also need means to hold the probe steady while it is immersed, so that the water can be smooth when checking the reading. Use clean tap water. (See below the effects of highly conductive or sea water.) If the probe has been deployed, disassemble it and clean off the central sense wires according to the Unidata instructions.

There are calibration marks engraved on the instrument at the zero (0 mm) and full scale (1/2 meter, 1 meter, or 2 meter) points. The calibration according to the product literature should be zero volts at the lower mark and 2.560 volts at the upper mark (for a sensitivity of 0.00512 volts per millimeter). The response of the sensor is nonlinear at the lower and upper ends of its range, so it is best to calibrate it at points a bit in from the end marks. Taking as an example the 500mm sensor, I make auxiliary calibration marks at 50mm and at 450mm. The output voltage when water is at the 50mm mark should be 0.255 volts, and when the water is at the 450mm mark, the voltage should be 2.295 volts. That makes a linear response that passes through 0 volts at zero level, and 2.56 volts at full scale:

volts = millimeters * 0.00512     for 6521J 1/2 meter probe

But be aware that the actual response may veer away a little bit near the extremes.

For the 6521K 1 meter probe the auxiliary upper and lower calibration marks should be at 100mm above and below the engraved marks, and for the 6521J two meter probe, the auxiliary marks should be 200mm above and below the engraved marks. Use the same voltage points as above.

volts = millimeters * 0.00256     for 6521K 1 meter probe
volts = millimeters * 0.00128 for 6521L 2 meter probe

I prefer a calibration of 2.5 volts full scale (0.005 volts per millimeter), which if you want, needs the lower auxiliary calibration changed to 0.250 volt and the upper calibration changed to 2.250 volt.

volts = millimeters * 0.005       for 6521J 1/2 meter probe
volts = millimeters * 0.0025 for 6521K 1 meter probe
volts = millimeters * 0.00125 for 6521L 2 meter probe

To calibrate: Remove the top cap to expose the edge of the circuit board with the adjustment trimmers. If there is a strong chemical smell, put the instrument aside in a warm place with the cap off to allow the potting compound to cure for a few days. The calibration drifts by a few percent as the potting compound cures.

Here is the position of the adjustment trimmers, as you look down into the cap of the probe: 

The adjustment procedure is as follows:

  1. Measure Vl, the voltage output with a water level at the 50mm mark.
  2. Measure Vh, the voltage output with a water level at the 450mm mark.
  3. Calculate Vx=1.12555*(Vh-Vl)
    {or Vx=1.1250*(Vh-Vl) for alternative calibration}
  4. With the water level still at 450 mm, use the zero trimmer to adjust the voltage to the calculated Vx.
  5. With the water level still at 450mm, use the scale trimmer to adjust the voltage to 2.295 volts {alternative: 2.250 volts}.
  6. Check the output voltage with the level at 50 mm. It should be 0.256 volts {alternative: 0.250 volts}.
  7. Repeat if necessary.

When finished with the adjustment, seal the threads with teflon tape as you replace the cap firmly.

Remember that the response is nonlinear at the ends. Try to position the probe so that the measurement will be made in the middle 90% of the measurement range.

This sensor works well in clean water, however, I have had very poor results in salt water and in water with a high mineral or contaminant content. The inaccuracies are temperature, humidity and time (hysteresis) dependent.. As you immerse the sensor in salt water, the readings plunging in are fine, but as you pull the probe out of the water, the readings stay high and only gradually fall back toward the correct value. If you rinse off the center wire by shooting distilled water into the breather hole at the top of the sensor, the reading quickly comes back to its correct value. With age material encrusts the wire, and the reading becomes dependent on humidity and temperature, due to changes in the conductivity of the encrustation. This effect can amount to an error of several percent, e.g., a bogus daily fluctuation of water level of up to 5 cm with the 50cm probe.

The construction of the sensor gives it the effect of a stilling well. Rapid fluctuations in water level are damped inside the tube. Greater damping can be had by partially covering the breather hole the top of the sensor. There is a limit to how far this can be carried, and in a rapidly flowing stream the eddies caused by objects in the stream or by the sensor itself can lead to considerable fluctuations in the reading. It may be necessary to construct a stilling well at the side of the stream, with a narrow inlet tube extending out the the steam bottom. Be careful of the buildup of minerals in the stilling well, in relation to the concerns raised the the previous paragraph.

We have found that the electronics in the sensor are very stable in relation to temperature, once the potting compound cures. So having the cap of the sensor in full sun or shade changes the reading by less than 0.5cm. Still, it is a good idea to shade the cap if possible. The sensor is specified to operate on 5.0 volts from the Unidata series of data loggers. However, it will work without calibration changes on any voltage from 4.8 to 12 volts. But not above 13 volts. We operate it from the 5.12 volt switched, regulated supply, or from the 6 volt switched, unregulated supply on the OWL2c logger.

The routines to read data from the depth probe into the OWL2c/BS2 are very straightforward. Here is example code for the U6521J, 500mm depth probe. The three wires from the sensor are connected as follows:

  1. red) +6 volts switched
  2. white) input channel #AD5
  3. black) common
    ' probe calibrated for 2.5 volts span
    result var word ' result of A/D conversion
    ADch var nib ' AD channel for this sensor
    ADch=5 ' assume the probe is connected to channel AD5
    gosub ADread ' subroutine not shown
    ' returns 0-2500 for depth gage in result
    result = result/5 ' convert millivolts to depth, 0-500 mm U6521J
    ' depth = result * 2 / 5 ' to read out 0-1000 mm U6521K
    ' depth = result * 4 / 5 ' to read out 0-2000 mm U6521L
    debug DEC result, CR ' show it
    goto loop

In the OWL2c, the data can be logged as a byte from 0-250 with a resolution of 2mm (within the 1% accuracy of the probe), or as a word with 1mm or better resolution. Note the remarks for changes that need to be made to use the 1 meter or 2 meter versions of the sensor.

How it works: The sensor works by using the teflon insulation of the center conductor as the dielectric of a capacitor. One electrode of the capacitor is this central wire, while the other electrode is the water that is in contact with the wire. It is important to understand that the water serves as a conductor, not as a dielectric. As the water moves up and down the center conductor, the capacitance varies. At intervals of about 80 microsecond, the circuitry charges that capacitor with a tiny electrical current and monitors the voltage V=I*t/C. When the water level is low and the capacitance is low, the capacitor charges quickly and the circuit generates a short pulse of about 6 microseconds. When the water level is high, the capacitor charges slower and the pulse is longer, about 36 microseconds. The circuitry transforms the repeated pulse width into an output voltage proportional to water level.



The SDI-12 protocol was proposed in 1988 as a standard to provide a way for data recorders to communicate with multiple instruments and sensors out in the field using digital 1200 baud signalling on a multidrop network. The standard has been adopted by an number of manufacturers, at least as an option, especially in the field of hydrology. The full current specification (version 1.3) can be found at the SDI-12 support group. The data recorder and the sensors have to be smart enough to understand the commnads, that is to say, the sensor as well as the data recorder must have an embedded microcontroller. The data recorder, which is always the master, sends out commands that address one of the attached slave instruments at a time. All the other instruments ignore the command. The addressed instrument responds, by taking a measurement and by sending one or more data values in the proper format and at the proper time to the recorder. Only one device can be talking at a time.

All of the instruments are connected to one set of 3 wires, which consist of a common ground, the single signal line, and a +12 volt (optional) power line .

Electrically, the signal interface is similar to RS232. The voltage is nominally either zero or +5 volts. The line is passively pulled to a low ("marking") level., but it can be taken actively high or low by either the the data recorder, or in their turn by any of the instruments attached to the line. The command protocol assures that only one device will be talking at once. As with standard RS232, there is a limit to cable length, roughly 200 feet, due to the capacitance of the line in relation to the signal drive capabilities. I see no reason why the distance could not be much improved by transition to RS485 at each node, and running a twisted pair for the signals. The SDI-12 specification also includes an acceptable drive impedance, roughly 1000 ohms from the driver to the line. There is also a passive pulldown on the line, about 100 kohms.

The timing is exactly the same as 1200 baud RS232, with 7 data bits, framed by a start bit, an even parity bit, and a stop bit. The transmissions use the standard ASCII printable character codes in the range of 32 to 127, plus carriage return <13> and line feed <10>. Also important is the BREAK condition, which mean that the master data recorder forces the data line high for at least 12 milliseconds. That is what wakes up all the other instruments on the line and makes them listen for their address as the first byte of each command sequence. The BREAK condition is also used to abort measurements or other actions in progress.

Here is a simple BASIC Stamp command/response exchange to read a continuously recording stream stage instrument:

SDIp    con 0       ' this pin for data
baud con $32A + $4000 + $2000 ' 1200 baud, inverted (stop bit low), 7bit even parity
high SDIp ' generate BREAK
pause 12
low SDIp ' end BREAK
pause 7 ' let it sink in
serout SDIp,baud,["0R0!"] ' command for device 0, Read, value 0, ! ends command
input SDIp ' release the serial line to await response
serin SDIp,baud,100,noResponse,[wait ("0"),SDEC result]
debug SDEC result, " millimeters",cr
nap 6
goto SDI12

debug "something went wrong",cr
goto SDI12

The Stamp first generates the break condition, followed by a low level, and then it sends a command, "0R0!". That addresses the device set up to answer to "0", then the "read", command, and finally the command terminator "!". The data line is turned to an input, so that it can await the response from the device. The serin command awaits the echo of the address byte, followed by the signed decimal result, which is terminated with <CR>.

Other SDI-12 command interchanges can be more complicated, but the specification is very clear in how the master and slave should interact.

Some SDI-12 instruments can return quite long responses containing several different data values, and the data values can include decimal points. That means that the Stamp has to read in the data as a long string and then parse the values. This is most easily done with the BS2p or the BS2pe (elfOWL), in order to use the SPSTR modifier to put the incoming data into successive bytes in the scratchpad ram.

The Stamp can alternatively be on the receiving end of an SPI-12 system, as part of a smart sensor. In this case, the stamp has to detect the BREAK condition on the data line, so that it can listen for its assigned address.

Call us if you have a special SDI problem that can benefit from the PBASIC programmability of the BASIC Stamp and the OWL2 data logger.

 .<top> <index> <home> logo< mailto:info@emesystems.com >