Hello there,
I am using Arduino for the first time so let me know if I'm missing out something!
My goal is to control a robot using 2 DC motors via Arduino MEGA and the adafruit_MCP4725 library.
When sending commands, the motors that should be active simultanious are driving with an offset. For example, when sending the command to drive in the same direction for x seconds, one of the motors starts a few seconds later which results in the problem that driving to specific locations is not possible for me. The motors offset duration or which one of them shows the problem is allways different so I can't figure out an exact pattern.
I allready tried to check the hardware with an exernal voltage source. It showed that the hardware is fine, both motors approach at the same time when the needed voltage is reached. But the moment I attach them to the Arduino MEGA the problem occurs again.
To control the motors direction I am using a Joystick that sends commands "Forward, Backward, Left, Right, Stop" via a Bluetooth connection to the main board.
Unfortunately the used code is way bigger than the following so it's possible that i miss something you need for the understanding. So feel free to let me know about that and I'll try to give you the information. Also i provide you my current curcuit diagram with the two DA-Converters.
Here are some more information that are not shown in the code:
"v" is the value 1650. The motors work with voltages between 0,8 V and 3,6 V. Giving the value 1650 means that they get a Voltage value of 1,65 V
The Code I am using to process the commands is the following:
//Definition of the two DAC
Adafruit_MCP4725 dac_links;
Adafruit_MCP4725 dac_rechts;
const int Dir_right_wheel =3;
const int Dir_left_wheel =2;
pinMode(Dir_right_wheel,OUTPUT); //Deklariert Motorwerte als Ausgänge
pinMode(Dir_left_wheel,OUTPUT);
dac_links.begin(0x62); // Deklariert die Adressen der Motoren für DA-Wandler
dac_rechts.begin(0x63);
// Integration Part Motorsteurung
#include <SoftwareSerial.h>
#include <Adafruit_MCP4725.h>
{
{
//Hier wird die Nachricht des Clients gelesen in der Variable "Message" gespeichert
char message = client.read();
// Die Nachricht des Client wird im seriellen Monitor ausgegeben
Serial.write(message);
client.print(message);
if (message == 'B')
{
digitalWrite(Dir_left_wheel,HIGH); //High and Low sind zur Steuerung der Richtung
digitalWrite(Dir_right_wheel,LOW);
dac_links.setVoltage(v,true); // Der Wert gibt an wie schnell sich die Räder drehen
dac_rechts.setVoltage(v,true);
Serial.println("Forward"); // Ausgabe im seriellen Monitor
// LED leuchtet beim Rückwärtsfahren weiß
strip.setLEDcolor(0, WHITE);
strip.setLEDcolor(1, WHITE);
strip.writeStrip();
// Serial.println("A wurde geschickt!"); // Alternative 2, Rückgabewert über die Arduino Konsole
// delay gibt die Fahrdauer an, hier 5 Sekunden
}
else if (message == 'F')
{
digitalWrite(Dir_left_wheel,LOW); //High and Low sind zur Steuerung der Richtung
digitalWrite(Dir_right_wheel,HIGH);
dac_links.setVoltage(v,true); // Der Wert gibt an wie schnell sich die Räder drehen
dac_rechts.setVoltage(v,true);
Serial.println("Forward"); // Ausgabe im seriellen Monitor
// Beim Vorwärtsfahren leuchtet die LED grün
strip.setLEDcolor(0, BLUE);//In der Library sind Blue und Green vertauscht
strip.setLEDcolor(1, BLUE);
strip.writeStrip();
// Delay gibt die Fahrdauer an, hier 5 Sekunden
}
else if (message == 'L')
{
digitalWrite(Dir_left_wheel,LOW); //High and Low sind zur Steuerung der Richtung
digitalWrite(Dir_right_wheel,LOW);
dac_links.setVoltage(v,true); // Der Wert gibt an wie schnell sich die Räder drehen
dac_rechts.setVoltage(v,true); //
Serial.println("Left"); // Ausgabe im seriellen Monitor
// Beim nach Linksfahren leuchtet die LED Blau
strip.setLEDcolor(0,GREEN);
strip.setLEDcolor(1,BLACK);
strip.writeStrip();
// Delay gibt die Fahrdauer an, hier eine Sekunde
}
else if (message == 'R')
{
digitalWrite(Dir_left_wheel,HIGH); //High and Low sind zur Steuerung der Richtung
digitalWrite(Dir_right_wheel,HIGH);
dac_links.setVoltage(v,true); //Der Wert gibt an wie schnell sich die Räder drehen
dac_rechts.setVoltage(v,true); //
Serial.println("Right"); // Ausgabe im seriellen Monitor
// Beim nach Rechtsfahren leuchtet die LED Blau
strip.setLEDcolor(0,BLACK);
strip.setLEDcolor(1,GREEN);
strip.writeStrip();
// Delay gibt die Fahrdauer an, hier 7 Sekunden
}
else if (message == 'S')
{
digitalWrite(Dir_left_wheel,HIGH); //High and Low sind zur Steuerung der Richtung
digitalWrite(Dir_right_wheel,LOW);
dac_links.setVoltage(0,true); // Der Wert gibt an wie schnell sich die Räder drehen
dac_rechts.setVoltage(0,true); //
Serial.println("Stop"); // Ausgabe im seriellen Monitor
// Die LED blinkt bei einem Stop-Befehl 6 mal rot auf
strip.setLEDcolor(0,RED);
strip.setLEDcolor(1,RED);
strip.writeStrip();
}
}
}
Thank you everyone in advance for your help. As allready mentioned, I'll try to support you with missing information as fast and best i can.
