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.
Photo

Coding troubles


  • Please log in to reply
2 replies to this topic

#1 Frickr

Frickr

    New Member

  • Members
  • Pip
  • 6 posts

Posted 09 January 2013 - 01:18 AM

im very new to netduino, and programming in general. i've been reading a ton, and have learned alot, this forum being one of the biggest helps to me as far as getting started. after working through all the updating for the shield base, i started working on my project for a reverse osmosis system that i am currantly building and would like to include a netduino to power it.

 

my first question is, after writing the code for the netduinoGo, how hard is it to transfer it over to the mini? the small size is appealing for this project, and the go makes a great prototyping board.

 

secondly im having some troubles with my code for it. everything works fine except for the alarm sequence on the flush cycle. the code is identical to the run cycle, which works as intended, but doesnt work when it gets to the flush cycle.

 

also on the alarm sequence how would i go about setting up a reset button to cancel out of the while loop?

 

thanks for your help, and if you see any major defects or ways i can organize better please let me know.

heres the code:

 

 public static void Main()        {            //two float switches [high, low] activate the system when the tank drains, deactivates system when full,            //3 modes: run, flush, rest,            //Run: SolIn opens, sleep for 1 second, pump turns on, sleep 10 seconds, check for flow, if no flow system            //shuts down and alarm sounds,            //After tank full or 8 hours of Run, Flush sequense initiated,            //Flush: pump on, SolFlush opens, SolIn closes, check flow after 10 seconds if no flow alarm, sleep 1 minute,             //pump off, SolFlush closes, sleep 30 mins.            //Include MOA switch keeping timing for flush sequence.                        NetduinoGo.ShieldBase shieldBase = new NetduinoGo.ShieldBase(GoSockets.Socket5);            OutputPort solIn = new OutputPort(shieldBase.Pins.GPIO_PIN_D3, false);            OutputPort solFlush = new OutputPort(shieldBase.Pins.GPIO_PIN_D4, false);            OutputPort pump = new OutputPort(shieldBase.Pins.GPIO_PIN_D5, false);            OutputPort Buzzer = new OutputPort(shieldBase.Pins.GPIO_PIN_D9, false);            InputPort high = new InputPort(shieldBase.Pins.GPIO_PIN_D6, false, Port.ResistorMode.PullUp);            InputPort low = new InputPort(shieldBase.Pins.GPIO_PIN_D7, false, Port.ResistorMode.PullUp);            InputPort alarm = new InputPort(shieldBase.Pins.GPIO_PIN_D8, false, Port.ResistorMode.PullUp);            bool highState = false;            bool lowState = false;            bool flushseq = false;            bool alarmState1 = false;            bool alarmState2 = false;            bool runState = false;            bool flushState = false;                        while (true)            {                //2 float switches controlling tank level                highState = high.Read();                lowState = low.Read();                alarmState1 = alarm.Read();                alarmState2 = alarm.Read();                 if (!highState)                {                                    if (!lowState)                    {                        runState = true;                                           }                }                if (flushseq)                {                    if (highState)                    {                        if (lowState)                        {                            flushState = true;                        }                    }                }                //Run: SolIn opens, sleep for 1 second, pump turns on, sleep 10 seconds, check for flow, if no flow system                //shuts down and alarm sounds,                if (runState)                {                    solIn.Write(true);                    Thread.Sleep(1000);                    pump.Write(true);                    Thread.Sleep(10000);                    if (alarmState1)                        while (true)                        {                            solIn.Write(false);                            pump.Write(false);                            Buzzer.Write(true);                            Thread.Sleep(1000);                            Buzzer.Write(false);                            Thread.Sleep(1000);                        }                    flushseq = true;                    runState = false;                }                //Flush: pump on, SolFlush opens, SolIn closes, check flow after 10 seconds if no flow alarm, sleep 1 minute,                 //pump off, SolFlush closes, sleep 30 mins.                if (flushState)                {                    pump.Write(true);                    solIn.Write(false);                    solFlush.Write(true);                    Thread.Sleep(10000);                    if (alarmState2)                        while (true)                        {                            solIn.Write(true);                            solFlush.Write(false);                            pump.Write(false);                            Buzzer.Write(true);                            Thread.Sleep(1000);                            Buzzer.Write(false);                            Thread.Sleep(1000);                        }                    Thread.Sleep(1000); //60000                    pump.Write(false);                    solFlush.Write(false);                    Thread.Sleep(1000); //1800000                    flushseq = false;                    flushState = false;                }            }        }    }}

 



#2 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 09 January 2013 - 01:30 PM

im very new to netduino, and programming in general. i've been reading a ton, and have learned alot, this forum being one of the biggest helps to me as far as getting started. after working through all the updating for the shield base, i started working on my project for a reverse osmosis system that i am currantly building and would like to include a netduino to power it.

 

my first question is, after writing the code for the netduinoGo, how hard is it to transfer it over to the mini? the small size is appealing for this project, and the go makes a great prototyping board.

 

secondly im having some troubles with my code for it. everything works fine except for the alarm sequence on the flush cycle. the code is identical to the run cycle, which works as intended, but doesnt work when it gets to the flush cycle.

 

also on the alarm sequence how would i go about setting up a reset button to cancel out of the while loop?

 

thanks for your help, and if you see any major defects or ways i can organize better please let me know.

heres the code:

 

1) The GO and the MINI are different Animals in that you are using the Shield Base with the GO for the GPIO pins.  The MINI is closer code-wise to the Standard Netduino which directly exposes the GPIO pins.  So basically you'de be dropping the Shield Base Reference, removing the shieldbase prefix for the definition of the pins and changing the DLL reference from SecretLabs.NETMF.Hardware.NetduinoGo to SecretLabs.NETMF.Hardware.NetduinoMini.

 

