XBee wireless troubles
gennarobasso81
Posts: 84
thank you for looking at my post,
I am having some issues with the xbee. I read through the manual for reference and still not sure.
I am trying to make a wireless remote control for a boe bot.
Using:
1 x 2 axis joystick
2 x push buttons
2 x BS2
1 x lcd
so far i am still testing the xbee's to get a better understanding of them. I have code for making the pushbuttons make two leds light up. I would like to make the pushbuttons do preset servo actions.
eventually i would like to use the 2 axis joystick to control the servo's forward and back, left and right. The push buttons would be for a 90 degree turn left and right. The code is still in the begining stage.
the code above just controls two leds
The code below is an attemp to control servos in a faster response from the xbees. I am very new to this and dont fully understand all of pbasic and how everything works. so this is all trial and error.
any help is appreciated
I am having some issues with the xbee. I read through the manual for reference and still not sure.
I am trying to make a wireless remote control for a boe bot.
Using:
1 x 2 axis joystick
2 x push buttons
2 x BS2
1 x lcd
so far i am still testing the xbee's to get a better understanding of them. I have code for making the pushbuttons make two leds light up. I would like to make the pushbuttons do preset servo actions.
eventually i would like to use the 2 axis joystick to control the servo's forward and back, left and right. The push buttons would be for a 90 degree turn left and right. The code is still in the begining stage.
' {$STAMP BS2} ' {$PBASIC 2.5} '----------------[Initialize]--------------------------- PAUSE 5 SEROUT 2, 84, [22,12] SEROUT 2, 84,50, [22,17, "Hello", 13, "Geno"] PAUSE 1000 SEROUT 2, 84, [22,12] PAUSE 5 '---------------[Variables]----------------------------- LR VAR Word UD VAR Word btn1wrk VAR Byte btn2wrk VAR Byte '---------------[Constants]----------------------------- BUTTON btn1, 1, 0, 0, btn1Wrk,0, No_Press BUTTON btn2, 1, 0, 0, btn2Wrk,0, No_Press Btn1 PIN 6 Btn2 PIN 7 Tx PIN 14 ' XBee DIN Rx PIN 15 ' XBee DOUT stickUD CON 25 stickLD CON 25 led CON 0 led1 CON 1 '-------------------------[Main]--------------------------- Main: HIGH 13 PAUSE 2 RCTIME 13, 1, UD HIGH 12 PAUSE 2 RCTIME 12, 1, LR DEBUG HOME, "UD =", DEC UD, CLREOL, CR, "LR = ", DEC LR, CLREOL IF UD > stickUD + 2 THEN GOSUB Forward IF UD < stickUD - 2 THEN GOSUB Backwards IF UD = stickUD THEN GOSUB Clear IF LR > stickLD + 2 THEN GOSUB Right IF LR < stickLD - 2 THEN GOSUB Left IF LR = stickLD THEN GOSUB Clear IF btn1 =1 THEN DEBUG CR, "Button 1 pushed" GOSUB Left_Turn DEBUG CLS ENDIF IF btn2 = 1 THEN DEBUG CR, "Button 2 pushed" GOSUB Right_Turn DEBUG CLS ENDIF No_Press: GOTO main GOTO main '-------------------------[Sub Routine]----------------------- Forward: SEROUT 2,84, 20, [17, 128, "Forward"] PAUSE 200 RETURN Backwards: SEROUT 2, 84, 20, [17, 128, "Backwards"] PAUSE 200 RETURN Right: SEROUT 2, 84, 20, [17, 148, "Right"] PAUSE 200 RETURN Left: SEROUT 2, 84, 20, [17,148, "left"] PAUSE 200 RETURN Clear: SEROUT 2, 84, [12,17] PAUSE 200 RETURN Left_Turn: IF Btn1 = 1 THEN SEROUT 2, 84, ["Left", 13, "Turn"] SEROUT Tx, 84,[DEC 0,CR] PAUSE 500 IF Btn1 = 0 THEN SEROUT 2, 84, [12] PAUSE 5 RETURN Right_Turn: IF btn2 = 1 THEN SEROUT 2, 84, ["Right", 13, "Turn"] SEROUT Tx, 84, [DEC 1,CR] PAUSE 500 IF btn2 = 0 THEN SEROUT 2, 84, [12] PAUSE 5 RETURN
the code above just controls two leds
The code below is an attemp to control servos in a faster response from the xbees. I am very new to this and dont fully understand all of pbasic and how everything works. so this is all trial and error.
' {$STAMP BS2} ' {$PBASIC 2.5} ' ***************** Configure XBee in AT Command Mode PAUSE 500 DEBUG CLS,"Configuring XBee..." PAUSE 3000 ' Guard time SEROUT Tx,84,["+++"] ' Command Mode Sequence PAUSE 2000 ' Guard time SEROUT Tx,84,["ATGT 3,MY 0",CR] ' Set low guard time and Base address SEROUT TX,84,["ATCN",CR] ' Exit Command Mode '----------------[Initialize]--------------------------- PAUSE 5 SEROUT 2, 84, [22,12] SEROUT 2, 84,50, [22,17, "Hello", 13, "Geno"] PAUSE 1000 SEROUT 2, 84, [22,12] PAUSE 5 '---------------[Variables]----------------------------- LR VAR Word UD VAR Word btn1wrk VAR Byte btn2wrk VAR Byte '---------------[Constants]----------------------------- BUTTON btn1, 1, 0, 0, btn1Wrk,0, No_Press BUTTON btn2, 1, 0, 0, btn2Wrk,0, No_Press Btn1 PIN 6 Btn2 PIN 7 Tx PIN 14 ' XBee DIN Rx PIN 15 ' XBee DOUT stickUD CON 25 stickLD CON 25 led CON 0 led1 CON 1 '-------------------------[Main]--------------------------- Main: HIGH 13 PAUSE 2 RCTIME 13, 1, UD HIGH 12 PAUSE 2 RCTIME 12, 1, LR DEBUG HOME, "UD =", DEC UD, CLREOL, CR, "LR = ", DEC LR, CLREOL IF UD > stickUD + 2 THEN GOSUB Forward IF UD < stickUD - 2 THEN GOSUB Backwards IF UD = stickUD THEN GOSUB Clear IF LR > stickLD + 2 THEN GOSUB Right IF LR < stickLD - 2 THEN GOSUB Left IF LR = stickLD THEN GOSUB Clear IF btn1 =1 THEN DEBUG CR, "Button 1 pushed" GOSUB Left_Turn DEBUG CLS ENDIF IF btn2 = 1 THEN DEBUG CR, "Button 2 pushed" GOSUB Right_Turn DEBUG CLS ENDIF No_Press: GOTO main GOTO main '-------------------------[Sub Routine]----------------------- Forward: SEROUT 2,84, 20, [17, 128, "Forward"] PAUSE 200 RETURN Backwards: SEROUT 2, 84, 20, [17, 128, "Backwards"] PAUSE 200 RETURN Right: SEROUT 2, 84, 20, [17, 148, "Right"] PAUSE 200 RETURN Left: SEROUT 2, 84, 20, [17,148, "left"] PAUSE 200 RETURN Clear: SEROUT 2, 84, [12,17] PAUSE 200 RETURN Left_Turn: IF Btn1 = 1 THEN SEROUT 2, 84, ["Left", 13, "Turn"] SEROUT Tx, 84,[DEC 0,CR] PAUSE 500 IF Btn1 = 0 THEN SEROUT 2, 84, [12] PAUSE 5 RETURN Right_Turn: IF btn2 = 1 THEN SEROUT 2, 84, ["Right", 13, "Turn"] SEROUT Tx, 84, [DEC 1,CR] PAUSE 500 IF btn2 = 0 THEN SEROUT 2, 84, [12] PAUSE 5 RETURN
any help is appreciated
Comments
I notice that routines like Left_Turn and Right_Turn use indenting for nesting. That works for Spin and the Propeller, but doesn't exist in PBasic. Look at the examples for the IF statement in the PBasic manual.
thank you for replying...sorry it has been so long since i have been on to say thank you. Crazy month here had a baby then had hurricane sandy hit us directly. Just getting back to normal life now.
You are correct in ur observation though, i am new to programing and reading ever bit of info i can while working on a project at the same time.
so if the button command isnt the right command to use then what should i use?
Yeah, new babies and massive hurricanes have a way of distracting people. Glad things are getting back to normal although babies have a way of shifting that mark.
BUTTON is useful mostly if you need its auto-repeat capability, where holding down a key causes its action to repeat at some interval. Otherwise it is overkill. Straightforward code needs only a single bit variable to manage the button actions for key-up-transition, key-down-transition, key-held-up and key-held-down. I have a writeup on the inner workings of BUTTON posted at http://emesystems.com/BS2fsm.htm#BUTTON.
and the receiver
ok so i can use the 2 axis joy stick to move my bot around now. I just did the joystick for now but since i got it working i will try on the other features...maybe just the ping like graffix is trying. Anyway here is code
Base code:
Remote code: (Note: the Remote xbee is the boe-bot)