A0 is connected to an LDR, the N17DH 'Linker Light Sensor'. This generally produces sensible values.
A1 is connected to an LM35 temperature sensor, the N11DH 'Linker Temperature Module'. This causes the main problem (and I replaced it with a new one two weeks ago).
A2 is connected direct to a potential divider consisting of a 180 ohm 3-watt resistor and a zero-to-190 ohm water-tank depth sensor. It generally works, but once or twice a day produces an impossible reading around 26750 (yes, from a ten-bit port).
I don't want to post the whole program (if you really want to see my horrible code I have linked it as http://cchd.eu/read7.py). Essentially it starts with
- Code: Select all
firmata = PyMata( SERIAL_PORT, max_wait_time=5 )
firmata.set_pin_mode( LDR, firmata.INPUT, firmata.ANALOG)
firmata.set_pin_mode( Temp, firmata.INPUT, firmata.ANALOG)
firmata.set_pin_mode( Depth, firmata.INPUT, firmata.ANALOG)
then reads the ports with
- Code: Select all
LDR_value=firmata.analog_read( LDR )
time.sleep( DR_delay)
LDR_value=firmata.analog_read( LDR )
time.sleep( MUX_delay )
Temp_value=firmata.analog_read( Temp )
time.sleep( DR_delay )
Temp_value=firmata.analog_read( Temp )
time.sleep( MUX_delay )
Depth_value=firmata.analog_read( Depth )
time.sleep( DR_delay )
Depth_value=firmata.analog_read( Depth )
where DR_delay is currently 0.1 sec and MUX_delay is 2 seconds - it works OK down to a MUX_delay of 0.7 seconds below which bad values increase in frequency. There are further delays - the total cycle delay is about ten seconds.
The big problem is with A1, temperature. It reads OK for between one and twelve hours. Then, at some time which seems quite random, it drops to a port figure that varies between 0 and 18, mean 4 (a temperature around -50C). The drop is sudden and it sticks there. I find no way to restore good figures apart from a power-off of at least five minutes. Pressing the co-op reset button has no effect. Halting the python program on the pi and restarting it has no effect. A brief power-off has no effect. The analogue port is stuck and the low reading continues. Only a long power-off restores normal operation, this being a port figure of around 142 (a temperature of 19.3). The connections seem fine, as wiggling the leads does not trigger the problem. But applying a DVM [an inexpensive one] does: it initiates an immediate drop to low figures and shows 0.05 volts or less (matching a port figure of 10). These low figures never recover, except after a ten-minute power-off.
Unplugging the Vout signal lead from port A1 for ten minutes does not fix the problem. Nor does unplugging both GND and Vcc power leads to the module from the co-op board. Only a total power-down works.
I tried setting the internal pullup resistor with the command
- Code: Select all
firmata.digital_write( Temp, firmata.HIGH )
but this had no effect.
Can anyone suggest any hardware or software method to avoid this problem or to reset the port? I can detect the problem in the raspberry python code, but I do not have the hardware to trigger a ten-minute mains power cut.