/* Tranmitter_test
* From "Transmitter" by Felix Rusu
* Modified by Dave Gundlach
* 9/23/16
*
* Transmitter_test and Receiver_test is an example of how to remote control
* servos, and LEDs with pots and buttons.
*
* Libraries:
* RFM69 library and code by Felix Rusu - felix@lowpowerlab.com
* Get libraries at: https://github.com/LowPowerLab/
* SPI.h - Included in Arduino IDE
*
* Components:
* Adafruit Feather 32u4 with RFM69HCW Packet Radio - 433MHz
* Two Axis joystick (10K pots)
* Potentiometer (10K)
* Tactile Button Switch (momentary contace)
*
* Wiring:
* Feather:
* Pin A0 - Joystick Up/Down (center pot pin)
* Pin A1 - Joystick Left/Right (center pot pin)
* Pin A2 - Potentiometer (center pin)
* Pin 5 - Tactile Button Switch (Sketch uses internal pullup)
*
* Change Log
* V01 - Added Notes
* V02 - Clean up
*/
#include <RFM69.h> //get it here: https://www.github.com/lowpowerlab/rfm69
#include <SPI.h>
//*********************************************************************************************
// *********** IMPORTANT SETTINGS - YOU MUST CHANGE/ONFIGURE TO FIT YOUR HARDWARE *************
//*********************************************************************************************
#define NETWORKID 100 // The same on all nodes that talk to each other
#define NODEID 2 // The unique identifier of this node
#define RECEIVER 1 // The recipient of packets
//Match frequency to the hardware version of the radio on your Feather
#define FREQUENCY RF69_433MHZ
//#define FREQUENCY RF69_868MHZ
//#define FREQUENCY RF69_915MHZ
#define ENCRYPTKEY "sampleEncryptKey" //exactly the same 16 characters/bytes on all nodes!
#define IS_RFM69HCW true // set to 'true' if you are using an RFM69HCW module
//*********************************************************************************************
#define SERIAL_BAUD 115200
#define RFM69_CS 8
#define RFM69_IRQ 7
#define RFM69_IRQN 4 // Pin 7 is IRQ 4!
#define RFM69_RST 4
#define BUTTON 5 // Button Pin
#define POT A2 // Pot Pin
#define LR A1 // Joystick Left Right Pin
#define UD A0 // Joystick Up Down Pin
RFM69 radio = RFM69(RFM69_CS, RFM69_IRQ, IS_RFM69HCW, RFM69_IRQN);
void setup() {
// while (!Serial); // wait until serial console is open, remove if not tethered to computer
Serial.begin(SERIAL_BAUD);
Serial.println("Feather RFM69HCW Transmitter");
pinMode(BUTTON, INPUT_PULLUP); // Button Pin setup
// Hard Reset the RFM module
pinMode(RFM69_RST, OUTPUT);
digitalWrite(RFM69_RST, HIGH);
delay(100);
digitalWrite(RFM69_RST, LOW);
delay(100);
// Initialize radio
radio.initialize(FREQUENCY,NODEID,NETWORKID);
if (IS_RFM69HCW) {
radio.setHighPower(); // Only for RFM69HCW & HW!
}
radio.setPowerLevel(31); // power output ranges from 0 (5dBm) to 31 (20dBm)
radio.encrypt(ENCRYPTKEY);
Serial.print("\nTransmitting at ");
Serial.print(FREQUENCY==RF69_433MHZ ? 433 : FREQUENCY==RF69_868MHZ ? 868 : 915);
Serial.println(" MHz");
}
void loop() {
//delay(1000);
char radiopacket[20]; // packet
int updn = analogRead(UD); // Read Joystick Up/Down pin value
updn = map(updn, 0, 1023, 0, 180); // Map value from 0 to 180
//Serial.println(updn);
int ltrt = analogRead(LR); // Read Joystick Left / Right pin value
ltrt = map(ltrt, 0, 1023, 0, 180); // Map value from 0 to 180
int knob = analogRead(POT); // Read pot value
knob = map(knob, 0, 1023, 0, 255); // Map value from 0 to 255
//Serial.println(knob);
int btn = digitalRead(BUTTON); // Read button value
itoa(updn+100, radiopacket, 10); // Add 100 to Up/Down value, convert to char, put in packet
itoa(ltrt+100, radiopacket+3, 10); // Add 100 to Left/Right value, convert to char, put in packet after Up/Down
itoa(knob+100, radiopacket+6, 10); // Add 100 to pot value, convert to char, put in packet after Left/Right
itoa(btn, radiopacket+9, 10); // convert button value to char, put in packet after pot
//Serial.print("Sending "); Serial.println(radiopacket);
radio.send(RECEIVER, radiopacket, strlen(radiopacket)); //target node Id, message as string or byte array, message length
//Serial.println("OK");
radio.receiveDone(); //put radio in RX mode
Serial.flush(); //make sure all serial data is clocked out before sleeping the MCU
}
/* Receiver_test
* From "Receiver" by Felix Rusu
* Modified by Dave Gundlach
* 9/24/16
*
* Transmitter_test and Receiver_test is an example of how to remote control
* servos, and LEDs with pots and buttons.
*
* Libraries:
* RFM69 library and code by Felix Rusu - felix@lowpowerlab.com
* Get libraries at: https://github.com/LowPowerLab/
* SPI.h - Included in Arduino IDE
* Servo.h - Included in Arduino IDE
*
* Components:
* Adafruit RFM69HCW 433MHz Packet Radio Breakout
* Arduino Mega
* 2 Hobby Servos
* 2 LED's (red and green)
* 2 330 Ohm resistors (for LEDs)
*
* Wiring:
* Packet Radio to Mega
* Vin to 5V
* GND to Ground
* SCK to pin 52
* MISO to pin 50
* MOSI to pin 51
* CS to pin 10
* RST to pin 9
* Go to pin 2 (IRQ 0)
* LEDs:
* Red to pin 3
* Green to pin 4
* Servos:
* Up/Down servo to pin 6
* Left/Right servo to pin 7
* (Power to servos from 6V battery pack
* bond battery pack ground to Mega ground)
*
*
* Change Log
* V01 - Added Notes
* V02 - Added Servo & LED code
*/
#include <RFM69.h> //get it here: https://www.github.com/lowpowerlab/rfm69
#include <SPI.h>
#include <Servo.h> // servo library
//*********************************************************************************************
// *********** IMPORTANT SETTINGS - YOU MUST CHANGE/ONFIGURE TO FIT YOUR HARDWARE *************
//*********************************************************************************************
#define NETWORKID 100 //the same on all nodes that talk to each other
#define NODEID 1
#define RECEIVER 2 // The recipient of packets
//Match frequency to the hardware version of the radio on your Feather
#define FREQUENCY RF69_433MHZ
//#define FREQUENCY RF69_868MHZ
//#define FREQUENCY RF69_915MHZ
#define ENCRYPTKEY "sampleEncryptKey" //exactly the same 16 characters/bytes on all nodes!
#define IS_RFM69HCW true // set to 'true' if you are using an RFM69HCW module
//*********************************************************************************************
#define SERIAL_BAUD 115200
#define RFM69_CS 10
#define RFM69_IRQ 2
#define RFM69_IRQN 0 // Pin 2 is IRQ 0!
#define RFM69_RST 9
#define RLED 13 // Red LED pin
#define GLED 12 // Green LED pin
RFM69 radio = RFM69(RFM69_CS, RFM69_IRQ, IS_RFM69HCW, RFM69_IRQN);
Servo udServo; // Up/Down servo
Servo lrServo; // Left/Right servo
void setup() {
while (!Serial); // wait until serial console is open, remove if not tethered to computer
Serial.begin(SERIAL_BAUD);
Serial.println("RFM69HCW Receiver");
pinMode(RLED, OUTPUT); // LED setup as output
pinMode(GLED, OUTPUT); // LED setup as output
// Hard Reset the RFM module
pinMode(RFM69_RST, OUTPUT);
digitalWrite(RFM69_RST, HIGH);
delay(100);
digitalWrite(RFM69_RST, LOW);
delay(100);
udServo.attach(6); // Up/Down servo attached to pin 6
lrServo.attach(7); // Left/Right servo attached to pin 7
// Initialize radio
radio.initialize(FREQUENCY,NODEID,NETWORKID);
if (IS_RFM69HCW) {
radio.setHighPower(); // Only for RFM69HCW & HW!
}
radio.setPowerLevel(31); // power output ranges from 0 (5dBm) to 31 (20dBm)
radio.encrypt(ENCRYPTKEY);
Serial.print("\nListening at ");
Serial.print(FREQUENCY==RF69_433MHZ ? 433 : FREQUENCY==RF69_868MHZ ? 868 : 915);
Serial.println(" MHz");
}
void loop() {
uint8_t buf[RF69_MAX_DATA_LEN]; // Reciever Buffer
uint8_t buflen = radio.DATALEN; // Buffer Length
int value[10]; // Integer Value
char valueChar[4]; // Char Value
int sv[4]; // Sensor Value
//Serial.println("aan het ontvangen...");
//check if something was received (could be an interrupt from the radio)
if (radio.receiveDone()){
//print message received to serial
Serial.print("iets ontvangen");
Serial.println('[');Serial.print(radio.SENDERID);Serial.print("] ");
Serial.print((char*)radio.DATA);
Serial.print(" [RX_RSSI:");Serial.print(radio.RSSI);Serial.println("]");
for(int i=0; i<buflen; i++){ // Fill recieve buffer
buf[i]=radio.DATA[i];
}
for (int i=0; i<3; i++){ // for first 3 values
for(int j=0; j<3; j++){ // data has 3 digits
valueChar[j]=char(buf[j+(i*3)]); // make ascii char values
}
value[i] = atoi(valueChar)-100; // convert char to int (subtract 100)
}
for (int i=0; i<3; i++){ // for sensor values in message
sv[i] = value[i]; // put sensor values in aray
}
for(int i=0; i<3; i++){ // Clear variables
value[i]=0;
valueChar[i]=0;
}
valueChar[0] = char(buf[9]); // Last digit value ascii to char
value[0] = atoi(valueChar); // char to int
sv[3] = value[0]; // put value into aray
Serial.print(sv[0]); Serial.print(", "); // debug
Serial.print(sv[1]); Serial.print(", ");
Serial.print(sv[2]); Serial.print(", ");
Serial.print(sv[3]); Serial.println(" ");
if(!sv[3]){ // Turn on/off Red LED
digitalWrite(RLED, HIGH);
}
else{
digitalWrite(RLED, LOW);
}
analogWrite(GLED, sv[2]); // Dim Green LED
lrServo.write(sv[1]); // Move Left/Right Servo
udServo.write(sv[0]); // Move Up/Down Servo
}
radio.receiveDone(); //put radio in RX mode
Serial.flush(); //make sure all serial data is clocked out before sleeping the MCU
}
I don't think your pins are correct. One of your sketches has comments for a mega. I doubt you are actually transmitting anything.
Read the adafruit tutorial here and pay attention to the which pins are used, specifically the CS line needs to be low for the radio to work. They also recommend a library that comes with example code.