25-03-2022, 12:43 AM
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
y el de la placa receptora este:
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);
}
}
}