Arduino Nano freezes after some time (Radio comms)

Hello all,

I'm having some troubles with a Nano and I just cannot identify the issue.

The setup:

  1. Arduino Uno R4 Minima: Has a Radio module and a joystick connected.
  2. Arduino Nano: Has a Radio module and 2 servos connected.

The goal:
Move the two servos according to the movement of the joystick.

(expected) Operation:
The Uno takes the X and Y position of the joystick and makes it into a simple data "telegram" (string) the following way: data = position_X,position_Y.
The joystick positions are always between 0 and 90. So an average data string looks something akin to this: "43,12". Then the Uno sends it via radio to the Nano every 10 ms.

The Nano takes the data telegram cuts it in two using strtok() and sets the position of the two servos respectively.

The issue:
I fire up both Arduinos and all seem fine first. The data telegrams arrive as expected (it is set to first print out the telegrams before doing anything with them) and it actually works for some time. I can move the joystick around and the two servos follow (great success) however after a couple of seconds of movement it simply freezez. Even the serial output is stuck. I suspected at first some faulty data in the telegrams (like a sudden Ő instead of numbers) but according to the serial output the telegrams are all fine.

Also note that if i don't touch the joystick at all it goes on indefinitely without freezing. It also
seems like it freezes more frequently when I move the joystick more "wildly". I tried really hard to get a faulty telegram out of the Uno but i just couldn't so i highly suspicious the issue is with the Nano.

Any idea? Is it possible I'm running out of memory?

See the complete code for the Nano:

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

//Radio pins CE, CSN
RF24 radio(9, 10); 

//Create servo objects
Servo myServoV;
Servo myServoH;

const byte address[6] = "00001";

void setup() {
  Serial.begin(9600);
  //Setup servo pins
  myServoV.attach(7);
  myServoH.attach(8);

  //setup radio and start listening
  radio.begin();
  radio.openReadingPipe(0, address);
  radio.setPALevel(RF24_PA_MIN);
  radio.startListening();
}

void loop() {
  if (radio.available()) {
    //Declare variables
    int servo_V;
    int servo_H;
    char joystick[32] = "";
    char * data;

    //Get and print radio data
    radio.read(&joystick, sizeof(joystick));
    Serial.print("Data: ");
    Serial.println(joystick);

    //Get vertical servo pos
    data = strtok (joystick,",");
    servo_V = atoi(data);

    //Get horizontal servo pos
    data = strtok (NULL,",");
    servo_H = atoi(data);

    //Set servo positions
    myServoV.write(servo_V);
    myServoH.write(servo_H);
  }
}

Interesting problem. To me, it could be hardware or software-related. Do me a favor and comment out the joystick function, then check if moving the joystick still causes issues. If so, post an annotated schematic showing exactly how you’ve wired everything. Be sure to include all power sources and grounds, and make note of any wires longer than 10 inches (25 cm).

comment out the joystick function

Doesn't help. The Joystick is on the Uno and it is the Nano that freezes. There is no galvanic connection between the two boards at all.

When I comment out the Joystick part in the code of the Uno then only the default data is coming from it, which is 46,46 and will run indefinitely. Much the same as not touching the joystick at all.

How are the servos powered? If from Arduino 5V, that is a problem.

They are really small 9g servos. The problem occurs regardless of the power supply. (I have tried powering them from the Arduino or a separate 5V/2A PSU but still the same result)

Forget "really small". All inductive devices introduce electrical hash into the power supply.

The Arduino 5V output is a convenience intended for a couple of LEDs or low power sensors and MUST NOT be used for motors, servos or any high current devices.

Stick with the external servo power supply and if the Nano still hangs, then there are other problems.

As I said:

I have tried powering them from the Arduino or a separate 5V/2A PSU but still the same result

And I said

The Arduino 5V output is a convenience intended for a couple of LEDs or low power sensors and MUST NOT be used for motors, servos or any high current devices

Good luck with your project!

Okay, it turns out it maybeeee was a power supply issue but not what you'd expect.

Turns out one of the servos had an internal short circuit. It overheated over time and also drained tonns of power even from external power supplies.

After replacing it, everything works flawlessly.

1 Like

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