Unexpected values returned from Potentiometer module

Hi all,

I’m using a Potentiometer module on my FEZ Hydra (flashed to 4.2) to control the speed of a pair of motors. I’m trying to use the ReadPotentiometerPercentage method, but it appears to be returning incorrect values.

The values I’m seeing from that method range from 0.171509 (etc.) at the low end to 0.30303030303030304 at the high end, which seems incorrect at best.

Even weirder, the values returned from the ReadPotentiometerVoltage method look more like what should be returned from the ReadPotentiometerPercentage method, at least at the high end, with a low end value of 0.562 (etc.) and a high end value of 1.

I’ve tested this with two different physical potentiometers, one of which I know works, since I’ve used it successfully in a Spider project based on NETMF/Gadgeteer 4.1.

I am one release behind on the beta 4.2 stuff, so I’m wondering if this is a known issue that’s fixed in a later release? Seems kind of strange that the potentiometer would be so flaky in 4.2, since it’s a pretty simple API.

2 questions:

[ol]Has anyone else run into this issue on 4.2?
For GHI folks, is this a known issue, and will updating to the latest 4.2 beta fix it?[/ol]

I wonder if this is related to this one?


For 4.2, the analog values returned by the GetVoltage() and GetPercentage() calls appear to be swapped. For now, you’ll have to swap the calls until this issue is resolved.

@ Architect - Looks like it, or at least the thread describes part of what I’m seeing.

@ Aron’s analysis that the Voltage and Percentage APIs appear to be swapped is consistent with what I’m seeing, but it looks like in his testing he was at least seeing the full range of values (or close enough) for each. I seem to be unable to see values below about 50% of either of the APIs.

So there seems to be more than one issue I’m running into.

As noted above in my reply to @ Architect, that’s consistent with what I’m seeing, and I can certainly swap as a temporary workaround.

But have you seen instances where the pot doesn’t return anything lower than about 50% of either voltage or percentage?

Per my original message, this is on Hydra.

@ Steven - FYI, I tested the pot directly using a multimeter, and as expected it runs from 0-10K ohm on both sides, when tested from the center pin to each outer pin.

So to reiterate the outstanding question, are there any known issues where the ReadPotentiometerVoltage and/or ReadPotentiometerPercentage methods do not return zero (or near zero) values when the pot is turned all the way down?

We haven’t seen that issue, but we will see if we can replicate and report back.

@ Steven - Just to follow up, I just wrote essentially the same code in a Spider project targeting 4.1, and it worked exactly as expected. There’s definitely something weird between 4.1 and 4.2 going on here.

I also had a look at the source tree for the driver, and as expected, it’s about as simple as a driver gets, so I don’t see how the issue could actually be in the driver. I did notice that there are some differences in how the AnalogInput interface is written, as it seems that some of the underlying plumbing may have changed between 4.1 and 4.2. I didn’t see anything obvious, but then I’m not entirely sure what to look for.

I’d be happy to email you both of the projects I put together (both the 4.2 Hydra version that doesn’t work properly and the 4.1 Spider version that does), if you like. Just tell me where to send, and I’ll zip em up.

As an interesting test, get the value the ADC reads when connected directly to GND and directly to 3v3. If it doesn’t read 0% and 100% then something weird is going on in the internals potentially (no pun intended) at a hardware level.

@ Brett - Forgive my ignorance, but how do I go about testing that? Are you saying I need to measure across the analog pin (pin 3 in this case, I believe) and either ground or 3.3v? Or something else?

I had Mike Dodaro, who also has a Hydra on 4.2, try to repro and he’s seeing the same output from a potentiometer on Hydra, but not on Cerberus. So that seems to suggest that the issue may be Hydra-specific, rather than a bug in the driver or underlying NETMF code.

I just checked the the Potentiometer 1.1 on both socket 13 and 14 in Gadgeteer 4.2 and I am getting the full range of values, albeit swapped, as was previously discussed. However, when I deployed on socket 14, I was getting a momentary anomaly where Debug.Print was only outputting the full voltage regardless of me changing the voltage on the potentiometer. It fixed itself and gave the correct values. I was using this code to test:

GT.Timer timer = new GT.Timer(100); // every second (100ms)
timer.Tick += new GT.Timer.TickEventHandler(timer_Tick);

