How to include multiple directories in arduino library - c++

I have my arduino libraries folder which holds one library called DHT_sensor_Library. In this folder, I have another folder called DHT_U. In this folder, I have DHT_U.ccp and DHT_U.h.
The problem is that when I include DHT_U.h in my arduino IDE:
#include "DHT_U.h"
The error says:
Tempreture_Humidity_Sensor:2:19: error: DHT_U.h: No such file or directory
compilation terminated.
exit status 1
DHT_U.h: No such file or directory
I have already tried
#include "DHT_U/DHT_U.h" ,
#include "DHT_U\DHT_U.h"
and
#include ..\DHT_U.h". None of these worked.
This is a snippet of my code:
#include "DHT.h"
#include "DHT_U.h"
#include "LiquidCrystal.h"
#include "DHT.h"
Full code can be shown here:
#include <DHT.h>
#include <DHT_U.h>
// include the library code:
#include <LiquidCrystal.h>
#include "DHT.h"
// set the DHT Pin
#define DHTPIN 8
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
dht.begin();
// Print a message to the LCD.
lcd.print("Temp: Humidity:");
}
void loop() {
delay(500);
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
// read humidity
float h = dht.readHumidity();
//read temperature in Fahrenheit
float f = dht.readTemperature(true);
if (isnan(h) || isnan(f)) {
lcd.print("ERROR");
return;
}
lcd.print(f);
lcd.setCursor(7,1);
lcd.print(h);
}
How should I fix this?

Try including the hole path like "/home/your_username/arduino/lib/foo.h" or something like this. Are you sure it is a .h file and not a .hpp ?

One thing to consider is that you need to be careful when your #include methods.
If DHT_U.h is located in the same direction as your .ino file you can include it with this:
#include "DHT_U.h"
However, if you installed the library using the library manager from Arduino IDE, you should do:
#include <DHT_U.h>
If none of these works, make sure that you have installed correctly your library. You could try by testing the examples from the Arduino IDE with the library that you have installed.

Related

Including the Geos library into a new Visual Studio project

It's been years since I used C++ and so I'm very rusty. I'm trying to test out the Geos library, but I'm unable to get a simple Hello World example to compile
https://libgeos.org/usage/download/
This is what I tried:
I downloaded and extracted the files
Created a new C++ project in Visual Studio
Added the headers folder into the Visual Studio Include Directories for the project.
Then I tried to use the library in my main.cpp:
#include <geos/geom/PrecisionModel.h>
#include <geos/geom/Polygon.h>
#include <geos/geom/LinearRing.h>
#include <geos/geom/CoordinateSequenceFactory.h>
#include <geos/geom/Geometry.h>
#include <geos/geom/GeometryFactory.h>
#include <iostream>
#include <memory>
geos::geom::Polygon * MakeBox(double xmin, double ymin, double xmax, double ymax) {
std::unique_ptr<geos::geom::PrecisionModel> pm(new geos::geom::PrecisionModel());
geos::geom::GeometryFactory::unique_ptr factory = geos::geom::GeometryFactory::create(pm.get(), -1);
geos::geom::CoordinateSequence* temp = factory->getCoordinateSequenceFactory()->create((std::size_t)0, 0);
temp->add(geos::geom::Coordinate(xmin, ymin));
temp->add(geos::geom::Coordinate(xmin, ymax));
temp->add(geos::geom::Coordinate(xmax, ymax));
temp->add(geos::geom::Coordinate(xmax, ymin));
//Must close the linear ring or we will get an error:
//"Points of LinearRing do not form a closed linestring"
temp->add(geos::geom::Coordinate(xmin, ymin));
geos::geom::LinearRing* shell = factory->createLinearRing(temp);
//NULL in this case could instead be a collection of one or more holes
//in the interior of the polygon
return factory->createPolygon(shell, NULL);
}
int main() {
geos::geom::Polygon* box = MakeBox(0, 0, 10, 10);
std::cout << box->getArea() << std::endl;
delete box; //Important to avoid memory leaks
}
I'm getting multiple errors, but they all seem to indicate that the library is not loaded correctly
Severity Code Description Project File Line Suppression State Error
(active) E0135 class "geos::geom::GeometryFactory" has no member
"unique_ptr" TestGeos C:\TestGeos\TestGeos.cpp 15
What am I missing in order to use the library?

Library using another library

