I am using the code below to interface the Arduino nano and android cell phone to enable serial communication through the USB port. I downloaded the filter library from GitHub https://github.com/JonHub/Filters
I am getting an error saying thet the library is not found. I would really appreciate some suggestions on this.
Here is my code:
//This code is for arduino communicating to android phone through USb serial port.
//For arduino nano
#include <Filters.h> //implements digital filters which mimic the analog filter, keep track of variable statistics in realtime
char data_read; //character datatype takes up to 1 byte of memory
unsigned int analog_out;
unsigned long time;
float filterFrequency = 10.0;
FilterOnePole lowpassFilter( LOWPASS, filterFrequency );//implements digital RC type filter; both highpass and lowpass
void setup()
{
Serial.begin(115200); //open the serial port and set the baud rate for communication
// create a one pole (RC) lowpass filter
}
void loop()
{
}
void serialEvent() { //Used when data is unavailable yet
if (Serial.available()) //checks the number of bytes available for reading from the serial port
{
data_read = Serial.read();
if (data_read == '0') {
Serial.print("#");
//Serial.print("10100");
analog_out = lowpassFilter.input( analogRead(0) );
Serial.print(analog_out + 10000);
Serial.print(":");
//Serial.print("20200");
analog_out = lowpassFilter.input( analogRead(1) );
Serial.print(analog_out + 20000);
Serial.print(":");
//Serial.print("30300");
analog_out = lowpassFilter.input( analogRead(2) );
Serial.print(analog_out + 30000);
Serial.print("p");
}
/*if(data_read == '0' || data_read == '1' || data_read == '2' || data_read == '3' || data_read == '4' || data_read == '5'){
analog_out = lowpassFilter.input( analogRead( data_read-48 ) );
Serial.print((analog_out)+(data_read-48)*10000);
Serial.print(":");
}else if(data_read =='p'){
Serial.print("p");
}*/
}
}
Here is my error message:
Arduino: 1.8.5 (Windows 10), Board: "Arduino Nano, ATmega328P"
C:\Users\daphn\Documents\Arduino\Analog_Serial_out\Analog_Serial_out.ino:4:129: fatal error: Filters.h: No such file or directory
#include <Filters.h> //implements digital filters which mimic the analog filter, keep track of variable statistics in realtime
^
compilation terminated.
exit status 1
Error compiling for board Arduino Nano.
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
-
1And where did you put the library?gre_gor– gre_gor2018年03月05日 18:39:13 +00:00Commented Mar 5, 2018 at 18:39
-
I've included the library in the same folder where I had saved my codeDaphFab– DaphFab2018年03月05日 18:39:50 +00:00Commented Mar 5, 2018 at 18:39
-
Have you read these 2 pages? gcc.gnu.org/onlinedocs/gcc-2.95.3/cpp_1.html#SEC6 , gcc.gnu.org/onlinedocs/cpp/Search-Path.htmlVE7JRO– VE7JRO2022年05月18日 15:47:55 +00:00Commented May 18, 2022 at 15:47
2 Answers 2
You have to put the folder with the library files in the folder libraries
under your sketchbook folder. Then the IDE should be able to find them.
I think there is also a possibility to save them in the same folder as your .ino
file, but it I don't know how exactly you have to do this.
-
I did try including the filters.h header file under the main libraries folder, but still I get the same error. I am wondering if there is any mistake with the source of the header file itself. Usually, when I include external libraries, I place it in the same folder as the code itself and it works.DaphFab– DaphFab2018年03月05日 19:08:59 +00:00Commented Mar 5, 2018 at 19:08
-
I tested it with your code and the linked library and it works for me. Check in the IDEs settings, to where the sketchbook folder is setchrisl– chrisl2018年03月05日 19:45:51 +00:00Commented Mar 5, 2018 at 19:45
-
The library is more than a .h file. You need ALL the files, and all placed in a folder named Filters within your libraries folder in your sketchbook. Nothing else will do.Majenko– Majenko2018年03月05日 20:29:17 +00:00Commented Mar 5, 2018 at 20:29
-
@Majenko What do you mean by ALL the files?DaphFab– DaphFab2018年03月05日 22:25:50 +00:00Commented Mar 5, 2018 at 22:25
-
1Ok got it. I had already done that before. Anyway, I solved the issue by changing
#include <Filters.h>
to#include "Filters.h"
DaphFab– DaphFab2018年03月05日 22:32:06 +00:00Commented Mar 5, 2018 at 22:32
Here is your definitive answer.
You have to do the #include like the following (with double-quotes, not < > brackets)
#include "Filters.h"
This will make Arduino compiler look in the project folder.
Using < > brackets tells the compiler that it is in the standard library area.
I just tested this with the following script.
#include "mytest.h"
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}
The mytest.h
file is blank (has no text in it).
It wouldn't work until I included it using the double-quotes method.