Ah, my bad.
Couldn't find the spoiler button, so I'm just putting it in quotes
// Simple RFM12B sender program, with ACK and optional encryption
// It initializes the RFM12B radio with optional encryption and passes through any valid messages to the serial port
// felix@lowpowerlab.com
#include <RFM12B.h>
#include <avr/sleep.h>
// You will need to initialize the radio by telling it what ID it has and what network it's on
// The NodeID takes values from 1-127, 0 is reserved for sending broadcast messages (send to all nodes)
// The Network ID takes values from 0-255
// By default the SPI-SS line used is D10 on Atmega328. You can change it by calling .SetCS(pin) where pin can be {8,9,10}
#define NODEID 2 //network ID used for this unit
#define NETWORKID 99 //the network ID we are on
#define GATEWAYID 1 //the node ID we're sending to
#define ACK_TIME 50 // # of ms to wait for an ack
#define SERIAL_BAUD 115200
//encryption is OPTIONAL
//to enable encryption you will need to:
// - provide a 16-byte encryption KEY (same on all nodes that talk encrypted)
// - to call .Encrypt(KEY) to start encrypting
// - to stop encrypting call .Encrypt(NULL)
uint8_t KEY[] = "ABCDABCDABCDABCD";
int interPacketDelay = 1000; //wait this many ms between sending packets
// Need an instance of the Radio Module
RFM12B radio;
byte sendSize=0;
char payload[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890~!@#$%^&*(){}[]`|<>?+=:;,.";
bool requestACK=false;
void setup()
{
pinMode(13, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, INPUT);
pinMode(3, OUTPUT);
digitalWrite(4, HIGH);//this is the high voltage pin for the button.
digitalWrite(3, HIGH);//should power up the transciever (I have it powering the transciever)
radio.Initialize(NODEID, RF12_915MHZ, NETWORKID);
//radio.Encrypt(NULL);
radio.Sleep(); //sleep right away to save power
}
void loop()
{
if(digitalRead(5))//this is my button, I've tested it and it seems to work fine
{
payload[8] = '1';//set 8th character to a 1 to tell the recieving end to buzz
}
else
{
payload[8] = '0';//set the 8th character to a 0 to tell the recieving end to stop buzzing
}
requestACK = !(sendSize % 3); //request ACK every 3rd xmission
radio.Wakeup();
radio.Send(GATEWAYID, payload, sendSize+1, requestACK);
radio.Sleep();
sendSize = (sendSize + 1) % 88;
delay(interPacketDelay);
digitalWrite(13, !digitalRead(5)); //turns the LED to tell me if the button is pushed, but doesn't seem to work right :/
}
// wait a few milliseconds for proper ACK, return true if received
static bool waitForAck() {
long now = millis();
while (millis() - now <= ACK_TIME)
if (radio.ACKReceived(GATEWAYID))
return true;
return false;
}]
Recieving end
// Simple serial pass through program
// It initializes the RFM12B radio with optional encryption and passes through any valid messages to the serial port
// felix@lowpowerlab.com
#include <RFM12B.h>
// You will need to initialize the radio by telling it what ID it has and what network it's on
// The NodeID takes values from 1-127, 0 is reserved for sending broadcast messages (send to all nodes)
// The Network ID takes values from 0-255
// By default the SPI-SS line used is D10 on Atmega328. You can change it by calling .SetCS(pin) where pin can be {8,9,10}
#define NODEID 1 //network ID used for this unit
#define NETWORKID 99 //the network ID we are on
#define SERIAL_BAUD 115200
//encryption is OPTIONAL
//to enable encryption you will need to:
// - provide a 16-byte encryption KEY (same on all nodes that talk encrypted)
// - to call .Encrypt(KEY) to start encrypting
// - to stop encrypting call .Encrypt(NULL)
uint8_t KEY[] = "ABCDABCDABCDABCD";
// Need an instance of the Radio Module
RFM12B radio;
void setup()
{
pinMode(4, OUTPUT);
pinMode(3, OUTPUT);
digitalWrite(3, HIGH);
radio.Initialize(NODEID, RF12_915MHZ, NETWORKID);
//radio.Encrypt(NULL); //comment this out to disable encryption
Serial.begin(SERIAL_BAUD);
Serial.println("Listening...");
}
void loop()
{
radio.ReceiveComplete();
radio.CRCPass();
radio.GetSender();
for (byte i = 0; i < *radio.DataLen; i++) //can also use radio.GetDataLen() if you don't like pointers
Serial.print((char)radio.Data);
if(radio.Data[8] == '1')
{digitalWrite(4, HIGH);} //this part activates a buzzer (I've tested the buzzer, it works fine
else
{digitalWrite(4, LOW);}
if (radio.ACKRequested())
{
radio.SendACK();
}
}
I removed a lot of the serial stuff, which in hindsight may have been a bad idea, but it doesn't seem to work with the setup I'm using to program it (I have a very weird setup involving a https://www.sparkfun.com/products/12924 (https://www.sparkfun.com/products/12924) and a breadboard)
Made some modifications
transmit
// Simple RFM12B sender program, with ACK and optional encryption
// It initializes the RFM12B radio with optional encryption and passes through any valid messages to the serial port
// felix@lowpowerlab.com
#include <RFM12B.h>
#include <avr/sleep.h>
// You will need to initialize the radio by telling it what ID it has and what network it's on
// The NodeID takes values from 1-127, 0 is reserved for sending broadcast messages (send to all nodes)
// The Network ID takes values from 0-255
// By default the SPI-SS line used is D10 on Atmega328. You can change it by calling .SetCS(pin) where pin can be {8,9,10}
#define NODEID 2 //network ID used for this unit
#define NETWORKID 99 //the network ID we are on
#define GATEWAYID 1 //the node ID we're sending to
#define ACK_TIME 50 // # of ms to wait for an ack
#define SERIAL_BAUD 115200
//encryption is OPTIONAL
//to enable encryption you will need to:
// - provide a 16-byte encryption KEY (same on all nodes that talk encrypted)
// - to call .Encrypt(KEY) to start encrypting
// - to stop encrypting call .Encrypt(NULL)
uint8_t KEY[] = "ABCDABCDABCDABCD";
int interPacketDelay = 1000; //wait this many ms between sending packets
// Need an instance of the Radio Module
RFM12B radio;
byte sendSize=0;
char payload[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890~!@#$%^&*(){}[]`|<>?+=:;,.";
bool requestACK=false;
bool buttonPressed = false;
void setup()
{
pinMode(13, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, INPUT);
pinMode(3, OUTPUT);
digitalWrite(4, HIGH);
digitalWrite(3, HIGH);//should power up the transciever
radio.Initialize(NODEID, RF12_915MHZ, NETWORKID);
//radio.Encrypt(NULL);
radio.Sleep(); //sleep right away to save power
}
void loop()
{
interPacketDelay = 500;
buttonPressed = digitalRead(5);
if(buttonPressed == HIGH)
{
payload[8] = '1';
digitalWrite(13, HIGH);
}
else
{
digitalWrite(13, LOW);
payload[8] = '0';
}
requestACK = !(sendSize % 3); //request ACK every 3rd xmission
radio.Wakeup();
radio.Send(GATEWAYID, payload, sendSize+1, requestACK);
if(requestACK)
waitForAck();
radio.Sleep();
sendSize = (sendSize + 1) % 88;
delay(interPacketDelay);
}
// wait a few milliseconds for proper ACK, return true if received
static bool waitForAck() {
long now = millis();
while (millis() - now <= ACK_TIME)
if (radio.ACKReceived(GATEWAYID))
return true;
return false;
}
recieve
// Simple serial pass through program
// It initializes the RFM12B radio with optional encryption and passes through any valid messages to the serial port
// felix@lowpowerlab.com
#include <RFM12B.h>
// You will need to initialize the radio by telling it what ID it has and what network it's on
// The NodeID takes values from 1-127, 0 is reserved for sending broadcast messages (send to all nodes)
// The Network ID takes values from 0-255
// By default the SPI-SS line used is D10 on Atmega328. You can change it by calling .SetCS(pin) where pin can be {8,9,10}
#define NODEID 1 //network ID used for this unit
#define NETWORKID 99 //the network ID we are on
#define SERIAL_BAUD 115200
//encryption is OPTIONAL
//to enable encryption you will need to:
// - provide a 16-byte encryption KEY (same on all nodes that talk encrypted)
// - to call .Encrypt(KEY) to start encrypting
// - to stop encrypting call .Encrypt(NULL)
uint8_t KEY[] = "ABCDABCDABCDABCD";
// Need an instance of the Radio Module
RFM12B radio;
void setup()
{
pinMode(4, OUTPUT);
pinMode(3, OUTPUT);
digitalWrite(3, HIGH);
radio.Initialize(NODEID, RF12_915MHZ, NETWORKID);
//radio.Encrypt(NULL); //comment this out to disable encryption
Serial.begin(SERIAL_BAUD);
Serial.println("Listening...");
}
void loop()
{
radio.ReceiveComplete();
radio.CRCPass();
radio.GetSender();
for (byte i = 0; i < *radio.DataLen; i++) //can also use radio.GetDataLen() if you don't like pointers
Serial.print((char)radio.Data[i]);
if(radio.Data[8] != NULL)
{digitalWrite(4, HIGH);}
else
{digitalWrite(4, LOW);}
if (radio.ACKRequested())
{
radio.SendACK();
}
}
I'm not familiar with the RFM12 library so I just have a couple of observations:
1. Does the library really support packets as long as 88 bytes?
2. In the receiving code, where you're trying to print the data, you have:
Serial.print((char)radio.Data);
which should be:
Serial.print((char)radio.Data[i]);
3. The sender is sending varying lengths of packets from 1 to 88 bytes of data. Obviously you will not receive payload[8] until the data length is at least 9.
4. The Moteino LED is on pin 9, not 13.
5. Request Ack will not do much good for two reasons: 1. You're sleeping the radio as soon as you send so you're going to miss an Ack when it's sent. 2. The Ack will be send AFTER all the serial output takes place, delaying when the Ack is actually sent.
That's all I see at the moment with admittedly quick scan.
Tom