I'm posting this topic because I'm trying to use servos and the radio at the same time on a feather 32u4 RFM95W LoRa radio 433Mhz.
But when I want to compile it seams that there is a conflict between the library Servos (from Arduino) and the library RadioHead.
The code is the following :
Code: Select all
#include <Servo.h>
#include <RHReliableDatagram.h>
#include <RH_RF95.h>
#include <SPI.h>
#define REMOTE_ADDRESS 1
#define BLIMP_ADDRESS 2
// Singleton instance of the radio driver
#define RFM95_CS 8
#define RFM95_RST 4
#define RFM95_INT 7
typedef enum {
PING = 0,
BLIMP_MOTOR_CMD = 1,
BASE_MOTOR_CMD = 2,
BATT_STATUS = 3,
ERROR_MSG = 4,
MSG = 5
} motor_t;
// Singleton instance of the radio driver
RH_RF95 rf95(RFM95_CS, RFM95_INT);
//RHReliableDatagram manager(driver, BLIMP_ADDRESS);
#define NB_SERVOS 4
Servo servos[NB_SERVOS];
int servo_pins[NB_SERVOS] = {10, 11, 12, 13};
void setup()
{
Serial.begin(9600);
while (!Serial)
; // Wait for serial port to be available
rf95.init();
Serial.println("[lora] ready");
// servo
for (size_t i = 0; i < NB_SERVOS; ++i)
{
pinMode(servo_pins[i], OUTPUT);
servos[i].attach(servo_pins[i]);
servos[i].write(90);
}
// led
pinMode(13, OUTPUT);
// battery
pinMode(9, INPUT);
// power
rf95.setTxPower(23, false);
}
// Dont put this on the stack:
uint8_t buf[RH_RF95_MAX_MESSAGE_LEN] = {0};
void ping()
{
Serial.println("Received a PING");
uint8_t ping_packet[] = {PING};
rf95.send(ping_packet, sizeof(ping_packet));
}
//
void motor_cmd(const uint8_t *str, int len)
{
Serial.print("Received a MOTOR_CMD:");
Serial.println((int)str[1]);
// str[0] is the command (MOTOR_CMD), then we have the positions
for (int i = 1; i < len; ++i)
{
int sp = (int)str[i];
servos[i - 1].write(sp);
}
}
void batt_status()
{
float val = analogRead(A7) * 2 * 3.3 / 1024;
Serial.print("Received BATT_STATUS:");
Serial.println(val);
uint8_t data[2] = {BATT_STATUS, uint8_t(val * 10)};
rf95.send((uint8_t *)data, 2);
}
void handle_response(const uint8_t *str, int len)
{
// first byte is the instruction
switch (str[0])
{
case PING:
ping();
break;
case BLIMP_MOTOR_CMD:
motor_cmd(str, len);
break;
case BATT_STATUS:
batt_status();
break;
default:
Serial.print("ERROR: unrecognized instruction type:");
Serial.println((int)str[0]);
}
}
void loop()
{
if (rf95.waitAvailableTimeout(100))
{
digitalWrite(13, HIGH);
// Wait for a message addressed to us from the client
uint8_t len = sizeof(buf);
uint8_t from;
if (rf95.recv(buf, &len))
handle_response(buf, len);
digitalWrite(13, LOW);
}
}
And the error is :
If anyone have an answer, I would appreciate :)libraries\RadioHead\RH_ASK.cpp.o (symbol from plugin): In function `RH_ASK::maxMessageLength()':
(.text+0x0): multiple definition of `__vector_17'
libraries\Servo\avr\Servo.cpp.o (symbol from plugin):(.text+0x0): first defined here
collect2.exe: error: ld returned 1 exit status
exit status 1
Error compiling for board Adafruit Feather 32u4.
Thank you.