Connecting an etape using spi

I have an etape liquid level sensor http://www.adafruit.com/datasheets/eTape%20Datasheet%2012110215TC-12_040213.pdf hooked up to my raspberry pi model b through an MCP3008. The MCP3008 is connected following these instructions http://www.geeklee.co.uk/2014/01/12/rpi-mcp3008-tmp36-sqlite-lighttpd/. The eTape's second pin is wired to GND and the third pin is wired to CH0 of the MCP3008, with a 560 Ohm resistor between, connected to 3.3v, as instructed on the tutorials tab of the product page. The code is from the geeklee link

#!/usr/bin/python

import spidev
import time

spi = spidev.SpiDev()
spi.open(0,0)

spidata = spi.xfer2([1,(8+channel)<<4,0])
data = ((spidata & 3) << 8) + spidata
return data

try:
while True:
voltage = round(((channeldata * 3300) / 1024),0)
temperature = ((voltage - 500) / 10)
print("Data (dec)    {}".format(channeldata))
print("Data (bin)    {}".format(('{0:010b}'.format(channeldata))))
print("Voltage (mV): {}".format(voltage))
print("Temperature:  {} degC".format(temperature))
print("-----------------")
time.sleep(1)

except KeyboardInterrupt:
spi.close()

When dry, spidata output looks like this:

Voltage: 2291.0

When submerged roughly 5.5 inches:

Voltage: 1724.0

The sensor appears to be working but I would like to calculate the ohms, in order to follow the datasheet. I am guessing I need to know the amperage to figure out ohms but am having trouble finding it. I also would like to test this with my multimeter and was wondering the best place to test this in the circuit. I would think the wire going from inbetween the etape and resistor to the ADC would be best.

Any help is appreciated, I am a noob when it comes to electronics.

• Looking at the datasheet, I actually believe the 2291 is not the voltage but looks like it is the Ohms. Feb 16 '14 at 14:09

If you've got an multimeter, you can measure the amperage by putting the meter in-line in the circuit between any two points in the loop. i.e. disconnect the 560 Ohm resistor from the voltage source, set the black probe of the multimeter to the negative end of the circuit (the resistor, in this case) and the red end to the voltage source, and you can measure amps.

You don't even use a circuit to measure Ohms. You take the etape alone and set the multimeter probes across pins 2 & 3 and measure at different water depths.

You can also calculate the Ohms from the values you got. V=I*R, and if you are measuring 2.291 volts, that means that the 560 Ohm resistor is dropping the voltage by 3.3 - 2.291 = ~1 volts. So in this case,

V = I * R

1 = I * 560

I = 1 / 560

I = 1.8mA

Then turn it around, the same amperage is going across the etape. The circuit has 1.8mA running through it. The etape has 2.291V voltage drop.

V = I * R

2.291 = 0.0018 * R

R = 2.291/0.0018

R = 1272

That doesn't seem right, the data sheet says it should be 2200 Ohms dry. At 5.5 inches, I get 612 Ohms, instead of the 1500 expected on the chart. Maybe there's some extra voltage drop somewhere and that's why they don't match up. I suppose I could be using Ohm's law wrong, but it seems pretty simple.

On the other hand, I don't think you need to really care about the volts and amps. You want to relate the values read with inches. You've got two points and two points define a line. The dry spi reading is the number 711 (2*256 + 199). The 5.5 inch reading is 535. The data sheet says that you the resistance is flat for the bottom inch, so the points are (711, 1 inch) and (535, 5.5 inches). So you've got the line inches = -0.019*spi reading + 15.7 (Hope I didn't make any math mistakes)

That formula is only valid between 1 inch and 12.4 inches, so you can range check.

You should take some more readings and make sure that the readings are fairly linear. For example, at 8 inches, I would expect the spi reading to be about 400, based on the equation above, and 300 at 10 inches. Let me know, I'm doing this exact same thing this week, and a warning that it isn't linear would be nice.

One other thing, I've read that noise can be a problem. You may want to average the last few readings to stabilize voltage spikes. I'm going to do that, since I'm planning to send a text message when the values get out of the expected range.

Edited for my math mistake. I misread 711 as 771 earlier.

• This is very helpful thanks. Unfortunately when mounting it I was not careful enough and some glue dripped into the reference hole. I have decided to look for cheaper alternatives and am testing hall effect sensors and different magnets. Mar 13 '14 at 22:05
• Too bad. I would like to hear about that. I tested mine and it came up fairly linear, but I was hoping for slightly better. I'm going to use threshold values instead of a formula. Mar 14 '14 at 3:48