I am working on a project building a drone where an Arduino Nano sends a message throught UART to another Arduino Nano (TX from arduino sender to RX on arduino receiver), and according to the message, I move the servos connected to the arduino receiver.
To do this, first I tried to communicate both arduinos nano throught Serial, and it works perfectly. This is the code used for this first part of the project:
First try. Arduino sender sends throught UART a message to the arduino receiver:
Codes attached: “Arduino_sender.ino” and “Arduino_receiver.ino”
Everything works perfectly here, so I tried the second part: move the 4 servos connected to my drone according to the order sent from an arduino. To do this I just used one arduino nano, 4 standard servos of 1000KV with a 30A ESC attached to each one of them, and the arduino nano is connected to the PC via USB to send the orders throught the Serial monitor. Here is the code used in this part:
Arduino move servos sending the orders throught the Serial monitor:
Code attached: SetupAndMoveMotors.ino
What I am doing here is very simple. In the setup() I configure the motors to the minimum speed, and I am able to listen the “beep,beep,beep” of all the motors. When I open the Serial monitor, I only have to write first the value of the motor I am going to move, for example “1” for motor1, and after I have to write the speed of the motor1, for example “1500”. To move another motor, for example, motor2, I only have to write again “1” to disable the orders to motor1, and I write “2” to enable the orders to motor2, after I just write again the speed of the motor2, for example “1500”, and the motor2 starts moving. By reading the code is very intuitive to understand I think.
This code also works perfectly, so I only need to merge both parts of the project to be able to do what I said at the beginning. This is the merged code:
Arduino ender sends via UART to arduino receiver a message. According to this message, the arduino receiver sends the order to the motors:
Code attached: 1_Complete_code_UART_and_motors.ino
Here is the problem. If I comment the setup of the motors in the setup(), the message is received properly, and the value is printed, although the motors are not moving because their setup is commented. If the setup of the motors are not commented, it seems that everything goes perfectly during the setup() and the motors sound correctly because of their configuration, but when I send something from the arduino sender, nothing is received.
The key point here is to comment or not the setup of the motors. If it is commented, the message is received correctly. If it is uncommented, the setup() goes ok but when a message is sent from the arduino sender, nothing happens in the arduino receiver, the code Serial.available() in the loop is always false, so the order is never sent to the motors.
What could be the problem here? I am getting crazy with this because commenting the setup of the motors in the setup() is the only way to be able to read what I am receiving throught the UART.
Has this any sense? I am not able to see what I am doing wrong here…
Any comments or help would be much appreciated!!
Thanks a lot.
Arduino nano emisor.ino (708 Bytes)
Arduino nano receptor.ino (1.29 KB)
SetupAndMoveMotors.ino (3.48 KB)
1_Complete_code_UART_and_motors.ino (2.28 KB)