[reposted due to incorrect title] @UKHeliBob
Hello! I'm having some weirdness with my circuit containing Arduino Nano ESP32-S3, logic level converters (LLCs), and L298 motor drivers with motors. I am bewildered by what is happening here, so please bear with me as I try to explain it.
Note in advance:
The whole circuit worked fine with an Arduino Uno connected directly to the motors (with no logic level converters). It's after I switched from this to the Nano with the LLCs that everything went crazy.
The electrical schematic is attached (the motor LLCs are not included, but they're interposed between the Arduino and the drivers and are the same model as the other LLCs in the diagram).
robot schematic.pdf (20.4 KB)
Here is my firmware script. The comments above each the write-to-pin
code block indicate which motor the code should control based on physical wiring path. The three inline comments each for motors A and B show which Arduino pins are actually responsible for that motor's movement (based on process of elimination through commenting out code lines in the firmware).
// define MCU pin IDs
// motor A
#define PIN_ENA1_1 D12
#define PIN_IN1_1 D11
#define PIN_IN2_1 D10
// motor B
#define PIN_ENA2_1 D9
#define PIN_IN3_1 D8
#define PIN_IN4_1 D7
// motor C
#define PIN_ENA1_2 D6
#define PIN_IN1_2 D5
#define PIN_IN2_2 D4
// motor D
#define PIN_ENA2_2 D3
#define PIN_IN3_2 D2
#define PIN_IN4_2 D13
void setup() {
pinMode(PIN_IN1_1, OUTPUT);
pinMode(PIN_IN2_1, OUTPUT);
pinMode(PIN_ENA1_1, OUTPUT);
pinMode(PIN_IN3_1, OUTPUT);
pinMode(PIN_IN4_1, OUTPUT);
pinMode(PIN_ENA2_1, OUTPUT);
pinMode(PIN_IN1_2, OUTPUT);
pinMode(PIN_IN2_2, OUTPUT);
pinMode(PIN_ENA1_2, OUTPUT);
pinMode(PIN_IN3_2, OUTPUT);
pinMode(PIN_IN4_2, OUTPUT);
pinMode(PIN_ENA2_2, OUTPUT);
}
void loop() {
// MOTOR A
digitalWrite(PIN_IN1_1, HIGH);
digitalWrite(PIN_IN2_1, LOW);
analogWrite(PIN_ENA1_1, 60); // A, BL; motor A moves when zero
// // MOTOR B
digitalWrite(PIN_IN3_1, LOW);
digitalWrite(PIN_IN4_1, HIGH); // A
analogWrite(PIN_ENA2_1, 60); // A; motor A immobile when zero
// // MOTOR C
digitalWrite(PIN_IN1_2, LOW);
digitalWrite(PIN_IN2_2, HIGH); // BL
analogWrite(PIN_ENA1_2, 60); // BL
// // MOTOR D
digitalWrite(PIN_IN3_2, HIGH);
digitalWrite(PIN_IN4_2, LOW);
analogWrite(PIN_ENA2_2, 60);
}
The problem is that each motor is operating according to Arduino pins that they're not assigned to. For example, the motor that's supposed to operate according to logic associated with Arduino pins D10, D11, and D12 is operating according to pins D7, D9, and D12 (not necessarily in that order). By "D" here I mean a digital pin reference as is printed on the Arduino.
I have one Arduino, two motor drivers with two motors each (3 logic pins per motor, thus 6 per board, and 12 total), and three logic level converters (4 logic pins per board, 3 boards, 12 total). I need the LLCs to step up the 3.3 V from the Arduino to the 5 V necessary for the drivers.
Digital pins D12, D11, and D10 correspond to motor A.
Digital pins D9, D8, and D7 correspond to motor B.
Digital pins D6, D5, and D4 correspond to motor C.
Digital pins D3, D2, and D13 correspond to motor D.
For each motor, I have routed the three corresponding logic wires through the LLC(s) and into the respective control pins on its driver. By "through the LLC", I mean that, for example, the signal coming out of D12 on the Arduino goes into LV1 on an LLC, then out HV1 on that LLC, then to the driver.
Here's what I'm seeing:
Motor A moves when it receives a signal from pins D7, D9, and D12.
Motor D moves when it receives a signal from pins D4, D6, D12.
Motor C doesn't run at all, and motor B runs but I didn't bother to isolate its behavior yet.
These responses are consistent and don't change over multiple trials.
PWM on the "ENA" pins also doesn't seem to be working (motor speed doesn't change when I change the PWM value; only tested on motor A so far).
First, why are the motors responding to seemingly random pins?
Second, how in the world is one Arduino output (D12) taking part in the control of two different motors? For extra context, the motor A and motor D are on different driver boards and their intended control wires don't share the same LLC.
I've triple checked all of the following:
- The LLCs have the right HV and LV power (5 V and 3.3 V) and are grounded
- Each wire is routed correctly from the Arduino, through the LLC, and into the corresponding logic pin in the driver
- There are no shorts between pins/contacts on the Arduino, LLCs, or drivers