PPJOY - ARDUINO

Hey there! Look, I'm having some troubles interfacing my arduino with PPJOY, the thing is that the ppjoyCom it's not reading the bytes that the arduino sends from the readings of the potentiometer. I've realized that when I tried to map the controller and tried to scan the input. :( I'm using the arduino duemilanove, a 1k pot, and this code i've taken from the forum:

byte x = 0;

int x_pin = 0;

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

  pinMode(x_pin, INPUT);
}

void loop() {
  x = analogRead(x_pin);

  Serial.print(241,BYTE);
  Serial.print(0,BYTE);
  Serial.print(x,BYTE);
}

If someone outhere knows anything about configuring the ppjoy, or what's the proper way of sending the bytes from the analog read of the pot, it will be very welcome!

Here Danazkari from Costa Rica, "Muchas gracias por adelantado!!!!" :D :D :D

What is PPJOY? Never heard of it!

PPjoy it's a software that reads a COM port and makes a virtual joystick with the commands u send to the COM port, but, I already figured out how to send the commands, if youre intrested I could upload the code. Let me know! ;)

  pinMode(x_pin, INPUT);

Not sure why you're doing this; pin zero is already an input - it's the Rx pin of the serial.

yep i know now hehe, i've already solved the issues. This is the new code that I'm using and it is working perfectly fine!

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);

}

Sorry i didn't uploaded before hehehe i was too busy doing tests :) the results were kinda good, just needs some calibration but overall works fine, i'm working in the fiber-glass body for it. I'll show some pics and videos ASAP :)

hey man, i know it's an old post, but i'm trying to make own 'joystick' with only one potentiometer as rudder/throttle. ...i used exactly the same code as you stated, but with no luck :/

can you help me with it?

am i supposed to do:

Serial.print(241, BYTE); // i have only 1 axis Serial.print(0, BYTE); //no buttons Serial.print(analogRead(0)/4, BYTE); // potentiometer is in analog0 pin

..i have no idea, why should i use dividing by 4 ..could you pls explain this to me? google - no results :/

i have no idea, why should i use dividing by 4

The range of values received from the analogRead function is from 0 to 1023.

Dividing the value by 4 reduces the range to 0 to 255, which happens to be exactly the range of values that fits in a byte.

oh, you’re right, thank you.
anyway, I’m still not able to get it working.

i’m using ppjoy v0.84.5.000 with win7 x64

here’s the sketch:

and here’s the code:

int x= 0;

void setup(){
  Serial.begin(9600);
  pinMode(5,OUTPUT);
  pinMode(6,OUTPUT);
  pinMode(7,OUTPUT);
  pinMode(8,OUTPUT);
  pinMode(9,OUTPUT);
}

void loop(){
    digitalWrite(5, LOW);
    digitalWrite(6, LOW);
    digitalWrite(7, LOW);
    digitalWrite(8, LOW);
    digitalWrite(9, LOW);
 
  if(analogRead(0)<204.8 && analogRead(A0)>=0){
    digitalWrite(5, HIGH);
    digitalWrite(6, LOW);
    digitalWrite(7, LOW);
    digitalWrite(8, LOW);
    digitalWrite(9, LOW);
  }
  if(analogRead(0)>=204.8 && analogRead(A0)<409.6){
    digitalWrite(5, LOW);
    digitalWrite(6, HIGH);
    digitalWrite(7, LOW);
    digitalWrite(8, LOW);
    digitalWrite(9, LOW);
  }
  if(analogRead(0)>=409.6 && analogRead(A0)<614.4){
    digitalWrite(5, LOW);
    digitalWrite(6, LOW);
    digitalWrite(7, HIGH);
    digitalWrite(8, LOW);
    digitalWrite(9, LOW);
  }
  if(analogRead(0)>=614.4 && analogRead(A0)<819.2){
    digitalWrite(5, LOW);
    digitalWrite(6, LOW);
    digitalWrite(7, LOW);
    digitalWrite(8, HIGH);
    digitalWrite(9, LOW);
  }
   if(analogRead(0)>=819.2 && analogRead(A0)<1024){
    digitalWrite(5, LOW);
    digitalWrite(6, LOW);
    digitalWrite(7, LOW);
    digitalWrite(8, LOW);
    digitalWrite(9, HIGH);
  }
  x = analogRead(0) / 4;
  Serial.print(241,BYTE);
  Serial.print(0,BYTE);
  Serial.print(analogRead(0)/4,BYTE);
  delay(25);
}

the LED thing is just for displaying the state of potentiometer (balance - left to right)

can you pls check it and help me?
thx!

I don’t know exactly what your problem is - you don’t say - but there are some things in the code that are strange.

  if(analogRead(0)<204.8 && analogRead(A0)>=0){

204.8? The analogRead function returns an integer value. While there is nothing “wrong” with comparing ints to floats, there is a performance penalty for doing so.

In addition, you just read the potentiometer setting twice.

  if(analogRead(0)>=204.8 && analogRead(A0)<409.6){
  if(analogRead(0)>=409.6 && analogRead(A0)<614.4){
  if(analogRead(0)>=614.4 && analogRead(A0)<819.2){
   if(analogRead(0)>=819.2 && analogRead(A0)<1024){
  x = analogRead(0) / 4;
  Serial.print(analogRead(0)/4,BYTE);

That’s a total of 12 reads that almost certainly all returned the same value. Read once, and store the value read. That’s what you declared x for.

Then, use some else statements.

Finally, describe what problem you are having. Do the various LEDs light up correctly as the pot is turned?

Does the TX light on the board flash when the data is sent?

Is the ppjoy software configured to use the same baud rate? Does it receive any data?

hello, thx for comment, I'm newbie and i didn't know that it has to read the state everytime in one loop, thanks, i'll fix it....anyway, the leds are working properly.....

the problem is in communication between arduino and ppjoy app. ppjoy just does not receive any input...it's not able to detect any serial input while turning with potentiometer... yes, the baud rate is set to 9600 in ppjoy.

i just set 1 axis and 0 buttons...then defined it as rudder...after that it's asking about the port (there are optionas analog0 to analog63, digital0...) so i'm click autoscan and turning with potentiometer...no luck :/