2) Have your tried stepping through the code to see where it fails exactly?  You have no error handling in there so it could be throwing an error and you wouldn't know it.  Saying "but doesnt work when it gets to the flush cycle" is very vague and it could be any number of issues.  Try adding some error handling and also running in debug mode to see if you catch an exception.

 

3) The reset button is pretty easy. Check out this code example.  Basically in the beginning of your while loop you want to check the button state and if the button is presses break out of the loop or simply bypass all or portions of the code while the button is held.  Just depends how exactly you want to handle the reset press.



#3 Frickr

Frickr

    New Member

  • Members
  • Pip
  • 6 posts

Posted 09 January 2013 - 02:46 PM

the alarm state2 in the flush sequence fails to activate, it goes right though the flush sequence loop and skips right over the alarm sequence. it seems like theres an issue with the layering and how each line is exicuted.

 

i rewrote alot of the code last night and added a few more things. now i have a new set of problems, first - the run cycle works fine and as it should, the alarm turns on as expected, and the reset button stops the alarm, but then the code continues to the flush cycle instead of shutting down.

 

when it gets to the flush cycle, and i activate the switch for the alarm state, it now goes into the alarm loop, and gets stuck there. the reset button wont break it out of the loop and it keeps the loop active even though the alarm switch is back to a normal state.

 

also im trying to add a manual and an auto sequence to the code. but when i enter the manual, it gets stuck in the loop even though i change the state of the while loop by flipping the switch to the auto side.

 

my next big move is to add some timing functions to the code where after 8 hours of time in "run" it will start the flush sequence, then go back to the run sequence. but i still have alot more reading to do on that. 

 

i feel like im just having issues with the order of operation. i may record a video of my problem later on this afternoon if it would be at all helpful.

 

Thank you guys so much for helping me out with this, im looking forward to learning alot from this community.

 

heres my new revised code

 

