I would think it would be run off of 5v. That is what mine used, and it would connect into the same ps2 port, so I don't know how it could be anything else.
Look at the psx pin out I linked to and the pin number I posted as well.
Good luck.
I would think it would be run off of 5v. That is what mine used, and it would connect into the same ps2 port, so I don't know how it could be anything else.
Look at the psx pin out I linked to and the pin number I posted as well.
Good luck.
HI i'm using the psx and psx libraries from arduino webpage and apear this error:
arduino-0017/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:110: error: expected unqualified-id before 'int'
arduino-0017/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:110: error: expected `)' before 'int'
arduino-0017/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:110: error: expected `)' before 'int'
I don't now what happens and how to solve because if i modify this document will have repercusions in the arduino uses or what? I need help!
This or a code that rolls without libraries.
Thanks and sorry if my english is bad or very bad isn't my 1st lenguage
has anyone tried using the PS3 controller with the arduino mega, essientially I am trying to control a RC Car with a PS3 controller, and Im using Arduino Mega.
hey guys..
i, super new at this and i'm uploading shutter's program..
it compiles fine but it doesn't seem to work..
the readout just goes nuts and displays a bunch of commands really fast..
im using a ps2 controller if that matters....
help pleaaase
im using the arduino mega if that makes a difference
If you are getting fast comm, but it is legible, it is updates on a regular basis. Probably just too fast to read.
If it is gibberish, play with your comm settings they have to match between the arduino and the computer.
I hope that helps.
Don803
thnks!!
i'm guessing its going to fast.. how do i change this?
the controller pins are inserted in the analog correct??
some more info..
im not touching the controller and i get these fast readouts..
any ideas on how to fix it??
Oh wow, I had no idea this code has been usefull to so many people ![]()
I never enabled notifing to replies on this topic!
I think I should actually finish the librarry then seing it still work, which it should because I wrote it without using much of of the arduino librarry.
Oh boy, this code could use some improvments XD
OK, lets look at the At the Arduino Mega Schematic

AH there is your problem :3
/* These are AVR PORTB pins, +8 to convert to Arduino pins */
#define PS2clk 5
#define PS2cmd 3
#define PS2att 2
#define PS2dat 4
#define PS2PORT PORTB
#define PS2IN PINB
#define CTRL_CLK 20
#define CTRL_BYTE_DELAY 20
PORTB2 and PORTB3 are not hooked up to pins that you can use...Easily
the pins we are going to to be using are these here:

