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ę
}
}
I'm using "different" radio module from normal one.
https://pl.aliexpress.com/item/32783191387.html?spm=a2g0o.order_list.order_list_main.11.7adc1c24XT65Bf&gatewayAdapt=glo2pol
and adapter
https://pl.aliexpress.com/item/4000294210867.html?spm=a2g0o.order_list.order_list_main.5.7adc1c24XT65Bf&gatewayAdapt=glo2pol
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.
What did chatGPT say when you explained the problem?
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.
Using delay, a baudrate of 9600, no checks for send results,
no interest in the duration since the last valid reception.
The setup of the transmitter misses a radio.stopListening();
call.
You are sending a packet all 10 ms, but your printing takes way longer,
thanks to the atrocious baudrate, so you block on serial for sure.
Your special module may be illegal to operate, depending on the country your in.
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.
It decided to use "SensorData" after i told him, still doesn't work tho.
Does everyone know what frizzies are? My wife says it has something to do with her hair.
1 Like
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.
My point is that if you really don't want to see them then you should call them by name and maybe even explain why. But at least call them by name.
While it's fun for you to hate on them and have a funny euphemism for it, you can't really expect everyone else to know what you mean. That goes double for people who are new and haven't heard the constant moaning about fritzing.
So if your point is to make fun of Fritzing, then go ahead. But if you really don't want to see them then perhaps you should be a little more clear towards people who might not have heard of such a thing called by the name you're using.
I'm sorry if its hard to read, i can't provide a better schematic right now. And yes I'm using one 5 volt source and one ground.
Sure you can. Pencil and paper works very well, especially when you take a few moments to clearly place and label each connection.
1 Like
TBH It's easier with multicolored wires to tell what's crossing where and I can tell just fine in that drawing what's hooked where.
Can the Arduino source enough power for the radio through the 5V pin? Or should it have its own supply? I haven't worked with that type of radio before but I know radios can be power hungry.
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.
Yes, my bad. I think it can supply radio with enough power . Guy in that video uses same setup (I will add
capacitor when I will get home) Making a Long Range Remote Control. DIY 1 to 8-Channel Arduino RC PART-1 - YouTube
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?
As usual, it will not fix the problem but will provide tips for the question, bad idea to ask.
radio:
gps: ( I own 6M version )
Mpu 6050: