Hallo community,
Ich habe einen slotcarregler gebaut nach anleitung von dronebot.com
DC Motors with L298N Dual H-Bridge and Arduino | DroneBot Workshop
Mit einem Arduino uno
Das funktioniert soweit mit den 2 potentiometern carrera reglern.
Ich habe allerdings 3 probleme, für die ich über tipps dankbar wäre.
- das pwm signal am Arduino und am Ausgang des 298 ist kein rechteck. Die horizontale Flanke läuft logarythmisch aus.
- bei Vollgas ist das Signal keine vertikale linie, es bleiben kleine zacken.
- ich kann eigentlich nicht gut programmieren. Kann mier vielleicht jemand sagen, wo ich was ändern muss, dass das Auto bremst , wenn das poti auf 0 ist
Danke Frank
Anbei der code
/*
L298N Motor Control Demonstration with 2 Potentiometers
L298N-Motor-Control-Demo-2pots.ino
Demonstrates use of 2 potentiometers with Arduino and L298N Motor Controller
DroneBot Workshop 2017*/
// Motor A
int enA = 9;
int in1 = 8;
int in2 = 7;
// Motor B
int enB = 3;
int in3 = 5;
int in4 = 4;
// Speed control potentiometers
int SpeedControl1 = A0;
int SpeedControl2 = A1;
// Motor Speed Values - Start at zero
int MotorSpeed1 = 0;
int MotorSpeed2 = 0;
void setup(
{
// TCCR1B = TCCR1B & B11111000 | B00000010; // set timer 1 divisor to 1 for PWM frequency of 31372.55 Hz
// Set all the motor control pins to outputs
pinMode(enA, OUTPUT);
pinMode(enB, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);
}
void loop() {
// Set Motor A forward
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
// Set Motor B forward
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
// Read the values from the potentiometers
MotorSpeed1 = analogRead(SpeedControl1);
MotorSpeed2 = analogRead(SpeedControl2);
// Convert to range of 0-255
MotorSpeed1 = map(MotorSpeed1, 0, 1000, 0, 255);
MotorSpeed2 = map(MotorSpeed2, 0, 1023, 0, 255);
// Adjust to prevent "buzzing" at very low speed
if (MotorSpeed1 < 8)MotorSpeed1 = 0;
if (MotorSpeed2 < 8)MotorSpeed2 = 0;
// Set the motor speeds
analogWrite(enA, MotorSpeed1);
analogWrite(enB, MotorSpeed2);
}