Push Buttons

I recently made the leap from using the BS2 microcontroller and BOE development board to the Basic Atom Pro 28 with Bot Board II. While I have been tremendously impressed with the extra processing power and speed of the Basic Atom Pro, the transition hasn’t been entirely painless and I’m still unable to accomplish certain tasks on the new platform. Right now push-button input is giving me the most trouble.

I’ve wired a momentary normally open switch to one of the Bot Board II inputs with signal and ground tied together on one side of the switch and the 5V input on the other. This is how I’ve been using buttons on the Parallax BOE development board. At the moment I’m using the following excerpt of code in my program:

[code]trigger CON 4 ’ Define I/O pin

’ ----- Variables ]----------------------------------------------------------

delay VAR Byte
rate VAR Byte
count1 VAR Byte

’ Specify trigger button operation
delay = 0
rate = 0

input trigger

’ ----- Main Routine ]-------------------------------------------------------

main: ’ Begin main routine.

'button trigger,0,delay,rate,count1,1,GET_PULSES

goto SERVO_PULSES

goto main[/code]

Currently this code does not register a button press and in fact causes the entire board to go dead and reset when I activate the switch. I thought that my switch and wiring method may be the problem so I tried the same code using ButA as the trigger:

[code]butA var bit

BUTTON_DOWN con 0
BUTTON_UP con 1

’ ----- Initialization ]-----------------------------------------------------

butA = 0

’ ----- Main Routine ]-------------------------------------------------------

main: ’ Begin main routine.

if (trigger = button_up) then
	goto get_pulses
else
	goto SERVO_PULSES
endif

goto main[/code]

Again, no luck. Am I missing something important? I have my jumpers configured exactly as shown in the Bot Board II tutorial. Does button operation require use of VS and VL combined rather than VS alone? Is there something wrong with my BBII? Any assistance would be appreciated.

Dan Toborowski
President
Central Illinois Robotics Club
circ.mtco.com

Hi Dan,

On the BB2 the 3 buttons are on IO pins 12, 13 and 14. Here is part of a program from that does stuff on these buttons:

;button init
buttonA var bit
buttonB var bit
buttonC var bit

prevA var bit
prevB var bit
prevC var bit

input p12
input p13
input p14

 sound 9,[50\3800, 50\4200, 40\4100]
 
 
main:
    prevA = buttonA
    prevB = buttonB
    prevC = buttonC

    buttonA = in12
    buttonB = in13
    buttonC = in14

    if (buttonA = 0) AND (prevA = 1) then
        ; do your button A stuff here.endif
    endif

   if (buttonB = 0) AND (prevB = 1) then
        ; do your button B stuff here.endif
   endif
 
   if (buttonC = 0) AND (prevC = 1)  then
        ; do your button C stuff here.
   endif
   pause 50 
goto main

I hope that helps.
Kurt

I tried the following code which should play a tone from the speaker when each button is pressed. The corresponding LEDs do activate when the buttons are pressed but no tones play. Viewing the program in DEBUG mode seems to show the button presses as not registering with the Atom.

[code];button init
buttonA var bit
buttonB var bit
buttonC var bit

prevA var bit
prevB var bit
prevC var bit

input p12
input p13
input p14

main:
prevA = buttonA
prevB = buttonB
prevC = buttonC

buttonA = in12
buttonB = in13
buttonC = in14

if (buttonA = 0) AND (prevA = 1) then
    sound 9,[100\3800]
endif

if (buttonB = 0) AND (prevB = 1) then
    sound 9,[100\4200]
endif

if (buttonC = 0) AND (prevC = 1) then
    sound 9,[100\4100]
endif
pause 50

goto main [/code]
This result is most disappointing because I cannot even verify the code for my additional button using the built in push buttons. Is there something that would cause none of the built-in nor additional buttons to function?

I would really appreciate sample code and a description of how to implement a separate wired momentary push button. This is the primary goal of my project and the biggest problem I’m currently facing.

Dan Toborowski
President
Central Illinois Robotics Club
circ.mtco.com

The first thing to verify is that you can play any sounds?

Note: I have a tendancy to not use debug mode that often as sometime timings get a bit off…

But the built-in stuff depends on the appropriate jumpers in place on the BB2. Looking at the BB2 document: lynxmotion.com/images/html/build151.htm#aglance
The jumpers are installed to enable the LEDS and buttons.
Likewise it needs the jumper next to the speaker to be installed to use the speaker.

The schematic that is linked to from the document shows an example of hooking up a hooking up a button. There are probably several ways to do it. When I did it in the past I would hook up a pull-up resister to the input line to normally pull it high, I would then hook up the switch, that when pressed would go to ground. I believe this is more or less how the built in switches are installed.

Kurt

I double-checked the jumpers and everything appears to be in order. Currently I have the DAT, CMD, and ATT jumpers installed but not the CLK. I also added a initialization tone to verify that the buzzer is indeed operational. I had been using p12 and p13 as outputs for servos unaware that ButtonA and ButtonB are also assigned to these same I/O’s. During an earlier test I was trying to use these buttons while operating the servos which I fear may have had a negative effect considering this description from the Bot Board tutorial:

If the board was damaged, would I still be able to use p12 and p13 with only the push-buttons no longer operational? Could the problem be caused by an issue with the Basic Atom Pro 28?

Dan Toborowski
President
Central Illinois Robotics Club
circ.mtco.com

Hrmmm, please describe with more detail. It’s not clear to me how you have the switch wired. I use the following for reading switches. Using 5vdc from the regulator, not VS or VL as these are raw battery voltages that go to the board. From your description it sounds like you have the switch wired wrong. That would cause a reset if something is shorting out.

[code]
(+) 5vdc
|
| 10k
o-----///-----o-----> To I/O pin
|
|
switch |
|
/ |
o------o o------o
| black green
|


-[/code]

Thanks for the explanation. It looks like the pull-up resistor was the problem. I switched to a 10K and it works perfectly now.

Dan Toborowski
President
Central Illinois Robotics Club
circ.mtco.com

Hey! Glad you got it going! Proof that all the code in the world will never fix a wiring error. lol :wink:

Unless of course, it’s a T800 with SkyNet code that can re-rout its circuits. :laughing: :smiling_imp: