So the question I have is this:
How can I get Mike's code to talk to my Arduino's with 1 UART. I still want to use the Serial Monitor to see data coming in through the usual Seral.write(). But also want a seperate serial to use for RX/TX for my transceiver.
I tried creating a SoftwareSerial instance and changed the libraries code to accept this but no joy.
HRFMessage
5.1.1 HRFMessageClient
Sends an unaddressed message every second. Any HRFMEssageServer within range
will receive the message and send a reply. Test this with the HRFMessageServer below.
#include <HRFMessage.h>
// Declare the HRFMessage to use Serial1 for IO
// with the HM-TR module
HRFMessage client(&Serial1);
long lastSendTime = 0;
void setup()
{
Serial.begin(9600); // Monitoring via USB
Serial1.begin(9600); // defaults to 9600
}
void loop()
{
// Send a message to the server at most once a second
long thisTime = millis();
if (thisTime > lastSendTime + 1000)
{
client.send((uint8_t*)"test\n", 6);
Serial.print("sending\n");
lastSendTime = thisTime;
}
// But always look for a reply
uint8_t buf[HRF_MAX_MESSAGE_LEN];
uint8_t len = sizeof(buf);
if (client.recv((uint8_t*)&buf, &len))
{
// Got a reply from the server
Serial.print("got: ");
Serial.print((const char*)buf);
}
}
5.1.2 HRFMessageServer
Server to work with HRFMessageClient above. When it receives a message from
HRFMessageClient it sends a reply. #include <HRFMessage.h>
// Declare the HRFMessage to use Serial1 for
// IO with the HM-TR module
HRFMessage server(&Serial1);
void setup()
{
Serial.begin(9600); // Monitoring via USB
Serial1.begin(9600); // defaults to 9600
Sample code
6 of 12 HopeRF
}
void loop()
{
uint8_t buf[HRF_MAX_MESSAGE_LEN];
uint8_t len = sizeof(buf);
if (server.recv((uint8_t*)&buf, &len))
{
// Got a message from the client.
// Send a reply back
server.send((uint8_t*)"reply\n", 7);
Serial.print("got: ");
Serial.print((const char*)buf);
}
}
If you go back and post your code properly, I'll have a look at it. Modify your post. Select the code, press the icon with the # on it, and save.
Even better, though, would be to back to the IDE, use Tools + Auto Format, and then copy the code again. Modify your post, select the code, delete it, press the icon with the # on it, paste the properly formatted code, and save.
It isn't your code that you are trying to modify, is it? It's the library, so posting your code is not too useful. Posting the library code, or a link to it, would be more useful.
I tried creating a SoftwareSerial instance and changed the libraries code to accept this but no joy.
No joy is functionally equivalent to "it didn't work". Useless words with no semantic content.
Posting the modified library code, and explaining what issues it has, would be a lot more useful.