I'd like to read the position of a switch. So, when a button is pushed, I get a Boolean that becomes true (or an integer that becomes 1). As soon as the button is released the values changes back to 'false' or 0.
My line of code so far goes like this :
ImpactSensLeft = (EzB_Connect1.EZB.Digital.GetDigitalPort(EZ_B.Digital.DigitalPortEnum.D15))
But this always returns 'true' doesn't really matter if the button gets pushed or whatever. What am I missing here ?
Where can I put this code for optimal results (form Load event ?? etc...). I want to read out and interact with the switch all the time while other code is processed. The switch acts as an emergency switch that shuts down the motors of my robot as soon as the switch is pushed. When released, the motors start running again.
I'm really looking forward to this.
Upgrade to ARC Pro
Become a Synthiam ARC Pro subscriber to unleash the power of easy and powerful robot programming
That code will return the logic resut of the digital I/O pin D15. If > 0.1 volts is on the signal pin of D15, it will return true; otherwise false.
Sounds like your switch may be floating and picking up static. The wire is probably acting like a giant antenna.
My advice is to put a 10K resistor between GND and the Digital I/O pin D15. That way it will hold the pin LOW until the switch is shorted. That is called a PULL-DOWN RESISTOR
Anyway, both switches work fine with the ARC SDK (control, read digital). It just doesn't work when I put the same code in VB. I'm not a VB guru so I wonder where I go wrong. I have use this code within a Click event of a switch on my VB design form, but also in the form Load Event but that doesn't matter. Where can I place the code best so that it reacts immediately when the EZ-B switch is pressed ?
You need to make a connection first, then have some event that queries the port. Put that code inside of a button or a timer. If you use a timer, don't query too quick.
Weird things going on over here....
First let me explain. I'm testing the EZ-B at 2 computers (not at the same time) :
- laptop with Windows 7, Visual Studio 2008
- desktop with Windows XP, Visual Studio 2005
This is my code in a Timer_Tick event :
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
switch = (EzB_Connect1.EZB.Digital.GetDigitalPort(EZ_B.Digital.DigitalPortEnum.D15))
If switch = True Then
Label1.Text = "H I T"
Label1.Text = "S A F E"
Of course the timer is enabled and the interval is 100ms (I tried all kinds of values).
On the desktop I get no errors or messages but it doens't work at all. On the laptop however, I have a error message that the 'Reference Component EZ-B could not be found'.... but it works ! When I push the switch I get immediately result. However, when I release the switch it takes about 3 minutes to change the boolean back to 'False' (with Timer interval at 500ms and sometimes even less).
What is happening here ?
Please some help/advice because I'm speding many hours on this and I'm getting desperate.
Here is my tutorial sample: VB-Tutorial02-GetDigital.zip
Yes I did. I get exactely the same result. So I'm looking into VB right now. I made screenshot(s) and post this with some comments asap.
Thnxs for asking !
Can you try running my program with nothing attached to the ez-b. absolutely NO peripherals. Then run your finger along the digital input line. it also helps if you lick your finger Serious haha.. But anyway. if you do that, the eletricity from your body will flip the i/o ON and OFF while they float
Well, at least I do get response. In the mean time I also found out that the RC ESC that I use (Graupner) are interferring. As soon as I switch the main power on (= for the drive motors powerd by the ESC's), I get a HIGH on those digital inputs.
I removed all peripherals and licked my finger and indeed, I can make the digital port flip between on and off. However, I'm still puzled... the timer is set to 250 ms and the port filps back between on and off every 3 to 4 seconds. So it does respond, but rather with a delay.
For the next coming days, I'll swap the Graupner ESC's and try those from Robbe and see if that makes any difference.
All the above I carried out on my desktop with Visual Studio 2005.
On the laptop (Win7 and VS 2008) I get an error message but the thing works. Also with delays up to 4 seconds before the digital switches back to 'low'. I always put a reference control like a servo on the form to verify that the connection works. It's just the reading of a digital switch that's acting a little strange. I attachted a screenshot with the error message.
The compiler warnings are not errors, nothing to worry about
I'm a happy man ! It works ! The 10K resistor does the job perfectly and the interference can be reduced by adjusting wires etc. Next thing now is to tidy it up a little bit and send you some pictures.
Btw, happy holidays and best whishes for a wonderfull new year.