I am new with arduino and try to send a constant number with an rfm69hw. For this I am using this Sparkfun Library: github.com/sparkfun/RFM69HCW_Breakout.
In the code you can send the message by Serial.read() but I want to send a constant value. This could be a number or a name.
I tried to set a char to A like:
char input = {'A'};
but it sends a couple of A´s like:
Node 26 ready
sending to node 1: [AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA]
no ACK received :(
So I was wondering how Serial.read() work inside but I couldn´t find something.
Is there a way to use a constant instead of Serial.read()?
int val = analogRead(A2);
if (Serial.available() > 0)
{
char input = Serial.read();
if (input != '\r') // not a carriage return
{
sendbuffer[sendlength] = input;
sendlength++;
}
// If the input is a carriage return, or the buffer is full:
if ((input == '\r') || (sendlength == 61)) // CR or buffer full
{
// Send the packet!
Serial.print("sending to node ");
Serial.print(TONODEID, DEC);
Serial.print(": [");
for (byte i = 0; i < sendlength; i++)
Serial.print(sendbuffer[i]);
Serial.println("]");
// There are two ways to send packets. If you want
// acknowledgements, use sendWithRetry():
if (USEACK)
{
if (radio.sendWithRetry(TONODEID, sendbuffer, sendlength))
Serial.println("ACK received!");
else
Serial.println("no ACK received :(");
}
// If you don't need acknowledgements, just use send():
else // don't use ACK
{
radio.send(TONODEID, sendbuffer, sendlength);
}
sendlength = 0; // reset the packet
Blink(LED,10);
}
}
mcschiess:
I also tried Robin2´s idea to. If I use an char it does work. But if I use an int it is working a bit
For "Hello World" it´s just sending [He].
You need to post the code that you tried - otherwise we have no idea what you actually did.
NOTE that there was a mistake in my Reply #2 - apologies for any confusion.
here is the code I´m using now. It´s stripped to the main things I need.
// RFM69HCW Example Sketch
// Send serial input characters from one RFM69 node to another
// Based on RFM69 library sample code by Felix Rusu
// http://LowPowerLab.com/contact
// Modified for RFM69HCW by Mike Grusin, 4/16
// This sketch will show you the basics of using an
// RFM69HCW radio module. SparkFun's part numbers are:
// 915MHz: https://www.sparkfun.com/products/12775
// 434MHz: https://www.sparkfun.com/products/12823
// See the hook-up guide for wiring instructions:
// https://learn.sparkfun.com/tutorials/rfm69hcw-hookup-guide
// Uses the RFM69 library by Felix Rusu, LowPowerLab.com
// Original library: https://www.github.com/lowpowerlab/rfm69
// SparkFun repository: https://github.com/sparkfun/RFM69HCW_Breakout
// Include the RFM69 and SPI libraries:
#include <RFM69.h>
#include <SPI.h>
// Addresses for this node. CHANGE THESE FOR EACH NODE!
#define NETWORKID 0 // Must be the same for all nodes (0 to 255)
#define MYNODEID 26 // My node ID (0 to 255)
#define TONODEID 1 // Destination node ID (0 to 254, 255 = broadcast)
// RFM69 frequency, uncomment the frequency of your module:
#define FREQUENCY RF69_433MHZ
// AES encryption (or not):
#define ENCRYPT true // Set to "true" to use encryption
#define ENCRYPTKEY "TOPSECRETPASSWRD" // Use the same 16-byte key on all nodes
// Create a library object for our RFM69HCW module:
RFM69 radio;
void setup()
{
// Open a serial port so we can send keystrokes to the module:
Serial.begin(9600);
Serial.print("Node ");
Serial.print(MYNODEID,DEC);
Serial.println(" ready");
// Initialize the RFM69HCW:
radio.initialize(FREQUENCY, MYNODEID, NETWORKID);
radio.setHighPower(); // Always use this for RFM69HCW
// Turn on encryption if desired:
if (ENCRYPT)
radio.encrypt(ENCRYPTKEY);
}
void loop()
{
// SENDING
int val = analogRead(A2);
if(val>1000)
{
long myTestMessage = "A125";
if (radio.sendWithRetry(TONODEID, myTestMessage, sizeof(myTestMessage)))
Serial.println("ACK received!");
else
Serial.println("no ACK received :(");
}
delay(3000);
}
With the long I can have 4 Digits. I tried to use unsigned long to get more but it didn´t work.