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
}
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.
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?