View Full Version : Banner Sensor Programming Problem
I am having some trouble with the Banner Sensors (for detecting the white reflective line). We have the Banner Sensors wired up as I have read here in the forums (white OR black for Data on RC, blue for ground, brown for +). We currently have 2 Sensors: Sensor #1 is plugged into RC Digital IO port 1, and Sensor #2 is plugged into RC Digital IO port 18 (we have to use port 1 and 18 because our pin-wire connector is too fat on one side). When we power on the robot (and neither banner sensor detects anything), rc_dig_in01 broadcasts 257, and rc_dig_in18 broadcasts 0. If Sensor #1 detects something, rc_dig_in01 accordingly broadcasts 1. However, if Sensor #2 detects something, instead of changing rc_dig_in18 to 1, it changes rc_dig_in01 to 256, and rc_dig_in18 stays at 0. rc_dig_in18 is ALWAYS broadcasting zero! If both sensors detect something, then rc_dig_in01 broadcasts 0. I'm fairly certain this is a programming problem, but I am lost. I have 'rc_dig_in18 = INPUT' set in the User_Initialization() function, but can rc_dig_in18 not be programmed for Input? In the default_routine, it reads
relay8_fwd = !rc_dig_in18; /* Power pump only if pressure switch is off. */
So, what's going on? Can rc_dig_in18 only be used for some kind of pressure switch? I'm lost.
KenWittlief
23-02-2004, 19:16
Im more lost than you are - a digital input should only be able to give a value of 1 or 0
I have no idea how you are getting 256 or all those other values from a single bit pin
try searching your code on the variable names - maybe there is a stray equation someplace that is setting the bit variables to something else?
this is really strange.
deltacoder1020
23-02-2004, 21:08
Im more lost than you are - a digital input should only be able to give a value of 1 or 0
I have no idea how you are getting 256 or all those other values from a single bit pin
try searching your code on the variable names - maybe there is a stray equation someplace that is setting the bit variables to something else?
this is really strange.
the input you he's getting on rc_dig_in01 is actually 0 and 1, but it's being printf'd without being cast to an int - thus, the unsigned char value is being taken along with a second byte of padding, thus 0 + 256 = 256, and 1 + 256 = 257.
2Crisis, when you printf values, make sure you do it like this:
printf("dig in 1: %d", (int) rc_dig_in01);
make sure you have the banners wired correctly - the blue and brown wires for both sensors should be hooked up to a 20 amp fuse on your fuse panel, and either the white or the black wire (the same color for both sensors) should be hooked up to the SIG pin of the digital input port.
ZZII 527
23-02-2004, 21:37
We had a similar problem...in fact, it was exactly the same. We were getting 257 also and wondering how that was possible. Well, turns out the sensors were working fine, it was just printing the wrong numbers, if that is possible. Try printf-ing one at a time. I'm sure there is an explanation, I just have no idea what it is. :)
Thanks guys, it works now. I forgot about those unsigned chars :ahh: . When the #2 Sensor was plugged into rc_dig_in18, it still broadcasted a constant zero no matter what I did, so we soldered on new ends, and moved it to a different IO port... it now works correctly.
vBulletin® v3.6.4, Copyright ©2000-2017, Jelsoft Enterprises Ltd.