Hello,
I'm having problem with PlatformIO project compilation.
Here is the message from terminal:
Processing nanoatmega328 (platform: atmelavr; board: nanoatmega328; framework: arduino)
------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via -v, --verbose
option
CONFIGURATION: Redirecting...
PLATFORM: Atmel AVR > Arduino Nano ATmega328
HARDWARE: ATMEGA328P 16MHz 2KB RAM (30KB Flash)
Library Dependency Finder -> Library Dependency Finder (LDF) — PlatformIO latest documentation
LDF MODES: FINDER(chain) COMPATIBILITY(soft)
Collected 9 compatible libraries
Scanning dependencies...
Dependency Graph
|-- 1.1.3
|-- 1.89
| |-- 1.0
|-- 1.0
Compiling .pioenvs\nanoatmega328\src\main.cpp.o
In file included from C:\Users\Raadley.platformio\lib\RadioHead_ID124/RHGenericDriver.h:9:0,
from C:\Users\Raadley.platformio\lib\RadioHead_ID124/RH_ASK.h:9,
from src\main.cpp:7:
C:\Users\Raadley.platformio\lib\RadioHead_ID124/RadioHead.h:320:51: warning: "/" within comment [-Wcomment]
__cp /usr/local/projects/arduino/libraries/RadioHead/.h .__
^
C:\Users\Raadley.platformio\lib\RadioHead_ID124/RadioHead.h:321:51: warning: "/" within comment [-Wcomment]
__cp /usr/local/projects/arduino/libraries/RadioHead/.cpp .__
^
Linking .pioenvs\nanoatmega328\firmware.elf
RH_ASK.cpp.o (symbol from plugin): In function RH_ASK::maxMessageLength()':** **(.text+0x0): multiple definition of
__vector_11'
Servo.cpp.o (symbol from plugin):(.text+0x0): first defined here
collect2.exe: error: ld returned 1 exit status
*** [.pioenvs\nanoatmega328\firmware.elf] Error 1
======================================================= [ERROR] Took 2.48 seconds =======================================================
The terminal process terminated with exit code: 1
Previously I had one main.cpp file where I putted everything including functions etc., but I read some threads and I realised that I should divide it into .cpp files and .h files. There was mensioned that I should put "extern" to solve multiple definition in .h file. I thought it would solve the problem but it didn't.
Here is the source code:
Main.cpp:
#include <Arduino.h>
//including servo library
#include <Servo.h>
//including radioHead library to use 433MHz transmitter
#include "RH_ASK.h"
//this library need to be also included because RH_ASK is using files from that library?
#include <SPI.h>
//including different file with function to transmit data through 433MHz transmitter
#include "transmitData.h"
//defining ultra sonic sensor pins
#define trigPin 2
#define echoPin 4
//defining servo pin
#define servoPin 3
//creating servo object to control servo motor
Servo myServo;
//the same time interval for servo movement and radar reading in millis
const int servoAndRadarInterval = 500;
//storing previous millis - necessary for equal intervals
unsigned long previousServoAndRadarMillis = 0;
//variables to calculate how much time microcontroller spent to walk through the loop
unsigned long beforeLoopMillis = 0;
unsigned long afterLoopMillis = 0;
int loopTimeDifference;
//values which are storing radar echoTime and calculated distance
int echoTime = 0;
int calculatedDistance = 0;
//value which is storing current servo angle
int servoAngle = 15;
//value storing single servo step
int servoStep = 1;
//defining radiohead transmitter object
RH_ASK rfDriver;
//defining String which will be send through transmitter to receiver
String strMessageOut;
String strServoAngle = String(servoAngle);
String strCalculatedDistance = String(calculatedDistance);
/*
Calculating distance between obstacle and radar.
@ returning calculated distance
*/
int calculateDistance() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
echoTime = pulseIn(echoPin, HIGH);
return echoTime/58;
}
/*
Transmitting data through 433MHz transmitter
*/
/*
void transmitData() {
strMessageOut = strServoAngle + ',' + strCalculatedDistance + '.';
const char *msg = strMessageOut.c_str();
rfDriver.send((uint8_t *)msg, strlen(msg));
rfDriver.waitPacketSent();
}
*/
void setup() {
//initialize radiohead object
rfDriver.init();
//begin serial communication with 9600 bytes per second - the same rate need to be in terminal or processing
Serial.begin(9600);
//set sensor trigPin as output
pinMode(trigPin, OUTPUT);
//set sensor echoPin as input
pinMode(echoPin, INPUT);
//using servo library - arduino pin set for servo controlling
myServo.attach(servoPin);
//set servo initial position
myServo.write(servoAngle);
//wait for servo to reach initial position
delay(1000);
}
void loop() {
//calculating distance and moving servo in equal intervals
if(millis() - previousServoAndRadarMillis >= servoAndRadarInterval) {
beforeLoopMillis = millis();
//calling function which is calculating distance using ultrasonic sensor
calculatedDistance = calculateDistance();
//incrementing servo angle
servoAngle += servoStep;
//calling servo function to set servo in specific angle
myServo.write(servoAngle);
//reversing servo step if angle is boundary
if(servoAngle == 15 or servoAngle == 165) {
servoStep = -servoStep;
}
String strMessageOut = strServoAngle + ',' + strCalculatedDistance + '.';
transmitData(strMessageOut);
/*
//Sending data through Serial Communication
Serial.print(servoAngle);
Serial.print(',');
Serial.print(calculatedDistance);
Serial.print('.');
*/
/*
Serial.print("<<<");
//Serial.print(echoTime/1000);
Serial.print(afterLoopMillis-beforeLoopMillis);
Serial.print(">>>");
*/
//adding servoAndRadarInterval and adding echo time to previousServoAndRadarMillis to imitate delay
previousServoAndRadarMillis += servoAndRadarInterval;
afterLoopMillis = millis();
loopTimeDifference = afterLoopMillis - beforeLoopMillis;
previousServoAndRadarMillis += loopTimeDifference;
}
}
rfTransmitter.h:
#include <Arduino.h>
#include "RH_ASK.h"
#include <SPI.h>
extern RH_ASK rfDriver;
void transmitData(String msgOut);
rfTransmitter.cpp
#include <Arduino.h>
#include "transmitData.h"
#include "RH_ASK.h"
#include <SPI.h>
void transmitData(String msgOut) {
//rfDriver.init();
const char *msg = msgOut.c_str();
rfDriver.send((uint8_t *)msg, strlen(msg));
rfDriver.waitPacketSent();
}
Could you please provide me the solution?
Thank you in advance.