Hello everyone i am new to arduino and i am trying to send ecg data (ad5232) using lora hopeRF RFM9x and arduino nano
here's my transmitter code
// LoRa 9x_TX
// -*- mode: C++ -*-
// Example sketch showing how to create a simple messaging client (transmitter)
// with the RH_RF95 class. RH_RF95 class does not provide for addressing or
// reliability, so you should only use RH_RF95 if you do not need the higher
// level messaging abilities.
// It is designed to work with the other example LoRa9x_RX
//#include <SD.h>
#include <SPI.h>
#include <RH_RF95.h>
#define RFM95_CS 10
#define RFM95_RST 9
#define RFM95_INT 2
// Change to 434.0 or other frequency, must match RX's freq!
#define RF95_FREQ 433.0
// Singleton instance of the radio driver
RH_RF95 rf95(RFM95_CS, RFM95_INT);
void setup()
{
pinMode(RFM95_RST, OUTPUT);
digitalWrite(RFM95_RST, HIGH);
while (!Serial);
Serial.begin(9600);
//delay(100);
////////////////////////////////////////////////////////////////////
pinMode(8, INPUT); //input pin 8 untuk lead off L0+
pinMode(9, INPUT); //input pin 9 untuk lead off L0-
///////////////////////////////////////////////////////////////////
//Serial.println("Arduino LoRa TX Test!");
// manual reset
digitalWrite(RFM95_RST, LOW);
//delay(10);
digitalWrite(RFM95_RST, HIGH);
//delay(10);
while (!rf95.init()) {
Serial.println("LoRa radio init failed");
while (1);
}
//Serial.println("LoRa radio init OK!");
// Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM
if (!rf95.setFrequency(RF95_FREQ)) {
Serial.println("setFrequency failed");
while (1);
}
//Serial.print("Set Freq to: "); Serial.println(RF95_FREQ);
// Defaults after init are 434.0MHz, 13dBm, Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on
// The default transmitter power is 13dBm, using PA_BOOST.
// If you are using RFM95/96/97/98 modules which uses the PA_BOOST transmitter pin, then
// you can set transmitter powers from 5 to 23 dBm:
rf95.setTxPower(23, false);
}
void loop()
{
int16_t data = 0;
int16_t packetnum = 0; // packet counter, we increment per xmission
byte sendLen;
char buffer[3];
//Serial.println("Sending to rf95_server");
// Send a message to rf95_server
//////////////////////////////////////////////////////////////
if((digitalRead(8) == 1) || (digitalRead(9) == 1))
{
Serial.println('!');
}
else
{
data = analogRead(A0);
}
//////////////////////////////////////////////////////////////
sprintf(buffer, "%d", data);
Serial.println(buffer);
sendLen = strlen(buffer);
rf95.send((uint8_t *)buffer, sendLen);
//Serial.println("Waiting for packet to complete..."); delay(10);
//rf95.waitPacketSent();
// Now wait for a reply
delay(10);
}
and here's my receiver code
// Arduino9x_RX
// -*- mode: C++ -*-
// Example sketch showing how to create a simple messaging client (receiver)
// with the RH_RF95 class. RH_RF95 class does not provide for addressing or
// reliability, so you should only use RH_RF95 if you do not need the higher
// level messaging abilities.
// It is designed to work with the other example Arduino9x_TX
#include <SPI.h>
#include <RH_RF95.h>
#define RFM95_CS 10
#define RFM95_RST 9
#define RFM95_INT 2
// Change to 434.0 or other frequency, must match RX's freq!
#define RF95_FREQ 433.0
// Singleton instance of the radio driver
RH_RF95 rf95(RFM95_CS, RFM95_INT);
// Blinky on receipt
#define LED 13
void setup()
{
pinMode(LED, OUTPUT);
pinMode(RFM95_RST, OUTPUT);
digitalWrite(RFM95_RST, HIGH);
while (!Serial);
Serial.begin(9600);
delay(100);
//Serial.println("Arduino LoRa RX Test!");
// manual reset
digitalWrite(RFM95_RST, LOW);
delay(10);
digitalWrite(RFM95_RST, HIGH);
delay(10);
while (!rf95.init()) {
Serial.println("LoRa radio init failed");
while (1);
}
Serial.println("LoRa radio init OK!");
// Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM
if (!rf95.setFrequency(RF95_FREQ)) {
Serial.println("setFrequency failed");
while (1);
}
Serial.print("Set Freq to: "); Serial.println(RF95_FREQ);
// Defaults after init are 434.0MHz, 13dBm, Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on
// The default transmitter power is 13dBm, using PA_BOOST.
// If you are using RFM95/96/97/98 modules which uses the PA_BOOST transmitter pin, then
// you can set transmitter powers from 5 to 23 dBm:
rf95.setTxPower(23, false);
}
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);
memset(buf, '\0', sizeof(buf));
if (rf95.recv(buf, &len))
{
digitalWrite(LED, HIGH);
//RH_RF95::printBuffer("Received: ", buf, len);
//Serial.print("Got: ");
Serial.println((char*)buf);
//Serial.print("RSSI: ");
//Serial.println(rf95.lastRssi(), DEC);
// Send a reply
//uint8_t data[] = "And hello back to you";
//rf95.send(data, sizeof(data));
//rf95.waitPacketSent();
//Serial.println("Sent a reply");
digitalWrite(LED, LOW);
}
else
{
Serial.println("Receive failed");
}
}
}
both lora module and ecg sensor use pin d10 and d11, so i change ecg sensor pin from 10 and 11 to 8 and 9. when i am try to run the program and open serial plotter at arduino shows weird graph like this and it shows no error
(sorry i try to upload a image but not shows)
but if i am disable code rf95.send((uint8_t *)buffer, sendLen); from transmitter graph look like this, and this the right graph
Is there somewhere else that I need to make a change?
sorry for my bad english