simple wiring question
#1
Posted 11 October 2012 - 06:25 PM
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.
#2
Posted 11 October 2012 - 08:05 PM
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
Posted 11 October 2012 - 09:08 PM
Perkunas,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.
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
Posted 11 October 2012 - 09:28 PM
#5
Posted 11 October 2012 - 09:33 PM
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
Posted 11 October 2012 - 11:16 PM
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
Posted 11 October 2012 - 11:30 PM
#8
Posted 11 October 2012 - 11:56 PM
#9
Posted 12 October 2012 - 12:16 AM
#10
Posted 12 October 2012 - 12:34 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.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.
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
Posted 12 October 2012 - 08:26 AM
I have actually no clue what so ever, sorryStefan 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.
Do you have a screenshot, maybe it can help me understand your question.
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs
#12
Posted 12 October 2012 - 10:55 AM
If I have understood this correctly you are trying to achieve the following: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.
- 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
Posted 12 October 2012 - 11:35 AM
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users