Ill be right back to help after I get the snow off my trees. ;D
Also, I think I will improve this code to make it easier for people to use, and i will add lots of coments.
I am snowed in the house so it will give me something to work on ![]()
Sorry I didn't see all of these replies!
Update:
I finished re-writting the code a bit, I need to test it out and see how well it works ![]()
I have an arduino Decimilla and Mega and I will see how it preforms on both.
Hi, i have a very similar problem to Pol_c_j however i am using version 0018.
I can compile shutter's code, however when i attempt to compile the Psx library from arduino playground i get the same errors as above.
this is for every contributed library i place in \my documents\Arduino\Libraries. NOT for a library that is included with the software.
can someone please tell me if it is a mistake on my part or if there is something wrong with the 0018 environment
Sounds like a problem with the enviorment
What are the compiler errors?
thanks for replying
i get the following errors
c:/documents and settings/haroon/desktop/arduino-0018/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:111: error: expected unqualified-id before 'int'
c:/documents and settings/haroon/desktop/arduino-0018/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:111: error: expected `)' before 'int'
c:/documents and settings/haroon/desktop/arduino-0018/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:111: error: expected `)' before 'int'
i have tried other libraries and it works on and off eg AFMotor library
works, But the test library does not (from arduino website)
thanks
Thanks Shutter for replying but i have found the solution to this problem (I think it works for me)
The solution was to replace
#include "WConstants.h"
with #include "WProgram.h"
in Psx.h
The member mem explained the problem
"WConstants.h includes wiring.h and it is that file when included in a sketch that causes the problem.
The errors are because wiring.h defines macros for abs and round that conflict with function names in a system header file called math.h
Avoid including wiring,h (or WConstants.h) prevents this problem."
thanks again
Ok, So should I make this code into an Update PSx lib or what?
yes please.. ![]()
is there still trouble with the Arduino Mega...?
do you think i should just use the Arduino Duemilanove ?
you've been super helpful!
i can't wait to get it working on thrusday!!
Nah, It is not a big deal, I THink it should work. Ill post the new code.
great!! you've been super helpful
i will be testing the code tomorrow.. hope all goes well
I optomized PSButton() -
It is now:
uint16_t buttons = *(uint16_t*)(PS2data+3);
return (~buttons & button > 0);
instead of
int byte = 3;
if (button >= 0x100) {
byte = 4;
button = button >> 8;
}
if (~PS2data[byte] & button)
return true;
else
return false;
#include <math.h>
#include <stdio.h>
#include <stdint.h>
#include <avr/io.h>
#define LED_PIN 13
#define DELAY(wait) digitalWrite(LED_PIN,LOW); delay(wait); digitalWrite(LED_PIN,HIGH);
/* These are AVR PORTB pins, +8 to convert to Arduino pins */
#if defined(__AVR_ATmega1280__)
//PortB pin mapping on arduino Mega
#pragma message("Arduino Mega")
#define PS2clk 7 //13
#define PS2cmd 5 //11
#define PS2att 4 //10
#define PS2dat 6 //12
#else
#pragma message("Arduino")
//PortB mapping on arduino168/8 bassed boards
#define PS2clk 5 //13
#define PS2cmd 3 //11
#define PS2att 2 //10
#define PS2dat 4 //12
#endif
#define PS2PORT PORTB
#define PS2IN PINB
#define PS2DDR DDRB
#define CTRL_CLK 20
#define CTRL_BYTE_DELAY 20
//These are our button constants
#define PSB_SELECT 0x0001
#define PSB_L3 0x0002
#define PSB_R3 0x0004
#define PSB_START 0x0008
#define PSB_PAD_UP 0x0010
#define PSB_PAD_RIGHT 0x0020
#define PSB_PAD_DOWN 0x0040
#define PSB_PAD_LEFT 0x0080
#define PSB_L2 0x0100
#define PSB_R2 0x0200
#define PSB_L1 0x0400
#define PSB_R1 0x0800
#define PSB_GREEN 0x1000
#define PSB_RED 0x2000
#define PSB_BLUE 0x4000
#define PSB_PINK 0x8000
#define SET(x,y) (x|=(1<<y))
#define CLR(x,y) (x&=(~(1<<y)))
#define CHK(x,y) (x & (1<<y))
#define TOG(x,y) (x^=(1<<y))
boolean PSButton(uint16_t button);
unsigned char PS2data[9];
void read_gamepad();
void config_gampad();
unsigned char get_gamepad_mode();
unsigned char i;
void setup() {
Serial.begin(57600);
pinMode(LED_PIN,OUTPUT);
digitalWrite(LED_PIN,HIGH);
//similar to pinmod(pin,OUTPUT)
//Setting up the pin to be output
SET(PS2DDR,PS2clk);
SET(PS2DDR,PS2att);
SET(PS2DDR,PS2cmd);
//Sets pin to Input mode
CLR(PS2DDR,PS2dat);
SET(PS2PORT,PS2dat);
config_gampad();
}
void loop () {
read_gamepad();
if(PSButton(PSB_SELECT))
Serial.print("Select\n");
if(PSButton(PSB_L3))
Serial.print("L3\n");
if(PSButton(PSB_R3))
Serial.print("R3\n");
if(PSButton(PSB_START))
Serial.print("Start\n");
if(PSButton(PSB_PAD_UP))
Serial.print("Up\n");
if(PSButton(PSB_PAD_RIGHT))
Serial.print("Right\n");
if(PSButton(PSB_PAD_LEFT))
Serial.print("LEFT\n");
if(PSButton(PSB_PAD_DOWN))
Serial.print("DOWN\n");
if(PSButton(PSB_L1))
Serial.print("L1\n");
if(PSButton(PSB_R1))
Serial.print("R1\n");
if(PSButton(PSB_L2))
Serial.print("L2\n");
if(PSButton(PSB_R2))
Serial.print("R2\n");
if(PSButton(PSB_GREEN))
Serial.print("Triangle\n");
if(PSButton(PSB_RED))
Serial.print("Circle\n");
if(PSButton(PSB_PINK))
Serial.print("Square\n");
if(PSButton(PSB_BLUE))
Serial.print("X\n");
}
boolean PSButton(uint16_t button) {
uint16_t buttons = *(uint16_t*)(PS2data+3);
return (~buttons & button > 0);
}
unsigned char _gamepad_shiftinout (char byte) {
unsigned char tmp = 0;
for(i=0;i<8;i++) {
if(CHK(byte,i)) SET(PS2PORT,PS2cmd);
else CLR(PS2PORT,PS2cmd);
CLR(PS2PORT,PS2clk);
delayMicroseconds(CTRL_CLK);
if(CHK(PS2IN,PS2dat)) SET(tmp,i);
SET(PS2PORT,PS2clk);
}
SET(PS2PORT,PS2cmd);
delayMicroseconds(CTRL_BYTE_DELAY);
return tmp;
}
void _gamepad_shiftout (char byte) {
for(i=0;i<8;i++) {
if(CHK(byte,i)) SET(PS2PORT,PS2cmd);
else CLR(PS2PORT,PS2cmd);
CLR(PS2PORT,PS2clk);
delayMicroseconds(CTRL_CLK);
SET(PS2PORT,PS2clk);
//delayMicroseconds(CTRL_CLK);
}
SET(PS2PORT,PS2cmd);
delayMicroseconds(CTRL_BYTE_DELAY);
}
unsigned char _gamepad_shiftin() {
unsigned char tmp = 0;
for(i=0;i<8;i++) {
CLR(PS2PORT,PS2cmd);
CLR(PS2PORT,PS2clk);
delayMicroseconds(CTRL_CLK);
if(CHK(PS2IN,PS2dat)) SET(tmp,i);
SET(PS2PORT,PS2clk);
delayMicroseconds(CTRL_CLK);
}
SET(PS2PORT,PS2cmd);
delayMicroseconds(CTRL_BYTE_DELAY);
return tmp;
}
void read_gamepad() {
SET(PS2PORT,PS2cmd);
SET(PS2PORT,PS2clk);
CLR(PS2PORT,PS2att); // low enable joystick
delayMicroseconds(CTRL_BYTE_DELAY);
//Send the command to send button and joystick data;
char dword[9] = {0x01,0x42,0,0,0,0,0,0,0};
for (int i = 0; i<9; i++) {
PS2data[i] = _gamepad_shiftinout(dword[i]);
}
SET(PS2PORT,PS2att); // HI disable joystick
}
unsigned char get_gamepad_mode() {
SET(PS2PORT,PS2cmd);
SET(PS2PORT,PS2clk);
CLR(PS2PORT,PS2att); // low enable joystick
_gamepad_shiftout(0x01);
unsigned char x = _gamepad_shiftin();
SET(PS2PORT,PS2att); // HI disable joystick
return x;
}
void config_gampad() {
SET(PS2PORT,PS2cmd);
SET(PS2PORT,PS2clk);
CLR(PS2PORT,PS2att); // low enable joystick
_gamepad_shiftout(0x01);
_gamepad_shiftout(0x43);
_gamepad_shiftout(0x00);
_gamepad_shiftout(0x01);
_gamepad_shiftout(0x00);
// Lock to Analog Mode on Stick
_gamepad_shiftout(0x01);
_gamepad_shiftout(0x44);
_gamepad_shiftout(0x00);
_gamepad_shiftout(0x01);
_gamepad_shiftout(0x03);
_gamepad_shiftout(0x00);
_gamepad_shiftout(0x00);
_gamepad_shiftout(0x00);
_gamepad_shiftout(0x00);
// Vibration
/*
_gamepad_shiftout(0x01);
_gamepad_shiftout(0x4D);
_gamepad_shiftout(0x00);
_gamepad_shiftout(0x00);
_gamepad_shiftout(0x01);
*/
_gamepad_shiftout(0x01);
_gamepad_shiftout(0x4F);
_gamepad_shiftout(0x00);
_gamepad_shiftout(0xFF);
_gamepad_shiftout(0xFF);
_gamepad_shiftout(0x03);
_gamepad_shiftout(0x00);
_gamepad_shiftout(0x00);
_gamepad_shiftout(0x00);
_gamepad_shiftout(0x01);
_gamepad_shiftout(0x43);
_gamepad_shiftout(0x00);
_gamepad_shiftout(0x00);
_gamepad_shiftout(0x5A);
_gamepad_shiftout(0x5A);
_gamepad_shiftout(0x5A);
_gamepad_shiftout(0x5A);
_gamepad_shiftout(0x5A);
SET(PS2PORT,PS2att);
}
A well made guide
has anyone tested the new code..
it is not working for me.. ![]()