Before starting to test communicate with Rfm95 with Arduino uno download radio head library
radio head library for arduino uno with rfm
https://drive.google.com/open?id=1iBQWCOm13X3bdDKEcy0czGebPDz_PqQ-
RFM95 with arduino uno connections:
radio head library for arduino uno with rfm
https://drive.google.com/open?id=1iBQWCOm13X3bdDKEcy0czGebPDz_PqQ-
RFM95 with arduino uno connections:
ARDUINO
UNO
|
RFM
95
|
Gnd
|
Gnd
|
3.3v
|
3.3v
|
D5
|
reset
|
D2
|
DIO 0
|
D3
|
DIO1
|
D13(SCK)
|
SCK
|
D12(MISO)
|
MISO
|
D11(MOSI)
|
MOSI
|
D10(SS)
|
NSS
|
NOTE:
LEVEL SHIFTER FOR BETTER OUTPUT
sender side code:
#include <SPI.h>
#include <RH_RF95.h>
RH_RF95 rf95;
int led = 9;
void setup()
{
pinMode(led, OUTPUT);
Serial.begin(9600);
while (!Serial) ; // Wait for serial port to be available
if (!rf95.init())
Serial.println("init failed");
}
void loop()
{
if (rf95.available())
{
// Should be a message for us now
uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
uint8_t len = sizeof(buf);
if (rf95.recv(buf, &len))
{
digitalWrite(led, HIGH);
// RH_RF95::printBuffer("request: ", buf, len);
Serial.print("got request: ");
Serial.println((char*)buf);
// Serial.print("RSSI: ");
// Serial.println(rf95.lastRssi(), DEC);
/***************************************/
// Send a reply
/***************************************/
char data[32]="";
int availableBytes = Serial.available();
for(int i=0; i<availableBytes; i++)
{
data[i]=Serial.read();
}
rf95.send(data, sizeof(data));
rf95.waitPacketSent();
Serial.println("Sent::");
Serial.print(data);
digitalWrite(led, LOW);
}
else
{
Serial.println("recv failed");
}
}
delay(100);
}
receiver side code:
sender side code:
#include <SPI.h>
#include <RH_RF95.h>
RH_RF95 rf95;
int led = 9;
void setup()
{
pinMode(led, OUTPUT);
Serial.begin(9600);
while (!Serial) ; // Wait for serial port to be available
if (!rf95.init())
Serial.println("init failed");
}
void loop()
{
if (rf95.available())
{
// Should be a message for us now
uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
uint8_t len = sizeof(buf);
if (rf95.recv(buf, &len))
{
digitalWrite(led, HIGH);
// RH_RF95::printBuffer("request: ", buf, len);
Serial.print("got request: ");
Serial.println((char*)buf);
// Serial.print("RSSI: ");
// Serial.println(rf95.lastRssi(), DEC);
/***************************************/
// Send a reply
/***************************************/
char data[32]="";
int availableBytes = Serial.available();
for(int i=0; i<availableBytes; i++)
{
data[i]=Serial.read();
}
rf95.send(data, sizeof(data));
rf95.waitPacketSent();
Serial.println("Sent::");
Serial.print(data);
digitalWrite(led, LOW);
}
else
{
Serial.println("recv failed");
}
}
delay(100);
}
receiver side code:
// rf95_client.pde
#include <SPI.h>
#include <RH_RF95.h>
int led = 9;
RH_RF95 rf95;
void setup()
{
pinMode(led, OUTPUT);
Serial.begin(9600);
while (!Serial) ; // Wait for serial port to be available
if (!rf95.init())
Serial.println("init failed");
}
void loop()
{
rfm95_uart();
}
void rfm95_uart()
{
Serial.println("Sending to rf95_server::");
char data[32]="";
int availableBytes = Serial.available();
for(int i=0; i<availableBytes; i++)
{
data[i]=Serial.read();
}
rf95.send(data, sizeof(data));
rf95.waitPacketSent();
Serial.println("Sent::");
Serial.print(data);
digitalWrite(led, LOW);
uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
uint8_t len = sizeof(buf);
if (rf95.waitAvailableTimeout(3000))
{
// Should be a reply message for us now
if (rf95.recv(buf, &len))
{
Serial.print("got reply: ");
Serial.println((char*)buf);
// Serial.print("RSSI: ");
// Serial.println(rf95.lastRssi(), DEC);
}
else
{
Serial.println("recv failed");
}
}
else
{
Serial.println("No reply, is rf95_server running?");
}
delay(400);
}
out put:
after some modification::
send code:
#include <SPI.h>
#include <RH_RF95.h>
RH_RF95 rf95;
int led = 9;
void setup()
{
pinMode(led, OUTPUT);
Serial.begin(9600);
while (!Serial) ; // Wait for serial port to be available
if (!rf95.init())
Serial.println("init failed");
}
void loop()
{
if (rf95.available())
{
// Should be a message for us now
uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
uint8_t len = sizeof(buf);
if (rf95.recv(buf, &len))
{
digitalWrite(led, HIGH);
// RH_RF95::printBuffer("request: ", buf, len);
Serial.print("got request: ");
Serial.println((char*)buf);
/***************************************/
// Send a reply
/***************************************/
char data[32]="";
int availableBytes = Serial.available();
for(int i=0; i<availableBytes; i++)
{
data[i]=Serial.read();
}
rf95.send(data, sizeof(data));
rf95.waitPacketSent();
Serial.println("Sent::");
Serial.print(data);
digitalWrite(led, LOW);
}
else
{
Serial.println("recv failed");
}
}
delay(100);
}
Receiver code:
// rf95_client.pde
#include <SPI.h>
#include <RH_RF95.h>
int led = 9;
RH_RF95 rf95;
void setup()
{
pinMode(led, OUTPUT);
Serial.begin(9600);
while (!Serial) ; // Wait for serial port to be available
if (!rf95.init())
Serial.println("init failed");
}
void loop()
{
rfm95_uart();
}
void rfm95_uart()
{
//Serial.println("Sending to rf95_server::");
char data[32]="";
int availableBytes = Serial.available();
for(int i=0; i<availableBytes; i++)
{
data[i]=Serial.read();
}
rf95.send(data, sizeof(data));
rf95.waitPacketSent();
Serial.println("Sent::");
Serial.print(data);
digitalWrite(led, LOW);
uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
uint8_t len = sizeof(buf);
if (rf95.waitAvailableTimeout(3000))
{
if (rf95.recv(buf, &len))
{
Serial.print("got reply: ");
Serial.println((char*)buf);
}
else
{
Serial.println("recv failed");
}
}
else
{
Serial.println("No reply, is rf95_server running?");
}
delay(400);
}
#include <SPI.h>
#include <RH_RF95.h>
int led = 9;
RH_RF95 rf95;
void setup()
{
pinMode(led, OUTPUT);
Serial.begin(9600);
while (!Serial) ; // Wait for serial port to be available
if (!rf95.init())
Serial.println("init failed");
}
void loop()
{
rfm95_uart();
}
void rfm95_uart()
{
Serial.println("Sending to rf95_server::");
char data[32]="";
int availableBytes = Serial.available();
for(int i=0; i<availableBytes; i++)
{
data[i]=Serial.read();
}
rf95.send(data, sizeof(data));
rf95.waitPacketSent();
Serial.println("Sent::");
Serial.print(data);
digitalWrite(led, LOW);
uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
uint8_t len = sizeof(buf);
if (rf95.waitAvailableTimeout(3000))
{
// Should be a reply message for us now
if (rf95.recv(buf, &len))
{
Serial.print("got reply: ");
Serial.println((char*)buf);
// Serial.print("RSSI: ");
// Serial.println(rf95.lastRssi(), DEC);
}
else
{
Serial.println("recv failed");
}
}
else
{
Serial.println("No reply, is rf95_server running?");
}
delay(400);
}
out put:
after some modification::
send code:
#include <SPI.h>
#include <RH_RF95.h>
RH_RF95 rf95;
int led = 9;
void setup()
{
pinMode(led, OUTPUT);
Serial.begin(9600);
while (!Serial) ; // Wait for serial port to be available
if (!rf95.init())
Serial.println("init failed");
}
void loop()
{
if (rf95.available())
{
// Should be a message for us now
uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
uint8_t len = sizeof(buf);
if (rf95.recv(buf, &len))
{
digitalWrite(led, HIGH);
// RH_RF95::printBuffer("request: ", buf, len);
Serial.print("got request: ");
Serial.println((char*)buf);
/***************************************/
// Send a reply
/***************************************/
char data[32]="";
int availableBytes = Serial.available();
for(int i=0; i<availableBytes; i++)
{
data[i]=Serial.read();
}
rf95.send(data, sizeof(data));
rf95.waitPacketSent();
Serial.println("Sent::");
Serial.print(data);
digitalWrite(led, LOW);
}
else
{
Serial.println("recv failed");
}
}
delay(100);
}
Receiver code:
// rf95_client.pde
#include <SPI.h>
#include <RH_RF95.h>
int led = 9;
RH_RF95 rf95;
void setup()
{
pinMode(led, OUTPUT);
Serial.begin(9600);
while (!Serial) ; // Wait for serial port to be available
if (!rf95.init())
Serial.println("init failed");
}
void loop()
{
rfm95_uart();
}
void rfm95_uart()
{
//Serial.println("Sending to rf95_server::");
char data[32]="";
int availableBytes = Serial.available();
for(int i=0; i<availableBytes; i++)
{
data[i]=Serial.read();
}
rf95.send(data, sizeof(data));
rf95.waitPacketSent();
Serial.println("Sent::");
Serial.print(data);
digitalWrite(led, LOW);
uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
uint8_t len = sizeof(buf);
if (rf95.waitAvailableTimeout(3000))
{
if (rf95.recv(buf, &len))
{
Serial.print("got reply: ");
Serial.println((char*)buf);
}
else
{
Serial.println("recv failed");
}
}
else
{
Serial.println("No reply, is rf95_server running?");
}
delay(400);
}
No comments:
Post a Comment