Giter Club home page Giter Club logo

arduinojoystickwithffblibrary's People

Contributors

jonlidgard avatar yukminglaw avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

arduinojoystickwithffblibrary's Issues

When used, causes MASSIVE FPS drop on certain games. (but works otherwise)

Hello, I have made a code for my wheel, which works just fine, but when i turn on games like DiRT rally, Assetto Corsa or Euro truck simulator 2, it causes a massive FPS drop. before i was getting 75 FPS in DiRT, but when i just plug in the arduino it instantly jumps to 8FPS. only game that i have registered no issue with FPS what so ever is BeamNG Drive.

The weird part to me is that when i disconnect my arduino the fps jump back up instantly, but if i connect it back again it immediately slows down again to 8FPS, also mind that the arduino isnt even doing anything when i connect it, the game seeing my arduino as a wheel with force feedback is enough for it to be slown down. Also mind the force feedback is working just fine in every game mentioned, but the FPS are not

I use arduino ProMicro is anyone was wondering

15. effect feedback.

Hello, sorry for my bad English, I want to add 15th feedback effect to your project but unfortunately I couldn't find where to change.

notepad++_XJk1aRbt1s

Try to make FFB on Z Axis (Rudder)??

Hi! I am working on my full FFB Yoke and Pedals. I have made them on separate pro micro bords and used the X-Axis force for the Z-Axis (Rudder). It works, but when using the yoke and I bank. The ruder pedals move to. I use XPForce on MSFS2020. Is there anyone who knows how I might solve this??

Thanx!

The FFB Capabilities

Hi. You have written the name of this repo as joystick with ffb but i couldnt see any connection between the joystick library and the descriptor. Are you working on it? Im trying to find a easy way to do it too. But i dont know yet.

will not show as controller

will compile but wont show up as a controller. if i use the ArduinoJoystick library without the FFB it shows as controller. also force tester wont recognize it as a controller unless i use the library without FFB it shows but since no FFB it cant test anything. please help. im trying to use with Assetto corsa.

This is the code for no ffb if i use your library it dose not work if i use the other it dose.

#include <Joystick.h>

// set joystick to library
// always start id at 0x03 also defalt
// 0x01,and 0x02 are used for internal mouse and keyboard lybrary
Joystick_ Joystick(0x03, JOYSTICK_TYPE_MULTI_AXIS, 8, 0, false, false, false, false, false, false, false, true, true, true, true);

const int steeringpot = A0;
const int throttlepot = A1;
const int brakepot = A2;
const int clutchpot = A3;

//arrys for buttons and sets state to zero
const int button[8] = { 5, 6, 7, 8, 9, 10, 11, 12};
int lastButtonState[8] = {0, 0, 0, 0, 0, 0, 0, 0};

void setup() {
//Serial.begin(9600);
// sets joystick
Joystick.begin();

// sets pins to input
for (int i = 0; i < 8; i++) {
pinMode(button[i], INPUT_PULLUP);
}

}

void loop() {

// reads pots and sends data to control steering, throttle, brake, and clutch
// delay to read pots
float steering = analogRead(steeringpot);
Joystick.setSteering(steering);
delay(1);

float throttle = analogRead(throttlepot);
throttle = map(throttle, 391.00, 750.00, 0.00, 1023.00);
Joystick.setThrottle(throttle);
delay(1);

float brake = analogRead(brakepot);
Joystick.setBrake(brake);
delay(1);

float clutch = analogRead(clutchpot);
Joystick.setAccelerator(clutch);

for (int i = 0; i < 8; i++) {
// Read pin values and replaces lastButtonState with new state
int currentButtonState = !digitalRead(button[i]);
if (currentButtonState != lastButtonState[i])
{
Joystick.setButton(i, currentButtonState);
lastButtonState[i] = currentButtonState;
}

}
//Serial.println(throttle);
}

This is the code for ffb and it compiles and shows as a controller in my devices but will not work on anything. please help!!!

#include <Joystick.h>
#include <Encoder.h>

int32_t forces[2] = { 0 };

long posX;
long posY;

int centerX;
int centerY;

int lastX = 0;
int lastY = 0;

// Motor
int dirX = 12;
int dirY = 13;

int brakeX = 9; // NIU
int brakeY = 8; // NIU

int motorX = 3; //
int motorY = 11; //

//current draw on motors
int loadX = A0;
int loadY = A1;

// joystick encoders
int encoderX1 = 0;
int encoderX2 = 1;
int encoderY1 = 2;
int encoderY2 = 4;

int xDirection = LOW;
int yDirection = LOW;
int centerFound = LOW;

int dur = 2;
int strength = 100;

long oldX = -999;
long oldY = -999;

const int loopDelay = 20;

int minX = 0;
int maxX = 0;
int minY = 0;
int maxY = 0;
const int throttlepot = A3;
const int brakepot = A2;
Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID,JOYSTICK_TYPE_JOYSTICK,
0, 0, // Button Count, Hat Switch Count
true, true, false, // X and Y, but no Z Axis
false, false, false, // No Rx, Ry, or Rz
false, true, // No rudder or throttle
true, true, true); // No accelerator, brake, or steering

Gains gain[2];
EffectParams effects[2];

//

Encoder encoderX(encoderX1, encoderX2);
Encoder encoderY(encoderY1, encoderY2);

void setup() {
Serial.begin(9600);
delay(2000); //Give the serial port time to catch up so we can debug
Serial.println("Setting up...");
pinMode(dirX, OUTPUT); //Initiates Motor Channel X pin
pinMode(dirY, OUTPUT); //Initiates Motor Channel Y pin

Joystick.begin(true);
doSetGains();
}

void loop(){
float throttle = analogRead(throttlepot);
throttle = map(throttle, 391.00, 750.00, 0.00, 1023.00);
Joystick.setThrottle(throttle);
delay(1);

float brake = analogRead(brakepot);
Joystick.setBrake(brake);
delay(1);

if (centerFound == 0){
Serial.println("--Centering");
doFindCenter();
}
doJoystickStuff();
doFFBStuff();
delay(loopDelay);
}

