Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.

ncsteinb's Content

There have been 4 items by ncsteinb (Search limited from 10-December 18)


By content type

See this member's

Sort by                Order  

#61909 Searching issue...??

Posted by ncsteinb on 20 March 2015 - 03:11 AM in General Discussion

I'm trying to find threads about I2C, but whenever I search "I2C", I get no hits.... What's going on here? Or what am I doing wrong?




#60308 How do I properly use PWM?

Posted by ncsteinb on 30 September 2014 - 10:55 PM in Netduino Mini

Hello, 

 

I'm trying to use a PWM output to drive a solid state relay. The output turns the fan on, but does not seem to control the speed or ever turn off... 

 

What am I doing wrong? I've got a fresh out-of-the-box Netduino Mini.

using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.NetduinoMini;

//R0.0 - Base Project (Nevin Steinbrink 7/25/2014)
//R0.1 - Added PWM motor control functionality (Nevin Steinbrink 8/2/2014)
//R0.2 - Added third Program Select input, changed Status Pointer configuration (Nevin Steinbrink 9/21/2014)
//R0.3 - Debug (Nevin Steinbrink 9/27/2014)

namespace NetduinoMiniApplication1
{
    public class ICE_Box
    {
        public static int StatusPointer; //Used for Status LED flash pattern

        public static void Main()
        {
            Thread a = new Thread(Status); //Thread for Status LED control
            a.Start();
            Thread b = new Thread(BlowerControl); //Thread for Blower Motor control
            b.Start();

            while (true)
            {
                Thread.Sleep(Timeout.Infinite);
            }
        }

        static void BlowerControl()
        {
            InputPort StartButton = new InputPort(Pins.GPIO_PIN_5, true, Port.ResistorMode.PullUp); //Start button input
            InputPort PS_1 = new InputPort(Pins.GPIO_PIN_6, true, Port.ResistorMode.PullUp); //Program select 1 input, 1 Liter
            InputPort PS_2 = new InputPort(Pins.GPIO_PIN_7, true, Port.ResistorMode.PullUp); //Program select 2 input, 3 Liter
            InputPort PS_3 = new InputPort(Pins.GPIO_PIN_8, true, Port.ResistorMode.PullUp); //Program select 3 input, 5 Liter

            SecretLabs.NETMF.Hardware.PWM BlowerOutput = new PWM(Pins.GPIO_PIN_17); //PWM output for blower relay

            bool PS_1State = true; //Program select 1, initialize as HIGH
            bool PS_2State = true; //Program select 2, initialize as HIGH
            bool PS_3State = true; //Program select 3, initialize as HIGH
            bool StartButtonState = true; //Start button, initialize as LOW
            bool StartLatch = false;
            bool BlowerRunning = false;

            int RunTime = 0; //Blower ON time in ms
            int PWMDutyCycle = 0; //In percent, initialize at 0%

            uint PWMFreq = 400; //In Hz <-- Adjust this value
            uint PWMPeriod;
            uint PWMPulseWidth; //In microseconds

            PWMPeriod = 2500; //((1 / PWMFreq) * 1000000); //In microseconds
            StatusPointer = 1; //Ready LED indication

            while (true)
            {
                PS_1State = PS_1.Read(); //Read state of Program Select switch 
                PS_2State = PS_2.Read(); //Read state of Program Select switch
                PS_3State = PS_3.Read(); //Read state of Program Select switch
                StartButtonState = StartButton.Read(); //Read state of Start button 

                if (StartButtonState == false) //Check if Start button is pressed
                {
                    StartLatch = true; //Start button debounce
                }

                if (PS_1State == false) //Check which program is selected, Program 1 selected
                {
                    RunTime = 5000; //Blower ON for 5 seconds
                    PWMDutyCycle = 10; //Blower at 50% power
                }

                if (PS_2State == false) //Check which program is selected, Program 2 selected
                {
                    RunTime = 8000; //Blower ON for 8 seconds
                    PWMDutyCycle = 30; //Blower at 90% power
                }

                if (PS_3State == false) //Check which program is selected, Program 3 selected
                {
                    RunTime = 10000; //Blower ON for 10 seconds
                    PWMDutyCycle = 100; //Blower at 90% power
                }

                if (PS_1State & PS_2State & PS_3State == false | PS_1State & PS_2State & PS_3State == true)
                {
                    StatusPointer = 4;
                }

                while (StartLatch == true & BlowerRunning == false) //Check if OK to start and blower is currently OFF
                {
                    PWMPulseWidth = 250; //(uint)(PWMPeriod * (PWMDutyCycle / 100));
                    BlowerRunning = true; //Prevents re-entering while loop
                    StatusPointer = 2; //Changes LED indication to 'in operation'
                    BlowerOutput.SetPulse(PWMPeriod, PWMPulseWidth); //Turn on Blower at set PWM
                    Thread.Sleep(RunTime); //For this long
                    BlowerOutput.SetPulse(0, 0); //Turn off Blower
                    StartLatch = false; //Reset StartLatch
                    BlowerRunning = false; //Reset BlowerRunning
                    StatusPointer = 3; //Changes LED indication to 'completed'
                }
            }
        }

I've commented out some stuff to help debug, but no help. 

 

Thanks!!

-Nevin




#60171 Unhandled exception error

Posted by ncsteinb on 21 September 2014 - 05:44 PM in Netduino Mini

Figured it out. I guess Netduino Mini only supports Port.ResistorMode.Disabled and Port.ResistorMode.PullUp ...

 

Time to rewire some stuff....

 

-Nevin




#60170 Unhandled exception error

Posted by ncsteinb on 21 September 2014 - 04:40 PM in Netduino Mini

Hello all!

 

I'm having a (seemingly peculiar) error when deploying some code to my Netduino Mini. I just received the Mini, dumped a simple Blink program on it to verify it works, and then tried to dump the following code onto the Mini. 

 

The error I am getting is "An unhandled exception of type 'System.ArgumentException' occurred in Microsoft.SPOT.Hardware.dll" Occuring on Line:33 

 

I have tried changing the Input pin, but same issue. Currently running .NETMF 4.1 as my current program framework. Any ideas?

using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.NetduinoMini;

//R0.0 - Base Project (Nevin Steinbrink 7/25/2014)
//R0.1 - Added PWM motor control functionality (Nevin Steinbrink 8/2/2014)
//R0.2 - Added third Program Select input, changed Status Pointer configuration (Nevin Steinbrink 9/21/2014)

namespace NetduinoMiniApplication1
{
    public class ICE_Box
    {
        public static int StatusPointer; //Used for Status LED flash pattern