namespace RO1{    public class Program    {        public static void Main()        {            //two float switches [high, low] activate the system when the tank drains, deactivates system when full,            //3 modes: run, flush, rest,            //Run: SolIn opens, sleep for 1 second, pump turns on, sleep 10 seconds, check for flow, if no flow system            //shuts down and alarm sounds,            //After tank full or 8 hours of Run, Flush sequense initiated,            //Flush: pump on, SolFlush opens, SolIn closes, check flow after 10 seconds if no flow alarm, sleep 1 minute,             //pump off, SolFlush closes, sleep 30 mins.            //Include MOA switch keeping timing for flush sequence.                        NetduinoGo.ShieldBase shieldBase = new NetduinoGo.ShieldBase(GoSockets.Socket5);            OutputPort solIn = new OutputPort(shieldBase.Pins.GPIO_PIN_D3, false);            OutputPort solFlush = new OutputPort(shieldBase.Pins.GPIO_PIN_D4, false);            OutputPort pump = new OutputPort(shieldBase.Pins.GPIO_PIN_D5, false);            OutputPort Buzzer = new OutputPort(shieldBase.Pins.GPIO_PIN_D9, false);            InputPort high = new InputPort(shieldBase.Pins.GPIO_PIN_D6, false, Port.ResistorMode.PullUp);            InputPort low = new InputPort(shieldBase.Pins.GPIO_PIN_D7, false, Port.ResistorMode.PullUp);            InputPort alarm = new InputPort(shieldBase.Pins.GPIO_PIN_D8, false, Port.ResistorMode.PullUp);            InputPort reset = new InputPort(shieldBase.Pins.GPIO_PIN_D2, false, Port.ResistorMode.PullUp);            InputPort auto = new InputPort(shieldBase.Pins.GPIO_PIN_D10, false, Port.ResistorMode.PullUp);            InputPort manual = new InputPort(shieldBase.Pins.GPIO_PIN_D11, false, Port.ResistorMode.PullUp);            bool highState = false;            bool lowState = false;            bool flushseq = false;            bool alarmState = false;            bool runState = false;            bool flushState = false;            bool resetState = false;            bool autoState = false;            bool manualState = false;            autoState = auto.Read();            resetState = reset.Read();            manualState = manual.Read();            while (autoState)            {                //2 float switches controlling tank level                highState = high.Read();                lowState = low.Read();                                if (!highState)                {                                    if (!lowState)                    {                        runState = true;                                           }                }                if (flushseq)                {                    if (highState)                    {                        if (lowState)                        {                            flushState = true;                        }                    }                }                //Run: SolIn opens, sleep for 1 second, pump turns on, sleep 10 seconds, check for flow, if no flow system                //shuts down and alarm sounds,                while (runState)                {                     solIn.Write(true);                    Thread.Sleep(1000);                    pump.Write(true);                    Thread.Sleep(5000);                    alarmState = alarm.Read();                    flushseq = true;                    runState = false;                }                //Flush: pump on, SolFlush opens, SolIn closes, check flow after 10 seconds if no flow alarm, sleep 1 minute,                 //pump off, SolFlush closes, sleep 30 mins.                while (flushState)                {                    pump.Write(true);                    solIn.Write(false);                    solFlush.Write(true);                    Thread.Sleep(5000);                    alarmState = alarm.Read();                      Thread.Sleep(1000); //60000                    pump.Write(false);                    solFlush.Write(false);                    Thread.Sleep(1000); //1800000                    flushseq = false;                    flushState = false;                }                    while(alarmState)                {                    solIn.Write(false);                    solFlush.Write(false);                    pump.Write(false);                    Buzzer.Write(true);                    Thread.Sleep(1000);                    Buzzer.Write(false);                    Thread.Sleep(1000);                    if (resetState)                    {                        break;                     }                }            }            while (manualState)            {                solIn.Write(true);                Thread.Sleep(1000);                pump.Write(true);            }        }    }}





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

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.