Hi, I need help with this because I can't figure it out. So I'm trying to build "flight computer" for drone, what I mean by that, I have Mpu 6050 and GPS Neo 6m connected to Uno which should transmit data from them to Leonardo on ground. Of course I have plans to transmit inputs from leonardo such as yaw roll pitch etc. However I've already found a problem. After transmiting that data (Longtitude, Latitude, Speed, Elevation, XYZ rotation) after some time (depends on delay im using) my nRF24L01 stops working, until i reset it. I can't let that happen if i want to make that thing fly. Heres my transmitter code:
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Wire.h>
#include <MPU6050_tockn.h>
#include <TinyGPS++.h>
RF24 radio(9, 10); // Utwórz obiekt RF24 i zdefiniuj piny CE i CSN
const byte address[6] = "00001"; // Adres do komunikacji (musi być taki sam w odbiorniku)
TinyGPSPlus gps; // Utwórz obiekt TinyGPSPlus
MPU6050 mpu6050(Wire);
struct SensorData {
double latitude;
double longitude;
double altitude;
double speed;
int angleX;
int angleY;
int angleZ;
};
SensorData sensorData;
void setup() {
Serial.begin(9600);
Wire.begin();
mpu6050.begin();
mpu6050.calcGyroOffsets(true);
radio.begin(); // Inicjalizuj moduł nRF24L01
radio.openWritingPipe(address); // Ustaw adres nadawczy
}
void loop() {
// Odczytaj dane z GPS
while (Serial.available() > 0) {
if (gps.encode(Serial.read())) {
if (gps.location.isUpdated()) {
sensorData.latitude = gps.location.lat();
sensorData.longitude = gps.location.lng();
sensorData.altitude = gps.altitude.meters();
sensorData.speed = gps.speed.kmph();
}
}
}
// Odczytaj dane z żyroskopu
mpu6050.update();
sensorData.angleX = mpu6050.getAngleX();
sensorData.angleY = mpu6050.getAngleY();
sensorData.angleZ = mpu6050.getAngleZ();
// Wyślij dane przez radio
radio.write(&sensorData, sizeof(sensorData));
delay(10); // Odczekaj 0.01 sekundy przed kolejnym wysłaniem danych
}
receiver:
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(9, 10); // Utwórz obiekt RF24 i zdefiniuj piny CE i CSN
const byte address[6] = "00001"; // Adres do komunikacji (musi być taki sam jak w nadajniku)
struct SensorData {
double latitude;
double longitude;
double altitude;
double speed;
int angleX;
int angleY;
int angleZ;
};
SensorData receivedData;
void setup() {
Serial.begin(9600);
pinMode(LED_BUILTIN, OUTPUT); // Ustaw pin wbudowanej diody na wyjście
radio.begin(); // Inicjalizuj moduł nRF24L01
radio.openReadingPipe(1, address); // Ustaw adres odbiorczy
radio.startListening(); // Rozpocznij nasłuchiwanie
}
void loop() {
if (radio.available()) {
radio.read(&receivedData, sizeof(receivedData));
// Odbierz dane i wyświetl
digitalWrite(LED_BUILTIN, HIGH); // Włącz diodę
Serial.print("Latitude: ");
Serial.println(receivedData.latitude, 6);
Serial.print("Longitude: ");
Serial.println(receivedData.longitude, 6);
Serial.print("Altitude: ");
Serial.println(receivedData.altitude);
Serial.print("Speed: ");
Serial.println(receivedData.speed);
Serial.print("Angle X: ");
Serial.println(receivedData.angleX);
Serial.print("Angle Y: ");
Serial.println(receivedData.angleY);
Serial.print("Angle Z: ");
Serial.println(receivedData.angleZ);
Serial.println();
digitalWrite(LED_BUILTIN, LOW); // Wyłącz diodę
}
}
Thats pretty much it, rest is ordinary stuff. I would be really thankful if you could help me, Im a beginner and most of my code is either copy and pasted (parts) or from chat gpt.
Why do you think the problem is with the transmitter, and not the receiver?
Put in Serial.print() statements to verify where the hangup might be.
I'm using "different" radio module from normal one
Items from Aliexpress are likely to be factory rejects, recycled or counterfeit.
or from chat gpt
Bad idea, for a beginner, because you are unlikely to spot the sort of mistakes it tends to make. ChatGPT doesn't test the code it so confidently produces for you, and it repeats all the beginner mistakes on this forum.
Okay so as I do understand it acts as a jammer? Also im operating in Poland, and what part could be illegal? Frequency or how often im sending packets? Should i change the baudrate to 115200 or something similar? And as i do understand my transmitter should ask receiver if it recevied? Also should I put radio.stopListening(); before end of void loop() ? I have flysky RC setup for car also using 2.4 Ghz
Jamming is not legal anywhere in the USA or most other countries. It sounds like a hardware problem, post an annotated schematic showing all connections as you made them, be sure to include power, ground, and power sources. Also post links to technical information on each of the hardware devices. Note: I do not read word problems or frizzies.
You overflow your receiver.
Should not really be a problem, but you will always be two packets behind.
You don't want packets to pile up, you have only a 3 element deep queue.
The emitted energy.
I think these modules can put out 100 mW,
which I think is outside the allowed range, at least here in Germany.
Higher is better, and you could also make the printing less chatty.
No, this is done by the chip and reported via write(), someone should just care.
Don't puzzle code.
Make it the last radio configuration in setup.
The frequency of your setup is ok and legal, unless you configure it into the 2.5 GHz range.
The high power modules may be able to output more than allowed,
but you don't have to use MAX output.
That is one of frizzies many definitions, my wife agrees with her! Fritzing creates frizzies similar to hair as nothing is easy to see nor is it well defined.
Technically, it uses 2-3.6 Volts however, I'm using adapter which makes you be able to connect it to 5 Volts without burning it. So i guess it's ok with current type of power supply.
Okay, I checked and it's perfectly on maximum value I can legally use. Also as i do understand it just gets flooded with data it can't read in time so after 3 packets pile up it basically crashes. When I will change baud rate it will go away or I have to somehow debbug the radio when it gets flooded? And if I have to "debbug" how to do it?
No. But it will definitely impact your communication.
Maybe, depends on your baudrate.
One character needs around 10 bits, compute it yourself.
I would not regard the data you print as useful, and I can not read nearly as fast.
Remember, you want to send 100 packets each second.
Remove any form of delay from your sketches.
Perhaps lower the packet rate, and lower it drastically while testing.
Raise the baudrate,
condense the output,
check the result of the transmission,
look for retries, or measure the duration of the transmission with micros.
Count retries, fails and successes.
Note the timestamp of the last successful transmission and reception.
Enable dynamic payloads to shrink the packets.
If you include a running packet number in the packet, the receiver can detect missing packets.
You should run the high power module in low settings,
or you risk overpowering the receiver if it is nearby.
Okay I was researching about packets piling up and I came across something called " flush_rx();". I tried to implement it but it does not work. I'm assuming it's my bad implementation. Could it be sollution or should I leave this idea behind?