void timer_Tick(GT.Timer timer)
    Debug.Print("Voltage value: " + potentiometer.ReadPotentiometerPercentage());

Were you using a different program example? Try to use this example I just posted to see if you get a different result. Maybe re deploying your other code may work?

@ Aron - Here’s the code I’m using:

    public partial class Program
        static double potVal;
        static GT.Timer timer;
        static GTM.DCMotorDriver.DCMotor motorDriver1;

        // This method is run when the mainboard is powered up or reset.   
        void ProgramStarted()
            motorDriver1 = new GTM.DCMotorDriver.DCMotor(7);

            timer = new GT.Timer(200); // every second (1000ms)
            timer.Tick += new GT.Timer.TickEventHandler(timer_Tick);

            button.ButtonPressed += new Button.ButtonEventHandler(button_ButtonPressed);
            // Use Debug.Print to show messages in Visual Studio's "Output" window during debugging.
            Debug.Print("Program Started");


        void timer_Tick(GT.Timer timer)
            potVal = potentiometer.ReadPotentiometerVoltage();
            Debug.Print("Potentiometer voltage reading: " + potVal.ToString());
            Debug.Print("Potentiometer percentage reading: " + potentiometer.ReadPotentiometerPercentage().ToString());
            motorDriver1.SetMotor(GTM.DCMotorDriver.DCMotor.Motor.Motor1, GTM.DCMotorDriver.DCMotor.Direction.Reversed, potVal);
            motorDriver1.SetMotor(GTM.DCMotorDriver.DCMotor.Motor.Motor2, GTM.DCMotorDriver.DCMotor.Direction.Reversed, potVal);

        void button_ButtonPressed(Button sender, Button.ButtonState state)
            if (button.IsLedOn)
                motorDriver1.SetMotor(GTM.DCMotorDriver.DCMotor.Motor.Motor1, GTM.DCMotorDriver.DCMotor.Direction.Neutral, 0.0);
                motorDriver1.SetMotor(GTM.DCMotorDriver.DCMotor.Motor.Motor2, GTM.DCMotorDriver.DCMotor.Direction.Neutral, 0.0);
                Debug.Print("Motors stopped.");
                Debug.Print("Starting motors.");

The output from either potentiometer API never goes below around half of the max value, and the motors continue to turn at around half their max speed, regardless of whether I turn the pot all the way down.

As noted above, I tested the pots using a meter, and they’re definitely working properly. I also tested similar code on my FEZ Spider on 4.1 and it worked as expected.

FWIW, I’m not on the very latest beta build (the one that was pulled earlier this week), but rather the previous beta build, so perhaps you and I have different firmware?

That could be a possibility. I am using the one that was pulled so maybe that is the case. Let me try your code to see if I get the same results that I got on the code I posted.

Hi devhammer,

I just tried the code (less the motor module) and I am getting the full range of the potentiometer. Is the motor module you are using GHI’s? If so, could you point to the code that you are using for the motor driver so I can give a full analysis? By the way, I had the Potentiometer in socket 13 and 14 and the button in socket 6 with the display attached.

Perhaps try a different cable. When I was testing socket 14 it seemed loose and was showing full voltage when I had the potentiometer on half and even at zero.

If none of that works, we will have the new SDK out soon. :slight_smile:

All I meant was instead of changing the potentiometer’s setting by turning, directly wire the Analog in pin to GND and then to 3v3 to see if it reads zero when on GND and 100% when on 3v3. That would mean the ADC read was working correctly, and you just simulate direct short to 3v3 and massive resistance.

@ Aron - Not GHI’s motor module, no. But again, Mike Dodaro was able to repro the issue on his Hydra with 4.2, so I don’t think it has anything to do with the motor module. Also makes it unlikely to be a cable issue, but I will try it with a different cable. I’ll also try socket 13 and see if the issue repros there.

@ Aron - Tested on socket 13, and it’s actually worse. Not seeing much change at all across the range of the pot, and there are spots in the range where the values seem especially jumpy.

Swapped cables…made no difference.

@ Aron - Following up. Finally had time to uninstall the old bits and update with the latest beta release for 4.2, and that seems to have fixed the potentiometer issue.

Still seeing a weird issue where the program only seems to work when debugging (powering the board from battery, or even straight from USB, doesn’t seem to run the program). But I’ll start a separate thread if I can’t get it figured out here shortly.