I’m trying to read the voltage of analog inputs wired on socket 9. I use all 3 analog inputs of socket 9, on pin 3,4 and 5. I built the following code based on existing examples. The problem I have is that the 3 analog inputs seem linked ! On PIN 3, if the voltage varies, the 2 other analog inputs remain unmodified, but that is not the same when I apply the voltage on the other PINs :
The voltage on PIN 4 is also read at 3/4 of its value on PINs 3 and 5
The voltage on PIN 5 is also read at the same value on PIN 3.
Any hint or advice on what is hapenning ? How can I correct the code ?
I use NETMF 4.1 as 4.2 is still a beta code and I need WIFI.
Thanks a lot for your help !
Here is the code I wrote :
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
public partial class Program
protected Gadgeteer.Socket Socket9; // Socket 9
protected Gadgeteer.Interfaces.AnalogInput IN_pHCaptor; // Socket 9 // Pin 3
protected Gadgeteer.Interfaces.AnalogInput IN_TempCaptor; // Socket 9 // Pin 4
protected Gadgeteer.Interfaces.AnalogInput IN_DensityCaptor; // Socket 9 // Pin 5
protected GT.Timer _timer;
protected double pHValue;
protected double tempValue;
protected double densityValue;
// This method is run when the mainboard is powered up or reset.
Socket9 = Gadgeteer.Socket.GetSocket(9, true, null, null);
IN_pHCaptor = new GT.Interfaces.AnalogInput(Socket9, GT.Socket.Pin.Three, null);
IN_TempCaptor = new GT.Interfaces.AnalogInput(Socket9, GT.Socket.Pin.Four, null);
IN_DensityCaptor = new GT.Interfaces.AnalogInput(Socket9, GT.Socket.Pin.Five, null);
_timer = new GT.Timer(2000);
_timer.Tick += new GT.Timer.TickEventHandler(TimerTick);
void TimerTick(GT.Timer timer)
pHValue = IN_pHCaptor.ReadVoltage();
tempValue = IN_TempCaptor.ReadVoltage();
densityValue = IN_DensityCaptor.ReadVoltage();
Debug.Print("pH = " + pHValue.ToString());
Debug.Print("temp = " + tempValue.ToString());
Debug.Print("density = " + densityValue.ToString());
Pull down or pull up will mean you do not get the reading you want - but you get 0 or 3v3 instead. Pull-down/up is used to guarantee a digital signal is in a certain state before a device uses it; the device is able to override the pull-down/up and set the correct value as needed, but an analog signal cannot do that.
Thinking about your problem, perhaps there’s some simple explanations. Perhaps there is a solder bridge between pins. To test that, do you have a makebread/extender module you can connect up to some LEDs? Use the pins as an digital IO and see if they light up differently. Or perhaps you need to GND out the other unused analog pins in your other sockets - I haven’t checked a Spider to see how many of those there are. I don’t expect that to be a problem, but I do know we’ve seen that on USBizi based boards (Spider is NOT one of these).
The other thing I would ask is how are you changing the values? Do you have a potentiometer connected and changing the voltage, or are you just adjusting what your sensor reads?
ADC tends to be tricky on many of these development boards. They are very sensitive to noise and then share grounds. Since you are using gadgeteer and not building your own hardware your options to work around are limited.
Previously, I have tried implementing software solutions to filter out the noise, but I am not sure you have the horsepower for that on the .netmf platform. Additionally, grounding the unused ADC inputs may help with the noise as well.