arduino and ppjoy protocol - arduino as joystick ?

Hi all,

any one have coded protocol for linking an Arduino with the ppJoy virtual joystick Yahoo | Mail, Weather, Search, Politics, News, Finance, Sports & Videos ???
I'm looking a way to using arduino as joystick interface in windows and it seam that this is an good startup to deal with :
we can input serial data in ppjoy with com port or use the ppm pulse and create a virtual joystick from arduino. I don't know really the byte order for now but if someone as an idea about it ....

Bye.

fbm

Hi fbm,

I think there was some code posted on a thread somewhere here a while ago for generating multichannel PPM signal that should be suitable for driving ppjoy.

If you can't find anything, let me know and I will try and dust off some old code using timer1 to generate pulses that simulated the 'training port' output of a six channel transmitter.

hi mem !

thank's for your answer.
Don't find any old trade about ppm multichanel on the forum ....
maiby i don't looking for the good word...

i have found this on the net for general purpose about joystick :

http://www.epanorama.net/documents/joystick/pc_joystick.html

if you remenber about this old code.. :slight_smile:

well,

i have found this information on the web from man who made an interface for ppjpy....2log.de

One of the ppjoy HMS protocol is from tis type :

One byte with 0xF0 + a number of channel (for synchro)
and channel byte maped between 0x00 and 0xEF
at the baudrat of 9600 with first channel reserved for 0x00
exemple for 6 channel : 0xF6 0x00 0xF8 0xF8 0xF8 0xF8 0xF8 0xF6 ....ect

and an auther is at 19200 baud :
Sync Byte which is constant 0xFF plus as many bytes that map the transmitters channels between 0x00 and 0xFE

exemple : 0xFF 0xF8 0xF8 0xF8 0xF8 0xF8 0xFF 0xF8.....ect
for 5 channel.

so, for the first metod i writing this code :

#define joyPin 2

void setup(){

Serial.begin(9600);
pinMode(joyPin,INPUT);
}

void loop(){
int joyYvalue=analogRead(joyPin);
joyYvalue/=2;

Serial.print(0xF5);
Serial.print(0x00)
Serial.print(0x80);
Serial.print(0x80);
Serial.print(0x80);
Serial.print(joyYvalue);

delay(100);
}

and ppjoy com can seen the arduino serial...but give me a message with "invalide synchro byte"...

don't know why !