void doFindCenter(){
int cDur = 80;
int cStrength = 255;
int tXDir;
int tYDir;
int tPosX;
int tPosY;

doMoveX(cStrength,cDur,HIGH);
maxX = stopXMove();
doMoveX(cStrength,cDur,LOW);
minX = stopXMove();
int centerX = (minX + maxX)/2;
doMoveY(cStrength,cDur,HIGH);
maxY = stopYMove();
doMoveY(cStrength,cDur,LOW);
minY = stopYMove();
int centerY = (minY + maxY)/2;

centerX = ((minX + maxX)/2)-2;
centerY = ((minY + maxY)/2)-2;

Joystick.setXAxisRange(minX,maxX);
Joystick.setYAxisRange(minY,maxY);
tPosX = encoderX.read();
tPosY = encoderY.read();
do {
//center X
if (centerX > tPosX){tXDir = HIGH;} else {tXDir = LOW;}
doMoveX(255,2,tXDir);
tPosX = stopXMove();

}
while (tPosX != centerX);
do {
//center Y
if (centerY > tPosY){tYDir = HIGH;} else {tYDir = LOW;}
doMoveY(255,2,tYDir);
tPosY = stopYMove();

}
while (tPosY != centerY);
stopXMove();
stopYMove();
centerFound = 1;
}

int stopXMove(){
return doMoveX(0, 10, HIGH);
}

int stopYMove(){
return doMoveY(0, 10, HIGH);
}

int doMoveX(int tStrength, int tDuration, int tDirection){
digitalWrite(dirX, tDirection); //High=Forward / Low=Reverse
analogWrite(motorX, tStrength); //Spins the motor on Channel A at full speed
delay(tDuration);
// analogWrite(motorX, 0); //Stops motor
delay(2);
return encoderX.read();
}

int doMoveY(int tStrength, int tDuration, int tDirection){
digitalWrite(dirY, tDirection); //High=Forward / Low=Reverse
analogWrite(motorY, tStrength); //Spins the motor on Channel A at full speed
delay(tDuration);
// analogWrite(motorY, 0); //Stops motor
delay(2);
return encoderY.read();
}

void doFFBStuff(){
//}

}

void doJoystickStuff(){

posX = encoderX.read();
posY = encoderY.read();

Joystick.setXAxis(posX);
Joystick.setYAxis(posY);

effects[0].springMaxPosition = maxX/2;
effects[1].springMaxPosition = maxY/2;
effects[0].frictionMaxPositionChange = lastX - posX;
effects[1].frictionMaxPositionChange = maxY;
effects[0].inertiaMaxAcceleration = maxX;
effects[1].inertiaMaxAcceleration = 100;
effects[0].damperMaxVelocity = 10;
effects[1].damperMaxVelocity = 100;

effects[0].springPosition = posX;
effects[1].springPosition = posY;
effects[0].frictionPositionChange = lastX - posX;
effects[1].frictionPositionChange = lastY - posY;
effects[0].inertiaAcceleration = 100;
effects[1].inertiaAcceleration = 100;
effects[0].damperVelocity=100;
effects[1].damperVelocity=100;

Joystick.setEffectParams(effects);
Joystick.getForce(forces);

int xMoveDir = 0;
int yMoveDir = 0;
//Get Force [-255,255] you can set PWM with this value
Serial.println("");
Serial.print(" - XF: ");
Serial.print(forces[0]);
Serial.print(" YF: ");
Serial.print(forces[1]);
//if (forces[0] != 0 || forces[1] != 0 ){
if (forces[0]<0){
xMoveDir = LOW;
} else if (forces[0]>0){
xMoveDir = HIGH;
}
if (forces[1]<0){
yMoveDir = LOW;
} else if (forces[1]>0){
yMoveDir = HIGH;
}
if (forces[0]!=0){
doMoveX(abs(forces[0]),dur,xMoveDir);
} else {
doMoveX(0,2,xMoveDir);
};
if (forces[1]!=0) {
doMoveY(abs(forces[1]),dur,yMoveDir);
} else {
doMoveY(0,2,yMoveDir);
};

lastX = posX;
lastY = posY;

}

void doSetGains(){
//set x axis gains
gain[0].totalGain = 100;
gain[0].constantGain = 100;
gain[0].rampGain = 100;
gain[0].squareGain = 100;
gain[0].sineGain = 100;
gain[0].triangleGain = 100;
gain[0].sawtoothdownGain = 100;
gain[0].sawtoothupGain = 100;
gain[0].springGain = 100;
gain[0].damperGain = 100;
gain[0].inertiaGain = 100;
gain[0].frictionGain = 100;

//set y axis gains
gain[1].totalGain = 100;
gain[1].constantGain = 100;
gain[1].rampGain = 100;
gain[1].squareGain = 100;
gain[1].sineGain = 100;
gain[1].triangleGain = 100;
gain[1].sawtoothdownGain = 100;
gain[1].sawtoothupGain = 100;
gain[1].springGain = 100;
gain[1].damperGain = 100;
gain[1].inertiaGain = 100;
gain[1].frictionGain = 100;

Joystick.setGains(gain);

}

Force Value reverses after hitting 255

Hi, the force feedback works just fine, but if i turn the wheel really fast, the Force[0] value reverses back until it hits 0 and then into negative. It feels like a Variable overshoots and goes back down instead of having a limit.

In my code i just get the Force Value and tell the wheel to turn in the direction depending on positive or negative and how high the value is.

This is my setup:


//Setup
void setup() {

define_can_messages();
pinMode(A3, INPUT);
pinMode(A5, INPUT);
Serial.begin(115200);

Joystick.begin();
//Steering wheel

Joystick.setXAxisRange(0, 1023);
//set X Axis gains
mygains[0].totalGain = 100;//0-100                                                      //setting up everything
mygains[0].springGain = 100;//0-100
//mygains[0].damperGain = 100;
//mygains[0].inertiaGain = 10;
//enable gains REQUIRED
Joystick.setGains(mygains);

Joystick.begin();
Setup_MCP2515();
c = 0;

}


And this is the Signal for the Steering wheel:


//Lenkrad
void Signal_Lenkrad() {
int HighP = canMsg.data[1];
int LowP = canMsg.data[0];
uint16_t Position = (HighP << 8) + (LowP & 0xff);
long corrPos = 0;
corrPos = Position;
if (canMsg.data[3] == 255) {
corrPos = corrPos - 65535;
}

Signalrdy = corrPos / 124 + 512; // Wandelt corrPos in Signal von 0 bis 1023 um

if (Signalrdy < 0) {          //
  Signalrdy = 0;              //
}                             // Setzen des Maximums des Lenkeinschlags auf 0 - 1023
else if (Signalrdy > 1023) {  //
  Signalrdy = 1023;           //
}                             //

int posChange = feedback + 255;

//set EffectParameters for force feedback
myeffectparams[0].springMaxPosition = 1023;
myeffectparams[0].springPosition = Signalrdy; //0 - 1023

// myeffectparams[0].damperMaxVelocity = 0;
// myeffectparams[0].damperVelocity = 0;

//myeffectparams[0].inertiaMaxAcceleration = 512;
//myeffectparams[0].inertiaAcceleration = posChange;

//myeffectparams[0].frictionMaxPositionChange = 255;
//myeffectparams[0].frictionPositionChange = posChange;

Serial.println(feedback);

//Joystick.getGains();
Joystick.setEffectParams(myeffectparams);
Joystick.getForce(forces); //get the forces of the Wheel
Joystick.setXAxis(Signalrdy);

}


