HC12 L298N souběh motorů

Dobrý den, chtěl bych Vás požádat o radu, kde nevím, proč mi nejdou současně dva motory (pohyb vpřed a vzad). Vlevo a vpravo pracují správně.
Při zapojení joystiku k L298N vše pracovalo správně, ale při zapojení HC12 již pohyb vpřed a vzad nejde, vždy pouze jeden motor a to levý nebo pravý. Vyzkoušel jsem dva různé kódy z různých zdrojů a problém je pořád stejný. Předpokládám, že bude chyba někde v zapojení HC12. Moc děkuji za případnou pomoc.

Postupoval jsem např. podle tohoto návodu:

Vysílač:

int xAxis, yAxis;

void setup() {
Serial.begin(9600); // Default communication rate of the Bluetooth module
}

void loop() {
xAxis = analogRead(A0); // Read Joysticks X-axis
yAxis = analogRead(A1); // Read Joysticks Y-axis

// Send the values via the serial port to the slave HC-05 Bluetooth device
Serial.write(xAxis/4); // Dividing by 4 for converting from 0 - 1023 to 0 - 256, (1 byte) range
Serial.write(yAxis/4);
delay(20);
}

Přijímač:

#define enA 9
#define in1 4
#define in2 5
#define enB 10
#define in3 6
#define in4 7

int xAxis, yAxis;
int x = 0;
int y = 0;

int motorSpeedA = 0;
int motorSpeedB = 0;

void setup() {
pinMode(enA, OUTPUT);
pinMode(enB, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);

Serial.begin(9600); // Default communication rate of the Bluetooth module
}

void loop() {
// Default value - no movement when the Joystick stays in the center
xAxis = 510;
yAxis = 510;

// Read the incoming data from the
while (Serial.available() == 0) {}
x = Serial.read();
delay(10);
y = Serial.read();
delay(10);

// Convert back the 0 - 255 range to 0 - 1023, suitable for motor control code below
xAxis = x * 4;
yAxis = y * 4;

// Y-axis used for forward and backward control
if (yAxis < 470) {
// Set Motor A backward
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
// Set Motor B backward
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
// Convert the declining Y-axis readings for going backward from 470 to 0 into 0 to 255 value for the PWM signal for increasing the motor speed
motorSpeedA = map(yAxis, 470, 0, 0, 255);
motorSpeedB = map(yAxis, 470, 0, 0, 255);
}
else if (yAxis > 550) {
// Set Motor A forward
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
// Set Motor B forward
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
// Convert the increasing Y-axis readings for going forward from 550 to 1023 into 0 to 255 value for the PWM signal for increasing the motor speed
motorSpeedA = map(yAxis, 550, 1023, 0, 255);
motorSpeedB = map(yAxis, 550, 1023, 0, 255);
}
// If joystick stays in middle the motors are not moving
else {
motorSpeedA = 0;
motorSpeedB = 0;
}

// X-axis used for left and right control
if (xAxis < 470) {
// Convert the declining X-axis readings from 470 to 0 into increasing 0 to 255 value
int xMapped = map(xAxis, 470, 0, 0, 255);
// Move to left - decrease left motor speed, increase right motor speed
motorSpeedA = motorSpeedA - xMapped;
motorSpeedB = motorSpeedB + xMapped;
// Confine the range from 0 to 255
if (motorSpeedA < 0) {
motorSpeedA = 0;
}
if (motorSpeedB > 255) {
motorSpeedB = 255;
}
}
if (xAxis > 550) {
// Convert the increasing X-axis readings from 550 to 1023 into 0 to 255 value
int xMapped = map(xAxis, 550, 1023, 0, 255);
// Move right - decrease right motor speed, increase left motor speed
motorSpeedA = motorSpeedA + xMapped;
motorSpeedB = motorSpeedB - xMapped;
// Confine the range from 0 to 255
if (motorSpeedA > 255) {
motorSpeedA = 255;
}
if (motorSpeedB < 0) {
motorSpeedB = 0;
}
}
// Prevent buzzing at low speeds (Adjust according to your motors. My motors couldn't start moving if PWM value was below value of 70)
if (motorSpeedA < 70) {
motorSpeedA = 0;
}
if (motorSpeedB < 70) {
motorSpeedB = 0;
}
analogWrite(enA, motorSpeedA); // Send PWM signal to motor A
analogWrite(enB, motorSpeedB); // Send PWM signal to motor B
}

Vaše téma bylo na fóru přesunuto na vhodnější místo. Instalace a odstraňování problémů se nevztahuje na problémy s vaším projektem (ani na rady ohledně) :wink: Viz About the Installation & Troubleshooting category.

Zveřejněte prosím svůj dotaz v angličtině; můžete použít https://translate.google.com

Upravte prosím svůj příspěvek, vyberte celý kód a kliknutím na tlačítko </> použijte takzvané kódové značky a poté svůj příspěvek uložte. Usnadňuje čtení, snazší kopírování a brání tomu, aby jej software fóra zobrazoval správně.

Translation for others (google translate):

