This is Neal.
I have one RFM69 Radio and Servos and Sensors wired to an Arduino Nano and another Arduino Nano wired to another RFM69 Radio and Servo and Sensors.
I am trying to simply send a message through my RFM69 Radios with using part of the RadioHead69_RawDemoTXRX_OLED in my code.
My code moves a servo once the pressure sensors get pushed too much.
I commented out all the parts that has to do with buttons because I simply want it to send a message to the radios after my servo moves.
I commented where the radios are supposed to send a message to each other with "Start of Radio Sending Message" and "End of Radio Sending Message".
Here is my code:
Code: Select all
#include <Servo.h>
#include "Wire.h"
#include "Adafruit_LiquidCrystal.h"
#include <RH_RF69.h>
#define LED 13// FOR LED
#define RF69_FREQ 434.0
#if defined (__AVR_ATmega328P__) // Feather 328P w/wing
#define RFM69_INT 3 //
#define RFM69_CS 4 //
#define RFM69_RST 2 // "A"
#endif
// Singleton instance of the radio driver
RH_RF69 rf69(RFM69_CS, RFM69_INT);
Adafruit_LiquidCrystal lcd(0);
Servo myservo1;
Servo myservo2;
//cant do A4 and A5(they are for lcd)
// Analogs 0 to 5
const int knockSensor = A0;
const int knockSensor1= A1;
const int knockSensor2= A2;
const int knockSensor3= A3;
const int knockSensor4= A6;
const int knockSensor5= A7;
const int threshold = 0;
int health = 500;
// 6 total sensor readings (from 0 to 5)
int sensorReading = 0;
int sensorReading1 =0;
int sensorReading2 =0;
int sensorReading3 =0;
int sensorReading4 =0;
int sensorReading5 =0;
int pos =0;
int deaths=1;// gonna be number of deaths
void setup()
{
// pinMode(LED_BUILTIN, OUTPUT); //LED ON ARDUINO
pinMode(LED, OUTPUT);//FOR LED
Serial.begin(115200);//was 9600
Serial.println("Nerf Target v0.0.1, github.com/mcoms/nerf-target, 2014.");
pinMode(LED, OUTPUT);
pinMode(RFM69_RST, OUTPUT);
digitalWrite(RFM69_RST, LOW);
if (!rf69.init()) {
Serial.println("RFM69 radio init failed");
while (1);
} // failed
rf69.setTxPower(14, true);
// sg90
lcd.begin (20 , 4);
lcd.clear();
Serial.begin(9600);
myservo1.attach(9);
myservo1.write(0);//was 0
myservo2.attach(10);
myservo2.write(45);//was 179
}
void loop()
{
do
{
myservo1.detach();
myservo2.detach();
sensorReading = analogRead(knockSensor);
lcd.setCursor(0, 1);
Serial.println(health);
lcd.println(health);
if (sensorReading > threshold) {
Serial.println("Knock!");
health = health - sensorReading;
Serial.print(sensorReading);
lcd.print(sensorReading);
int sensorValue = analogRead(A0);
Serial.println(sensorValue);
delay(1);
}
//duplicate
sensorReading1= analogRead(knockSensor1);
if (sensorReading1 > threshold) {
Serial.println("Knock!");
health = health - sensorReading1;
Serial.print(sensorReading1);
lcd.print(sensorReading1);
int sensorValue = analogRead(A1);
Serial.println(sensorValue);
delay(1);
}
//duplicate
sensorReading2= analogRead(knockSensor2);
if (sensorReading2 > threshold) {
Serial.println("Knock!");
health = health - sensorReading2;
Serial.print(sensorReading2);
lcd.print(sensorReading2);
int sensorValue = analogRead(A2);
Serial.println(sensorValue);
delay(1);
}
//duplicate
sensorReading3= analogRead(knockSensor3);
if (sensorReading3 > threshold) {
Serial.println("Knock!");
health = health - sensorReading3;
Serial.print(sensorReading3);
lcd.print(sensorReading3);
int sensorValue = analogRead(A3);
Serial.println(sensorValue);
delay(1);
}
//duplicate
sensorReading4= analogRead(knockSensor4);
if (sensorReading4 > threshold) {
Serial.println("Knock!");
health = health - sensorReading4;
Serial.print(sensorReading4);
lcd.print(sensorReading4);
int sensorValue = analogRead(A6);
Serial.println(sensorValue);
delay(1);
}
//duplicate
sensorReading5= analogRead(knockSensor5);
if (sensorReading5 > threshold) {
Serial.println("Knock!");
health = health - sensorReading5;
Serial.print(sensorReading5);
lcd.print(sensorReading5);
int sensorValue = analogRead(A7);
Serial.println(sensorValue);
delay(1);
}
} while (health > 1);
digitalWrite(LED_BUILTIN, HIGH);
delay(2000);//was 2000 // FOR LED IN ARDUINO
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
/*
digitalWrite(LED, HIGH);
delay(2000); //FOR LED
digitalWrite(LED, HIGH);
delay(1000);
*/
myservo1.attach(9);
myservo2.attach(10);
delay(15);
//Servo Starts Moving Here
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo1.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15 ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo1.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15 ms for the servo to reach the position
//Servo Stops Moving Here
}
delay(1000);
//lcd.setCursor(0, 2);
//Serial.println(deaths); //showind number of deaths on the lcd
//lcd.println(deaths);
//deaths= deaths + 1;// adding deaths
//Start of Radio Sending Message
{ if (rf69.waitAvailableTimeout(100)) {
// Should be a message for us now
uint8_t buf[RH_RF69_MAX_MESSAGE_LEN];
uint8_t len = sizeof(buf);
if (! rf69.recv(buf , & len )) {
Serial.println("Receive failed");
return;
}
digitalWrite(LED, HIGH);
rf69.printBuffer("Received: ", buf, len);
buf[len] = 0;
Serial.print("Got: "); Serial.println((char*) buf);
}
// if (!digitalRead(Servo_B) )
// {
Serial.println("Servo Moved!");
char radiopacket[20] = "Servo #";
// if (!digitalRead(Servo_B)) radiopacket[8] = 'B';
//radiopacket[9] = 0;
Serial.print("Sending "); Serial.println(radiopacket);
rf69.send((uint8_t *)radiopacket, strlen(radiopacket));
rf69.waitPacketSent();
}
//End of Radio Sending Message
health = 500;
}
But I keep on getting the error "Error compiling for Arduino Nano"
A picture of the error is attached to this post.
Even when I added one of the libraries from the RadioHead69_RawDemoTXRX_OLED sketch to my code I got the same error.
Can you tell me how to fix this error?
If so that would be great.