After that i just insert the forces[0] value into the motor. but the forces[0]value itself is overshooting like written above.

Rumble

Hello, reading users comments and looking at examples made me clear how to setup my arduino for force feedback, but what about rumble? Is it supported? If yes, how should I define it?
(Thanks for the work so far!)

Spring only works on one axis

Hi! First of all thank you so much for this library. I'm making a lot of progress creating a joystick and I would have never been able without this!

I am trying to create a working example and test several effects. I can't manage to work the damper and inertia but that's probably just me having to learn.
It seems like the spring effect does only work on one axis. I have created an example of a joystick with x and y axes and tried running a spring effect. It only seems to affect the Y axis.
I have tested in both fedit.exe and ForceTest.exe.

#define DEBUG
#include <Joystick.h>

// --------------------------
// Joystick related variables
// --------------------------
#define minX 0
#define maxX 1023
#define minY 0
#define maxY 1023
int16_t posX;
int16_t posY;
#define default_gain 100
Gains gain[2];
EffectParams effects[2];
int32_t forces[2] = {0};

Joystick_ Joystick(
    JOYSTICK_DEFAULT_REPORT_ID, JOYSTICK_TYPE_JOYSTICK,
    2, 0, // Button Count, Hat Switch Count
    true, true, false, // X, Y, Z
    false, false, false, // Rx, Ry, Rz
    false, false, // rudder, throttle
    false, false, false); // No accelerator, brake, or steering

void setup() {
    // setup connections
    Serial.begin(9600);
    delay(2000); //Give the serial port time to catch up so we can debug
    
    // setupJoystick
    Joystick.setXAxisRange(minX, maxX);
    Joystick.setYAxisRange(minY, maxY);
    
    //set x axis gains
    gain[0].totalGain = 100;
    gain[0].springGain = 100;
    //set y axis gains
    gain[1].totalGain = 100;
    gain[1].springGain = 100;
    Joystick.setGains(gain);
    
    Joystick.begin();
}

void loop(){
    posX = 0; posY = 0;
    doJoystickStuff();
    delay(1);
}

void doJoystickStuff(){
    effects[0].springMaxPosition = maxX;
    effects[1].springMaxPosition = maxY;
    effects[0].springPosition = posX;
    effects[1].springPosition = posY;

    Joystick.setXAxis(posX);
    Joystick.setYAxis(posY);
    Joystick.setEffectParams(effects);
    Joystick.getForce(forces);

    //Get Force [-255,255] you can set PWM with this value
    #ifdef DEBUG
    Serial.println("");
    Serial.print(" - X: ");
    Serial.print(posX);
    Serial.print(" - Y: ");
    Serial.print(posY);
    Serial.print(" - XF: ");
    Serial.print(forces[0]);
    Serial.print(" YF: ");
    Serial.print(forces[1]);
    #endif
}

This is the code I'm using. You can see debug messages in serial about the x and y positions and the x and y forces.
Thanks in advance!

more examples

I don't know much programming. Can you add a few more illustrative examples and for which axes we can get ffb

JOYSTICK_TYPE_GAMEPAD Crashes DCS (Digital Combat Simulator)

The sketch below works in windows joystick usb configuration. However when I start DCS (Digital Combat Simulator) DCS crashes.

/*
switch in pin 2
potentiometers in A0, A1 and A2
Arduino pro micro
*/

#include "Joystick.h"

Joystick_ Joystick(
JOYSTICK_DEFAULT_REPORT_ID, // hidReportId
JOYSTICK_TYPE_GAMEPAD, // joystickType
1, // buttonCount
0, // hatSwitchCount
true, // includeXAxis
true, // includeYAxis
true, // includeZAxis
false,// includeRxAxis
false,// includeRyAxis
false,// includeRzAxis
false,// includeRudder
false,// includeThrottle
false,// includeAccelerator
false,// includeBrake
false // includeSteerings
);

const int pinButton = 2;

int sx, sy, sz; // sensor values
int x, y, z; // values to Joy X, Y, Z

void setup() {
pinMode(pinButton, INPUT_PULLUP);

Joystick.setXAxisRange(-1023, 1023);
Joystick.setYAxisRange(-1023, 1023);
Joystick.setZAxisRange(-127, 127);

Joystick.begin(false);
}

void loop() {
if (digitalRead(pinButton)) {
Joystick.pressButton(0); // 0..31
} else {
Joystick.releaseButton(0);
}

sx = analogRead(A0);
sy = analogRead(A1);
sz = analogRead(A2);

x = map(sx, 0, 1023, -1023, 1023);
y = map(sy, 0, 1023, -1023, 1023);
z = map(sz, 0, 1023, -127, 127);

Joystick.setXAxis(x);
Joystick.setYAxis(y);
Joystick.setZAxis(z);

Joystick.sendState();

delay(20);
}

BTS7960 + DC Motor for FFB Wheel

Hi all

First of all thanks YukMingLaw for creating this, I think this will be the final piece to finish my racing arcade cabinet project.

I've got my arcade wheel, pedals and 6 speed shifter working using the standard Joystick library and I'm now trying to get FFB working. I'm still new to Arduino and coding so my logic and explanation will be very basic.

My steering wheel uses a potentiometer and is connected to A0 on the Leonardo. As far as I know the BTS7960 motor drive has two input pins Right PWM and Left PWM which I've connected to pin 3 and 4.

My question is would this setup work with this library? I saw that the example has 3 outputs which I'm not sure how they would work with the BTS7960. I'm guessing in the example (SingleJoystickFFB.ino) Pin 6 and 7 would connect to the BTS7960 motor drive Right and Left PWM?

Any help/links would be appreciated.

Cheers

stearing wheel with ffb, asseto corsa CPU 99%, slow respond in game

Hello friend,

I have a project to make a steering wheel, when I first started this project I only used the rotary encoder IP2770 and 6 buttons, at that time the game Asseto Corsa was running very smoothly and I often played SRP.

when I try to use FFB the game feels very unresponsive and can't be played, when I return to the previous code (FFB off), it runs very smoothly.

please see and review my code, does it still have a delay()? or something else.

thanks very much.