        public static void Main()
        {
            Thread a = new Thread(Status); //Thread for Status LED control
            a.Start();
            Thread b = new Thread(BlowerControl); //Thread for Blower Motor control
            b.Start();

            while (true)
            {
                Thread.Sleep(Timeout.Infinite);
            }
        }

        static void BlowerControl()
        {
            InputPort StartButton = new InputPort(Pins.GPIO_PIN_13, true, Port.ResistorMode.PullDown); //Start button input
            InputPort PS_1 = new InputPort(Pins.GPIO_PIN_6, true, Port.ResistorMode.PullDown); //Program select 1 input, 1 Liter
            InputPort PS_2 = new InputPort(Pins.GPIO_PIN_7, true, Port.ResistorMode.PullDown); //Program select 2 input, 3 Liter
            InputPort PS_3 = new InputPort(Pins.GPIO_PIN_8, true, Port.ResistorMode.PullDown); //Program select 3 input, 5 Liter

            PWM BlowerOutput = new PWM(Pins.GPIO_PIN_17); //PWM output for blower relay

            bool PS_1State = false; //Program select 1, initialize as LOW
            bool PS_2State = false; //Program select 2, initialize as LOW
            bool PS_3State = false; //Program select 3, initialize as LOW
            bool StartButtonState = false; //Start button, initialize as LOW
            bool StartLatch = false;
            bool BlowerRunning = false;

            int RunTime = 0; //Blower ON time in ms
            int PWMDutyCycle = 0; //In percent, initialize at 0%

            uint PWMFreq = 400; //In Hz <-- Adjust this value
            uint PWMPeriod;
            uint PWMPulseWidth; //In microseconds

            PWMPeriod = ((1 / PWMFreq) / 1000000); //In microseconds

            while (true)
            {
                StatusPointer = 1; //Ready LED indication
                PS_1State = PS_1.Read(); //Read state of Program Select switch 
                PS_2State = PS_2.Read(); //Read state of Program Select switch
                StartButtonState = StartButton.Read(); //Read state of Start button 

                if (StartButtonState == true) //Check if Start button is pressed
                {
                    StartLatch = true; //Start button debounce
                }

                if (PS_1State == true) //Check which program is selected, Program 1 selected
                {
                    RunTime = 5000; //Blower ON for 5 seconds
                    PWMDutyCycle = 50; //Blower at 50% power
                }

                if (PS_2State == true) //Check which program is selected, Program 2 selected
                {
                    RunTime = 8000; //Blower ON for 8 seconds
                    PWMDutyCycle = 90; //Blower at 90% power
                }

                if (PS_3State == true) //Check which program is selected, Program 3 selected
                {
                    RunTime = 10000; //Blower ON for 10 seconds
                    PWMDutyCycle = 90; //Blower at 90% power
                }

                while (StartLatch == true & BlowerRunning == false) //Check if OK to start and blower is currently OFF
                {
                    PWMPulseWidth = (uint)(PWMPeriod * (PWMDutyCycle / 100));
                    BlowerRunning = true; //Prevents re-entering while loop
                    StatusPointer = 2; //Changes LED indication to 'in operation'
                    BlowerOutput.SetPulse(PWMPeriod, PWMPulseWidth); //Turn on Blower at set PWM
                    Thread.Sleep(RunTime); //For this long
                    StartLatch = false; //Reset StartLatch
                    BlowerRunning = false; //Reset BlowerRunning
                    StatusPointer = 3; //Changes LED indication to 'completed'
                }
            }
        }

        static void Status()
        {
            OutputPort StatusLED = new OutputPort(Pins.GPIO_PIN_9, true);

            while (true)
            {
                if (StatusPointer == 1) //LED indication 'Ready'
                {
                    StatusLED.Write(false);
                    Thread.Sleep(1000);
                    StatusLED.Write(true);
                    Thread.Sleep(1000);
                }

                if (StatusPointer == 2) //LED indication 'In Operation'
                {
                    StatusLED.Write(false);
                    Thread.Sleep(800);
                    StatusLED.Write(true);
                    Thread.Sleep(800);
                }

                if (StatusPointer == 3) //LED indication 'Completed'
                {
                    StatusLED.Write(false);
                    Thread.Sleep(200);
                    StatusLED.Write(true);
                    Thread.Sleep(200);
                    StatusLED.Write(false);
                    Thread.Sleep(200);
                    StatusLED.Write(true);
                    Thread.Sleep(1000);
                }

                if (StatusPointer == 4) //LED indication 'Error'
                {
                    StatusLED.Write(false);
                    Thread.Sleep(200);
                    StatusLED.Write(true);
                    Thread.Sleep(200);
                    StatusLED.Write(false);
                    Thread.Sleep(200);
                    StatusLED.Write(true);
                    Thread.Sleep(200);
                }
            }
        }
    }
}

Thanks for the help in advance!

-Nevin





home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.