Sketch Works on Everything BUT Nano IoT

The code below is the sample provided by Handson Tech for the Xy160D motor driver. I added the built in LED flash code to make sure it was looping. It runs perfectly on an Elegoo Mega2560 R3 and two different Nanos (Arduino and clone), but will not run on my Arduino NANO 33 IoT devices (I've tried two). On the IoT 33s, the LED blinks so I know the code is running, but the motor (in this case on a linear actuator) does not. I've triple checked the wiring. I've tried powering the devices using both USB and a benchtop power supply set to 5V.

When I connect the driver board's power, plus the PWM plus the INA line, the actuator powers up and runs continuously. If I disconnect the INA and connect INB, the actuator runs continuously in the opposite direction. With the PWN, INA, and INB all connected to the IoT 33, the actuator does nothing.

I've tried using different pins on the IoT 33 with the same result. Any ideas?

Note: the code is provided for both sides of the driver board (what the author notes as Motor1 and Motor2), but I am only using Motor1 on Arduino pins 5, 4, and 6.

/*==========================================================================
//  Author      : Handson Technology
//  Project     : Arduino Uno with H-Bride 7A Motor Driver
//  Description : XY160D 7A high Power H-Bridge motor Driver Module
//  Source-Code : H-Bride-7A-Motor-CTR.ino
//  Program: Control 2 DC motors using L298N H Bridge Driver
//==========================================================================
*/

const int IN1=5;
const int IN2=4;
const int ENA=6;

const int IN3=8;
const int IN4=7;
const int ENB=9;

bool ledState;

void setup() {
     pinMode(IN1, OUTPUT);
     pinMode(IN2, OUTPUT);
     pinMode(ENA, OUTPUT);
     
     pinMode(IN4, OUTPUT);
     pinMode(IN3, OUTPUT);
     pinMode(ENB, OUTPUT);

     pinMode(13,OUTPUT);
}

void loop() {
  ledState = !ledState;
  if (ledState) {
    digitalWrite(13, HIGH);
  } else {
    digitalWrite(13, LOW);
  }
  
 Motor1_Brake();
 Motor2_Brake();
 delay(100);
 Motor1_Forward(200);
 Motor2_Forward(200);
 delay(1000);
 Motor1_Brake();
 Motor2_Brake();
 delay(100);
 Motor1_Backward(200);
 Motor2_Backward(200);
 delay(1000); 
}

void Motor1_Forward(int Speed) 
{
     digitalWrite(IN1,HIGH); 
     digitalWrite(IN2,LOW);  
     analogWrite(ENA,Speed);
}
  
void Motor1_Backward(int Speed) 
{    
     digitalWrite(IN1,LOW); 
     digitalWrite(IN2,HIGH);  
     analogWrite(ENA,Speed);
}
void Motor1_Brake()      
{
     digitalWrite(IN1,LOW); 
     digitalWrite(IN2,LOW); 
}     
void Motor2_Forward(int Speed) 
{
     digitalWrite(IN3,HIGH); 
     digitalWrite(IN4,LOW);  
     analogWrite(ENB,Speed);
}
  
void Motor2_Backward(int Speed) 
{    
     digitalWrite(IN3,LOW); 
     digitalWrite(IN4,HIGH);  
     analogWrite(ENB,Speed);
}
void Motor2_Brake()
{
     digitalWrite(IN3,LOW); 
     digitalWrite(IN4,LOW); 
}

I would suspect it's a problem with the Nano 33 being a 3.3V device. The Xy160D claims to be 3.3V compatible, but there may be qualifications to that. The board has optocouplers and the Nano need to sink/source enough current into the optos. Without a schematic or better spec for the board its hard to tell.

2 Likes

Do you have a separate power supply for the motors?

1 Like

Yes, separate 12V, 12AH power supply for the XY160D motors.

I guess the only alternative then would be to add a regular NANO (triggered from the NANO IoT 33) to drive the XY160D then since the regular NANO works without any dramas. Sloppy, but if it works... unless someone has an alternative. This is ultimately going in a battery only installation so current drain is an issue.

Is there a different driver I could use with the IoT 33? I only need forward and reverse at full speed. I'm going to start scouring the Intertron, but I'll take any recommendations.

Without knowing the motor details I cannot give you an accurate answer but take a look at the BTS7960. I have had great luck with them. You will have to use a level translator or do as I did and change the buffer chip to a HTC device but it still needs 5V.

Hey Bob, I think you're right. I ditched the Arduino IoT 33 for an ESP32 WROOM Dev and it's working like a charm.

Thanks everyone for your input. I was getting pretty frustrated, but all is well now.

But the ESP32 is also a 3.3V device. So there's probably something else we´re not seeing.

The SAMD on the Nano seems to have very low drive currents on the IO pins, which may be less than needed to drive the optos. ESP32 seems to have much higher drive current.

There are logic level shifters which might work for this type of thing, although can have their own problems.

1 Like

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