`#include <PWMFrequency.h>
#include "Joystick.h"

#define encoder0PinA 2
#define encoder0PinB 3

volatile int encoder0Pos = 0;
volatile int copyOfEncoder = 0;
volatile int latestEncoderPos = 0;

//X-axis & Y-axis REQUIRED
Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID,
JOYSTICK_TYPE_JOYSTICK, 6, 0,
true, true, true, //X,Y,Z
true, false, false,//Rx,Ry,Rz
false, false, false, false, false);

Gains mygains[2];
EffectParams myeffectparams[2];
int32_t forces[2] = {0};

//BTS7960
#define EN 12
#define R_PWM 11
#define L_PWM 10

void doEncoderA() {
// look for a low-to-high on channel A
if (digitalRead(encoder0PinA) == HIGH) {

// check channel B to see which way encoder is turning
if (digitalRead(encoder0PinB) == LOW) {
  encoder0Pos = encoder0Pos - 1;         // CW
}
else {
  encoder0Pos = encoder0Pos + 1;         // CCW
}

}

else // must be a high-to-low edge on channel A
{
// check channel B to see which way encoder is turning
if (digitalRead(encoder0PinB) == HIGH) {
encoder0Pos = encoder0Pos - 1; // CW
}
else {
encoder0Pos = encoder0Pos + 1; // CCW
}
}
//Serial.println (encoder0Pos, DEC);
// use for debugging - remember to comment out
}

void doEncoderB() {
// look for a low-to-high on channel B
if (digitalRead(encoder0PinB) == HIGH) {

// check channel A to see which way encoder is turning
if (digitalRead(encoder0PinA) == HIGH) {
  encoder0Pos = encoder0Pos - 1;         // CW
}
else {
  encoder0Pos = encoder0Pos + 1;         // CCW
}

}

// Look for a high-to-low on channel B

else {
// check channel B to see which way encoder is turning
if (digitalRead(encoder0PinA) == LOW) {
encoder0Pos = encoder0Pos - 1; // CW
}
else {
encoder0Pos = encoder0Pos + 1; // CCW
}
}
}

void setup() {
for (byte i = 4; i <= 9 ; i++) {
pinMode(i, INPUT_PULLUP);
}

for (byte i = 10; i <= 12 ; i++) {
pinMode(i, OUTPUT);
}

setPWMPrescaler(R_PWM, 8);
setPWMPrescaler(L_PWM, 8);

pinMode(encoder0PinA, INPUT);
pinMode(encoder0PinB, INPUT);

// encoder pin on interrupt 0 (pin 2)
attachInterrupt(0, doEncoderA, RISING);

// encoder pin on interrupt 1 (pin 3)
attachInterrupt(1, doEncoderB, RISING);

Joystick.setXAxisRange(-6450, 6450);
Joystick.setYAxisRange(0, 0);
Joystick.setZAxisRange(0, 1000);
Joystick.setRxAxisRange(0, 1000);

//set X Axis gains
mygains[0].totalGain = 20;//0-100
mygains[0].springGain = 30;//0-100
mygains[1].totalGain = 0;//0-100
mygains[1].springGain = 0;//0-100
//enable gains REQUIRED
Joystick.setGains(mygains);
Joystick.begin();
}

void loop() {
//read Encoder
noInterrupts();
if (!digitalRead(4) == 1){
encoder0Pos = 0;
}
latestEncoderPos = encoder0Pos;
interrupts();

if (latestEncoderPos != copyOfEncoder) {
copyOfEncoder = latestEncoderPos;
}

//Send HID data to PC
Joystick.setXAxis(copyOfEncoder);

//set X Axis Spring Effect Param
myeffectparams[0].springMaxPosition = 6450;
myeffectparams[0].springPosition = copyOfEncoder;
myeffectparams[1].springMaxPosition = 6450;
myeffectparams[1].springPosition = 0;

//Recv HID-PID data from PC and caculate forces
Joystick.setEffectParams(myeffectparams);
Joystick.getForce(forces);
if (forces[0] < 0) {
digitalWrite(EN, HIGH);
analogWrite(R_PWM, abs(forces[0]));
analogWrite(L_PWM, 0);
} else {
digitalWrite(EN, HIGH);
analogWrite(R_PWM, 0);
analogWrite(L_PWM, abs(forces[0]));
}

if (!digitalRead(8) == 1 && !digitalRead(5) == 1) {
if (!digitalRead(9) == 1) {
Joystick.setZAxis(1000);
} else {
Joystick.setZAxis(0);
}

if (!digitalRead(6) == 1) {
  Joystick.setRxAxis(1000);
} else {
  Joystick.setRxAxis(0);
}

} else {
if (!digitalRead(9) == 1) {
Joystick.setZAxis(1000);
} else {
Joystick.setZAxis(0);
}

if (!digitalRead(6) == 1) {
  Joystick.setRxAxis(1000);
} else {
  Joystick.setRxAxis(0);
}

}

Joystick.setButton(0, !digitalRead(4));
Joystick.setButton(1, !digitalRead(5));
Joystick.setButton(3, !digitalRead(7));
Joystick.setButton(4, !digitalRead(8));
}`

XYZ forces

Thank you for your great work. For my cockpit project I need force feedback for the X,Y und Z axis. Can you extend your library to get the Z axis force?

Support for stm32

Hello! How easy would this be to port to stm32duino? I saw the mmos firmware so I pulled the trigger, but it looks like it doesnt have the source code. I'm willing to work with you to get this done.

Force direction is backwards

It's possible I'm using the library wrong, but I've spent several hours trying to debug this.

I've noticed that, in games that use constant forces to do their own feedback, the direction of the force is in the wrong direction. This obviously makes the games unplayable. Spring forces, friction and damping all seem to work correctly though.

When I use the program "ForceTest" to inject a constant force, the direction is indeed backwards from what Microsoft's documentation says the convention is. https://docs.microsoft.com/en-us/previous-versions/windows/desktop/ee417536(v=vs.85)

A force of "60" with a direction of "90" should come from the direction of positive X, which on my steering wheel should push counterclockwise. I get a clockwise force instead, though.

Likewise, when I do a periodic force, the wheel is forced clockwise and then counterclockwise.

How to use the rumble/ vibration?

I've been looking through the documentation and examples in this library and I can't seem to find anything about how to add rumble (vibration is mentioned in the project statement). I assume that's what the RX RY and RZ flags are for but honestly, I have no idea how to add rumble to a project with this library and I'm not 100% it's even supported by this library.

Thanks for the library it's been really helpful if anyone can help I'd greatly appreciate it.

Set Periodic period size mismatch