I'm writing library for smart home arduino DIY project.
i want to use another library(not written by me).
here is the code:
boiler.cpp
#include "Boiler.h"
Boiler::Boiler(int pin)
{
_pin = pin;
dev.setDevice(_pin); // Set Device Output (on/off)
turnOff();
}
boiler.h
#ifndef BOILER_H_
#define BOILER_H_
// include RF24 libs
#include "RF24.h"
#include "RF24Network.h"
#include "RF24Mesh.h"
#include <SPI.h>
// SmartHome Lib Includes
#include "Device.h"
#include "TimerOne.h"
#include "timeSet.h"
class Boiler
{
private:
RF24 radio(7, 8);
RF24Network network(radio);
RF24Mesh mesh(radio, network);
int _pin ;
void timerIsr();
void DrawSCR();
public:
.
.
.
Boiler (int pin );
void turnOn();
void turnOff();
};
The problem is it's not compiling
the error I get is :
Boiler.h: 32:14: error: expected identifier before numeric constant
RF24 radio(7, 8)
What am i doing wrong?
Thanks,
I Have found the answer (by mistake)
i have added the includes to Boiler.cpp file
and moved the
RF24 radio(7, 8); // Init RF24 Radio
RF24Network network(radio); // Init RF24 Network
RF24Mesh mesh(radio, network); // Init RF24 Mesh
this is the new code :
#include "RF24.h"
#include "RF24Network.h"
#include "RF24Mesh.h"
#include <SPI.h>
.
.
.
#include "Boiler.h"
RF24 radio(7, 8); // Init RF24 Radio
RF24Network network(radio); // Init RF24 Network
RF24Mesh mesh(radio, network); // Init RF24 Mesh
Boiler::Boiler(int pin ,float Rev , String Last )
{
_pin = pin;
dev.setDevice(_pin); // Set Device Output (on/off)
turnOff();
}
void Boiler::init( char nodeID)
{
_nodeID = nodeID;
// Connect to the mesh and set Node ID
mesh.setNodeID(_nodeID);
if (_DEBUG) Serial.println(F("Connecting to the mesh..."));
mesh.begin();
// init LCD and print init data on LCD
myGLCD.InitLCD(60); // Init LCD 55 contrast
myGLCD.setFont(SmallFont); // Set small font
myGLCD.clrScr(); // clr screen
myGLCD.print("Boiler Device",0,0); //Print init Data on screen
myGLCD.print("Rev :" , 0 , 10);
myGLCD.printNumF(_rev,1 ,35,10,'.',1,'0');
myGLCD.print(_last,0,40);
myGLCD.update(); // Update display
turnOff();
}
and now it compiles ;-)

gcc compiler doesn't recognize my code for using Serial Port in Raspberry Pi 3

I'm compiling and running a C++/OpenCV program directly on the Raspberry Pi 3's Terminal with the line:
g++ pkg-config --cflags --libs opencv name.cpp -o name
I have been working like this without issues, but now I want to send some results like coordinates and numbers via serial port to Arduino, I tried to use this code:
#include <sstream>
#include <string>
#include <iostream>
#include <fstream>
#include <sys/time.h>
#include <termios.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <string.h>
#include <unistd.h>
#include <stdio.h>
//######################################################################
int fd = open("/dev/ttyAMS0", O_RDWR);
if (fd == -1) {
perror("/dev/ttyAMS0");
return 1;
}
struct termios tios;
tcgetattr(fd, &tios);
// disable flow control and all that, and ignore break and parity errors
tios.c_iflag = IGNBRK | IGNPAR;
tios.c_oflag = 0;
tios.c_lflag = 0;
cfsetspeed(&tios, B9600);
tcsetattr(fd, TCSAFLUSH, &tios);
// the serial port has a brief glitch once we turn it on which generates a
// start bit; sleep for 1ms to let it settle
usleep(1000);
// output to serial port
char msg[] = "hi there";
write(fd, msg, strlen(msg));
But now each time I try to compile I get the errors shown in the image Here:
So I guess I'm missing something, I have added all the libraries for the Serial Port as well but I don't know if I should add something on the line for compile as I did with the opencv libraries. Thanks in advance for your answers :)
I can't add comment so I will answer what I think about your problem.
Looks like your code written in global scope outer any function body.
You can't use if statement out of any function body.
Try to enclose your if statement in function body.
Something like this:
void chec(int fd) {
if (fd == -1) {
perror("/dev/ttyAMS0");
exit(1);
}
}
int fd = open("/dev/ttyAMS0", O_RDWR);
check(fd);

VS2015 Additional Include Directories not finding included header?

The question title says it all.
Here is the project settings for my addition include directories.
Here is my current program
#include <curses.h>
int main()
{
initscr(); /* Start curses mode */
printw("Hello World !!!"); /* Print Hello World */
refresh(); /* Print it on to the real screen */
getch(); /* Wait for user input */
endwin(); /* End curses mode */
return 0;
}
Here are the errors.
And the curses.h file is in the include folder
Anyone might have a clue as to where I went wrong?
Try to use #include "curses.h", instead of #include <curses.h>

reading linux inode bitmap

I'm going to fetch linux inode bitmaps with c++. I've use this code to fetch super block first:
#include <cstdlib>
#include <linux/ext2_fs.h>
#include <linux/fs.h>
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <fcntl.h>
#include <linux/fs.h>
using namespace std;
/*
*
*/
int main() {
int fd;
char boot[1024];
struct ext2_super_block super_block;
fd = open("/dev/sda1", O_RDONLY);
/* Reads the boot section and the superblock */
read(fd, boot, 1024);
read(fd, &super_block, sizeof (struct ext2_super_block));
/* Prints the Magic Number */
printf("%x\n", super_block.s_magic);
close(fd);
return 0;
}
but every time i run it , i get a error :
In file included from main.cpp:2:0:
/usr/include/linux/ext2_fs.h:181:18: error: ‘S_ISDIR’ was not declared in this scope
/usr/include/linux/ext2_fs.h:183:23: error: ‘S_ISREG’ was not declared in this scope
I couldn't find any good example or tutorial for this.is there anybody to help me?
EDIT :
I've include <linux/stat.h> but still get same error.
#grep -rw S_ISREG /usr/src/linux/include
/usr/src/linux/include/linux/fs.h: if (S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
/usr/src/linux/include/linux/fs.h.~1~: if (S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
/usr/src/linux/include/linux/stat.h:#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
So you should find stat.h in yours kernel source tree and include it.
The Linux source code "stat.h" is not the same file as that comes with the C-library. They just happen to have the same name. You will need to set your include path to find the correct stat.h (you may need BOTH, depending on what you are trying to do).