Hello,
I am trying to run a motor through an ESC on an arduino UNO or NANO. The ESC is connected either to D10, D9, R6 or D5. I can only master the motor speed on D10 (same behavior on UNO and NANO, no other pin works). The ESC is connected to the arduino on GND & D10 (or D9, D6, D5). I use the servo library to choose the speed.
I tried both write (with speed between 0 & 180) & writeMicroseconds (with speed between 1000 and 2000). Both code bring the same expected behavior on D10 and failing on D5, 6 or 9. You can also see I use a wifi connection to the controler, I would think this does not matter.
The ESC is also connected to a battery. Initialization sequence (with expected beeps) only happens on D10. On D5, D6 or D9, I get beeps every second or so, indicating failure.
If anyone could help to get the ability to run on any of D5, D6, D9 (or other) pins as I intend to run 4 motors.
Thank you
Here is the code
#include <SPI.h>
#include <RF24.h>
#include <Servo.h>
#define pinCE 7 // On associe la broche "CE" du NRF24L01 à la sortie digitale D7 de l'arduino
#define pinCSN 8 // On associe la broche "CSN" du NRF24L01 à la sortie digitale D8 de l'arduino
#define pinPwmNW 5
#define pinPwmNE 6
#define pinPwmSE 9
#define pinPwmSW 10
#define thrustMin 0
#define thrustMax 180
// WIFI
RF24 radio(pinCE, pinCSN);
// ESC & MOTOR
Servo mtrNW, mtrNE, mtrSE, mtrSW;
int impulse = thrustMax;
const byte adresse[6] = "YLDRN"; // Mise au format "byte array" du nom du tunnel
struct {
unsigned int forward, backward, right, left, up, down, clockwise, counterclockwise;
} msgToDrone;
void setup() {
// point pour le moteur
mtrNW.attach(pinPwmNW, thrustMin, thrustMax);
mtrNW.attach(pinPwmNE, thrustMin, thrustMax);
mtrNW.attach(pinPwmSE, thrustMin, thrustMax);
mtrNW.attach(pinPwmSW, thrustMin, thrustMax);
mtrNW.write(impulse);
mtrNE.write(impulse);
mtrSE.write(impulse);
mtrSW.write(impulse);
// Initialisation du port série (pour afficher les infos reçues, sur le "Moniteur Série" de l'IDE Arduino)
Serial.begin(9600);
Serial.println("NRF24L01 recepteur");
// Partie NRF24
if( radio.begin() )
Serial.println("radio hardware responding");
radio.setChannel(125);
radio.setPALevel(RF24_PA_MIN);
radio.setDataRate(RF24_250KBPS);
radio.openReadingPipe(0, adresse);
radio.startListening();
}
void loop() {
// On vérifie à chaque boucle si un message est arrivé
if (radio.available()) {
radio.read(&msgToDrone, sizeof(msgToDrone)); // Si un message vient d'arriver, on le charge dans la variable "message"
char txt[256];
sprintf(txt, "spd %d fwd %d, bwd %d rgt %d lft %d", msgToDrone.up, msgToDrone.forward, msgToDrone.backward, msgToDrone.right, msgToDrone.left);
Serial.println(txt); // … et on l'affiche sur le port série !
// Conversion de la vitesse en ms
impulse = map(msgToDrone.up, 0, 1023, thrustMin, thrustMax);
}
// Envoi du signal de commande à l'ESC
mtrNW.write(impulse);
mtrNE.write(impulse);
mtrSE.write(impulse);
mtrSW.write(impulse);
}```