PhG
Hi DJ,
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.
Best regards,
PhG
That's good code. That will work just great.
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
Yeah I know about the pull-down res. As a matter of fact, I have 2 switches to try different things. And one switch is indeed with a 10K res. I always have my 10K res. close at hand 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 ?
Oh, you can't use it on a Form Load event because the connection hasn't been established yet. So it's just returning some value.
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.
Hi DJ,
Weird things going on over here....
First let me explain. I'm testing the EZ-B at 2 computers (not at the same time) :
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
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.
PhG
Zip up your project and upload it here. Use the Attach File option to upload the ZIP. I don't have the time to teach you to program - but i can give you this example file. My advice is to follow some basic programming courses online, or see if there are any offered at your schools.
Here is my tutorial sample: VB-Tutorial02-GetDigital.zip
I have a bachelors degree in computers/programming and handle programming reasonably well. My programming skills do have a layer of dust on top, but I'm catching up and resuming quickly. It's the EZ-B that environment that puzzles me. Anyway, I'll prepare a zip folder and upload it by next week.
Did you try my tutorial zip that i posted above?
Hi DJ,
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 !
Best regards,
PhG
if you have ever hooked up the battery directly to the ez-b, then you may have blown the digital port transistor.
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
Guess what.... it works ! 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.
If the ESC is causing interference, then the line must be floating. You will need a 10K resistor across the Digital I/O Signal and GND (as a pull-down resistor). That will hold the signal low until the switch is flipped.
The compiler warnings are not errors, nothing to worry about
DJ,
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.
Best regards,
PhG
Thanx dude