The descriptor for period is specified as 32 bits:

	0x09, 0x72,           //  Usage (Period)
	0x15, 0x00,           //   Logical Minimum (0)
	0x27, 0xFF, 0x7F, 0, 0, //   Logical Maximum (32K)
	0x35, 0x00,           //   Physical Minimum (0)
	0x47, 0xFF, 0x7F, 0, 0, //   Physical Maximum (32K)
	0x66, 0x03, 0x10,     //   Unit (1003h) (English Linear, Seconds)
	0x55, 0xFD,           //   Unit Exponent (FDh) (X10^-3 ==> Milisecond)
	0x75, 0x20,           //   Report Size (32)
	0x95, 0x01,           //   Report Count (1)
	0x91, 0x02,           //   Output (Data,Var,Abs)
	0x66, 0x00, 0x00,     //  Unit (0)
	0x55, 0x00,           //  Unit Exponent (0)

But the corresponding struct uses a uint16_t:

typedef struct//FFB: Set Periodic Output Report
{
	uint8_t	reportId;	// =4
	uint8_t	effectBlockIndex;	// 1..40
	uint16_t magnitude;
	int16_t	offset;
	uint16_t	phase;	// 0..255 (=0..359, exp-2)
	uint16_t	period;	// 0..32767 ms
} USB_FFBReport_SetPeriodic_Output_Data_t;

This seems to happen to work because the data is little endian, the range is limited to 0-32767, and the code is simply reinterpret casting the raw data to the struct. It seems like it's probably worth either fixing the descriptor, using a uint32_t in the struct for consistency, or at least adding a comment to the struct, because otherwise it's alarming to stumble upon it when debugging.

higher than 8 bit force feedback resolution

Hello! Sorry to bug you again, I have implemented your code into my FFB wheel project (on my page), using a mige servo and a generic servo drive. I am wondering if it is possible to get higher than 9 bit resolution on the force feedback (8 bit each way, -255 to 255). The game I have tested is BeamNG.drive, and it only gives me 8 bit values. I would like to take advantage of the 13 bit analog control resolution on my servo drive.

Thanks in advance!

Force feedback doesn't work in linux

I'm not particularly familiar with USB HID descriptors, but it appears that the usbhid driver, hid-pidff.c, is looking for 0xa7 and not finding it.

[1172477.418129] hid-generic 0003:2341:8036.001A: starting pid init
[1172477.418132] hid-generic 0003:2341:8036.001A: found usage 0x21 from field->logical
[1172477.418134] hid-generic 0003:2341:8036.001A: found usage 0x5a from field->logical
[1172477.418135] hid-generic 0003:2341:8036.001A: found usage 0x5f from field->logical
[1172477.418137] hid-generic 0003:2341:8036.001A: found usage 0x6e from field->logical
[1172477.418138] hid-generic 0003:2341:8036.001A: found usage 0x73 from field->logical
[1172477.418139] hid-generic 0003:2341:8036.001A: found usage 0x74 from field->logical
[1172477.418140] hid-generic 0003:2341:8036.001A: found usage 0x77 from field->logical
[1172477.418142] hid-generic 0003:2341:8036.001A: found usage 0x90 from field->logical
[1172477.418143] hid-generic 0003:2341:8036.001A: found usage 0x96 from field->logical
[1172477.418144] hid-generic 0003:2341:8036.001A: found usage 0x7d from field->logical
[1172477.418145] hid-generic 0003:2341:8036.001A: found usage 0xab from collection array
[1172477.418147] hid-generic 0003:2341:8036.001A: found usage 0x89 from field->logical
[1172477.418148] hid-generic 0003:2341:8036.001A: found usage 0x7f from field->logical
[1172477.418149] usbhid: found 0 at 0->0
[1172477.418151] usbhid: maxusage and report_count do not match, skipping
[1172477.418152] usbhid: found 1 at 2->0
[1172477.418153] usbhid: maxusage and report_count do not match, skipping
[1172477.418154] usbhid: found 2 at 3->0
[1172477.418155] usbhid: maxusage and report_count do not match, skipping
[1172477.418156] usbhid: found 3 at 4->0
[1172477.418157] usbhid: maxusage and report_count do not match, skipping
[1172477.418158] usbhid: found 4 at 2->1
[1172477.418158] usbhid: maxusage and report_count do not match, skipping
[1172477.418159] usbhid: found 5 at 6->0
[1172477.418160] usbhid: maxusage and report_count do not match, skipping
[1172477.418161] usbhid: failed to locate 6
[1172477.418163] hid-generic 0003:2341:8036.001A: unknown set_effect report layout
[1172477.418165] hid-generic 0003:2341:8036.001A: input,hidraw8: USB HID v1.11 Multi-Axis Controller [Arduino LLC Arduino Leonardo] on usb-0000:02:00.0-3/input2

This is apparently a "start delay" parameter. Looking in PIDReportType.h, I can see that it's commented out in the corresponding struct:

typedef struct //FFB: Set Effect Output Report
{
	uint8_t	reportId;	// =1
	uint8_t	effectBlockIndex;	// 1..40
	uint8_t	effectType;	// 1..12 (effect usages: 26,27,30,31,32,33,34,40,41,42,43,28)
	uint16_t duration; // 0..32767 ms
	uint16_t triggerRepeatInterval; // 0..32767 ms
	uint16_t samplePeriod;	// 0..32767 ms
	uint8_t	gain;	// 0..255	 (physical 0..10000)
	uint8_t	triggerButton;	// button ID (0..8)
	uint8_t	enableAxis; // bits: 0=X, 1=Y, 2=DirectionEnable
	uint8_t	directionX;	// angle (0=0 .. 255=360deg)
	uint8_t	directionY;	// angle (0=0 .. 255=360deg)
	//	uint16_t	startDelay;	// 0..32767 ms
} USB_FFBReport_SetEffect_Output_Data_t;

This thread seems to talk about the same issue on a Granite Devices SimuCUBE. https://www.spinics.net/lists/linux-usb/msg190787.html

It seems like this is part of the HID PID spec, but maybe the windows driver is buggy and doesn't implement it, and so it's been omitted from the descriptor to make the device work in windows?

It's kind of a bummer that it doesn't work in linux, because it's much easier to develop my firmware from there. I'll try to work around it and report back, but maybe someone else has a better idea.

Game lagging because of FFB aka. why no to use delay()

Accured in ACC: Game lagging and showing CPU usage >99%, even tho it hardly using the CPU.
Got fixed by removing delay() in the code.
So apperntly games need to get confirmation of the FFB data being read, which means the Arduino need to receive the data as often as possible.
If you have code that would need delay(), put them in a function and use millis() or micros() to run them.

Sometimes hard shakes

