I am having trouble sending a value and then testing for that value after it is received. I have handshaking with the devices.
I have tried modifying several sample files. In the examples below I am just trying to make different LEDs light up depending on the message sent. Once I have that working I will be able to work it into my program.
To be clear, I do have the sample programs working. However, this only confirms handshaking. What I want to do is to control what is sent and to make a test on what is received.
Yes, my programs have a bunch of garbage in them as I try different things.
This pair is using RH_ASK.h, Transmitting:
// ask_transmitter.pde
// -*- mode: C++ -*-
// Simple example of how to use RadioHead to transmit messages
// with a simple ASK transmitter in a very simple way.
// Implements a simplex (one-way) transmitter with an TX-C1 module
#include <RH_ASK.h>
#include <SPI.h> // Not actually used but needed to compile
RH_ASK driver;
void setup()
{
Serial.begin(9600); // Debugging only
if (!driver.init())
Serial.println("init failed");
pinMode(13, OUTPUT);
}
void loop()
{
const char *msg = "B";
driver.send((uint8_t *)msg, strlen(1));
driver.waitPacketSent();
digitalWrite(13, HIGH); // To oberve program without connecting Serial Monitor
delay(200);
Serial.println("sent");
digitalWrite(13, LOW); // To oberve program without connecting Serial Monitor
}
This pair is using RH_ASK.h, Receive:
[code]
#include <RH_ASK.h>
#include <SPI.h> // Not actualy used but needed to compile
#define LED1 11
#define LED2 12
RH_ASK driver;
void setup()
{
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
Serial.begin(9600); // Debugging only
if (!driver.init())
Serial.println("init failed");
}
void loop()
{
uint8_t buf[RH_ASK_MAX_MESSAGE_LEN];
uint8_t buflen = sizeof(buf);
if (driver.recv(buf, &buflen)) // Non-blocking
{
int i;
// Message with a good checksum received, dump it.
driver.printBuffer("Got:", buf, buflen);
showA(); // checking the function call
showB(); // checking the function call
char printBuf = buf; // added to display received character
Serial.println(printBuf); // added to display received character
// Added to call functions depenfing on the message received
if (printBuf == "A") {
showA();
}
if (printBuf == "B") {
showB();
}
}
}
void showA() {
digitalWrite(LED1, HIGH);
delay (500);
digitalWrite(LED1, LOW);
delay (500);
}
void showB() {
digitalWrite(LED2, HIGH);
delay (500);
digitalWrite(LED2, LOW);
delay (500);
}
[/code]
This pair is using RH_RF95.h, Transmit:
[code]
// Feather9x_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 Feather9x_RX
// from this webpage https://learn.adafruit.com/adafruit-feather-32u4-radio-with-lora-radio-module/using-the-rfm-9x-radio
// pinout for AdaFruit Feather 32u4 LoRa here: https://learn.adafruit.com/adafruit-feather-32u4-radio-with-lora-radio-module/pinouts
#include <SPI.h>
#include <RH_RF95.h>
//for feather32u4
//#define RFM95_CS 8
//#define RFM95_RST 4
//#define RFM95_INT 7
// Change to 434.0 or other frequency, must match RX's freq!
#define RF95_FREQ 915.0
// Singleton instance of the radio driver
const int RFM95_CS = 8; // this is added by me
const int RFM95_RST = 4; // this is added by me
const int RFM95_INT = 7; // this is added by me
RH_RF95 rf95(RFM95_CS, RFM95_INT);
void setup()
{
pinMode(RFM95_RST, OUTPUT);
digitalWrite(RFM95_RST, HIGH);
Serial.begin(9600);
while (!Serial) {
delay(1);
}
delay(100);
Serial.println("Feather 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");
Serial.println("Uncomment '#define SERIAL_DEBUG' in RH_RF95.cpp for detailed debug info");
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);
}
int16_t packetnum = 0; // packet counter, we increment per xmission
void loop()
{
delay(1000); // Wait 1 second between transmits, could also 'sleep' here!
Serial.println("AF7JA Transmitting..."); // Send a message with callsign to rf95_server
int radiopacket = 2;
itoa(packetnum++, radiopacket, radiopacket);
sprintf(radiopacket, 1, radiopacket, radiopacket);
Serial.print("Sending "); Serial.println(radiopacket);
// radiopacket[19] = 0;
Serial.println("Sending...");
delay(10);
rf95.send((uint8_t *)radiopacket, 1);
Serial.println("Waiting for packet to complete...");
delay(10);
rf95.waitPacketSent();
// Now wait for a reply
uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
uint8_t len = sizeof(buf);
Serial.println("Waiting for reply...");
if (rf95.waitAvailableTimeout(1000))
{
// Should be a reply message for us now
if (rf95.recv(buf, &len))
{
Serial.print("Got reply: ");
Serial.println((char*)buf);
Serial.print("RSSI: ");
Serial.println(rf95.lastRssi(), DEC);
}
else
{
Serial.println("Receive failed");
}
}
else
{
Serial.println("No reply, is there a listener around?");
}
}
[/code]
This pair is using RH_ASK.h, Receive:
#include <SPI.h>
#include <RH_RF95.h>
// Change to 434.0 or other frequency, must match RX's freq!
#define RF95_FREQ 915.0
const int RFM95_CS = 8; // this is added by me
const int RFM95_RST = 4; // this is added by me
const int RFM95_INT = 7; // this is added by me
// Singleton instance of the radio driver
RH_RF95 rf95(RFM95_CS, RFM95_INT);
// Blinky on receipt
#define LED 13
#define LED1 11
#define LED2 12
void setup()
{
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(RFM95_RST, OUTPUT);
digitalWrite(RFM95_RST, HIGH);
//
Serial.begin(9600);
//// while (!Serial) {
//// delay(1);
//// }
delay(100);
showA();
showB();
Serial.println("Feather 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");
Serial.println("Uncomment '#define SERIAL_DEBUG' in RH_RF95.cpp for detailed debug info");
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()
{
int buf;
if (rf95.available())
{
// Should be a message for us now
uint8_t buf;
// [RH_RF95_MAX_MESSAGE_LEN];
uint8_t len = 1;
// 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);
int sentValue = buf;
if (sentValue == 1) {
showA();
}
if (sentValue == 2) {
showB();
}
// Send a reply
digitalWrite(LED, HIGH);
uint8_t data[] = "AF7JA Says Hello";
rf95.send(data, sizeof(data));
rf95.waitPacketSent();
Serial.println("Sent a reply");
digitalWrite(LED, LOW);
}
else
{
Serial.println("Receive failed");
}
}
}
void showA() {
digitalWrite(LED1, HIGH);
delay (500);
digitalWrite(LED1, LOW);
delay (500);
}
void showB() {
digitalWrite(LED2, HIGH);
delay (500);
digitalWrite(LED2, LOW);
delay (500);
}