Force Feed Back Joystick Leonardo


I am new to arduino and i am working on a Force Feed Back joystick project. I found a library for exactly what i am looking for but i am a little confused on the hookup to the arduino.

This is the Library

They have example code

#include "Joystick.h"

//X-axis & Y-axis REQUIRED
  true, true, true, //X,Y,Z
  false, false, false,//Rx,Ry,Rz
  false, false, false, false, false);

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

void setup(){
    Joystick.setXAxisRange(0, 1023);
    //Steering wheel
    //Joystick.setXAxisRange(-512, 512);
    //set X Axis gains
    mygains[0].totalGain = 100;//0-100
    mygains[0].springGain = 100;//0-100
    //enable gains REQUIRED

void loop(){
  int value = analogRead(A2);
  //set X Axis Spring Effect Param
  myeffectparams[0].springMaxPosition = 1023;
  myeffectparams[0].springPosition = value;//0-1023
  //Steering wheel
  //myeffectparams[0].springMaxPosition = 512;
  //myeffectparams[0].springPosition = value - 512; //-512-512

  //Send HID data to PC

  //Recv HID-PID data from PC and caculate forces
  //Steering wheel
  //Joystick.setXAxis(value - 512);
  if(forces[0] > 0){

So in this example we are going to be using pins A0, 6, 7, 9

Seeing that pin A0 is listed as a input, I am assuming that is going to be used for the encoder for the axis

Pin 6, 7, 9 my guess is going to be used to send the Step and Dir to a motor driver for the feed back but which is which. I am using a BTS7960 which has the following pin out

VCC: Module power supply – 5V
GND: Ground
IS-R: Input signal for detecting high current – Straight rotation
IS-L: Input signal for detecting high current – Inverse rotation
EN-R: Output Signal for controlling motor direction – Straight rotation
EN-L: Output Signal for controlling motor direction – Inverse rotation
WM-R: PWM Signal for controlling motor speed – Straight rotation
PWM-L: PWM Signal for controlling motor speed – Inverse rotation

VCC and GND are easy...

In the code, pin 6 and 7 are listed as "HIGH" and "LOW" does that go to IS-R and IS-L to set the direction?

And then Pin 9 is using a "force" value which my guess is a PWM signal, would that go to PWM-L? I am also seeing that the driver has WM-R for a "Straight Rotation".... wouldn't that be set based on which pin is HIGH on 6, and 7?

I think i am on the right track here, just wanted to get your guys opinion?

Thank You

Did you by chance mean pin A2? I do not see any A0 reference in your code.

Since A2 is read and used to set the sprint effect, I'm guessing it is connected to some potentiometer you can use to adjust the feedback.

It does look like pins 6 & 7 are the direction and pin 9 is the speed control.

Given your description of your BTS7960, it looks like pin 6 = EN-R, pin 7 = EN-L but pin 9 would have to go to both PWM-R and PWM-L since you have 2 speed pins.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.