I have 3 Arduinos.
First ARD connected rc522 RFID Reader : reading id and sending to second arduino via TX pin.
Second ARD is connected nRF24l01 : receiving id from first ARD via RX pin and transmiting to third arduino via nRF24.
Third Arduino connected nRF24 : receiving id from second ARD via nRF24 but writing strange characters.
i'm sending number with code below but why receiving strange characters (§,ô, ...)
Getting correctly, when i sent a string (example: "111,222")
i need to transmitting the number I read from RX.
TRANSMITTER
...
void loop(){
while (Serial.available() > 0)
{
Serial.println(Serial.readStringUntil('\n'));
int data = Serial.read();
Mirf.send((byte*) &data);
}
}
RECEIVER
void loop(){
byte data[32];
if(!Mirf.isSending() && Mirf.dataReady()){
Serial.print("Gelen:");
Mirf.getData((byte *) data);
Serial.write(byte(data[0]));
Serial.write(byte(data[1]));
Serial.write(byte(data[2]));
Serial.write(byte(data[3]));
Serial.write(byte(data[4]));
Serial.write(byte(data[5]));
Serial.write(byte(data[6]));
Serial.println("");
}
}
What is Mirf.payload set to?
Serial.println(Serial.readStringUntil('\n'));
int data = Serial.read();
Mirf.send((byte*) &data);
Serial.read() reads 1 byte.
There is no guarantee that your delimiter ('\n') stops before the payload length.
On the receive side, again, you should read a chunk of the payload size.
Also ensure your payload length is the same on all your radios.
#include <SPI.h>
#include <Mirf.h>
#include <nRF24L01.h>
#include <MirfHardwareSpiDriver.h>
#define MIRF_PAYLOAD 16
void setup(){
Serial.begin(9600);
Mirf.spi = &MirfHardwareSpi;
Mirf.init();
Mirf.setTADDR((byte *)"serv1");
Mirf.payload = MIRF_PAYLOAD;
Mirf.config();
}
void loop(){
while (Serial.available() > 0)
{
Serial.println(Serial.readStringUntil('\n'));
int data = Serial.read();
Mirf.send((byte*) &data);
}
}
Can you write a code transmiting and receiving integer for nRF24
for example;
TRANSMITTER CODE
...
...
int data=123;
Mirf.send (...)
RECEIVER CODE
if(!Mirf.isSending() && Mirf.dataReady()){
Mirf.getData(... data);
Serial.write(data); //as number or string but same with transmited
Why don't you cut out the serial part and just send the number? Should be pretty straight forward, and it elimates all the ascii to numeric equivalent nonsense. That should then tell you if its a serial issue, but I still think you should be sending full payload chunks not single bytes, and im not convinced of your Serial parsing on the transmit side.
inexperience !
It is simple for experienced people but I do not know how to do it!
It does not matter how.
Enough to write the same thing on the receiver, when I transmit a number.
If you type an example, I'll be happy.
Is it splitting your ints up into bytes thats the issue?
int send_int = 398;
byte data[2] = { 0, 0 };
data[0] = ((byte*)(&send_int))[0];
data[1] = ((byte*)(&send_int))[1];
int recieve_int = *((int*)&data[0]);
Also if you have an array of ints, you can just straight cast them to byte* on each side.
Here's the array method I mentioned:
// Transmitt end ...
int int_array_send[4] = { 5, 344, 1044, 55 };
char *data_p = (char*)&int_array_send[0];
// Revieve end ...
int *int_array_recieve_p;
int_array_recieve_p = (int*)data_p; // int_array_recieve_p can be used like an array, ie int_array_recieve_p[0] is the first element.
// alternatively:
int copy_array[4];
memcpy( copy_array, data_p, sizeof( copy_array )); // this is probably safer if data_p is goign to change before you use the values.
tammytam:
Is it splitting your ints up into bytes thats the issue?
int send_int = 398;
byte data[2] = { 0, 0 };
data[0] = ((byte*)(&send_int))[0];
data[1] = ((byte*)(&send_int))[1];
int recieve_int = ((int)&data[0]);
Also if you have an array of ints, you can just straight cast them to byte* on each side.
[Transmitter Code]
int send_int = Serial.read();
byte data[2] = { 0, 0 };
data[0] = ((byte*)(&send_int))[0];
data[1] = ((byte*)(&send_int))[1];
Mirf.send((byte *) &data);
//control codes are ..
Serial.print(send_int); //for control
Serial.print(":");
Serial.print(*data);
Serial.println("");
[control codes are writing: -1:255]
[Receiver Code]
Mirf.getData((byte*) data);
int recieve_int = ((int)&data[0]);
Serial.print(((int)&data[0]));
Serial.print(":");
Serial.print(((int)&data[1]));
Serial.println("");
[i see that: -1:1023]
tammytam:
Why don't you cut out the serial part and just send the number? Should be pretty straight forward, and it elimates all the ascii to numeric equivalent nonsense. That should then tell you if its a serial issue, but I still think you should be sending full payload chunks not single bytes, and im not convinced of your Serial parsing on the transmit side.
i have to send ID come from RC522, therefore I can't send just number..
Not necessarily; received data to be number format, but i have to send ID come from RC522.
Results should be 123 or "123" but should come through the RC522 (so from RX pin)
This will work; If I turn to the string, the information I received from RX.
Try this and tell me if 450 appears on both ends ...
[Transmitter Code]
int send_int = 450; // We'll test using a value that requires both bytes to represent ...
byte data[2] = { 0, 0 };
data[0] = ((byte*)(&send_int))[0];
data[1] = ((byte*)(&send_int))[1];
Mirf.send((byte *) &data);
//control codes are ..
Serial.print(send_int); // Print out what we're sending
[Receiver Code]
Mirf.getData((byte*) data);
int recieve_int = *((int*)&data[0]);
Serial.print( recieved_int ); // print out what we're recieving
tammytam:
...
YES, I see both sides 450
Good, so that tells you your problem lies with the serial.read() part.
This kind of thing doesn't work:
int send_int = Serial.read();
Serial.read() reads 1 byte. An int requires 2. The above code will truncate anything above the value of 255 (the maximum you can fit into a byte).
There is a convenience function if you don't want to read and parse the bytes yourself, its called ParseInt():
parseInt()
i understand, it is working.
i will write again, if need to get help.
THANKS 