Moisture Gadget not working

Have connected a Moisture gadget to socket 4 (A type) to fez Cobra 2 and i get an exception on the ReadMoisture. ie Exception was thrown: System.InvalidOperationException and using firmware 4.3.8

        public int ReadMoisture()
        {
            return (int)(this.input.ReadProportion() * 1600);
        }

Any ideas?

@ anthonys - Does it occur when using the below code only:


void ProgramStarted() {
   this.moisture.ReadMoisture();
}

@ John - yes.

@ anthonys - Using the latest SDK and the below code, I was not able to reproduce your exception. It ran without issue. Can you try to erase and deploy TinyBooter and the firmware and then retest just the below code only?


using System.Threading;
using Microsoft.SPOT;

namespace GadgeteerApp1 {
    public partial class Program {
        void ProgramStarted() {
            while (Program.Mainboard.LDR0.Read()) {
                Thread.Sleep(100);
                Program.Mainboard.SetDebugLED(true);
                Thread.Sleep(100);
                Program.Mainboard.SetDebugLED(false);
            }

            while (true) {
                Debug.Print(this.moisture.ReadMoisture().ToString("N2"));

                Thread.Sleep(100);
            }
        }
    }
}

which socket did you use?

@ anthonys - Four

Still get error…have updated loader and firmware to 4.3.8

An exception of type ‘System.InvalidOperationException’ occurred in Microsoft.SPOT.Hardware.dll but was not handled in user code

@ anthonys - Unfortunately we can’t reproduce it so I would try to use different hardware if available.

Got it working :slight_smile: Does it matter that the readmoisture was in timer event?

@ anthonys - It’s possible. Hard to say without knowing the entire program context. It should work when read in a timer.