Hello, I would like to ask for your advice as I do not know why two motors do not work at the same time (forward and reverse movement). Left and right work correctly.
When connecting the joystick to the L298N, everything worked correctly, but when connecting the HC12, forward and backward movement is no longer possible, always only one motor, left or right. I tried two different codes from different sources and the problem is still the same. I assume that there will be an error somewhere in the HC12 connection. Thank you very much for any help.

Dobrý den, chtěl bych Vás požádat o radu, kde nevím, proč mi nejdou současně dva motory (pohyb vpřed a vzad). Vlevo a vpravo pracují správně.
Při zapojení joystiku k L298N vše pracovalo správně, ale při zapojení HC12 již pohyb vpřed a vzad nejde, vždy pouze jeden motor a to levý nebo pravý. Vyzkoušel jsem dva různé kódy z různých zdrojů a problém je pořád stejný. Předpokládám, že bude chyba někde v zapojení HC12. Moc děkuji za případnou pomoc.

Postupoval jsem např. podle tohoto návodu:

Vysílač:

int xAxis, yAxis;

void setup() {
Serial.begin(9600); // Default communication rate of the Bluetooth module
}

void loop() {
xAxis = analogRead(A0); // Read Joysticks X-axis
yAxis = analogRead(A1); // Read Joysticks Y-axis

// Send the values via the serial port to the slave HC-05 Bluetooth device
Serial.write(xAxis/4); // Dividing by 4 for converting from 0 - 1023 to 0 - 256, (1 byte) range
Serial.write(yAxis/4);
delay(20);
}

Přijímač:

#define enA 9
#define in1 4
#define in2 5
#define enB 10
#define in3 6
#define in4 7

int xAxis, yAxis;
int x = 0;
int y = 0;

int motorSpeedA = 0;
int motorSpeedB = 0;

void setup() {
pinMode(enA, OUTPUT);
pinMode(enB, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);

Serial.begin(9600); // Default communication rate of the Bluetooth module
}

void loop() {
// Default value - no movement when the Joystick stays in the center
xAxis = 510;
yAxis = 510;

// Read the incoming data from the
while (Serial.available() == 0) {}
x = Serial.read();
delay(10);
y = Serial.read();
delay(10);

// Convert back the 0 - 255 range to 0 - 1023, suitable for motor control code below
xAxis = x * 4;
yAxis = y * 4;

// Y-axis used for forward and backward control
if (yAxis < 470) {
// Set Motor A backward
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
// Set Motor B backward
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
// Convert the declining Y-axis readings for going backward from 470 to 0 into 0 to 255 value for the PWM signal for increasing the motor speed
motorSpeedA = map(yAxis, 470, 0, 0, 255);
motorSpeedB = map(yAxis, 470, 0, 0, 255);
}
else if (yAxis > 550) {
// Set Motor A forward
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
// Set Motor B forward
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
// Convert the increasing Y-axis readings for going forward from 550 to 1023 into 0 to 255 value for the PWM signal for increasing the motor speed
motorSpeedA = map(yAxis, 550, 1023, 0, 255);
motorSpeedB = map(yAxis, 550, 1023, 0, 255);
}
// If joystick stays in middle the motors are not moving
else {
motorSpeedA = 0;
motorSpeedB = 0;
}

// X-axis used for left and right control
if (xAxis < 470) {
// Convert the declining X-axis readings from 470 to 0 into increasing 0 to 255 value
int xMapped = map(xAxis, 470, 0, 0, 255);
// Move to left - decrease left motor speed, increase right motor speed
motorSpeedA = motorSpeedA - xMapped;
motorSpeedB = motorSpeedB + xMapped;
// Confine the range from 0 to 255
if (motorSpeedA < 0) {
motorSpeedA = 0;
}
if (motorSpeedB > 255) {
motorSpeedB = 255;
}
}
if (xAxis > 550) {
// Convert the increasing X-axis readings from 550 to 1023 into 0 to 255 value
int xMapped = map(xAxis, 550, 1023, 0, 255);
// Move right - decrease right motor speed, increase left motor speed
motorSpeedA = motorSpeedA + xMapped;
motorSpeedB = motorSpeedB - xMapped;
// Confine the range from 0 to 255
if (motorSpeedA > 255) {
motorSpeedA = 255;
}
if (motorSpeedB < 0) {
motorSpeedB = 0;
}
}
// Prevent buzzing at low speeds (Adjust according to your motors. My motors couldn't start moving if PWM value was below value of 70)
if (motorSpeedA < 70) {
motorSpeedA = 0;
}
if (motorSpeedB < 70) {
motorSpeedB = 0;
}
analogWrite(enA, motorSpeedA); // Send PWM signal to motor A
analogWrite(enB, motorSpeedB); // Send PWM signal to motor B
}

Thanks for using code tags this time :wink: Your original was hidden for a while by the anti-spam.

Your previous post is here: HC12 L298N souběh motorů

google translate:
Děkujeme, že jste tentokrát použili kódové značky :wink: Váš originál byl na chvíli skryt antispamem.

Váš předchozí příspěvek je zde: HC12 L298N souběh motorů

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