Strange behavior of Analog Inputs on Spider. How can I fix this?

Hi,

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 !

Stephan.

Here is the code I wrote :


using System;
using System.Collections;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Touch;
using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer.Modules.GHIElectronics;

namespace TestAnalogSpider
{
    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.

        void ProgramStarted()
        {
            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);
            _timer.Start();
            Debug.Print("Program Started");
        }

        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());
        }

    }
}

Using code tags will make your post more readable. This can be done in two ways:[ol]
Click the “101010” icon and paste your code between the

 tags or...
Select the code within your post and click the "101010" icon.[/ol]
(Generated by QuickReply)

Can you try reading twice like this and tell us what happens?


pHValue = IN_pHCaptor.ReadVoltage();
Thread.Sleep(5);
pHValue = IN_pHCaptor.ReadVoltage();

 tempValue = IN_TempCaptor.ReadVoltage();
Thread.Sleep(5);
tempValue = IN_TempCaptor.ReadVoltage();

 densityValue = IN_DensityCaptor.ReadVoltage();
Thread.Sleep(5);
densityValue = IN_DensityCaptor.ReadVoltage();

Hi WouterH,

I tried to read twice the analog inputs but the results are the same.

One question about the electronic part : Do I have to insert a pull down or a pull up resistor into the input channels ? Today their is no , and it may be the problem…

Thanks.

Stephan.

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.

Hi guys. we reviewed the electronic board and the problems was coming from it. Some static problems were misleading the inputs. Now that the circuit is fixed, the orignial code actually works !

Thanks for your help.

Steph