Hi,
first, thanks for your work!
I've created a 3d printed Force Feedback Yoke based on the Github Project "Fino" (https://github.com/jmriego/Fino)
which based on your code (see https://github.com/gagagu/Arduino_FFB_Yoke) as a free GitHub project.

The yoke seems to work but sometime i have hard movement or shakes that could damage my yoke so i have to reduced the pwm power signal of the dc motos.
I sadly do not understand how the effect settings works and hopefully would like to ask you if you can give me a hint what i could do or which setting i have to change to make everything smoother and not shaking hard in this way?

see a video if you like: https://youtu.be/QJRdzPXO4O4

Thanks foward

DiRT 2.0 problem

Hi! Thanks for a great repo! My code seams to work with wheelcheck, but i don get any force data from Dirt 2.0??

cpOffset from Spring Effect troubles

First a great thank you for this library!

Thanks to this i restarted my ffb stick project for use in Condor2.

When using ForceTest or force_edit everything seems to work fine, however when i try to use the test setup with Condor2 i do not get the desired change in CenterPoint of the spring effect when i change the trim. This works fine with my old msffb sidewinder2.
I tried to have a look at the usb packets with USBlyzers 33 day free trial but i dont seem to find where it is going wrong.
The Negative and Positive Force coefficients work (change with changing airspeed).

This is the last step missing to move from my proof of concept onto a real working setup.
Does anybody experience this with other software as well?
Or does someone know where it could go wrong?

LeonardoOnlyTrim.zip

library dont work?

Hello everyone, I'm new to arduino and I'm trying to write my own steering wheel with FFB, so far it's not very good. I can write code without FFB but I want to have it I have everything I need to create it motor and h-bridges the code I try to write gives me a lot of errors that I don't know how to fix. I would be very grateful if there is somewhere a code with ffb on this library, because while I understand a little. Also my experience in programming is low, all I did was read the book "a byte of python" I also know layout, but this has nothing to do with my question

rFactor 2

I tested with rFactor 2, the effects are not activated?

Recreate Logitech WingMan Force with Arduino Leonardo

Hello,

I have Logitech WingMan Force for very long time, but on Windows 10 it is not supported anymore (no driver) so I decided to replace the board with Arduino Leonardo. I already dismantled the board and connected the Leonardo to the potentiometers with the simple joystick x,y sample.
But I have lots of buttons and also hat buttons and most important I have two motors for "force back" that I would love to have them work as in the old days ;-)

Can you help with code for that?
Also I'll be happy for sketch how connect wires to Leonardo legs.

Of course I will upload this project with video for the benefit of everyone with credits ;-D

Thank you so much in advance

Spring effect Y axis sended to X axis ?

Hi

It seems that Y axis does not receive forces, it seems to me that Y spring effect forces goes to X axis. At least when I change offset values using ForceTest software I see a Y axis change. But when I change offset value in Y axis, nothing happens. Also, changing X axis strength in ForceTest, Y axis changes also. I tested Fortest with Microsft Sidewinder 2 joystick and it's performing well the software. I think there exists some bug in the library.

Games crashing on start, or in control setting menu (arduino pro micro + encoder)

`
#include <Joystick.h>

Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID, JOYSTICK_TYPE_MULTI_AXIS, 0, 0,false, false, false, false, false, false, false, false, false, false, true);

#define ENC_A 2 //Енкодер фаза А
#define ENC_B 3 //Енкодер фаза В

int16_t X_POS = 0;

void setup() {
Joystick.begin();
Joystick.setSteeringRange(-1500, 1500);
Joystick.setSteering(0);
pinMode (ENC_A, INPUT_PULLUP);
pinMode (ENC_B, INPUT_PULLUP);

attachInterrupt(digitalPinToInterrupt(ENC_A), ENC_TIC, RISING);
}

void loop() {
if(X_POS >= -1500 && X_POS <= 1500) {
Joystick.setSteering(X_POS);
}
}

void ENC_TIC ()
{
bool State = digitalRead(ENC_B);
if(State == LOW) {
X_POS++;
}
else {
X_POS--;
}
}
`
i have an arduino pro micro on ATMega 32u4 and 600 P/R encoder, but I don't understand why it not working, thanks in advance for the answer.

How to connect output steppers - Its not an issue with library, more like need help in using it

Thanks a lot for this wonderful library. Detailed work indeed!

I have gone through the "SingleJoystickFFB" in examples but unable to understand where or how to connect steppers in the arduino board. The sketch says pin 7, 6, 9 are outputs. Pin 9 gives PWM output (to motor driver) understood but unable to catch the idea of pin 6 & 7. I have used the previous Joystick library for my home cockpit building but I am new to controlling steppers.
Please help!

Regards,
Gaurav

Device crashing some games

I used a very basic setup just to test the library and so far have a potentiometer and two buttons set as the steering wheel and two buttons, windows seems to pick it up just fine but when I tried to launch F1 2020 with the Arduino Leonardo plugged in it wouldn't respond at all. So I tried it in Assetto Corsa and that seems to behave fine.

Here's the code I was using:
#include <Joystick.h>

Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID,JOYSTICK_TYPE_JOYSTICK,2,0,false, false,false,false, false, false,false, false,false, false, true);

void setup() {
//put your setup code here, to run once:
Joystick.setSteeringRange(0,1023);
Joystick.begin();
pinMode(A0,INPUT);
pinMode(5,INPUT);
pinMode(4,INPUT);
//Serial.begin(9600);
}

void loop() {
//put your main code here, to run repeatedly:

Joystick.setSteering(1023-analogRead(A0));
if (digitalRead(5) == HIGH){
Joystick.pressButton(1);
}
else{
Joystick.releaseButton(1);
}
if (digitalRead(4) == HIGH){
Joystick.pressButton(0);
}
else{
Joystick.releaseButton(0);
}
//Joystick.sendState();
//Serial.print(digitalRead(4));
//Serial.print(digitalRead(5));
//Serial.println(analogRead(A0));
//delay(10);
}

If anyone can help me out with this I'd greatly appreciate it.

STM32F103

I'm trying to port this code to STM32F103 using keil compiler.
I made changes to behave like C code (C99 mode).
The build completed perfectly, but the effects do not follow the timing.
Using fedit.exe, the effects work as if they are in infinite time, they don't stop.
'Periodic Force' does not work.
I have checked the code several times and I don't understand where the error is.
How is the 'Periodic Force' effect controlled and what could be wrong with looping other effects?

stm32 compile error

I try compile sample code for stm32 blue pill but error as follow:


In file included from e:\OneDrive\Documents\Arduino\libraries\ArduinoJoystickWithFFBLibrary\src/Joystick.h:24,
                 from C:\TEMP\arduino_modified_sketch_533235\SingleJoystickFFB.ino:1:
e:\OneDrive\Documents\Arduino\libraries\ArduinoJoystickWithFFBLibrary\src/DynamicHID/DynamicHID.h:37:12: fatal error: PluggableUSB.h: No such file or directory
   37 |   #include "PluggableUSB.h"
      |            ^~~~~~~~~~~~~~~~
compilation terminated.

Anybody can fix it?
Thanks.

