PDA

View Full Version : [Question(s)] arbotix digital pins and board turning on and off



06-23-2010, 02:43 PM
Guys and Gals,

Here is a question that I asked Vanadium labs about the Arbotix board. They asked me to post it here. If any of you can help, please do. Thanks, pm






Pat,

Could I ask you to post this to either the Trossen forum -- I promise we'll work through the issues -- it's just that I can see many people having this same foot sensor problem, and I have a very long response to come back to you about it, that I'd like the whole community to benefit from..

Sound OK?

-Mike

On Wed, Jun 23, 2010 at 3:06 PM, <[email protected]> wrote:
Hey Vanadium Lab dudes,

I have an arbotix board that I am doing bioloid stuff with. So far it works real good, I am using the xbee radios also to provide feedback.

I am working on a quadruped and it has foot contact switches. I have wired them into digital inputs 0 to 3. I have been using digital 7 as a test switch. I am having trouble getting consistent readings from pins 0 to 3, so as sanity check I checked all the switches on pin 7 and they work fine. I have noticed though that when the digital switch wires wiggle the board turns off. If I wiggle the wires a bit more it will come back on. It seems to be near pin 7 that effects it the most.

So, any help on the consistency and turn on/turn off would be great.

Here is the code:

pinMode(0, INPUT);
p0 = digitalRead(0);
delay(10);
Serial.print("pin "); Serial.print(0); Serial.print(" : = "); Serial.println(p0);

pinMode(1, INPUT);
p1 = digitalRead(1);
delay(10);
Serial.print("pin "); Serial.print(1); Serial.print(" : = "); Serial.println(p1);

pinMode(2, INPUT);
p2 = digitalRead(2);
delay(10);
Serial.print("pin "); Serial.print(2); Serial.print(" : = "); Serial.println(p2);

pinMode(3, INPUT);
p3 = digitalRead(3);
delay(10);
Serial.print("pin "); Serial.print(3); Serial.print(" : = "); Serial.println(p3);


/* Initialize the pushbutton pin as an input: */
pinMode(7, INPUT);
p7 = digitalRead(7);
delay(10);
Serial.print("pin 7 = "); Serial.println(p7);
Serial.println(" ");

I'll try switching to analog for now. Thanks, pm

lnxfergy
06-23-2010, 03:02 PM
Thanks for posting here Patrick. I notice quite a few people trying out foot sensors (I have been myself), and think we'll probably see some of this show up from time to time, so I wanted to get this response out there for the community.

We may need just a bit more information from you. How are your switches wired up? Typically I put the switch between ground and the pin on the Arduino that will do the measuring. I can then use the internal pullup of the Arduino to get a steady HIGH when the switch is not pressed, and a nice LOW when it is.

If you don't have a pullup resistor installed externally, you'll want to turn the pullup resistor in the Arduino on for each port, for pin digital 1 this would look like:

pinMode(1, INPUT); // make it an input, as you have been
digitalWrite(1, HIGH); // this turns on the pullup resistor

An issue that might also occur with foot sensors is switch bounce. The contact doesn't make perfect closure at first and so the signal bounces between high and low a bit. If you read at just the right time, you might get an incorrect value because of this.

Also, be careful here, the user LED is connected to pin 0, so I'd suggest using 1-4 instead of 0-3.

