Hello All. I am attempting to transmit switch depression data as text. The goal is to have the receiver compare the received text (string?) to the receivers text (string?) variables and act on a match.
The receiver is receiving correct data but it is in hex. The sketches are based on Radiohead's Transmit & Receive example sketches. Although the example codes have been modified to include code for other components, I have not changed any code that does the transmitting or receiving so as not mess with known good code. At least I think I have not messed it up somehow. I cannot detect any differences between my sketches and Radiohead's that would have my sketch act differently (displaying hex). Perhaps you guys can help. - Scotty
My Transmitter
#include <RH_ASK.h>
#include <SPI.h> //library defaults to using pin 12
#include <ezButton.h>
#define byte uint8_t
byte i = 0;
byte c = 0;
ezButton red_plus_button(5);
ezButton red_minus_button(7);
ezButton blue_plus_button(4);
ezButton blue_minus_button(6);
RH_ASK rf_transmitter;
void setup()
{
rf_transmitter.init();
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(9600);
}
void loop()
{
red_plus_button.loop();
red_minus_button.loop();
blue_plus_button.loop();
blue_minus_button.loop();
if (blue_plus_button.isPressed()) {
char *msg1 = "BLUE PLUS";
rf_transmitter.send((uint8_t *)msg1, strlen(msg1));
Serial.println(" blue plus");
Serial.println(msg1);
}
else if (red_plus_button.isPressed()) {
char *msg2 = "RED PLUS";
rf_transmitter.send((uint8_t *)msg2, strlen(msg2));
Serial.println(" red plus");
Serial.println(msg2);
}
else if (blue_minus_button.isPressed()) {
char *msg3 = "BLUE MINUS";
rf_transmitter.send((uint8_t *)msg3, strlen(msg3));
Serial.println(" blue minus");
Serial.println(msg3);
}
else if (red_minus_button.isPressed()) {
char *msg4 = "RED MINUS";
rf_transmitter.send((uint8_t *)msg4, strlen(msg4));
Serial.println(" red minus");
Serial.println(msg4);
}
rf_transmitter.waitPacketSent();
delay(250);
// Serial.print(" * ");
//Serial.println(msg);
//Serial.println(*msg);
//Serial.println(strlen(msg));
}
My Receiver
#include <RH_ASK.h>
#include <SPI.h> //library defaults to using pin 11
#define byte uint8_t
byte led_pin = 3;
byte buzzer_pin = 6;
RH_ASK rf_receiver;
void setup()
{
// Initialize ASK Object
//rf_driver.init();
rf_receiver.init();
// Setup Serial Monitor
Serial.begin(9600);
pinMode(led_pin, OUTPUT);
pinMode(buzzer_pin, OUTPUT);
digitalWrite(led_pin, HIGH);
digitalWrite(buzzer_pin, HIGH);
delay(1000);
digitalWrite(led_pin, LOW);
digitalWrite(buzzer_pin, LOW);
}
void loop()
{
uint8_t buf[RH_ASK_MAX_MESSAGE_LEN];
uint8_t buflen = sizeof(buf);
if (rf_receiver.recv(buf, &buflen))
{
int i;
rf_receiver.printBuffer("GOT: ", buf, buflen);
}
}
Radiohead Transmit
// 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");
}
void loop()
{
const char *msg = "hello";
driver.send((uint8_t *)msg, strlen(msg));
driver.waitPacketSent();
delay(200);
}
Radiohead Receive
showing as hex
// ask_receiver.pde
// -*- mode: C++ -*-
// Simple example of how to use RadioHead to receive messages
// with a simple ASK transmitter in a very simple way.
// Implements a simplex (one-way) receiver with an Rx-B1 module
#include <RH_ASK.h>
#include <SPI.h> // Not actualy used but needed to compile
RH_ASK driver;
void setup()
{
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);
}
}
Below is receiver serial monitor data
GOT:
52 45 44 20 4D 49 4E 55 53
GOT:
42 4C 55 45 20 4D 49 4E 55 53
GOT:
52 45 44 20 50 4C 55 53
GOT:
42 4C 55 45 20 50 4C 55 53
GOT:
42 4C 55 45 20 4D 49 4E 55 53
GOT:
52 45 44 20 4D 49 4E 55 53
GOT:
52 45 44 20 50 4C 55 53
GOT:
52 45 44 20 50 4C 55 53
GOT:
42 4C 55 45 20 4D 49 4E 55 53