240 is part of the binary math by applying a bitwise "AND" of 240 to the joystick value it creates a deadband so the joystick isnt jumpy. basically it rounds the joystick value to the nearest 16.
subtracting the joystick value from 255 inverts the value so one of the wheels acts opposite of the other.
if joystick x = 255
255 -x=0
if joystick x=0
255-x=255
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Have Fun
TR
Post Edited (TechnoRobbo) : 9/26/2006 12:57:49 AM GMT
9 bytes are read from the playstation controller into the "buff" array
Byte #0 is junk - ignore it
Byte #1 is a the joystick mode 41 --> Digital mode ,73 --> analog mode,F3 --> DS2 native mode
Byte #2 is 5A if the mode wasnt changed and 0 if it was
Byte #3 ARE 1/2 THE BUTTONS |LEFT|DOWN|RGHT| UP | STA| JL | JR | SEL|
Byte #4 is the other half | [noparse]/noparse | X | O | /\ | R1 | L1 | R2 | L2 | Each button is represented by a bit in the byte - 1 if not pushed 0 is pushed
Byte #5 is the right joystick left/right axis 0= left 255=right
Byte #6 is the right joystick up/down axis 0= up 255=down
Byte #7 is the left joystick left/right axis 0= left 255=right
Byte #8 is the left joystick up/down axis 0= up 255=down
"LOWBIT(?)" addresses the bit in the byte instead of the whole byte
the "~" inverts the bit 0=1 and 1=0
so if you press the "X" button the buff(4) byte will look like this in binary: ··································· 1 0 1 1 1 1 1 1
Bits are numbered like this·7 6 5 4 3 2 1 0
the zero is in the 6th bit position
So, in english the code means this:
tmpvar VAR byte -·computer, the label "tmpvar" refers to a byte
LED PIN 6·········· - coumputer, the label "LED" refers to pin6
tmpvar=buff(4)····- computer assign the contents of the 5th (starts with 0)·byte in th "buff" array to the byte called tmpvar
LED=~tmpvar.LOWBIT(6) - computer, assign the pin we labeled LED with the opposite value of bit 6 in the byte called tmpvar.
The Parallax documentation section offers lots of ideas. Use them as a jumping offpoint. Dream it then stop at nothing to build it. Learn basic electricity - Ohms Law and Kirschoffs Law are indispensible. Get yourself a multimeter if you dont have one. Troubleshooting is the key.
ok i have just bought a wireless mad catz and i found that it needs some kind of initalization sequence in order to work, it works fine in a ps2 but not in the bot, i have tried EVERY code in this forum and many others, and not one has worked. is there anyone who has found out how to initalize this controller, i would imagine it would not be that hard...
If you read this topic from the beginning you'll find that the madcatz requres a faster timing than the BS2 can deliver.
Pelican or a Thrustmaster work fine -
The initialization code for thrustmaster must exclude the "Set Native Mode" code else you will shift the bits.
Note: there are 2 sets of codes discussed in this topic Wireless and Wired -
With wireless Joysticks the first data bit ready before the first clock pulse
With wired joysticks the data is read in the middle of the clock pulse.
There are 2 schematics presented, 1 with a transistor (works best with wired) - one without (wireless)
the wireless code employs the Pulseout command.
the wired code uses Toggle or (Shiftin if your interface includes a transistor)
Read the thread from the beginning theres lots to download and study.
The Madcatz is a fine controller - very stable and centers it's joysticks nicely - I believe it's speed adds to it resolution during game play unfortunately it makes it the foil of the BS2
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Have Fun
TR
Post Edited (TechnoRobbo) : 9/28/2006 12:39:12 AM GMT
ya well i was thinking about doing this project on my own and actually wrote code strangely close to some of the stuff on here, but when it would not work i decided to check out the forums and found this... ah well e-bay is always an option because the store wont take it back (lucky me) anyway thanks for the help.
Hi, · I've been looking on the forum for a definitive answer as to whether or not the wireless PS2 controller will work to remotely control the BS2 Boe-Bot?· If so, does anyone know which applicable schematic to use and source code for a Pelican Chameleon PS2 Wireless Conroller to interface with the BS2 Boe-Bot?·
Thanks,
mrkak
Oh 1 more thing I recommend powering the servos from seperate power source than the bs2 (like 4 AA batteries in series) make sure to tie the negative from the batteries to the Vss of the BS2
Is it easier to run a seperate 5V power supply to the servos than to the PS2 RF reciever?· Do you have a schematic on how to wire the servos with a seperate power supply if this method is better?
Jumpers from the protoytpe board to the futaba plug and some electric tape may do the trick. Once you're satisfied with the result modify the plug on the servos.
Radio Shack has a 6v 4 AA holder cheap.
Servo wires:
Red to "+" on battery holder
Black to "-" on battery holder
white to BS2 pin
jumper the battery holder "-"· to the Vss and your done.
Hi Technorobbo,
I built the PS2 wireless BOE-Bot application to spec and it works great after a couple of minor changes to the code. Do you know if there is a significant difference between the Rev B USB Board of Education and Rev C Serial Board of Education that may be causing a command problem between the wireless control and the Rev G BS2 stamp. I was successful using the Rev B, but when I tried the same code and wiring on the Rev C the servos charge forward for a second and it goes into reverse from there and will not respond to the controller at all. I cycle the switch on and off on the Boe-Bot just to get the RF receiver to see the controller, but no commands are acknowledged by the Boe-bot. I double checked wiring and made sure I had good 5V at the applicable places, but I was wondering if I had a timing problem or something else and what I could do to resolve it.
If found the same issue when I was poweringup the servos from the Vdd. Thats why I tell everyone to use a 4AA supply for the servos making sure you share the Vss. Otherwise it seems that the Pelican Reciever is quite a draw and affects the Servos.·
If your using a 9v with your stamp you only have 400 mah(milliamp hours)·as compared to 1400 mah with a AA battery.
One other thought make sure your pelicans batteries are fresh.
· Thanks for the response.· I found that I had some poor contacts into the breadboard using the wires from the PS2 extension cable.· It appears to work fine on both rev b and rev c boards.· Do you know how I could use one of the other buttons (i.e. select, X, etc.) to switch boe-bot between using instructions loaded in the stamp and manual commands from the PS2 controller?
Below is an example gave before but you could modify it to jump to a second loop where your "auto"code is using an "if then" statement.·Then you can jump back using another "if then". One suggestion - if you can afford it get a PSC·board from Parallax·it will allow you to control the servos with out much programming allowing for better program control.
9 bytes are read from the playstation controller into the "buff" array
Byte #0 is junk - ignore it
Byte #1 is a the joystick mode 41 --> Digital mode ,73 --> analog mode,F3 --> DS2 native mode
Byte #2 is 5A if the mode wasnt changed and 0 if it was
Byte #3 ARE 1/2 THE BUTTONS |LEFT|DOWN|RGHT| UP | STA| JL | JR | SEL|
Byte #4 is the other half | [noparse]/noparse | X | O | /\ | R1 | L1 | R2 | L2 | Each button is represented by a bit in the byte - 1 if not pushed 0 is pushed
Byte #5 is the right joystick left/right axis 0= left 255=right
Byte #6 is the right joystick up/down axis 0= up 255=down
Byte #7 is the left joystick left/right axis 0= left 255=right
Byte #8 is the left joystick up/down axis 0= up 255=down
use "LOWBIT(?)" to address the bit in the byte instead of the whole byte
the "~" inverts the bit 0=1 and 1=0
so if you press the "X" button the buff(4) byte will look like this in binary: ··································· 1 0 1 1 1 1 1 1
Bits are numbered like this·7 6 5 4 3 2 1 0
the zero is in the 6th bit position
Example below:
tmpvar VAR byte -·computer, the label "tmpvar" refers to a byte
LED PIN 6·········· - coumputer, the label "LED" refers to pin6
tmpvar=buff(4)····- computer assign the contents of the 5th (starts with 0)·byte in th "buff" array to the byte called tmpvar
LED=~tmpvar.LOWBIT(6) - computer, assign the pin we labeled LED with the opposite value of bit 6 in the byte called tmpvar.
Hey TechnoRobbo, · I'll have to take a look at the PSC boards; I have never heard about them until you mentioned it.· Thanks a lot for the tip on programming some additional functions into this; this will help out a lot.
Hello, I have just gotten into this project. I have gotten a wired PS2 controller to work with my good old BS2, and now I want to try a Logitec cordless 'Action Controller.' The gamepad works with a PS2, but with the code pople have posted in this thread, the most I can get with a Stamp is the little green light on the reciever to blink. I can't get any data from the actual controller to the debug terminal.
I am confused as to whether I should use the transistor on the clock pin or not with the wireless controller. Also, what is the latest debug-output-only code for both circuits?
I also have heard that the regular BS2 is too slow to properly work with the faster gamepad, but I wanted to make sure I didn't have to spend an extra $80 on a new stamp if I don't need to.
You will have no luck with the logitec controller. I had also tried it out, but with no luck too.
You should haveone of the two controllers that work, Thrustmaster or Pelican.
I really enjoyed the NVN101 article. I also appreciate the contributions of turbo and others here. I've attached my BS2 hardwired version. I'll change the output to the screen to an LCD here shortly and repost. I'm using the code verbatim from the NVN article and it works well. My exceptions are I used a different set of pin outs.
I did have some problems getting the circuit setup however by trying to go w/o the transistor and resistors. This was a tragic mistake and I probablly burned out a pin or two... or 4. on my BS2. I still have to check this out for damage thoroughly but during debug, i decided to try shifting which pins I was operating on, and sure enough... it worked.
Here's a video of the debug to the computer screen:
Comments
subtracting the joystick value from 255 inverts the value so one of the wheels acts opposite of the other.
if joystick x = 255
255 -x=0
if joystick x=0
255-x=255
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Have Fun
TR
Post Edited (TechnoRobbo) : 9/26/2006 12:57:49 AM GMT
what about X, circle, square, and triangle code?
'Button Table:
'Bits 7 6 5 4 3 2 1 0
' | byte3 |LEFT|DOWN|RGHT| UP | STA| JL | JR | SEL|
' +
+----+----+----+----+----+----+----+----+
' | byte4 | [noparse]/noparse | X | O | /\ | R1 | L1 | R2 | L2 |
Sample Code:
tmpvar VAR byte ' temporary byte
LED PIN 6 'lets say an LED is Pin 6
tmpvar=buff(4) 'reassign data for bit addressing
LED=~tmpvar.LOWBIT(6) ' LED is assign the opposite of bit 6 byte 4
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Have Fun
TR
tmpvar=buff(4) 'does this mean byte4?
LED=~tmpvar.LOWBIT(6) 'whats LOWBIT(6)
im thinking what you mean is...
'Bits 7 6 5 4 3 2 1 0
' | byte3 |LEFT|DOWN|RGHT| UP | STA| JL | JR | SEL|
' +
+----+----+----+----+----+----+----+----+
' | byte4 | [noparse]/noparse | X | O | /\ | R1 | L1 | R2 | L2 |
'Bits 7 6 5 4 3 2 1 0
like does the code say (in english)
if X is down then light up PIN 6
Byte #0 is junk - ignore it
Byte #1 is a the joystick mode 41 --> Digital mode ,73 --> analog mode,F3 --> DS2 native mode
Byte #2 is 5A if the mode wasnt changed and 0 if it was
Byte #3 ARE 1/2 THE BUTTONS |LEFT|DOWN|RGHT| UP | STA| JL | JR | SEL|
Byte #4 is the other half | [noparse]/noparse | X | O | /\ | R1 | L1 | R2 | L2 |
Each button is represented by a bit in the byte - 1 if not pushed 0 is pushed
Byte #5 is the right joystick left/right axis 0= left 255=right
Byte #6 is the right joystick up/down axis 0= up 255=down
Byte #7 is the left joystick left/right axis 0= left 255=right
Byte #8 is the left joystick up/down axis 0= up 255=down
"LOWBIT(?)" addresses the bit in the byte instead of the whole byte
the "~" inverts the bit 0=1 and 1=0
so if you press the "X" button the buff(4) byte will look like this in binary:
··································· 1 0 1 1 1 1 1 1
Bits are numbered like this·7 6 5 4 3 2 1 0
the zero is in the 6th bit position
So, in english the code means this:
tmpvar VAR byte -·computer, the label "tmpvar" refers to a byte
LED PIN 6·········· - coumputer, the label "LED" refers to pin6
tmpvar=buff(4)····- computer assign the contents of the 5th (starts with 0)·byte in th "buff" array to the byte called tmpvar
LED=~tmpvar.LOWBIT(6) - computer, assign the pin we labeled LED with the opposite value of bit 6 in the byte called tmpvar.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Have Fun
TR
but one thing
i cant figure out how to make the code to work
is there a certain place to put it?
Example (new code is in black):
' {$STAMP BS2}
' {$PBASIC 2.5}
'i/o config
· '----[noparse][[/noparse]Declares an Equates]
· PsxAtt PIN 9 ' PSX joystick interface
· PsxClk PIN 8
· PsxCmd PIN 10
· PsxDat PIN 11
· ServoLeft PIN 12 'switch as necessary
· ServoRight PIN 13
·'--equates---
· buff VAR Byte(9)
· tmpout VAR Byte
· idx·· VAR Byte
· idy·· VAR Byte
· PWL VAR Word
· PWR VAR Word
· tmpvar VAR byte
· LED PIN 6·
· 'inits
· PAUSE 500 'give controller time to initialize
· OUTPUT PsxClk
· OUTPUT PsxAtt
· OUTPUT PsxCmd
· INPUT PsxDat
· HIGH PsxAtt
· HIGH PsxClk
··OUTPUT LED
· '----[noparse][[/noparse]Main Code]
· MAIN:
· DO
····tmpvar=buff(4) 'reassign data for bit addressing
····LED=~tmpvar.LOWBIT(6) ' LED is assign the opposite of bit 6 byte 4
··· PWL=(buff(8) & 240) + 637 'adjust for center
··· PWR=(255-buff(6)& 240) + 637 'adjust for center
··· GOSUB Get_PSX_Buttons
· LOOP
'
[noparse][[/noparse] Subroutines ]
· Get_PSX_Buttons:' This routine REQUIRES inverted clock signal from
··· OUTPUT PsxCmd
··· INPUT PsxDat
··· HIGH PsxClk
··· LOW PsxAtt
··· FOR idy = 0 TO 8
····· LOOKUP idy,[noparse][[/noparse]$01,$42,$00,$00,$00,$00,$00,$00,$00],tmpout
····· GOSUB BitSend
····· buff(idy)=tmpout
····· PULSOUT ServoLeft,PWL
····· PULSOUT ServoRight,PWR
··· NEXT
··· HIGH PsxAtt
··· HIGH PsxCmd
· RETURN
· BitSend:
··· FOR idx=0 TO 7
······ TOGGLE PsxClk
······ PsxCmd=tmpout.LOWBIT(idx)
······ tmpout.LOWBIT(idx)=PsxDat
······ TOGGLE PsxClk
······ 'PULSOUT PsxClk,1
··· NEXT
· RETURN
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Have Fun
TR
Post Edited (TechnoRobbo) : 9/27/2006 9:55:50 AM GMT
ill see if that works, i cant now, my sister is playing the sims 2
but you seem like your good with electronics
you mind telling me some projects to keep me busy?
thanks,
Weston
wouldnt it have something with
HIGH 6
and
LOW 6
because its a LED?
OUTPUT LED ' this sets pin 6 to output mode
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Have Fun
TR
I don't buy projects, I buy parts.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Have Fun
TR
Pelican or a Thrustmaster work fine -
The initialization code for thrustmaster must exclude the "Set Native Mode" code else you will shift the bits.
Note: there are 2 sets of codes discussed in this topic Wireless and Wired -
With wireless Joysticks the first data bit ready before the first clock pulse
With wired joysticks the data is read in the middle of the clock pulse.
There are 2 schematics presented, 1 with a transistor (works best with wired) - one without (wireless)
the wireless code employs the Pulseout command.
the wired code uses Toggle or (Shiftin if your interface includes a transistor)
Read the thread from the beginning theres lots to download and study.
The Madcatz is a fine controller - very stable and centers it's joysticks nicely - I believe it's speed adds to it resolution during game play unfortunately it makes it the foil of the BS2
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Have Fun
TR
Post Edited (TechnoRobbo) : 9/28/2006 12:39:12 AM GMT
· I've been looking on the forum for a definitive answer as to whether or not the wireless PS2 controller will work to remotely control the BS2 Boe-Bot?· If so, does anyone know which applicable schematic to use and source code for a Pelican Chameleon PS2 Wireless Conroller to interface with the BS2 Boe-Bot?·
Thanks,
mrkak
Make sure you press the analog button to go into analog mode. Left Joystick left wheel. right joystick right wheel.
Code follows:
' {$STAMP BS2}
' {$PBASIC 2.5}
'i/o config
· PsxAtt PIN 9 ' PSX joystick interface
· PsxClk PIN 8
· PsxCmd PIN 10
· PsxDat PIN 11
· ServoLeft PIN 12 'switch as necessary
· ServoRight PIN 13
·'--equates---
· buff VAR Byte(9)
· tmpout VAR Byte
· idx·· VAR Byte
· idy·· VAR Byte
· PWL VAR Word
· PWR VAR Word
· 'inits
· PAUSE 500 'give controller time to initialize
· OUTPUT PsxClk
· OUTPUT PsxAtt
· OUTPUT PsxCmd
· INPUT PsxDat
· HIGH PsxAtt
· HIGH PsxClk
· MAIN:
· DO
··· PWL=(buff(8) & 240) + 637 'adjust for center
··· PWR=(255-buff(6)& 240) + 637 'adjust for center
··· GOSUB Get_PSX_Buttons
· LOOP
'
[noparse][[/noparse] Subroutines ]
· Get_PSX_Buttons:
··· OUTPUT PsxCmd
··· INPUT PsxDat
··· HIGH PsxClk
··· LOW PsxAtt
··· FOR idy = 0 TO 8
····· LOOKUP idy,[noparse][[/noparse]$01,$42,$00,$00,$00,$00,$00,$00,$00],tmpout
····· GOSUB BitSend
····· buff(idy)=tmpout
····· PULSOUT ServoLeft,PWL
····· PULSOUT ServoRight,PWR
··· NEXT
··· HIGH PsxAtt
··· HIGH PsxCmd
· RETURN
· BitSend:
··· FOR idx=0 TO 7
······ PsxCmd=tmpout.LOWBIT(idx)
······ tmpout.LOWBIT(idx)=PsxDat
······ PULSOUT PsxClk,1
··· NEXT
· RETURN
'Code Ended
'
Use this interface with the code (don't bother with the 9 volts its for vibrating the wired controller):
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Have Fun
TR
Thanks a lot for your help; I'll try this out.
mrkak
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Have Fun
TR
Thanks,
mrkak
Radio Shack has a 6v 4 AA holder cheap.
Servo wires:
Red to "+" on battery holder
Black to "-" on battery holder
white to BS2 pin
jumper the battery holder "-"· to the Vss and your done.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Have Fun
TR
mrkak
I built the PS2 wireless BOE-Bot application to spec and it works great after a couple of minor changes to the code. Do you know if there is a significant difference between the Rev B USB Board of Education and Rev C Serial Board of Education that may be causing a command problem between the wireless control and the Rev G BS2 stamp. I was successful using the Rev B, but when I tried the same code and wiring on the Rev C the servos charge forward for a second and it goes into reverse from there and will not respond to the controller at all. I cycle the switch on and off on the Boe-Bot just to get the RF receiver to see the controller, but no commands are acknowledged by the Boe-bot. I double checked wiring and made sure I had good 5V at the applicable places, but I was wondering if I had a timing problem or something else and what I could do to resolve it.
Thanks,
mrkak
If your using a 9v with your stamp you only have 400 mah(milliamp hours)·as compared to 1400 mah with a AA battery.
One other thought make sure your pelicans batteries are fresh.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Have Fun
TR
· Thanks for the response.· I found that I had some poor contacts into the breadboard using the wires from the PS2 extension cable.· It appears to work fine on both rev b and rev c boards.· Do you know how I could use one of the other buttons (i.e. select, X, etc.) to switch boe-bot between using instructions loaded in the stamp and manual commands from the PS2 controller?
Thanks,
mrkak
http://www.parallax.com/detail.asp?product_id=28023
I highly recommend it.
9 bytes are read from the playstation controller into the "buff" array
Byte #0 is junk - ignore it
Byte #1 is a the joystick mode 41 --> Digital mode ,73 --> analog mode,F3 --> DS2 native mode
Byte #2 is 5A if the mode wasnt changed and 0 if it was
Byte #3 ARE 1/2 THE BUTTONS |LEFT|DOWN|RGHT| UP | STA| JL | JR | SEL|
Byte #4 is the other half | [noparse]/noparse | X | O | /\ | R1 | L1 | R2 | L2 |
Each button is represented by a bit in the byte - 1 if not pushed 0 is pushed
Byte #5 is the right joystick left/right axis 0= left 255=right
Byte #6 is the right joystick up/down axis 0= up 255=down
Byte #7 is the left joystick left/right axis 0= left 255=right
Byte #8 is the left joystick up/down axis 0= up 255=down
use "LOWBIT(?)" to address the bit in the byte instead of the whole byte
the "~" inverts the bit 0=1 and 1=0
so if you press the "X" button the buff(4) byte will look like this in binary:
··································· 1 0 1 1 1 1 1 1
Bits are numbered like this·7 6 5 4 3 2 1 0
the zero is in the 6th bit position
Example below:
tmpvar VAR byte -·computer, the label "tmpvar" refers to a byte
LED PIN 6·········· - coumputer, the label "LED" refers to pin6
tmpvar=buff(4)····- computer assign the contents of the 5th (starts with 0)·byte in th "buff" array to the byte called tmpvar
LED=~tmpvar.LOWBIT(6) - computer, assign the pin we labeled LED with the opposite value of bit 6 in the byte called tmpvar.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Have Fun
TR
· I'll have to take a look at the PSC boards; I have never heard about them until you mentioned it.· Thanks a lot for the tip on programming some additional functions into this; this will help out a lot.
mrkak
I am confused as to whether I should use the transistor on the clock pin or not with the wireless controller. Also, what is the latest debug-output-only code for both circuits?
I also have heard that the regular BS2 is too slow to properly work with the faster gamepad, but I wanted to make sure I didn't have to spend an extra $80 on a new stamp if I don't need to.
You should haveone of the two controllers that work, Thrustmaster or Pelican.
michael
Post Edited By Moderator (Chris Savage (Parallax)) : 1/8/2007 5:07:28 PM GMT
I did have some problems getting the circuit setup however by trying to go w/o the transistor and resistors. This was a tragic mistake and I probablly burned out a pin or two... or 4. on my BS2. I still have to check this out for damage thoroughly but during debug, i decided to try shifting which pins I was operating on, and sure enough... it worked.
Here's a video of the debug to the computer screen:
www.youtube.com/v/Ay0KCS-3RaA&hl=en&fs=1