This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

  • 0 voto(s) - 0 Media
  • 1
  • 2
  • 3
  • 4
  • 5
DUDA Envío de datos. Tarjeta feather 32u4
#1
Buenas, estoy usando un Adafruit Feather 32u4 y no encuentro la manera exacta de enviar datos de una placa a otra, concretamente los de el sensor BMP280 (Temperatura y Presión)

El codigo que tengo actualmente es este

Código:
#include <Wire.h>
#include <SPI.h>

#include <RH_RF69.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP280.h>


//Radio Parameters
#define NODEID        2    //unique for each node on same network
#define NETWORKID    100  //the same on all nodes that talk to each other
#define GATEWAYID    1    //Receiving node
#define ENCRYPTKEY    "cansateuskadi000" //exactly the same 16 characters/bytes on all nodes!
#define FREQUENCY RF69_433MHZ
#define IS_RFM69HCW true
#define SERIAL_BAUD 9600
#define RFM69_CS 8
#define RFM69_IRQ 7
#define RFM69_IRQN 4
#define RFM69_RST 4
#define DEST_ADDRESS 10
#define MY_ADDRESS 7

// Singleton instance of the radio driver
RH_RF69 rf69;


Adafruit_BMP280 bmp;


float TEMPERATURA;
float PRESION;



#if defined (__AVR_ATmega32U4__) // Feather 32u4 w/Radio
  #define RFM69_CS      8
  #define RFM69_INT    28
  #define RFM69_RST    4
  #define LED          13
#endif


