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.