Games don't return any force feedback

Hello
I made a program based on your lib
When i am using WheelCheck arduino gets information about forces and returns them to the serial port
However, when i try to get forces in games, it doesn't see it. it returns 0
Here is my code
`#include "Joystick.h"

Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID,JOYSTICK_TYPE_JOYSTICK,
0, 0,
true, false, false,
false, false, false,
false, false,false, false, false);

Gains mygains[1];
EffectParams myeffectparams[1];
int32_t forces[1];

unsigned long t,lt,dt,lastT; //time part
int x, lx, deltaX, dx,ldx, dx2; //differential part

void setup() {
mygains[0].totalGain = 50; //setting gains
mygains[0].rampGain = 50;
mygains[0].squareGain = 50;
mygains[0].sineGain = 50;
mygains[0].triangleGain = 50;
mygains[0].sawtoothdownGain = 50;
mygains[0].sawtoothupGain = 50;
mygains[0].springGain = 80;
mygains[0].damperGain = 50;
mygains[0].inertiaGain = 50;
mygains[0].frictionGain = 50;
mygains[0].customGain = 50;

Joystick.setGains(mygains);
Joystick.begin();
Joystick.setXAxisRange(-512, 512);
Serial.begin(500000);
lt=millis();
}

void loop() {
lt = t; //time part
t = millis();
dt = t - lt;

if(millis()-lastT>0){

lastT=millis();

lx=x; //last x
ldx=dx; // last x velocity
x=analogRead(A0)-512; //x
deltaX=x-lx;// delta x
dx=deltaX/dt;//x velocity
dx2=(dx-ldx)/dt;//x acceleration

myeffectparams[0].springMaxPosition = 512;
myeffectparams[0].springPosition = x;

myeffectparams[0].damperMaxVelocity = 100;
myeffectparams[0].damperVelocity = dx;

myeffectparams[0].inertiaMaxAcceleration = 5;
myeffectparams[0].inertiaAcceleration = dx2;

myeffectparams[0].frictionMaxPositionChange = 10;
myeffectparams[0].frictionPositionChange = deltaX;

Joystick.setXAxis(x);
Joystick.sendState();
Joystick.setEffectParams(myeffectparams);
Joystick.getForce(forces);

Serial.print(x);
Serial.print(" ");
Serial.println(forces[0]);
}

}`
I think games just don't recognize it as a force feedback device, that can use effects(like spring, friction, ect) because while Wheel check is working, Force Test says "Your joystick may not support this effect" for each effect
Do you know how to fix that?
Thanks in advance

Gains and Effects?

Hi,
i've used the based joystick library to repair my broken Saitek Yoke and it's working perfect. Now, i want to extend it to a FFB Yoke. My plan is to use a strong RC Servo (35Kg) to create the force. The Serve should rotate in the same angle as the yoke plus or minus the measured force.
I've made some tests with X-Plane and the XPForce Plugin but i have some problems to understand the Gains and Effects Parameters. Basely i do understand for what they are but i don't have enough experience to select the correct gains and parameters settings.
Is it possible for you to help me out to find the correct configuration?

Thx forward for your work!

it causes my game to crash or get stuck directly,I need help!

Hello, I tried to use your library to get the force feedback information sent back from the game, but when I upload your routine to my Arduino Leonardo board, I find that it causes my game to crash or get stuck directly, and the game returns to normal when I reset or unplug the USB cable, so I wonder what is the cause of this phenomenon? How can it be improved? Would love to hear from you!

FFB support for Arduino DUE (32bit ARM)

Firstly, this library is amazing and I'm happy that I found it.
It works nicely on 32u4, but that this chip is kinda too slow. My code takes like 9ms to execute. (Set axis and buttons).
For example, Forza Horizon 4, the frame rate drops to 4FPS because it's waiting for the chip to get data. (Physics refresh at 300hz) Assetto corsa won't even start the race.
So I realized that the library that this is build on supports Arduino DUE that's multiple times faster (now the execution time is only 0.85ms).

Now comes the problem with this library, I can see in the code a few tries to get it working on DUE, but only something...
In the DynamicHID.cpp the USB_Send is correctly translated to USBD_Send, but there are multiple other than this.
I tried to fix it and I got no errors regarding that, but there might be some problems because the DUE core has uint32 in the place instead of the uint8 in USBCore.cpp, that might couse problems...

Also I'm getting this error:

C:\Users\Speedy\Documents\Arduino\libraries\ArduinoJoystickWithFFBLibrary-master\src\DynamicHID\DynamicHID.cpp: In constructor 'DynamicHID_::DynamicHID_()':
C:\Users\Speedy\Documents\Arduino\libraries\ArduinoJoystickWithFFBLibrary-master\src\DynamicHID\DynamicHID.cpp:242:65: error: no matching function for call to 'PluggableUSBModule::PluggableUSBModule(int, int, uint8_t [2])'
                    protocol(DYNAMIC_HID_REPORT_PROTOCOL), idle(1)
                                                                 ^
C:\Users\Speedy\Documents\Arduino\libraries\ArduinoJoystickWithFFBLibrary-master\src\DynamicHID\DynamicHID.cpp:242:65: note: candidates are:
In file included from C:\Users\Speedy\Documents\Arduino\libraries\ArduinoJoystickWithFFBLibrary-master\src\DynamicHID\DynamicHID.h:35:0,
                 from C:\Users\Speedy\Documents\Arduino\libraries\ArduinoJoystickWithFFBLibrary-master\src\DynamicHID\DynamicHID.cpp:22:
C:\Users\Speedy\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.12\cores\arduino/USB/PluggableUSB.h:29:3: note: PluggableUSBModule::PluggableUSBModule(uint8_t, uint8_t, uint32_t*)
   PluggableUSBModule(uint8_t numEps, uint8_t numIfs, uint32_t *epType) :
   ^