.....;(

Not sure if this is the problem, but in yr code joyYvalue is an int, not a byte, try the following

void loop(){
byte joyYvalue=analogRead(joyPin) / 4
if(joyYvalue > 0xEF)
joyYvalue = 0xEF ;

Serial.print(0xF5);
Serial.print(0x00)
Serial.print(0x80);
Serial.print(0x80);
Serial.print(0x80);
Serial.print(joyYvalue);

delay(100);
}

p.s. sorry I missed yr earlier reply to my post. if you still need some code to generate PPM then let me know.

hi mem,

thanks for the tip.
but nothing to do with the ppjoy pbm....
i think about that delay between bytes packet can do a pbm for the sync....what do you thinc about ?
it's a pause...then the bytes pack...then pause...ans so fort...

p.s. nope about your missed..:wink:

this page http://www.welwyn.demon.co.uk/fms_lead/fms_lead.htm says the protocol is as follows:

Serial Protocol Used
The serial output is at 9600 baud, 8 data bits, No parity and 1 stop bit. The first character will be in the range 241 to 248 decimal, this is made up from 240 + the number of pulses measured. The second character contains the status of 4 push buttons that can be connected to the interface unit. The third to last (max 16) characters contain the values of the control channel pulses. Decimal 100 = 1mS, 200 = 2mS.

This implies you need to send an additional byte after the synch, try it and see if that helps.

testing with this 2 type of protocol :

Serial.print(0xF4);
Serial.print(0x00);
Serial.print(0x80);
Serial.print(0x80);
Serial.print(0x80);
Serial.print(0x80);

and :

Serial.print(0xF5);
Serial.print(0x00);
Serial.print(0x80);
Serial.print(0x80);
Serial.print(0x80);
Serial.print(0x80);

.....but sam result...;(

Any luck with this? I'm just starting to think about how to make a joystick device for the mac based on arduino output and wondering if your approach above might work - though obviously the windows app won't do it :confused:

good luck

Im working on this and checked the forums to see if anyone else was truly onto this before I forge ahead.

I find it useful to also have the windows joystick properties open from control panel. It will give a good idea of how the data is affecting ppjoy.

SUCCESS!!!

To connect with PPJoy via the COM port your arduino is attached to, make sure that you are operating a 9600 baud, AND that each of your serial.print statements are in the format serial.print(data,BYTE);

including BYTE makes sure that each statement sends 1 byte instead of changing the format to human readable type. It struck me while browsing the examples and finding ASCII Table, and noticing the BYTE included in the print statements for the char data.

Using FMS PIC 9600 baud (Generic):

Serial.print(241,BYTE); //sync byte, as on the website this is 240 + 1 because i will read one channel
Serial.print(0,BYTE); //Button states, zero meaning no buttons pressed
Serial.print(joystick_axis,BYTE); //joystick_axis would be a variable, likely given by analogRead

hello,
i'm busy with this too, but now i am having difficulties

i'm using this code

int x0 = 0;
int x1 = 0;
int y0 = 0;
int y1 = 0;

int x0_pin = 0;
int y0_pin = 1;
int x1_pin = 2;
int y1_pin = 3;

int button0 = 0;
int button1 = 0;

int button0_pin = 11;
int button1_pin = 12;

void setup() {
  Serial.begin(9600);
  
  pinMode(x0_pin, INPUT);
  pinMode(y0_pin, INPUT);
  pinMode(x1_pin, INPUT);
  pinMode(y1_pin, INPUT);
  
  pinMode(button0, INPUT);
  pinMode(button1, INPUT);
}

void loop() {
  x0 = analogRead(x0_pin);
  x0 = x0 / 2;
  y0 = analogRead(y0_pin);
  y0 = y0 / 2;
  x1 = analogRead(x1_pin);
  x1 = x1 / 2;
  y1 = analogRead(y1_pin);
  y1 = y1 / 2;
  
  button0 = digitalRead(button0_pin);
  button1 = digitalRead(button1_pin);
  
  Serial.print(246,BYTE);
  Serial.print(button0,BYTE);
  Serial.print(button1,BYTE);
  Serial.print(x0,BYTE);
  Serial.print(y0,BYTE);
  Serial.print(x1,BYTE);
  Serial.print(y1,BYTE);
}

in my gamecontroller menu in vista i get very odd results, joystick axis moving uncontrollable and the buttons too.

is there something i have to add to the code?

can't anyone tell me how to send a proper serial signal for ppjoy?

Did you try ClydeSha's code to see if that works. If that works for you then look at what needs to be sent for the number of channels you have. If Clyde's code doesn't work for you then you can look at your serial connectivity or PPJoy configuration.

now i used this code

int x0 = 0;
int y0 = 0;

int x0_pin = 0;
int y0_pin = 1;

void setup() {
  Serial.begin(9600);
  
  pinMode(x0_pin, INPUT);
  pinMode(y0_pin, INPUT);
}

void loop() {
  x0 = analogRead(x0_pin);
  y0 = analogRead(y0_pin);

Serial.print(241,BYTE);
Serial.print(0,BYTE);
Serial.print(x0,BYTE);
Serial.print(y0,BYTE);
}

i think it works, the y and x axis are good but it's still a bit uncontrollable

what does " a bit uncontrollable " mean?

perhaps try adding a delay(50) in loop so that your not flooding the serial port with messages.

it’s still the same.

i mean that in the game controller menu in windows, the pointer of the joystick moves upwards (if i move the joystick up) but it’s glitchy and the pointer suddenly moves left or right but then moves back up.

anyone?

IT WORKS!

i remembered that i read somewhere that the original gameport has 128 steps per axis (0 - 127) but the analog in on the arduino has 1024 steps (0 - 1023) so a simple calculation was made, divide it by 8!

in a few days you'll see my whole code and pics on the exhibition page

Hey there! I’m having some troubles with the interface of two potenciometers. I’m trying to use this pots to do some kind of a steering wheel, well, it kinda works… but only with one pot, if I hook up another one, THE DISASTER!!! it starts giving me odd results… I’m using one of the codes you guys uploaded…

byte x = 0;

int x_pin = 0;


void setup() {
  Serial.begin(9600);
  pinMode(x_pin, INPUT);
}

void loop() {
  x = analogRead(x_pin) / 4;
  
  Serial.print(241,BYTE);
  Serial.print(0,BYTE);
  Serial.print(x,BYTE);
}

As u can see, i’ve removed the y axis, cuz was giving me problems. This code works perfect, and if u divide the analogRead by 8 then u get a better read for a trhottle. Dividing it by 4 is better for a wheel. Now, how do I get the arduino to send to the PPJOY a signal so I can use ‘X’ number of joysticks???

Any help will be very very welcome!

I am just guessing based on information posted earlier in this thread, but try this:

byte x,y;

int x_pin = 0;
int y_pin = 1;


void setup() {
  Serial.begin(9600);
}

void loop() {
  x = analogRead(x_pin) / 4;
  y = analogRead(y_pin) / 4;

  Serial.print(242,BYTE); // 240 plus the number of channels
  Serial.print(0,BYTE);   // button presses
  Serial.print(x,BYTE);
  Serial.print(y,BYTE);
  delay(25);
}

Note that you should not call pinMode for analog inputs