Another thing to note is that the Arduino digitalRead() is pretty slow (it's very general purpose, but because of that it takes a lot of clock cycles). It's probably not an issue now, but later on, you may find that it's not fast enough if you have a very high rate loop reading the foot sensor. In this case, it'd be time to revert to using the faster, but slightly more complex AVR register reads. The digital 0-7 pins are on AVR port B on the ArbotiX. So, we can query the whole 8 pins using the PINB register. We can then use hexadecimal bitmasks to check individual ports:

if (PINB & 0x02) // will be true if digital 1 is high
if (PINB & 0x04) // will be true if digital 2 is high
if (PINB & 0x08) // will be true if digital 3 is high
if (PINB & 0x10) // will be true if digital 4 is high...

As for resetting the board, I can't see how this is happening unless you're getting a short? Knowing how you're wiring the switches would help here too.

-Fergs

jes1510
06-23-2010, 03:35 PM
I agree with Fergs that we need to know how everything is wired. My first thought is that you don't have the pullups enabled. That would cause all kinds of funkyness.

Secondly your code looks like it would be pretty bouncy. Your going to want to debounce it to remove some of the ugliness that is inherent in these things. Something like this pseudoCode usually works pretty well if you don't care about speed but it does work in a non-blocking fashion (note I have no way to test this right now) :



void setup(){
long startTime = millis(); // a Var to hold the time
int threshold = 10; // Number of mS to debounce
}

if(digitalRead(0) == 0) { // check the pin
if (millis() - startTime > threshold) { // wait 10mS
if (digitalRead(0) == 0) { // Only do this stuff if it's still low after the threshold time
doStuff() ;
startTime = millis(); // reset the counter

}
}

06-24-2010, 09:14 AM
Hey Dudes and Dudettes,

Thanks for all the help. I had talked to Mr. Ferguson on regular email and here is the our conversation, pretty much.

(Me talking to Mike)
Dude (Mike),
I read the explation about the pin sensitivity. I noticed that on my pin 7 switch a while back. I could just touch my fingers to the two wires (not connected) and the input would go high. So I tried this:

pinMode(0, INPUT);
digitalWrite(0, HIGH);
pinMode(1, INPUT);
digitalWrite(1, HIGH);
pinMode(2, INPUT);
digitalWrite(2, HIGH);
pinMode(3, INPUT);
digitalWrite(3, HIGH);

From the arduino web site, makes sense, so all switches were high for quite some time, now they are back to acting odd. So I am guessing I need to wire a resistor into the circuit or something? pm



(Now its Mike talking to me)
Yeah, since the pins have very high impedance, a very low current (what is conducted on your skin) can change the port.

How are your switches wired though? From the arduino pin to ground, is that correct?

(Me talking to Mike)
Mike,
Here is what I did. I am using a Vex touch sensor as my foot switch. On the Arbotix board I used if you plug a servo wire extender (black, red, yellow) in the digital port with the black wire to the side away from the chip, like it said in the little manual, I use the red and yellow wires as my switch wires. I think I tried using the other ones but it did not work. I think I tested red as source voltage and yellow as signal that the board reads. Does that make sense? pm

(Mike's reply)
Is it this guy: http://www.vexrobotics.com/products/accessories/sensors/276-2159.html ?

If so, they say black is ground, red is N/C, and yellow is the output -- they also specify that the microcontroller (in our case, teh ArbotiX), should pull the line to 5V, so you have to turn on the pullup resistor. So you should be fine plugging it into the way you are, it doesn't use the red at all, just the black and yellow wires -- but you have to enable the pullup resistor or the readings are going to be absolutely funky. You should put the pinMode() and digitalWrite() calls in the beginning of your setup() function, and be good to go for the rest of your program.

-Fergs

(Me again)
Somewhere in here I told Mike that I was using a VEX touch sensor, not the bump sensor, but they are wired the same way.

So should I rewire it back straight and do the the pinMode() and digitalWrite() thing. Straight = Arbotix BRY to Vex BRW. pm PS gotta go to workout joint. Thanks, will contact you again ASAP. pm

(Mikes reply)
Yeah, that's the way it should be wired -- black to black, red to red, signal to signal, and you'll have to enable the pullup with the digitalWrite().


So, I'll rewire it and let you know what happens. Thanks again. pm

06-24-2010, 12:07 PM
Okay Guys and Gals,

Here it is and it seems to work.

#include <stdarg.h>

// need to include header files, you can do this in the Arduino IDE, by selecting Sketch|Import Library|Bioloid.
#include <ax12.h>
#include <BioloidController.h>


void setup(){

/* Initialize the pushbutton pin as an input: */
pinMode(1, INPUT); // make it an input, as you have been
digitalWrite(1, HIGH); // this turns on the pullup resistor
pinMode(2, INPUT); // make it an input, as you have been
digitalWrite(2, HIGH); // this turns on the pullup resistor
pinMode(3, INPUT); // make it an input, as you have been
digitalWrite(3, HIGH); // this turns on the pullup resistor
pinMode(4, INPUT); // make it an input, as you have been
digitalWrite(4, HIGH); // this turns on the pullup resistor

pinMode(7, INPUT); // make it an input, as you have been
digitalWrite(7, HIGH); // this turns on the pullup resistor

Serial.begin(9600);
Serial.println("Hello TV Land!!");
}

void loop(){
int p1, p2, p3, p4, p7;

Serial.println(" ");

p1 = digitalRead(1);
delay(10);
Serial.print("pin "); Serial.print(1); Serial.print(" : = "); Serial.println(p1);

p2 = digitalRead(2);
delay(10);
Serial.print("pin "); Serial.print(2); Serial.print(" : = "); Serial.println(p2);

p3 = digitalRead(3);
delay(10);
Serial.print("pin "); Serial.print(3); Serial.print(" : = "); Serial.println(p3);

p4 = digitalRead(4);
delay(10);
Serial.print("pin "); Serial.print(4); Serial.print(" : = "); Serial.println(p4);

p7 = digitalRead(7);
delay(10);
Serial.print("pin "); Serial.print(7); Serial.print(" : = "); Serial.println(p7);


/* Wait one second. */
delay(1000);
}

The output of the line will be a 1 if the switch is open, a 0 if it is closed. Also of note, the VEX wire extensions fit loosely on the Arbotix board, so be careful there. One other thing, Arduino can eat your code (not save it) so be real careful there. Save you stuff, exit Arduino, come back in and it should be okay. Thanks again, pm :veryhappy::happy::tongue::wink::rolleyes::cool: