BrainPad AnalogInput exception

I had nothing to do so I picked up my BrainPad and tried some of your sample code.

Leave it up to me and something bad will happen.
(First time use of the BrainPad)

Using Book Electronics - Electronics Analog Inputs.

I received exceptions for:
AnalogInput lightSensor = new AnalogInput(BrainPad.Peripherals.LightSensor, 3.3, 0, 12);
AnalogInput temp = new AnalogInput(BrainPad.Peripherals.TemperatureSensor, 3300, 0, 12);

A first chance exception of type ‘System.InvalidOperationException’ occurred in Microsoft.SPOT.Hardware.dll

Just wondering in the hallways of my little world…


using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware; //AnalogInput

//Serial FTDI GND, RX and TX connections to the BrainPad.
//Must be 3.3v


namespace MFConsoleBrainPad1
{
    public class Program
    {
        public static void Main()
        {
            Debug.Print(Resources.GetString(Resources.StringResources.String1));
            BrainPad.TrafficLight.TurnGreenLightOn();

            Debug.Print("Is the GREEN traffic light on?"); //

            BrainPad.Display.Clear();
            BrainPad.Display.DrawString(1, 1, "Green LED ON", BrainPad.Color.Green);

            BrainPad.WriteDebugMessage("GREEN");


            //From BrainPad - Book Electronics - Electronics Analog Inputs

            //AnalogInput(Cpu.AnalogChannel channel, double scale, double offset, int precisionInBits);
            //The BrainPad microcontroller has a 12-bit ADC (int precisionInBits)
            //The light sensor connects to PB1 and ADC channel 9.

            try
            {
                AnalogInput lightSensor = new AnalogInput(BrainPad.Peripherals.LightSensor, 3.3, 0, 12);
            }
            catch (Exception e)
            {
                Debug.Print("Exception AnalogInput lightSensor: " + e.Message);
                //A first chance exception of type 'System.InvalidOperationException' occurred in Microsoft.SPOT.Hardware.dll
            }
            //

            try
            {
                AnalogInput temp = new AnalogInput(BrainPad.Peripherals.TemperatureSensor, 3300, 0, 12);
            }
            catch (Exception e)
            {
                Debug.Print("Exception AnalogInput temp: " + e.Message);
                //A first chance exception of type 'System.InvalidOperationException' occurred in Microsoft.SPOT.Hardware.dll
            }
            //
            //double tempC = (temp.Read() - 450) / 19.5; 
            //Debug.Print("Temperature: " + tempC.ToString("F2"));
            //BrainPad.Display.DrawString(1, 10, "Temperature: " + tempC.ToString("F2"), BrainPad.Color.Red);
        }
    }
}


Resources used in Gif

Did you remember to remove the brain pad drivers? Brainpad.vs file?

@ Gus -
Did you remember to remove the brain pad drivers? Brainpad.vs file?

Not sure I understand your question. I do not have a Brainpad.vs file in my solution. I have removed everything related to the Emulator from the project though.

As I recall, the only time I have seen a .vs file is when I tried using VS2015.
(I only tried 2015 to see if it would work)

I am using VS2013 Pro

CS I mean

@ Gus -

Sorry Gus … CS I do not know what that is. Blockhead here.
Unless you mean a CS file.

File BrainPad.cs is in my solution.

By the way, the following does not work either. It uses the same channel.


AnalogInput light = new AnalogInput((Cpu.AnalogChannel)9);

 while (true)
            {
                Debug.Print("Light level: " + light.ReadRaw());
                Thread.Sleep(200);
            }


Remove brainpad.CS from your project :slight_smile:

@ Gus -

Thank you…

EDIT: Sorry for the delay but I had to do something for my Granddaughter.

Remove BrainPad.cs from my project? This makes no sense to me.

brainpad.cs was a temporary driver file, it’s duplicating things that the firmware does, remove it from the project and you no longer will double-allocate things.

Actually no. The driver is only used in the beginner courses. Only when you do something basic like BrainPad.LightSensor.GetLevel(). Advanced courses brings the student to the hardware directly and so the driver should not be included. I hope this makes sense. We should clarify this better in the courses.

@ Gus -

If I remove BrainPad.cs how do I reference something like the following that uses BrainPad.Peripherals.ServoMotor Etc.

PWM servo = new PWM(BrainPad.Peripherals.ServoMotor, 20000, 1500, PWM.ScaleFactor.Microseconds, false);
servo.Start();

or

PWM buzzer = new PWM(BrainPad.Peripherals.Buzzer, 261, 0.5, false); Etc.

Or is using Scratch for .Net Micro Framework my only option?

Sorry for my dumb questions. I guess it boils down to I have no idea what firmware is on the BrainPad as shipped from GHI.

Let me get with the team to update and clarify the advanced courses.