I am trying to send a char array using Arduino Uno board and nRF24L01 modules
Here is the code for both transmitter and receiver:
#include <SPI.h> //~ #include <TMRh20nRF24L01.h> //~ #include <TMRh20RF24.h>
#include <nRF24L01.h>
#include <RF24.h>
#define CE_PIN 9
#define CSN_PIN 10
// NOTE: the "LL" at the end of the constant is "LongLong" type //
These are the IDs of each of the slaves const uint64_t slaveID[2] =
{0xE8E8F0F0E1LL, 0xE8E8F0F0E2LL} ;
RF24 radio(CE_PIN, CSN_PIN); // Create a Radio
char
> dataToSend[64]="e7665072be018b6b58ea9e40cf38553d6dc293cda4c9d94cda6e91ca61b3a073";
unsigned long currentMillis; unsigned long prevMillis; unsigned long
> txIntervalMillis = 1000; int txVal = 0; float ackMessg[2]={1,2}; byte
ackMessgLen = 4; // NB this 4 is the number of bytes in the 2 ints
that will be recieved
void setup() {
Serial.begin(9600);
Serial.println("Track Control Starting");
radio.begin();
radio.setDataRate( RF24_250KBPS );
radio.enableAckPayload();
radio.setRetries(3,5); // delay, count }
//====================
void loop() {
currentMillis = millis();
if (currentMillis - prevMillis >= txIntervalMillis) {
radio.openWritingPipe(slaveID[0]); // calls the first slave
// there could be a FOR loop to call several slaves in turn
bool rslt;
rslt = radio.write( dataToSend, sizeof(dataToSend) );
Serial.print("\nRSLT (1 = success) ");
Serial.println(rslt);
Serial.print("Data Sent ");
Serial.print(dataToSend[0]);
Serial.print(" ");
Serial.println(dataToSend[1]);
if ( radio.isAckPayloadAvailable() ) {
radio.read(ackMessg,ackMessgLen);
Serial.print("Acknowledge received: ");
Serial.print(ackMessg[0]);
#include <SPI.h> #include <nRF24L01.h> #include <RF24.h> #define CE_PIN 9 #define CSN_PIN 10 // NOTE: the "LL" at the end of the constant is "LongLong" type const uint64_t deviceID = 0xE8E8F0F0E1LL; // Define the ID for this slave int valChange = 1; RF24 radio(CE_PIN, CSN_PIN); char dataReceived[64]; int ackData[2] = {12,23}; void setup() { Serial.begin(9600); delay(1000); Serial.println("Hand Controller Starting"); radio.begin(); radio.setDataRate( RF24_250KBPS ); radio.openReadingPipe(1,deviceID); radio.enableAckPayload(); radio.writeAckPayload(1, ackData, sizeof(ackData)); radio.startListening(); } void loop() { if ( radio.available() ) { radio.read( dataReceived, sizeof(dataReceived) ); for (int x = 0; x <64; x++) { //if (dataReceived[x] < 16) { // Serial.write('0'); // } Serial.print(dataReceived[x]);} Serial.println(); radio.writeAckPayload(1, ackData, sizeof(ackData)); ackData[0] += valChange; // this just increments so you can see that new data is being sent } }
And here is the output that I get
Hand Controller Starting
e7665072be018b6b58ea9e40cf38553d
-
you get what you send. continue readingJuraj– Juraj ♦2019年02月19日 10:35:13 +00:00Commented Feb 19, 2019 at 10:35
-
yes i know that i got what i sent,my question was how to get the full char array as its size is more than payload sizeAmr Ahmed– Amr Ahmed2019年02月19日 11:19:30 +00:00Commented Feb 19, 2019 at 11:19
-
1how can i do that ?Amr Ahmed– Amr Ahmed2019年02月19日 22:13:22 +00:00Commented Feb 19, 2019 at 22:13
-
1thank u very much,but the array is generated from a hash function in sha256 library,i just simplified the code here to discuss the conceptAmr Ahmed– Amr Ahmed2019年02月20日 01:18:12 +00:00Commented Feb 20, 2019 at 1:18
-
1so can i send the unencoded output from the hash function then map it at the receiver side?Amr Ahmed– Amr Ahmed2019年02月20日 20:43:30 +00:00Commented Feb 20, 2019 at 20:43
1 Answer 1
TX code
#include "sha256.h"
#include <Arduino.h>
#include "./printf.h"
#include <SPI.h>
//~ #include <TMRh20nRF24L01.h>
//~ #include <TMRh20RF24.h>
#include <nRF24L01.h>
#include <RF24.h>
#define CE_PIN 9
#define CSN_PIN 10
// NOTE: the "LL" at the end of the constant is "LongLong" type
// These are the IDs of each of the slaves
const uint64_t slaveID = 0xE8E8F0F0E1L ;
RF24 radio(CE_PIN, CSN_PIN); // Create a Radio
unsigned long currentMillis;
unsigned long prevMillis;
unsigned long txIntervalMillis = 1000;
int txVal = 0;
int ackMessg[6];
byte ackMessgLen = 4;
uint8_t* hash;
uint8_t copy[32];
void printHash(uint8_t* hash) {
int i;
for (i=0; i<32; i++) {
Serial.print("0123456789abcdef"[hash[i]>>4]);
Serial.print("0123456789abcdef"[hash[i]&0xf]);
copy[i]=hash[i];
}
Serial.println();
}
void setup() {
printf_begin();
uint32_t a;
unsigned long ms;
Serial.begin(9600);
radio.begin();
radio.setDataRate( RF24_2MBPS );
radio.enableAckPayload();
radio.setRetries(3,5); // delay, count
// SHA tests
Serial.println("Test: FIPS 180-2 B.1");
Serial.println("Expect:ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad");
Serial.print("Result:");
ms = micros();
Sha256.init();
Sha256.print("abc");
printHash(Sha256.result());
Serial.println();
for(int x=0;x<32;x++)
{ Serial.print(copy[x]);
Serial.print(" ");
}
Serial.println();
Serial.print(" Hash took : ");
Serial.print((micros() - ms));
Serial.println(" micros");
Serial.println();
}
void loop() {
currentMillis = millis();
if (currentMillis - prevMillis >= txIntervalMillis) {
radio.openWritingPipe(slaveID);
bool rslt,rsltt;
rslt = radio.write( copy, 32 );
if ( radio.isAckPayloadAvailable() ) {
radio.read(ackMessg,ackMessgLen);
Serial.print("Acknowledge received: ");
Serial.print(ackMessg[0]);
Serial.print(" ");
Serial.println(ackMessg[1]);
}
prevMillis = millis();
}
}
Rx code
// HandController - the slave or the receiver
// http://tmrh20.github.io/RF24/
//~ - CONNECTIONS: nRF24L01 Modules See:
//~ http://arduino-info.wikispaces.com/Nrf24L01-2.4GHz-HowTo
//~ 1 - GND
//~ 2 - VCC 3.3V !!! NOT 5V
//~ 3 - CE to Arduino pin 9
//~ 4 - CSN to Arduino pin 10
//~ 5 - SCK to Arduino pin 13
//~ 6 - MOSI to Arduino pin 11
//~ 7 - MISO to Arduino pin 12
//~ 8 - UNUSED
#include <SPI.h>
//~ #include <TMRh20nRF24L01.h>
//~ #include <TMRh20RF24.h>
#include <nRF24L01.h>
#include <RF24.h>
#define CE_PIN 9
#define CSN_PIN 10
// NOTE: the "LL" at the end of the constant is "LongLong" type
const uint64_t deviceID[2] ={ 0xE8E8F0F0E1LL,0xE8E8F0F0E1LL}; // Define the ID for slaves
int valChange = 1;
RF24 radio(CE_PIN, CSN_PIN);
RF24 radioo(CE_PIN, CSN_PIN);
uint8_t dataReceived[32];
int ackData[2] = {12,23};
void setup() {
Serial.begin(9600);
Serial.println("Hand Controller Starting");
radio.begin();
radio.setDataRate( RF24_2MBPS );
radio.openReadingPipe(1,deviceID[1]);
radio.enableAckPayload();
radio.writeAckPayload(1, ackData, sizeof(ackData));
radio.startListening();
}
void loop() {
unsigned long startTimer = millis();
if ( radio.available() ) {
radio.read( dataReceived, sizeof(dataReceived) );
radio.writeAckPayload(1, ackData, sizeof(ackData));
Serial.println();
//Serial.println(startTimer);
Serial.println();
for(int x=0;x<32;x++)
{Serial.print(dataReceived[x]);
Serial.print(" ");}}
ackData[0] += valChange; // this just increments so you can see that new data is being sent
}
it is fully working now with both outputs on the same size
lang-cpp