Hello! I am working on a steering wheel with force feedback that needed a motor and a motor controller that could rotate the motor in both directions at any speed. I picked the l298n to do the job, and it doesn't work. It isn't broken because I had a another one and the same thing keeps happening. Nothing works. The small red led doesn't turn on, the motor doesn't turn nothing. I changed the arduino and it still didn't work. Here is the schematic and the code:
#include "Joystick.h"
//X-axis & Y-axis REQUIRED
Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID,
JOYSTICK_TYPE_GAMEPAD, //JOYSTICK, GAMEPAD, MULTI_AXIS
4, 0, //Button Count, Hat Switch Count
true, true, true, //X,Y,Z
false, false, false, //Rx,Ry,Rz
false, false, false, //Rudder,Throttle,Accelerator
false, false); //Brake,Steering
Gains mygains[2];
EffectParams myeffectparams[2];
int32_t forces[2] = {0};
void setup() {
pinMode(A3, INPUT);
pinMode(10, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
//Joystick.setXAxisRange(0, 1023);
//Steering wheel
Joystick.setXAxisRange(0, 1023);
//set X Axis gains
mygains[0].totalGain = 100;//0-100
mygains[0].springGain = 100;//0-100
//enable gains REQUIRED
Joystick.setGains(mygains);
Joystick.begin();
Serial.begin(9600);
digitalWrite(8,HIGH);
digitalWrite(7,HIGH);
analogWrite(10,25);
delay(50);
analogWrite(10,255);
delay(5000);
analogWrite(10,0);
digitalWrite(8,LOW);
digitalWrite(7,LOW);
}
void loop() {
int value = analogRead(A3);
//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
//Joystick.setXAxis(value);
//Recv HID-PID data from PC and caculate forces
//Steering wheel
Joystick.setXAxis(value);
Joystick.setEffectParams(myeffectparams);
Joystick.getForce(forces);
if (forces[0] > 0) {
digitalWrite(6, HIGH);
digitalWrite(7,LOW);
analogWrite(9, abs(forces[0]));
} else {
digitalWrite(6, LOW);
digitalWrite(7,HIGH);
analogWrite(9, abs(forces[0]));
}
Serial.println(digitalRead(7));
}