void setup()
{
  //Initialize serial connection for debugging
  delay(5000);
  Serial.begin(9600);
  Serial.println("REBOOT");
  delay(5000);

  //BMP280

  Serial.begin(9600);     
  Serial.println("Iniciando:");   

  if ( !bmp.begin() ) {     
    Serial.println("BMP280 no encontrado !");
    while (1);       
  }
 

  //Initialize radio
  rf69.setTxPower(20, true);
  if (!rf69.init()) {
    Serial.println("RFM69 radio init failed");
    while (1);
  }
  Serial.println("RFM69 radio init OK!");
 
  // Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM (for low power module)
  // No encryption


  // If you are using a high power RF69 eg RFM69HW, you *must* set a Tx power with the
  // ishighpowermodule flag set like this:
  rf69.setTxPower(20, true);  // range from 14-20 for power, 2nd arg must be true for 69HCW

  // The encryption key has to be the same as the one in the server
  uint8_t key[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
                    0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
  rf69.setEncryptionKey(key);
}

void loop()
{

 
  TEMPERATURA = bmp.readTemperature(); 
  PRESION = bmp.readPressure()/100; 
 

  rf69.send((uint8_t *)radiopacket, strlen(radiopacket));
    rf69.waitPacketSent();

}


y el de la placa receptora este:
Código:
//Include the required libraries

#include <Wire.h>
#include <SPI.h>
#include <Adafruit_BMP280.h>
#include <RH_RF69.h>
#include <RH_RF69.h>
#include <Adafruit_Sensor.h>


//Radio Parameters
#define NODEID        1    //unique for each node on same network
#define NETWORKID    100  //the same on all nodes that talk to each other
#define ENCRYPTKEY    "cansateuskadi000" //exactly the same 16 characters/bytes on all nodes!
#define FREQUENCY RF69_433MHZ
#define IS_RFM69HCW true
#define SERIAL_BAUD 9600

RH_RF69 rf69;

#if defined (__AVR_ATmega32U4__) // Feather 32u4 w/Radio
  #define RFM69_CS      8
  #define RFM69_INT    28
  #define RFM69_RST    4
  #define LED          13
#endif

void setup(){
 
  if (!rf69.init()) {
    Serial.println("RFM69 radio init failed");
    while (1);
  }
  Serial.println("RFM69 radio init OK!");
 
  // Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM (for low power module)
  // No encryption


  // If you are using a high power RF69 eg RFM69HW, you *must* set a Tx power with the
  // ishighpowermodule flag set like this:
  rf69.setTxPower(20, true);  // range from 14-20 for power, 2nd arg must be true for 69HCW

  // The encryption key has to be the same as the one in the server
  uint8_t key[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
                    0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
  rf69.setEncryptionKey(key);
 
}

void loop() {
if (rf69.available()) {
    // Should be a message for us now 
    uint8_t buf[RH_RF69_MAX_MESSAGE_LEN];
    uint8_t len = sizeof(buf);
    if (rf69.recv(buf, &len)) {
      if (!len) return;
      buf[len] = 0;
      Serial.print("Received [");
      Serial.print(len);
      Serial.print("]: ");
      Serial.println((char*)buf);
      Serial.print("RSSI: ");
      Serial.println(rf69.lastRssi(), DEC);

   
    }
  }
}
  Responder
#2
Buenos días

Has arreglado el problema de instalación de las librerías que te indique en la otra publicación?

No hace falta que abras un tema nuevo en varias zonas cada vez que tengas un problema, los mensajes se ven, lo que pasa es que hay poca gente dispuesta a ayudar, y todos trabajamos en otra cosa y se contesta cuando se puede.

Un saludo
  Responder
#3
(25-03-2022, 03:10 PM)asesorplaza1 escribió: Buenos días

Has arreglado el problema de instalación de las librerías que te indique en la otra publicación?

No hace falta que abras un tema nuevo en varias zonas cada vez que tengas un problema, los mensajes se ven, lo que pasa es que hay poca gente dispuesta a ayudar, y todos trabajamos en otra cosa y se contesta cuando se puede.

Un saludo

Si, las librerias están bien, lo que pasa es que no se exactamente como enviar los datos de una placa a otra.

Gracias!
  Responder
#4
Buenas noches.

Lo primero que tenemos que conseguir es que el programa compile, después ya veremos como arreglamos la comunicación.

De momento el programa "emisor", me da errores en la línea 64, 77, 93, y me hace referencia a errores de las librerías, no entiendo nada.

Si comparo tu programa con los ejemplos de RadioHead, no tienen nada que ver, es como si te hubieras comido parte de la configuración del RH_RF69

Por favor, pon el enlace a la pagina de donde copiaste el programa.

En el programa "receptor", incluyes dos veces la librería <RH_RF69.h>, líneas 6 y 7, quita una de ellas

En ninguno de los dos programas admite la línea

Código:
  rf69.setTxPower(20, true);  // range from 14-20 for power, 2nd arg must be true for 69HCW

Mañana me voy de viaje y no estaré operativo, el domingo le volveré a echar un vistazo a ver que encuentro.

Un saludo.
  Responder
#5
Para transmitir y recibir datos entre dos placas utilizando un sensor BMP280 y módulos RF69, es importante asegurarse de que los datos se envíen y reciban en el formato correcto. Parece que en tu código actual, el problema puede estar en cómo se están enviando y recibiendo los datos.

Código del Transmisor
El código para el transmisor parece estar casi completo, pero hay algunos detalles que debes ajustar. Aquí te muestro cómo podrías modificar el código del transmisor para enviar la temperatura y la presión en un formato adecuado:
cpp
Copiar código
#include <Wire.h>
#include <SPI.h>
#include <RH_RF69.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP280.h>

// Radio Parameters
#define NODEID        2    // Unique for each node on the same network
#define NETWORKID    100  // The same on all nodes that talk to each other
#define GATEWAYID    1    // Receiving node
#define ENCRYPTKEY    "cansateuskadi000" // Exactly the same 16 characters/bytes on all nodes!
#define FREQUENCY RF69_433MHZ
#define IS_RFM69HCW true
#define SERIAL_BAUD 9600
#define RFM69_CS 8
#define RFM69_IRQ 7
#define RFM69_IRQN 4
#define RFM69_RST 4
#define DEST_ADDRESS 10
#define MY_ADDRESS 7

// Singleton instance of the radio driver
RH_RF69 rf69;
Adafruit_BMP280 bmp;

// Buffer to hold the data to be sent
char radiopacket[32]; // Ensure this is large enough to hold your data

void setup() {
  // Initialize serial connection for debugging
  delay(5000);
  Serial.begin(9600);
  Serial.println("REBOOT");
  delay(5000);

  // BMP280 initialization
  if (!bmp.begin()) {
    Serial.println("BMP280 not found!");
    while (1);
  }

  // Initialize radio
  rf69.setTxPower(20, true);
  if (!rf69.init()) {
    Serial.println("RFM69 radio init failed");
    while (1);
  }
  Serial.println("RFM69 radio init OK!");

  // Set encryption key
  uint8_t key[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
                    0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
  rf69.setEncryptionKey(key);
}

void loop() {
  float temperatura = bmp.readTemperature();
  float presion = bmp.readPressure() / 100; // Convert to hPa

  // Format the data into a string
  snprintf(radiopacket, sizeof(radiopacket), "T:%.2f P:%.2f", temperatura, presion);

  // Send the data
  rf69.send((uint8_t *)radiopacket, strlen(radiopacket));
  rf69.waitPacketSent();

  // Delay before sending the next packet
  delay(2000);
}

Código del Receptor
En el código del receptor, debes asegurarte de que los datos recibidos se interpreten correctamente. Aquí hay una versión ajustada del código receptor:
cpp
Copiar código
#include <Wire.h>
#include <SPI.h>
#include <RH_RF69.h>
#include <Adafruit_Sensor.h>

// Radio Parameters
#define NODEID        1    // Unique for each node on the same network
#define NETWORKID    100  // The same on all nodes that talk to each other
#define ENCRYPTKEY    "cansateuskadi000" // Exactly the same 16 characters/bytes on all nodes!
#define FREQUENCY RF69_433MHZ
#define IS_RFM69HCW true
#define SERIAL_BAUD 9600

RH_RF69 rf69;

void setup() {
  Serial.begin(SERIAL_BAUD);
 
  // Initialize radio
  if (!rf69.init()) {
    Serial.println("RFM69 radio init failed");
    while (1);
  }
  Serial.println("RFM69 radio init OK!");

  // Set encryption key
  uint8_t key[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
                    0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
  rf69.setEncryptionKey(key);
}

void loop() {
  if (rf69.available()) {
    uint8_t buf[RH_RF69_MAX_MESSAGE_LEN];
    uint8_t len = sizeof(buf);
    if (rf69.recv(buf, &len)) {
      if (len > 0) {
        buf[len] = 0; // Null-terminate the received data
        Serial.print("Received: ");
        Serial.println((char*)buf);
        Serial.print("RSSI: ");
        Serial.println(rf69.lastRssi(), DEC);
      }
    }
  }
}

Puntos Clave
  1. Formato de los Datos: En el transmisor, utiliza
    snprintf
    para crear un string con la temperatura y la presión en un formato legible. Esto facilita la interpretación en el receptor.
  2. Buffer Adecuado: Asegúrate de que el buffer
    radiopacket
    sea lo suficientemente grande para contener todos los datos que deseas enviar.
  3. Envío y Recepción de Datos: En el receptor, verifica que el buffer recibido esté siendo procesado correctamente y que los datos sean interpretados adecuadamente.
  4. Delay en el Transmisor: Añade un retraso en el bucle del transmisor para evitar enviar paquetes demasiado rápido y saturar el canal.
Estos ajustes deberían ayudarte a transmitir y recibir datos de manera efectiva entre las dos placas usando el sensor BMP280 y los módulos RF69. Si necesitas más ayuda o tienes preguntas adicionales, no dudes en preguntar.
  Responder


Posibles temas similares…
Tema Autor Respuestas Vistas Último mensaje
  tarjeta creality silenciosa pipeferr 2 279 27-12-2024, 10:11 PM
Último mensaje: pipeferr
  CONSULTA error al compilar exit status1 error al compilar tarjeta arduino uno nestordaniel 3 1,664 29-07-2024, 10:04 PM
Último mensaje: Hectormonero
  Recuperar datos HDD CHA 6 2,802 07-05-2015, 08:29 AM
Último mensaje: battlestars3l4
  Problemas tarjeta de red Electromecánico 4 1,881 17-04-2015, 12:33 PM
Último mensaje: jumasape