ecg data become different when try to send it use lora rf95

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

buffer of sender is maybe too small. analogRead can return value 0-255. So the buffer must be at least 4 in length - accounting for null-terminated character.

arduino_new:
buffer of sender is maybe too small. analogRead can return value 0-255. So the buffer must be at least 4 in length - accounting for null-terminated character.

i try to change buffer to 4 but still have same weird graph and i am try change it again to 10 but graph still didn’t change

      char buffer[3];Too small. analogRead returns 0-1023, so you need at least 5 characters in buffer.

You don't need to send character data, just send binary data like this (with an analogous method for receiving):

   int data = analogRead(pin);
   rf95.send((uint8_t *)&data, 2);

do i need to make multiple SPI connection between ecg and lora? (ecg only have pin gdn, 3,3v, LO-, LO+, and SDN)

(ecg only have pin gdn, 3,3v, LO-, LO+, and SDN)

I have no idea what that means.

Hint: Learn how to send and correctly receive arbitrary example data using LoRa, before trying to add in the ECG part of the program.

jremington:
      char buffer[3];Too small. analogRead returns 0-1023, so you need at least 5 characters in buffer.

You don't need to send character data, just send binary data like this (with an analogous method for receiving):

   int data = analogRead(pin);

rf95.send((uint8_t *)&data, 2);

if i directly send the data like that, receiver will receive weird symbol like this

You have the wrong code in the receiver. Guaranteed.

i already try send increment of int to receiver and it's work fine, basicly ecg sensor just send some integer and if i try to show it with serial monitor it will look like this

if receiver code wrong can you tell me where?

Post the code properly, using code tags. ALL of it.

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);
      Serial.println((char*)buf);
      digitalWrite(LED, LOW);
    }
    else
    {
      Serial.println("Receive failed");
    }
  }
}

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()
    {
      digitalWrite(10 , HIGH);
      int16_t data = 0;
      
      int16_t packetnum = 0;  // packet counter, we increment per xmission  
      byte sendLen;
      char buffer[5];
      // read ecg data

      //////////////////////////////////////////////////////////////
      
      if((digitalRead(8) == 1) || (digitalRead(9) == 1))
      {
        Serial.println('!');
      }
      else
      {
        data = analogRead(A0); 
      }
      
      //////////////////////////////////////////////////////////////
      sprintf(buffer, "%d", data);
      sendLen = strlen(buffer);
      Serial.println(buffer);
      //send data to server
      rf95.send((uint8_t *)buffer, sendLen); 
      digitalWrite(10, HIGH);
      
      //Serial.println("Waiting for packet to complete..."); delay(10);
      rf95.waitPacketSent();
     
      
      delay(10);
    }

and here my transmitter code with dumb data increment of int with same code of receiver

    // 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);
    int16_t increment;
    
    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-
      ///////////////////////////////////////////////////////////////////
      //pinMode(10, OUTPUT);
      //pinMode(7, OUTPUT);
      
      //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);
      //SPI.begin();

      
    }
    
    
     
    void loop()
    {
      digitalWrite(10 , HIGH);
      int16_t data=0;
      
      
      int16_t packetnum = 0;  // packet counter, we increment per xmission  
      byte sendLen;
      char buffer[5];
      //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); 
        
      }
      
      //////////////////////////////////////////////////////////////
      increment++;
      sprintf(buffer, "%d", increment);
      sendLen = strlen(buffer);
      Serial.println(increment);
      digitalWrite(10, HIGH);
      rf95.send((uint8_t *)buffer, sendLen);
      //Serial.println("Waiting for packet to complete..."); delay(10);
      rf95.waitPacketSent();
      // Now wait for a reply
      
      delay(10);
    }

here my serial monitor result at receiver when use dumb data

is that enough? thanks btw for replying my post

I see you are still trying to send character data. Waste of time and space.

But, the receive code does not work because it does not properly terminate the receive buffer.

Try this:

 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))
    {
      buf[len] = 0;   //VERY IMPORTANT
      digitalWrite(LED, HIGH);
      Serial.println((char*)buf);
      digitalWrite(LED, LOW);
    }

i look from here thats where my code came from

https://lowpowerlab.com/forum/rf-range-antennas-rfm69-library/sending-first-packet-with-rfm95-lora-module/

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))
    {
      buf[len] = 0;   //VERY IMPORTANT
      digitalWrite(LED, HIGH);
      Serial.println((char*)buf);
      digitalWrite(LED, LOW);
    }

i try it but still have wrong data

but still have wrong data

This means nothing to us. Clearly describe what you expected the program to do, and what the program actually did. Cut and paste the actual output.

This is another problem:

      increment++;
      sprintf(buffer, "%d", increment);

If increment is larger than 9999, then buffer[5] is still too small.

i am try to send ecg (heart rate) data from one arduino to another arduino using lora rf95, transmitter use arduino nano, ecg sensor (ad5232), and lora module rf95. receiver use arduino and lora rf95

the ecg at the transmitter collect data heart rate from my body pass data to arduino nano and then send it to receiver via lora rf95.

ecg (heart rate) data is a group of int should be look like the right ecg (heart rate) data

and if it shows use serial plotter should be look like this right heart rate graph

but if i am send the data from trasmitter to receiver the data change and make the wrong heart rate graph

and the ecg (heart rate) data show like wrong ecg (heart rate) data

its still the int data but the number is different and create wrong heart rate graph

jremington:
This is another problem:

      increment++;

sprintf(buffer, "%d", increment);



If increment is larger than 9999, then buffer[5] is [u]still[/u] too small.

thats just me trying to show thats if i use dumb data like increment integer send from transmitter to receiver, the data is correct and didn't change

i am sorry if i make you confuse

You are trying to do too much at once for a beginner.

Put your heart rate measurements aside, and first learn how to send data successfully using the simplest possible examples.

When you understand how data transmission works, add back the code that makes heart rate measurements.