Controlling A2212/5T 2450KV brushless motor through nrflo1

Hi, I have an issue to control my motor trough data received from nr24l01.
Data is being send without any issues. I controlled this motors via cable by joystick using this tutorial: https://www.youtube.com/watch?v=cUdDNul4ybQ&t=180s . I can`t figure it why motors does not spin while controlling via wireless transfer.
Code for transmitter:

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

RF24 radio(7, 8); // Definiowanie pinów CSN i CE

const byte address[6] = "00001"; // Adres komunikacyjny

void setup() {
  Serial.begin(9600);

  radio.begin();
  radio.openWritingPipe(address);
  radio.setPALevel(RF24_PA_MAX);
  radio.setDataRate(RF24_250KBPS);
  radio.stopListening();
}

void loop() {
  int joystickValue = analogRead(A2);
  joystickValue = constrain(joystickValue, 550, 1023); // Ograniczenie wartości odczytu
  int motorSpeed = map(joystickValue, 550, 1023, 0, 180); // Mapa wartości na zakres 0-180
  char power[5]; // Tablica znaków o długości 5 (4 cyfry + znak końca stringa '\0')
  itoa(motorSpeed, power, 10); // Konwersja int na char (string) w systemie dziesiętnym

  Serial.print("Motor Speed: ");
  Serial.println(power); // Wyświetla prędkość silnika

  radio.write(&power, sizeof(power)); // Wysyłanie danych za pomocą nRF24L01
  delay(20); // Opóźnienie 2 sekundy
}

And receiver:

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

#define ESC_PIN1 3
#define ESC_PIN2 4
#define ESC_PIN3 5
#define ESC_PIN4 6

Servo esc1;
Servo esc2;
Servo esc3;
Servo esc4;

RF24 radio(7, 8);
const byte address[6] = "00001";

void setup() {
  Serial.begin(9600);

  radio.begin();
  radio.openReadingPipe(0, address);
  radio.setPALevel(RF24_PA_MAX);
  radio.setDataRate(RF24_250KBPS);
  radio.startListening();
  
  esc1.attach(ESC_PIN1, 1000, 2000);
  esc1.write(0);
  esc2.attach(ESC_PIN2, 1000, 2000);
  esc2.write(0);
  esc3.attach(ESC_PIN3, 1000, 2000);
  esc3.write(0);
  esc4.attach(ESC_PIN4, 1000, 2000);
  esc4.write(0);

  delay(5000); 

  esc1.write(1000);  
  esc2.write(1000);
  esc3.write(1000);
  esc4.write(1000);

  delay(5000);
}

char text[32] = ""; 
int power = 50;     

void loop() {
  if (radio.available()) {              
    radio.read(&text, sizeof(text));   
    power = atoi(text);                

    Serial.print("Odebrano: ");
    Serial.print(text);
    Serial.print(" | Skonwertowana wartość: ");
    Serial.println(power);

    esc1.write(power);
    esc2.write(power);
    esc3.write(power);
    esc4.write(power);
  }                                       
}

Post an annotated schematic and show exactly how you have wired it. Be sure to include all power sources. I missed the link to the motor, be sure to add links for each hardware device. Hint: I do not read frizzes or word schematics.

https://allegro.pl/oferta/adapter-nrf24l01-8pin-do-modulow-bezprzewodowych-jomardyan-16574-13280985633?bi_s=ads&bi_m=productlisting:desktop:query&bi_c=Y2U4NWU4MTgtNTY4YS00MmIxLTk5MGMtODQ5ZmJlZmIwNGYzAA&bi_t=ape&referrer=proxy&emission_unit_id=0327a5b3-b929-4a75-ac13-5f384489139d
https://allegro.pl/oferta/modul-radiowy-nrf24l01-pa-lna-2-4ghz-ze-wzmacniaczem-i-antena-12679799872
https://uelectronics.com/wp-content/uploads/2020/10/30A-BLDC-ESC-Product-Manual.pdf

I will check back in a day or so.

Post the code that worked with cable, I won't watch a video.

#include<Servo.h>


#define ESC_PIN1 3
#define ESC_PIN2 4
#define ESC_PIN3 5
#define ESC_PIN4 6

