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

simple wiring question


  • Please log in to reply
12 replies to this topic

#1 perkunas

perkunas

    Advanced Member

  • Members
  • PipPipPip
  • 108 posts

Posted 11 October 2012 - 06:25 PM

I have wired my digital inputs like this, and I'm using optical relay's as an output.
My question is in regards to, is it going to be on or off,when the switch closes.My thinking is when you close the switch it goes to ground so off
not sure.

Posted Image

#2 gbreder

gbreder

    Advanced Member

  • Members
  • PipPipPip
  • 53 posts
  • LocationGermany

Posted 11 October 2012 - 08:05 PM

Hi perkunas.
The connection "P2" will sense a low signal when the switch is closed. The resistor at the +5V and the switch at the bottom will form a voltage divider. The calculation is fairly easy because the switches resistance is (nearly) 0 ohm if closed and (nearly) infinite ohm if opened.
Closed: 5V * (0/(10000 + 0) = 0
see Wikipedia Voltage divider

The resistor at P2 is not relevant for the calculation.

Regards
Guido

#3 carb

carb

    Advanced Member

  • Members
  • PipPipPip
  • 352 posts
  • LocationCrystal River, Florida

Posted 11 October 2012 - 09:08 PM

I have wired my digital inputs like this, and I'm using optical relay's as an output.
My question is in regards to, is it going to be on or off,when the switch closes.My thinking is when you close the switch it goes to ground so off
not sure.

Posted Image

Perkunas,

I think I know what your asking.

The digital input that is connected at P2 will see 0 vdc with the switch closed, that is a logic 0 or false for that input when you read it.

Using that in code you can drive a digital output to a optical isolator (relay etc.) anyway that you want. Just write the value from the input to the output pin.

Or you can invert the value from the input.

That way yo can turn the relay either on or off when the switch is closed.

Chuck

#4 perkunas

perkunas

    Advanced Member

  • Members
  • PipPipPip
  • 108 posts

Posted 11 October 2012 - 09:28 PM

Here's why I'm asking, I want it to do this, when the switch is closed I think this should be this "while (anyinputfor6.Read() == false && method_state_6 == true)" public static void Method_6() { while (anyinputfor6.Read() == true && method_state_6 == true) { phcontroller.Write(false); Thread.Sleep(1 * SecondMs); phcontroller.Write(true); Thread.Sleep(10 * MinuteMs); }

#5 perkunas

perkunas

    Advanced Member

  • Members
  • PipPipPip
  • 108 posts

Posted 11 October 2012 - 09:33 PM

here's the whole program if that helps
using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;

namespace NetduinoApplication1
{
    public class Program
    {
        public const int SecondMs = 1000;
        public const int MinuteMs = 60 * SecondMs;
        public const int HourMs = 60 * MinuteMs;
        public const int DayMs = 24 * HourMs;
        public const int WeekMs = 7 * DayMs;

        static bool method_state_6, method_state_7;


        static InputPort anyinputfor6 = new InputPort(Pins.GPIO_PIN_A0, false, Port.ResistorMode.Disabled);
        static InputPort anyinputfor7 = new InputPort(Pins.GPIO_PIN_A1, false, Port.ResistorMode.Disabled);
        static OutputPort ph = new OutputPort(Pins.GPIO_PIN_D2, true);
        static OutputPort b = new OutputPort(Pins.GPIO_PIN_D3, true);
        static OutputPort a = new OutputPort(Pins.GPIO_PIN_D4, true);
        static OutputPort drain = new OutputPort(Pins.GPIO_PIN_D5, true);
        static OutputPort solenoid = new OutputPort(Pins.GPIO_PIN_D6, true);
        static OutputPort heater = new OutputPort(Pins.GPIO_PIN_D7, true);
        static OutputPort phcontroller = new OutputPort(Pins.GPIO_PIN_D8, true);
        static OutputPort tdscontrollerA = new OutputPort(Pins.GPIO_PIN_D9, true);
        static OutputPort tdscontrollerB = new OutputPort(Pins.GPIO_PIN_D10, true);
        static OutputPort led = new OutputPort(Pins.GPIO_PIN_D11, true);


        
        public static void Main()
        {

            try
            {
                Thread led_proc = new Thread(new ThreadStart(turn_led));
                led_proc.Start();
                while (true)
                {

                    method_state_6 = method_state_7 = true;
                    Method_1();
                    call2_5();
                    call6_8();
                    Method_10();
                    Thread.Sleep(10000);

                }
            }
            catch
            {
                //Something has gone wrong; reset to a safe condition
            }
        }


        static void turn_led() //turn led for 16 hr and off for 8hr in loop
        {
            while (true)
            {
                led.Write(false);
                Thread.Sleep(HourMs * 16);
                led.Write(true);
                Thread.Sleep(HourMs * 8);
            }
        }

        public static void call2_5()
        {
            Thread t2 = new Thread(new ThreadStart(Method_2));
            t2.Start();
            Thread t3 = new Thread(new ThreadStart(Method_3));
            t3.Start();
            Thread t4 = new Thread(new ThreadStart(Method_4));
            t4.Start();
            Thread t5 = new Thread(new ThreadStart(Method_5));
            t5.Start();
            #region Wait for finishing 2-5 methods
            t2.Join();
            t3.Join();
            t4.Join();
            t5.Join();
            #endregion
        }
        static void call6_8()
        {
            Thread t6 = new Thread(new ThreadStart(Method_6));
            t6.Start();
            Thread t7 = new Thread(new ThreadStart(Method_7));
            t7.Start();
            Thread t9 = new Thread(new ThreadStart(Method_9));
            t9.Start();

            // wait for Method_9 finishing
            t9.Join();
            method_state_6 = method_state_7 = false;
        }
        public static void Method_1()
        {
            drain.Write(false);
            Thread.Sleep(16 * MinuteMs);
            drain.Write(true);
        }
        public static void Method_2()
        {
            solenoid.Write(false);
            Thread.Sleep(16 * MinuteMs);
            solenoid.Write(true);
        }
        public static void Method_3()
        {
            a.Write(false);
            Thread.Sleep(5 * MinuteMs);
            a.Write(true);
        }
        public static void Method_4()
        {
            b.Write(false);
            Thread.Sleep(545 * SecondMs);
            b.Write(true);
        }
        public static void Method_5()
        {
            ph.Write(false);
            Thread.Sleep(3 * SecondMs);
            ph.Write(true);
        }
        public static void Method_6()
        {
            while (anyinputfor6.Read() == true && method_state_6 == true)
            {
                phcontroller.Write(false);
                Thread.Sleep(1 * SecondMs);
                phcontroller.Write(true);
                Thread.Sleep(10 * MinuteMs);
            }
        }
        public static void Method_7()
        {
            while (anyinputfor7.Read() == true && method_state_7 == true)
            {
                Thread.Sleep(5 * MinuteMs);
                tdscontrollerA.Write(false);
                Thread.Sleep(1 * SecondMs);
                tdscontrollerA.Write(true);
                tdscontrollerB.Write(false);
                Thread.Sleep(1818);
                tdscontrollerB.Write(true);
                Thread.Sleep(10 * MinuteMs);
            }
        }
        public static void Method_9()
        {
            heater.Write(false);
            for (int i = 0; i < 14; i++)
            {
                Thread.Sleep(1 * DayMs);
                solenoid.Write(false);
                Thread.Sleep(20 * SecondMs);
                solenoid.Write(true);


            }
            heater.Write(true); // added this
        }
        public static void Method_10()
        {
            drain.Write(false);
            Thread.Sleep(16 * MinuteMs);
            drain.Write(true);
            solenoid.Write(false);
            Thread.Sleep(16 * MinuteMs);
            solenoid.Write(true);
            Thread.Sleep(1 * MinuteMs);
          
        }

    }
}


#6 carb

carb

    Advanced Member

  • Members
  • PipPipPip
  • 352 posts
  • LocationCrystal River, Florida

Posted 11 October 2012 - 11:16 PM

Perkunas,

It may be a simple wiring question, but the code isn't easy. I am better with Visual Basic. Even when I converted it to VB I wasn't used to using that many threads.

Anyway I think the problem could be that you are using an Analog input instead of a digital input (I know yoy are short on DIOs). If you use an Analog input you would want the input to evaluate against a value 0.0 to 1.0

You have
while (anyinputfor6.Read() == true && method_state_6 == true)
Try changing to something like
while (anyinputfor6.Read() <= 0.5 && method_state_6 == true)
In other word if anyinputfor6 is less than or equal to 0.5 it would evaluate as true (ie. the switch is closed).

Hope that helps,
Chuck

#7 perkunas

perkunas

    Advanced Member

  • Members
  • PipPipPip
  • 108 posts

Posted 11 October 2012 - 11:30 PM

Actually the input is wired into the RX TX or digital pin 0 and 1 Thanks for pointing that out I have static InputPort anyinputfor6 = new InputPort(Pins.GPIO_PIN_A0, false, Port.ResistorMode.Disabled); static InputPort anyinputfor7 = new InputPort(Pins.GPIO_PIN_A1, false, Port.ResistorMode.Disabled); this should be static InputPort anyinputfor6 = new InputPort(Pins.GPIO_PIN_D0, false, Port.ResistorMode.Disabled); static InputPort anyinputfor7 = new InputPort(Pins.GPIO_PIN_D1, false, Port.ResistorMode.Disabled); and this should be while (anyinputfor6.Read() == false && method_state_6 == true) while (anyinputfor7.Read() == false && method_state_7 == true) I think that's it thanks for the help

#8 carb

carb

    Advanced Member

  • Members
  • PipPipPip
  • 352 posts
  • LocationCrystal River, Florida

Posted 11 October 2012 - 11:56 PM

No problem, glad I could at least get you on the right path. Most of my programing is actually in VBA (visual basic for applications) I am trying to learn VB & C# still. Chuck

#9 perkunas

perkunas

    Advanced Member

  • Members
  • PipPipPip
  • 108 posts

Posted 12 October 2012 - 12:16 AM

Since most of your programing is in visual basic. I got a question for you since I have never tried netduino with VB so here goes. years ago I wrote a program in vb it was a simple text editor that worked with an arduino program. All it did was change the variables graphically and with a push of a button uploaded the program. Was hoping to do something similar with the netduino but C# makes it almost impossible to do, there is no simple up loader. Nothing graphical built in, maybe the VB netduino version is better.

#10 carb

carb

    Advanced Member

  • Members
  • PipPipPip
  • 352 posts
  • LocationCrystal River, Florida

Posted 12 October 2012 - 12:34 AM

Since most of your programing is in visual basic.
I got a question for you since I have never tried netduino with VB so here goes.
years ago I wrote a program in vb it was a simple text editor that worked with an arduino program.
All it did was change the variables graphically and with a push of a button uploaded the program.
Was hoping to do something similar with the netduino but C# makes it almost impossible to do, there is no simple up loader.
Nothing graphical built in, maybe the VB netduino version is better.

Stefan may be able to answer that better than I can. From what I have seen VB & C# have similar capabilities. I am not aware of any way to graphically change the variables.

Some are working on a graphical interface that produce a deployable program. Two come to mind, Bender has a project that he is working on that generates a console for controlling servos and the likes. Mario is also working on some things that have great potential to help some of the non programmer types.

The best thing about the 2 projects is it looks like they can maybe be used together.

When I start a project I have been trying to get a working version in both VB & C#, if nothing else I will use a converter to convert from VB to C#.

Chuck

#11 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 12 October 2012 - 08:26 AM

Stefan may be able to answer that better than I can. From what I have seen VB & C# have similar capabilities. I am not aware of any way to graphically change the variables.

I have actually no clue what so ever, sorry ;)

Do you have a screenshot, maybe it can help me understand your question.
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#12 Nevyn

Nevyn

    Advanced Member

  • Members
  • PipPipPip
  • 1072 posts
  • LocationNorth Yorkshire, UK

Posted 12 October 2012 - 10:55 AM

Since most of your programing is in visual basic.
I got a question for you since I have never tried netduino with VB so here goes.
years ago I wrote a program in vb it was a simple text editor that worked with an arduino program.
All it did was change the variables graphically and with a push of a button uploaded the program.
Was hoping to do something similar with the netduino but C# makes it almost impossible to do, there is no simple up loader.
Nothing graphical built in, maybe the VB netduino version is better.

If I have understood this correctly you are trying to achieve the following:

- Windows application running on a PC.
- The Windows application modifies/generates a Netduino application
- The Netduino application is compiled and then deployed to the Netduino by the Windows application

Assuming I have understood you correctly I think it should be possible although it will take some work. You can integrate the MFDeploy engine into a Windows application (there are some threads discussing that). You would just need to automate the build process which I would have though possible by shelling out to MSBuild.

Just a thought, have you considered having a Windows application which talks to the Netduino over serial and have the Netduino store the variables initial values in EEPROM?

Hope this helps,
Mark

To be or not to be = 0xFF

 

Blogging about Netduino, .NET, STM8S and STM32 and generally waffling on about life

Follow @nevynuk on Twitter


#13 perkunas

perkunas

    Advanced Member

  • Members
  • PipPipPip
  • 108 posts

Posted 12 October 2012 - 11:35 AM

"- Windows application running on a PC. - The Windows application modifies/generates a Netduino application - The Netduino application is compiled and then deployed to the Netduino by the Windows application" exactly its surprisingly simple program using the other guy for a bunch of reasons. You are only changing the variables graphically ie. buttons nuds and in fact the program has no Idea what its changing, as it was written in another programing language. Seeing as though your just changing variables in a language it didn't understand, all it did was upload it that even made it simpler. I find it a little funny how Visual basic being all graphical and all would not have this sort of thing built in. anyway,, I'm still a little confused here my line static InputPort anyinputfor6 = new InputPort(Pins.GPIO_PIN_A0, false, Port.ResistorMode.Disabled); should this be false or true?. When the switch (input)closes, it goes to 0 or false but is the false meaning the InputPort is off or disabled The 1st thing it sees will be power. also I'm using optical relays that work opposite so now I'm all confused I think I got this right with this static InputPort anyinputfor6 = new InputPort(Pins.GPIO_PIN_D0, false, Port.ResistorMode.Disabled); and while (anyinputfor6.Read() == false && method_state_6 == true) it doesn't take much to confuse me lol




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.