C:\Users\Speedy\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.12\cores\arduino/USB/PluggableUSB.h:29:3: note:   no known conversion for argument 3 from 'uint8_t [2] {aka unsigned char [2]}' to 'uint32_t* {aka long unsigned int*}'
C:\Users\Speedy\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.12\cores\arduino/USB/PluggableUSB.h:27:7: note: constexpr PluggableUSBModule::PluggableUSBModule(const PluggableUSBModule&)
 class PluggableUSBModule {
       ^
C:\Users\Speedy\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.12\cores\arduino/USB/PluggableUSB.h:27:7: note:   candidate expects 1 argument, 3 provided
C:\Users\Speedy\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.12\cores\arduino/USB/PluggableUSB.h:27:7: note: constexpr PluggableUSBModule::PluggableUSBModule(PluggableUSBModule&&)
C:\Users\Speedy\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.12\cores\arduino/USB/PluggableUSB.h:27:7: note:   candidate expects 1 argument, 3 provided

Which shows the problem that the SAM (DUE) core expects uint32, not uint8 (tried to fix that but when app tries to access the FFB data, it crashes) and also I've found that the USBAPI.h from the SAM core is missing some things that are connected with the "PluggableUSBModule", for example "EP_TYPE_INTERRUPT_IN".

I'm not very good at this level of programming, but I hope that I pointed out some things and I will be happy if somebody can help me port this library to the way faster Arduino DUE.

Englisch and Pinout

Hi,
firstable thanks for your work and sharing it with us!
I want to use your library for a force feedback flight stick but i don't know how to connect the electric components.
Is it possible for you to make a readme in englisch so that everyone in the world can read it?

Thx forward!

updates

Is the project at a standstill or has it reached a satisfactory point?

Gains

It appears gains should be set in setup() and not before as in your example.

Y-axis work in MSFS2020 but not X-axis?!?!

So I make the code work and the y-axis works whit everything but not the x-axis. The x-axis and y-axis work in the force tester but in MSFS2020 only the Y-axis works correctly. The x-axis (roll) is banking to the left 100%. Y-axis (pitch) finds the center and works perfectly. any anyone knows way this is?

----------------My code---------------

#include "Joystick.h"

int32_t forces[2] = {0};

int PITCH_R_EN = 16;
int PITCH_L_EN = 16;
int PITCH_R_PWM = 10;
int PITCH_L_PWM = 5;

int ROLL_R_EN = 8;
int ROLL_L_EN = 8;
int ROLL_R_PWM = 9;
int ROLL_L_PWM = 6;

//X-axis & Y-axis REQUIRED
Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID, JOYSTICK_TYPE_JOYSTICK,
0, 0, //Button Count, Hat Switch Count
true, true, false, //X,Y,Z
false, false, false,//Rx,Ry,Rz
false, false, false, false, false); //Rudder, Throttle, Accelerator, Brake, Steering

Gains mygains[2];
EffectParams myeffectparams[2];

void setup(){
//In & Outputs For Pitch Motor
pinMode(PITCH_R_EN, OUTPUT);
pinMode(PITCH_L_EN, OUTPUT);
pinMode(PITCH_R_PWM, OUTPUT);
pinMode(PITCH_L_PWM, OUTPUT);
digitalWrite(PITCH_R_EN, HIGH);
digitalWrite(PITCH_L_EN, HIGH);
pinMode(A0,INPUT);

//In & Outputs For Roll Motor
pinMode(ROLL_R_EN, OUTPUT);
pinMode(ROLL_L_EN, OUTPUT);
pinMode(ROLL_R_PWM, OUTPUT);
pinMode(ROLL_L_PWM, OUTPUT);
digitalWrite(ROLL_R_EN, HIGH);
digitalWrite(ROLL_L_EN, HIGH);
pinMode(A1,INPUT);

Joystick.setXAxisRange(0, 1023);
Joystick.setYAxisRange(0, 1023);

//set X Axis gains
mygains[0].totalGain = 30;//0-100
mygains[0].springGain = 30;//0-100
//mygains[0].damperGain = 10;//0-100
//mygains[0].inertiaGain = 10;//0-100
//mygains[0].frictionGain = 10;//0-100

//set Y Axis gains
mygains[1].totalGain = 10;//0-100
mygains[1].springGain = 10;//0-100
//mygains[1].damperGain = 10;//0-100
//mygains[1].inertiaGain = 10;//0-100
//mygains[1].frictionGain = 10;//0-100

//enable gains REQUIRED
Joystick.setGains(mygains);
Joystick.begin();

}

void loop(){
int valueX = analogRead(A1); //Pitch Input
int valueY = analogRead(A0); //Roll Input

//set X Axis Spring Effect Param
myeffectparams[0].springMaxPosition = 1023;
myeffectparams[0].springPosition = valueX;//0-1023

//set Y Axis Spring Effect Param
myeffectparams[1].springMaxPosition = 1023;
myeffectparams[1].springPosition = valueY;//0-1023

//set X Axis Damper Effect Param
//myeffectparams[0].damperMaxVelocity = 1023;
//myeffectparams[0].damperVelocity = valueX;//0-1023

//set Y Axis Damper Effect Param
//myeffectparams[1].damperMaxVelocity = 1023;
//myeffectparams[1].damperVelocity = valueY;//0-1023

//set X Axis Inertia Effect Param
//myeffectparams[0].inertiaMaxAcceleration = 1023;
//myeffectparams[0].inertiaAcceleration = valueX;//0-1023

//set Y Axis Inertia Effect Param
//myeffectparams[1].inertiaMaxAcceleration = 1023;
//myeffectparams[1].inertiaAcceleration = valueY;//0-1023

//set X Axis Friction Effect Param
//myeffectparams[0].frictionMaxPositionChange = 1023;
//myeffectparams[0].frictionPositionChange = valueX;//0-1023

//set Y Axis Friction Effect Param
//myeffectparams[1].frictionMaxPositionChange = 1023;
//myeffectparams[1].frictionPositionChange = valueY;//0-1023

//Send HID data to PC
Joystick.setXAxis(valueX);
Joystick.setYAxis(valueY);

//Recv HID-PID data from PC and caculate forces
Joystick.setEffectParams(myeffectparams);
Joystick.getForce(forces);

    // X Axis Funktion

if(forces[0] > 0){
analogWrite(ROLL_L_PWM,abs(forces[0]));
analogWrite(ROLL_R_PWM, 0);
digitalWrite(ROLL_L_EN,HIGH);
}else{
analogWrite(ROLL_R_PWM,abs(forces[0]));
analogWrite(ROLL_L_PWM, 0);
digitalWrite(ROLL_R_EN,HIGH);
}
delay(10);
// Y Axis Funktion
if(forces[1] > 0){
analogWrite(PITCH_L_PWM, 0);
analogWrite(PITCH_R_PWM,abs(forces[1]));
digitalWrite(PITCH_R_EN,HIGH);
}else{
analogWrite(PITCH_R_PWM, 0);
analogWrite(PITCH_L_PWM,abs(forces[1]));
digitalWrite(PITCH_L_EN,HIGH);
}
delay(10);
}

Pinout for buttons, axes and motors?

Hello.
I've been following a LONG time the adapt-ffb-joy project to give a second life to my Microsoft Sidewinder Force Feedback Wheel (gameport edition, sadly), but seems kinda dead.
I don't know if I can achieve it with this library, but I'm not afraid of crack opening the wheel and try to wire it up.
However, I have no clue about how to start wiring it.
Can anyone shed a light?
Thank you.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.