PWM A2212 Issues

Hi I am trying to control some A2212 motors with 30A ESC. These are powered by a 3S LiPo Battery in parallel and I am using an Arduino Nano powered with an external different battery of 9V powering the Nano through the VIN pin.

I get the motors to work but in some test that have done, in an unexpected moment some motors (I don't know with certain if all or just some of them, nor why) start to rotate at max speed uncontrolled and ignoring the PWM signals of Nano.

For turning off the motors it should be sufficient to power off the nano right, so they stop receiving PWM signal and so stop? But it didn't work, I unplugged the VIN and the motors were still spinning uncontrolled. After disconnecting the LiPo Battery the motors stopped.

Any clues of what could have happened? I am using PWM Nano pins at default frequencies of 490Hz and 980Hz and I am using servo library with the writeMicroseconds method. But I think that the software is not affecting as when I disconnected the power to the Nano the motors were still spinning. Maybe any example code for testing if hardware is well (I think is well as when I don't have this issue al works)

Please post schematics! Something is seriously wrong.

Your post tells You need to work trough this link: How to get the best out of this forum - Using Arduino / Project Guidance - Arduino Forum

1 Like

Hi, sorry for previous bad post.

I am trying to control some motors on a Nano setted up as receiver which receives the speed of the motors from another Nano.

Hardware:
I don't have specific datasheet for them, but if needed I can search generic datasheet on google

  • A2212 1000KV
  • 30A ESCs (1 for each motor)
  • 3S LiPo
  • Arduino Nano
  • 6xAA
  • NRF24L01

This is the schematic on topic for ESC (without the motors connections as they can just affect on CW or CCW)


(I have all ESC connected on parallel, three of them are wired to a PWM pin of Nano with default frequency of 980Hz, the other one to a 490Hz. They are not all 980 because I need the D11 980Hz PWM pin for SPI)

For powering the Arduino Nano I use 6AA (9V) and I connect to VIN and GND, GND is common with 3S LiPo.

I have done some test and these are some notes that I would like to highlight:
Sometimes all works well, I can control velocity and all seems to have no problems. But in some cases when the motors are already spinning, suddenly some of them starts to spin at max speed (or very fast). Then I unplug the transmitter and the Nano should send instructions to stop the motors (this is in the code) but they don't stop, then I disconnected Arduino Nano that controls the ESC and they still spin (idk how), and finally I unplug the 3S Lipo and they stop spinning.

The wireless communication is always stable and I control the speed when then suddenly (this always happened when motors are already spinning) some motors go out of control and even tough I try to control the speed I can't. I say that the communication is stable because on code is specified that if there is no connection then stop the motors, as well, because even though I unconnected the Nano that controls the ESC, the motors were still spinning.

Moreover, on the code I have a part that I am not pretty sure about, I added one day because if not it didn't worked, as well right now it seems that even though I have that part it works in some cases well, and for my mind the software is not affecting too much (but I don't know) as I have said before even though I disconnected the power for Nano the motors were still spinning

This is the code:

#include <Arduino.h>  // This is because I am using PlatformIO on VSCode

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Servo.h>

Servo mot1, mot2, mot3, mot4;

#define signal1 3
#define signal2 6
#define signal3 9
#define signal4 10

RF24 radio(7, 8);  // CE, CSN

const byte address[6] = "12345";

int motSpeeds[4];


void setup() {
  pinMode(signal1, OUTPUT);
  pinMode(signal2, OUTPUT);
  pinMode(signal3, OUTPUT);
  pinMode(signal4, OUTPUT);

  radio.begin();
  radio.openReadingPipe(0, address);
  radio.setPALevel(RF24_PA_MAX);
  radio.startListening();

// This is the part, could this be leading to a uncalibration of ESCs? 
// if so, why if I disconnect Nano the motors are still spinning?
  mot1.attach(signal1, 1000, 2000);
  delay(1000);
  mot2.attach(signal2, 1000, 2000);
  delay(1000);
  mot3.attach(signal3, 1000, 2000);
  delay(1000);
  mot4.attach(signal4, 1000, 2000);
  delay(1000);

  mot1.writeMicroseconds(1000);
  mot2.writeMicroseconds(1000);
  mot3.writeMicroseconds(1000);
  mot4.writeMicroseconds(1000);

  delay(5000);
}


void loop() {
  if (radio.available()) {
    radio.read(motSpeeds, sizeof(motSpeeds)); // With another Nano I send some values for speed control

    int esc1 = motSpeeds[0];
    int esc2 = motSpeeds[1];
    int esc3 = motSpeeds[2];
    int esc4 = motSpeeds[3];

    mot1.writeMicroseconds(esc1);
    mot2.writeMicroseconds(esc2);
    mot3.writeMicroseconds(esc3);
    mot4.writeMicroseconds(esc4);
  } else {
    mot1.writeMicroseconds(1000);
    mot2.writeMicroseconds(1000);
    mot3.writeMicroseconds(1000);
    mot4.writeMicroseconds(1000);
  }
}

If there is needed some more info or I am not explaining very good myself, then please tell me and I will try my best to explain.

Why? The more separation of power things from logics, the better. Many times not needed, rather unwanted. Most motor controllers have a low voltage logic side and a high voltage motor side.

Without any bad intension I guess You assembled the lot, and started coding. Correct?

The suggestion is to cut off all that's not needed for the motor control. Make that work.
Then instal debug prints for the radio data received. I don't know the radio.read function. Does it return integers or bytes or something else?

What is connected to the controller 5 volt pin? Know that it supplies a very low amount of current in this configuration.

Didn't know that, thanks, I will try without GND common with 3s LiPo. I thought that common GND was good.

If you mean a prebuild lot no, I have searched for info and bought the components individually, but they seem to work well, is that sometimes I get this strange comportment, but I think it is so dangerous for ignoring it. But yes, after wiring I started coding.

Sorry, I don't understand too much this text. What are the debug prints for the radio data received?

What I do is check if there is data available with the radio.read() that returns true or false, if true then the motors are spinning at the velocity received but if false (no wireless connection) then the motors should go to 0 velocity that works when I don't get the issue.

I have just realized this: is there a possibility that the connection is lost and as the motors are spinning they cannot go to 0 speed directly?

There is anything connected to 5 volt, I just use 3.3V for the NRF24L01 module.

And one more thing, can a bad ESC calibration produce this problem?

The Nano is powered by an external 9 volt battery...... Is it a PP3 battery? That battery will not work. The PP3 can not output enough current.
... The NRF powered by Nano 3.3 volt pin.... Will not work. Use a stronger 3.3 volt supply. A buck converter between
LiPo cells and NRF would be better.
Please make and post schematics for this powering.

Hi thanks for the help but they are 6 AA batteries in series providing 9V which is working great to power Nano and by using more than 3.3V on NRF24L01 will burn it.

I think the problem is not with the transmission but with the ESC working, that sometimes they make the motor spin uncontrolled ignoring the PWM nano signal.

?

?

6 x AA is okey.
Do not use the onboard 3.3 volt converter. It doesn't deliver enough current. Use a buck converter converting 9 volt to 3.3 volt.
Put Your thoughts into action a try them! I don't have Your setup and can't try it.

Try calibrating the ESC.

Hi,
Have you got code that JUST tests and controls 1 ESC?

If not, them for the moment forget your main code and JUST write code to control 1 ESC.

Prove your individual bits of hardware with separate codes before attempting your full code.

A schematic is ESSENTIAL in this application.

Can we please have a circuit diagram?
An image of a hand drawn schematic will be fine, include ALL power supplies, component names and pin labels.

Sorry but this is not a schematic;

Thanks.. Tom.. :grinning: :+1: :coffee: :australia:

Hi,

Right now no, but when they arrived I have tested them and they did not show non-normal behavior, they seemed to work well.

This is the schematic, I don't know if this is what I should provide, if not, let me know how it should be please

So after calibration it still does not work?

Yes but no. Like it works, but I don't know if I will get the same problem as before, I don't have any clue if I solved my issue.

Before it already worked, I could make my motors spin with remote control but sometimes some motors, out of nowhere, they start to spin at max speed because they want, they are not supposed to do that.

I will be doing so many tests so if there is still the problem I get more changes to get it and see that I haven't solved the issue. But I think calibration is not really the problem (maybe yes but I dunno) because some days ago I have already calibrated the ESC, but well, is worth trying another time.

Some ESC need calibration, some don't but once calibrated it should remain calibrated.
However I seen a lot on info on the web about ESC needing re- calibration if you remove power.
With your unknown type ESCs you will just have to experiment to see what works.

News: I have made some tests and I don't have any video but I think the problem is with the calibration. But I don't know why happens nor how can I solve it.

I have done one time calibration with software and all worked good, I controlled the motors with remote control. But then I recalibrated with controller, I followed the steps and after just finish the calibration I controlled a little bit and then after aprox 3 seconds of controling the motors went to max speed. I put thrust 0 with remote control but they were still spinning, by powering off the nano they stopped.

It is like if they start to spin uncontrolled then I can not stop them if I don't power off.

*I am following strictly the steps on calibrating.

Servo signals are NOT PWM, they don't need to be connected to PWM pins, you could use A0, A1, A2 and A3.

What do you mean controller?
Not using the Arduino?

I mean Remote control that is another arduino with joysticks

In which cases is compulsory to connect to PWM pins? I have seen that some people use as well servo 50Hz in normal digital pins.

Well maybe you should check if the received motor speed is in the valid range of 1000 to 2000 and if it's not print an error