Hi everyone , i have the project to make communication between two phone by nRF24 with antenna and Bluetooth HC-05 .... I have programmed an Android application for messaging via Bluetooth HC-05 , what I want now is to program the Arduino so that I connect the Bluetooth and the nRF24 with the Arduino Uno, the application sends a text message to the HC-05 and then this message is sent through the nRF24 the nRF24 receiver!
I programmed it but there are several errors or maybe it is not right?
I hope to modify the code or guide me to something in order to complete the project.
this my code:
#include <SPI.h>
#include <Wire.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <rf24g.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <SoftwareSerial.h>
SoftwareSerial Serialb(7, 8);
char radiopacket[100];
char inChar;
byte index = 0;
boolean test;
Adafruit_SSD1306 oled = Adafruit_SSD1306();
#define BUTTON_A 0
#define BUTTON_B 16
#define BUTTON_C 2
#define LED 0
#define RF24_FREQ 915.0
#define nRF24_INT 3 //
#define nRF24_CS 4 //
#define nRF24_RST 2 // "A"
RF24 rf24(nRF24_CS, nRF24_INT);
void setup()
{
delay(500);
Serial.begin(115200);
Serialb.begin(9600);
pinMode(13, OUTPUT);
oled.begin(SSD1306_SWITCHCAPVCC, 0x3C);
oled.display();
delay(500);
oled.clearDisplay();
oled.display();
pinMode(BUTTON_A, INPUT_PULLUP);
pinMode(BUTTON_B, INPUT_PULLUP);
pinMode(BUTTON_C, INPUT_PULLUP);
pinMode(LED, OUTPUT);
pinMode(nRF24_RST, OUTPUT);
digitalWrite(nRF24_RST, LOW);
Serial.println("Feather RFM69 RX/TX Test!");
// manual reset
digitalWrite(nRF24_RST, HIGH);
delay(10);
digitalWrite(nRF24_RST, LOW);
delay(10);
if (!rf24.int()) {
Serial.println("RFM69 radio init failed");
while (1);
if (!rf24.setFrequency(RF24_FREQ)) {
Serial.println("setFrequency failed");
}
rf24.setTxPower(14, true);
uint8_t key[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
rf24.setEncryptionKey(key);
{
pinMode(LED, OUTPUT);
Serial.print("nRF69 radio @");
Serial.print((int)RF24_FREQ);
Serial.println("MHz");
}
oled.setTextSize(2);
oled.setTextColor(WHITE);
oled.setCursor(0,0);
oled.println("NRF24 @ ");
oled.print((int)RF24_FREQ);
oled.println(" MHz");
oled.display();
delay(500);
}
void loop()
{
if (rf24.waitAvailableTimeout(100)) {
uint8_t buf[NRF24_MAX_MESSAGE_LEN];
uint8_t len = sizeof(buf);
if (! rf24.recv(buf, &len)) {
Serial.println("Receive failed");
return;
}
digitalWrite(LED, HIGH);
rf24.printBuffer("Received: ", buf, len);
buf[len] = 0;
Serial.print("Got: "); Serial.println((char*)buf);
Serial.print("RSSI: "); Serial.println(rf24.lastRssi(), DEC);
String t=(char*)buf;
Serialb.println((char*)buf);
oled.clearDisplay();
oled.setCursor(0,0);
oled.println((char*)buf);
oled.print("RSSI: "); oled.print(rf24.lastRssi());
oled.display();
digitalWrite(LED, LOW);
}
while(Serialb.available() > 0
{
if(index < 99)
{
inChar = Serialb.read();
radiopacket[index] = inChar;
index++;
radiopacket[index] = '\0';
}
test=true;
}
if(index>0 && test==true)
{
Serial.print("Sending "); Serial.println(radiopacket);
rf24.send((uint8_t *)radiopacket, strlen(radiopacket));
rf24.waitPacketSent();
if(inChar == '1')
digitalWrite(13, HIGH);
else if(inChar == '0')
digitalWrite(13, LOW);
test=false;
index=0;
}}