Servo esc1;
Servo esc2;
Servo esc3;
Servo esc4;


void setup() 
{
   esc1.attach(ESC_PIN1, 1000, 2000);
  esc1.write(0);
  esc2.attach(ESC_PIN2, 1000, 2000);
  esc2.write(0);
  esc3.attach(ESC_PIN3, 1000, 2000);
  esc3.write(0);
  esc4.attach(ESC_PIN4, 1000, 2000);
  esc4.write(0);
  delay(2000);
}

void loop() 
{
  //int joystickValue = analogRead(A0);
  //joystickValue = constrain(joystickValue, 550, 1023);  //Read upper half of joystick value from center.
  int mmotorSpeed = 180;
  esc1.write(mmotorSpeed);  
  esc2.write(mmotorSpeed); 
  esc3.write(mmotorSpeed); 
  esc4.write(mmotorSpeed); 
}

In your transmit sketch you are mapping the servo range to 0 - 180. (Degrees)

In the receiving sketch you are using 1000 - 2000 (microseconds)

This is best very confusing, and at worst is the cause of your problem.

it's the way it worked without wireless communication. Or should i send by transmiter values from 550-1023 (joystick default values) and convert them in reciver?

The wired code you posted writes 180 to all speed controllers. I looked at the servo.h code a bit and found a reference to a method called something like “servo.writemillis”. I cannot recall the exact spelling. Anyway that method was capable of writing to the servo using the millisecond timing or if the value it was called with was in the valid range for an angle it would control the servo using the angle.

Anyway, I think we need to simplify a bit and take small steps. I notice that you have a serial print programmed in the receiver code. Have you seen anything print on the serial monitor?

(Bold adde to make the question stand out from my Rambling).

I have to be honest, the stage of my programming abilities in C++ is barely above beginner level, although I have done significant cording in other languages. My knowledge of string manipulation is almost nonexistent, so I can decipher your intent with your string manipulations but I cannot determine immediately if the syntax is correct.

However, I am not particularly offended by “Fritzy” diagrams or other forms of wiring diagrams, especially when the wiring is relatively simple as is the case here. So I am willing to help you but it would be nice if others could help out with the code.

I notice that you are reading a string the length your text array. Will that method (I think that is the correct term) return a string shorter than that length if it encounters a null string terminator?

Answering to bolded question, yes data was transmitted without any issues and displayed without any issues (tried with connection to pc and also battery (i displayed data to lcd). By writing "servo.writemillis” i found sth ”writeMicroseconds".

Yes, that sounds familiar. I found that by browsing through the.cpp of the servo.h file of the library.

The lcd code does not appear in your sketch. Perhaps you used that in a previous iteration. So we at least know the data is getting received.

One thing I haven’t asked about is if you are doing an arming routine for the ESC’s. Most often used routine is to cycle the command to the ESC to max throttle and back to minimum throttle.

[quote="nbzlew, post:8, topic:1295143, full:true"]m
it's the way it worked without wireless communication. Or should i send by transmiter values from 550-1023 (joystick default values) and convert them in reciver?
[/quote]
I think I am going to have to study the servo library further. This is the first I have seen the additional arguments when creating the servo instances. Perhaps there is no need to map the potentiometer reading to anything if the servo instance is created like this:

esc1.attach(ESC_PIN1, 550, 1023);

Do you know if the nRF24L01 radios can transmit anything besides text (ASCII) ? Could you send integers or floating point for example?

I have found some informative documentation on the GitHub for servo.h.

Study that and ask about anything you don’t understand.

I am learning much more about the servo library than I previously knew.

Depending on the resolution you need to achieve with your ESC’s we may want to use the writeMicroseconds method.

as i watched video which i mentioned before i wasn't necessary. I can send code with lcd display if necessary.

Didn't try that yet. I can test if u want

i will look on to it thanks

That info would be in the documentation.

More info. It looks like we can use any data format.

Very detailed description of the RF24 methods. I just skimmed and now my head hurts.

https://nrf24.github.io/RF24/classRF24.html#ace7dd139fabc16b77cb8325faa07620f