LowPowerLab / RFM69

RFM69 library for RFM69W, RFM69HW, RFM69CW, RFM69HCW (semtech SX1231, SX1231H)
GNU General Public License v3.0
778 stars 381 forks source link

setHighPower freezes #192

Open mantielero opened 2 weeks ago

mantielero commented 2 weeks ago

I have an arduino nano v3 and a RFM69HW. Everything works fine, but when I set: radio.setHighPower(); it gets blocked when I perform: radio.send(TONODEID,sendbuffer,9);.

The RFM69HW is fed using the 3V3 from the RFM69HW (I am not sure if this could be an issue).

My code:

// RFM69HCW Example Sketch
// Send serial input characters from one RFM69 node to another
// Based on RFM69 library sample code by Felix Rusu
// http://LowPowerLab.com/contact
// Modified for RFM69HCW by Mike Grusin, 4/16

// This sketch will show you the basics of using an
// RFM69HCW radio module. SparkFun's part numbers are:
// 915MHz: https://www.sparkfun.com/products/12775
// 434MHz: https://www.sparkfun.com/products/12823

// See the hook-up guide for wiring instructions:
// https://learn.sparkfun.com/tutorials/rfm69hcw-hookup-guide

// Uses the RFM69 library by Felix Rusu, LowPowerLab.com
// Original library: https://www.github.com/lowpowerlab/rfm69
// SparkFun repository: https://github.com/sparkfun/RFM69HCW_Breakout

// Include the RFM69 and SPI libraries:

#include <RFM69.h>
#include <RFM69_ATC.h>     //get it here: https://www.github.com/lowpowerlab/rfm69
#include <SPI.h>
#include <DHT.h>

// Temperature / Humidity sensor
#define DHTTYPE DHT11  // Dependiendo del tipo de sensor
DHT dht(3,DHTTYPE);    // Initialization

// Distance sensor
const int Trigger = 5; //Pin digital 2 para el Trigger del sensor
// el 2 es usado por el IRQ del RFM69
const int Echo = 4;    //Pin digital 3 para el Echo del sensor

#define IS_RFM69HW
// Addresses for this node. CHANGE THESE FOR EACH NODE!

#define NETWORKID     0   // Must be the same for all nodes
#define MYNODEID      1   // My node ID
#define TONODEID      2   // +Destination node ID

// RFM69 frequency, uncomment the frequency of your module:
#define FREQUENCY     RF69_868MHZ  // In Europe

// AES encryption (or not):

#define ENCRYPT       true // Set to "true" to use encryption
#define ENCRYPTKEY    "TOPSECRETPASSWRD" // Use the same 16-byte key on all nodes

// Use ACKnowledge when sending messages (or not):

#define USEACK        true // Request ACKs or not

// Packet sent/received indicator LED (optional):

#define LED           9 // LED positive pin
#define GND           8 // LED ground pin

// Create a library object for our RFM69HCW module:

RFM69 radio;
// NOTA: para el ATmega328p, RFM.h define: RF69_IRQ_PIN=2

void setup()
{
  // Open a serial port so we can send keystrokes to the module:

  Serial.begin(9600);

  // Distance sensor
  pinMode(Trigger, OUTPUT); //pin como salida
  pinMode(Echo, INPUT);  //pin como entrada
  digitalWrite(Trigger, LOW);//Inicializamos el pin con 0

  // Comenzamos el sensor DHT
  dht.begin();

  // Print some info to the serial console
  Serial.print("Node ");
  Serial.print(MYNODEID,DEC);
  Serial.println(" ready");  

  // Set up the indicator LED (optional):

  // Initialize the RFM69HCW:
  radio.initialize(FREQUENCY, MYNODEID, NETWORKID);
  radio.setHighPower(); // Always use this for RFM69HCW
  //radio.setPowerDBm(20);
  //radio.setPowerLevel(31);

  // Turn on encryption if desired:

  if (ENCRYPT)
    radio.encrypt(ENCRYPTKEY);
}

void loop()
{

  static char sendbuffer[9];

  // Leemos la humedad relativa
  float humidity = dht.readHumidity();
  // Leemos la temperatura en grados centígrados (por defecto)
  float temperature = dht.readTemperature();
  // Comprobamos si ha habido algún error en la lectura
  if (isnan(humidity) || isnan(temperature)) {
    Serial.println("Error obteniendo los datos del sensor DHT11");
    return;
  }
  float velocity = 331.4 + 0.606 * temperature + 0.0124 * humidity;

  Serial.println("- Velocity calculated"); 
  //-----------
  long t; //tiempo que demora en llegar el eco
  long d; //distancia en centimetros

  digitalWrite(Trigger, HIGH);
  delayMicroseconds(10);          //Enviamos un pulso de 10us
  digitalWrite(Trigger, LOW);

  t = pulseIn(Echo, HIGH); //obtenemos el ancho del pulso
  Serial.println("- Trigger + Echo");   

  d = velocity * t  / 20000;  

  Serial.println("Before print");
  Serial.print("Humedad: ");
  Serial.print(humidity,0);
  Serial.print("%   ");
  Serial.print("Temperatura: ");
  Serial.print(temperature,0);
  Serial.print("*C   ");
  Serial.print("   Velocity: ");
  Serial.print(velocity,0);
  Serial.print("m/s  ");  
  Serial.print("Distancia: ");
  Serial.print(d,0);      //Enviamos serialmente el valor de la distancia
  Serial.println("cm  ");

  snprintf(sendbuffer, sizeof(sendbuffer), "%02d%03d%03d",  
            (int)round(humidity), 
            (int)round(temperature), 
            (int)round(d));

  Serial.println(sendbuffer);

  // SENDING
  delay(500);

  Serial.println("Sending: start");
  delay(500);
  radio.send(TONODEID,sendbuffer,9);
  delay(500);
  Serial.println("Sending: end");
  delay(500);

  delay(2000);          //Hacemos una pausa de 100ms
}

Any suggestion? I am a newbie by the way.

mantielero commented 2 weeks ago

By feeding the RFM69HW with: (Arduino Nano V3 - 5V) --> (Regulator: 5V-->3V3) --> (RFM69), it sends the message once, but it freezes in the second iteration after printing: Sending: start.