Compilation Error Connecting ADS1115 with ESP8266 - c++

I'm getting this fatal error:
util/delay.h: No such file or directory
when compiling the below sketch:
#include <Wire.h>
#include <Adafruit_ADS1115.h>
Adafruit_ADS1115 ads;
void setup(void)
{
Serial.begin(115200);
ads.setGain(GAIN_ONE);
ads.begin();
}
void loop(void)
{
int16_t adc0, adc1, adc2, adc3;
adc0 = ads.readADC_SingleEnded(0);
Serial.print("AIN0: ");
Serial.println(adc0);
delay(1000);
}
I tried including "Arduino.h" as suggested by friends, but no use. While if I compile with "Adafruit_ADS1x15.h" instead of the above, it do upload but the ADC is not giving values.
Could anybody assist me?

Related

Problem with "No matching constructor for initialization of 'LM35' in "main.cpp", Line: 16, Col: 27"

I'm a student, learning about MBEDs. I'm using Nucleo board and the MBED online compiler.
Here's my code:
LM35.h
#ifndef MBED_LM35
#define MBED_LM35
#include "mbed.h"
class LM35
{
public:
LM35(PinName pin);
void mjerenje();
private:
AnalogIn _pin;
};
#endif
LM35.cpp
#include "LM35.h"
#include "mbed.h"
LM35::LM35(PinName pin) : _pin(pin) {}
float temperatura;
void LM35::mjerenje()
{
Serial pc(USBTX, USBRX);
temperatura = _pin.read();
temperatura = (temperatura*5000)/10;
pc.printf("Temperatura je %.2f stupnjeva Celzijevih.\n \r", temperatura);
return temperatura;
}
and here's Main.cpp
#include "mbed.h"
#include "LM35.h"
DigitalOut led1(PC_12);
Serial pc(USBTX, USBRX);
LM35 senzor(PC_0);
int main()
{
senzor.mjerenje();
float temperatura2 = LM35();
pc.printf("%f", temperatura2);
}
I'm having trouble with getting temperatura out of library and using it in main.cpp.
I get following error: Error: No matching constructor for initialization of 'LM35' in "main.cpp", Line: 16, Col: 27
Can someone help me?
in LM35.cpp
void LM35::mjerenje()
return a float value, should be -->
float LM35::mjerenje()
in the main.cpp
float temperatura2;
temperatura2 = senzor.mjerenje();

Can't compile arduino code based on SinricPro libraries

I'm trying to compile my code based on SinricPro but I'm getting a huge error.
Libraries:
Wifi - 1.2.7
ArduinoJson - 6.12.0
SinricPro - 2.4.0
WebSockets - 2.2.0
Arduino board:
Node MCU with ESP8266MOD
The error:
Arduino: 1.8.13 (Windows Store 1.8.39.0) (Windows 10), Board: "NodeMCU 0.9 (ESP-12 Module), 80 MHz, 115200, 4M (3M SPIFFS)"
In file included from C:\Users\amng8\Documents\ArduinoProjects\Sinric\Sinric.ino:13:0:
C:\Users\amng8\Documents\Arduino\libraries\SinricPro\src/SinricPro.h:122:5: error: 'vector' in namespace 'std' does not name a type
std::vector<SinricProDeviceInterface*> devices;
^
C:\Users\amng8\Documents\Arduino\libraries\SinricPro\src/SinricPro.h: In member function 'SinricProDeviceInterface* SinricProClass::getDevice(String)':
C:\Users\amng8\Documents\Arduino\libraries\SinricPro\src/SinricPro.h:139:23: error: 'devices' was not declared in this scope
for (auto& device : devices) {
^
In file included from C:\Users\amng8\Documents\ArduinoProjects\Sinric\Sinric.ino:13:0:
C:\Users\amng8\Documents\Arduino\libraries\SinricPro\src/SinricPro.h: In member function 'DeviceType& SinricProClass::add(const char*, long unsigned int)':
C:\Users\amng8\Documents\Arduino\libraries\SinricPro\src/SinricPro.h:211:3: error: 'devices' was not declared in this scope
devices.push_back(newDevice);
^
C:\Users\amng8\Documents\Arduino\libraries\SinricPro\src/SinricPro.h: In member function 'void SinricProClass::add(SinricProDeviceInterface*)':
C:\Users\amng8\Documents\Arduino\libraries\SinricPro\src/SinricPro.h:219:3: error: 'devices' was not declared in this scope
devices.push_back(newDevice);
^
C:\Users\amng8\Documents\Arduino\libraries\SinricPro\src/SinricPro.h: In member function 'void SinricProClass::add(SinricProDeviceInterface&)':
C:\Users\amng8\Documents\Arduino\libraries\SinricPro\src/SinricPro.h:226:3: error: 'devices' was not declared in this scope
devices.push_back(&newDevice);
^
C:\Users\amng8\Documents\Arduino\libraries\SinricPro\src/SinricPro.h: In member function 'void SinricProClass::handleRequest(ArduinoJson6120_000001::DynamicJsonDocument&, interface_t)':
C:\Users\amng8\Documents\Arduino\libraries\SinricPro\src/SinricPro.h:305:23: error: 'devices' was not declared in this scope
for (auto& device : devices) {
^
C:\Users\amng8\Documents\Arduino\libraries\SinricPro\src/SinricPro.h: In member function 'void SinricProClass::connect()':
C:\Users\amng8\Documents\Arduino\libraries\SinricPro\src/SinricPro.h:391:23: error: 'devices' was not declared in this scope
for (auto& device : devices) {
^
exit status 1
Error compiling for board NodeMCU 0.9 (ESP-12 Module).
My code:
// Uncomment the following line to enable serial debug output
#define ENABLE_DEBUG
#ifdef ENABLE_DEBUG
#define DEBUG_ESP_PORT Serial
#define NODEBUG_WEBSOCKETS
#define NDEBUG
#endif
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include "SinricPro.h"
#include "SinricProGarageDoor.h"
#include "SinricProSwitch.h"
#define WIFI_SSID "DUMMY"
#define WIFI_PASS "DUMMY"
#define APP_KEY "DUMMY"
#define APP_SECRET "DUMMY"
#define GARAGEDOOR_ID "DUMMY"
#define SWITCH_LIGHTS_ID "DUMMY"
#define BAUD_RATE 9600
#define STATUS_LED D0
#define RELAY_1 D4
#define RELAY_2 D1
#define RELAY_3 D2
#define RELAY_4 D3
bool myPowerState = false;
bool onDoorState(const String& deviceId, bool &doorState) {
digitalWrite(RELAY_1, LOW);
delay(500);
digitalWrite(RELAY_1, HIGH);
Serial.printf("Garagedoor is %s now.\r\n", doorState?"closed":"open");
return true;
}
bool onPowerState(const String &deviceId, bool &state) {
Serial.printf("Device %s turned %s (via SinricPro) \r\n", deviceId.c_str(), state?"on":"off");
myPowerState = state;
digitalWrite(RELAY_2, myPowerState?HIGH:LOW);
return true; // request handled properly
}
void setupWiFi() {
Serial.printf("\r\n[Wifi]: Connecting");
WiFi.begin(WIFI_SSID, WIFI_PASS);
while (WiFi.status() != WL_CONNECTED) {
Serial.printf(".");
digitalWrite(STATUS_LED, HIGH);
delay(500);
digitalWrite(STATUS_LED, LOW);
delay(500);
}
IPAddress localIP = WiFi.localIP();
Serial.printf("connected!\r\n[WiFi]: IP-Address is %d.%d.%d.%d\r\n", localIP[0], localIP[1], localIP[2], localIP[3]);
digitalWrite(STATUS_LED, HIGH);
}
void setupSinricPro() {
SinricProGarageDoor &myGarageDoor = SinricPro[GARAGEDOOR_ID];
myGarageDoor.onDoorState(onDoorState);
SinricProSwitch &mySwitch = SinricPro[SWITCH_LIGHTS_ID];
mySwitch.onPowerState(onPowerState);
// setup SinricPro
SinricPro.onConnected([](){ Serial.printf("Connected to SinricPro\r\n"); });
SinricPro.onDisconnected([](){ Serial.printf("Disconnected from SinricPro\r\n"); });
SinricPro.begin(APP_KEY, APP_SECRET);
}
void setup() {
pinMode(STATUS_LED, OUTPUT);
pinMode(RELAY_1, OUTPUT);
pinMode(RELAY_2, OUTPUT);
pinMode(RELAY_3, OUTPUT);
pinMode(RELAY_4, OUTPUT);
digitalWrite(STATUS_LED, LOW);
digitalWrite(RELAY_1, HIGH);
digitalWrite(RELAY_2, HIGH);
digitalWrite(RELAY_3, HIGH);
digitalWrite(RELAY_4, HIGH);
Serial.begin(BAUD_RATE); Serial.printf("\r\n\r\n");
setupWiFi();
setupSinricPro();
}
void loop() {
SinricPro.handle();
}
This error seems something from the SinricPro libraries and I can't seem to understand why is this error occurring.
GitHub issue

How to handle compile errors thrown from M5Stack libraries in Arduino

I'm currently trying to program my M5Stack with an ESP32 chip in it. I downloaded (or atleast I thought) all of the dependencies needed to upload to the board, but I can't even get my program to compile. I downloaded the ESP32 throught the board manager, I followed the M5Stack tutorial on their website and seem to be finding errors in thheir library itself. I'm not sure how to fix, below is my code and below that are the error messages im getting.
#include <M5Stack.h>
#include <Wire.h>
#define SPEAKER_PIN 25
#include "config.h"
AdafruitIO_Feed *voltage1 = io.feed("V1");
AdafruitIO_Feed *voltage2 = io.feed("V2");
AdafruitIO_Feed *curr = io.feed("Current");
void setup() {
// put your setup code here, to run once:
M5.begin(true, true, true, false);
Serial.begin(115200);
dacWrite(25,0);
M5.Lcd.fillScreen(BLACK);
M5.Lcd.setTextSize(5);
// wait for serial monitor to open
while(! Serial);
Serial.print("Connecting to Adafruit IO");
// connect to io.adafruit.com
io.connect();
// wait for a connection
while(io.status() < AIO_CONNECTED) {
Serial.print(".");
delay(500);
}
// we are connected
Serial.println();
Serial.println(io.statusText());
// ads.getAddr_ADS1100(ADS1100_DEFAULT_ADDRESS);
// ads.setGain(GAIN_ONE);
// ads.setMode(MODE_CONTIN);
// ads.setRate(RATE_32);
// ads.setOSMode(OSMODE_SINGLE);
// ads.begin();
}
void loop() {
io.run();
// put your main code here, to run repeatedly:
float v1 = (float)analogRead(36) / 4096 * 17.4 * 0.975;
float v2 = (float)analogRead(35) / 4096 * 17.4 * 0.975;
float current = (float)analogRead(5);
Serial.print("v1: ");
Serial.print(v1);
Serial.println("V");
Serial.print("v2: ");
Serial.print(v2);
Serial.println("V");
M5.Lcd.setTextColor(WHITE);
M5.Lcd.setCursor(10, 10);
M5.Lcd.print("V1: ");
M5.Lcd.print(v1);
M5.Lcd.print("V");
M5.Lcd.setTextColor(WHITE);
M5.Lcd.setCursor(10, 70);
M5.Lcd.print("V2: ");
M5.Lcd.print(v2);
M5.Lcd.print("V");
M5.Lcd.setTextColor(WHITE);
M5.Lcd.setCursor(10, 140);
M5.Lcd.print("Current: ");
M5.Lcd.print(current);
M5.Lcd.print("A");
delay(500);
M5.Lcd.setCursor(10, 10);
M5.Lcd.setTextColor(BLACK);
M5.Lcd.print("V1: ");
M5.Lcd.print(v1);
M5.Lcd.print("V");
M5.Lcd.setCursor(10, 70);
M5.Lcd.setTextColor(BLACK);
M5.Lcd.print("V2: ");
M5.Lcd.print(v2);
M5.Lcd.print("V");
M5.Lcd.setTextColor(BLACK);
M5.Lcd.setCursor(10, 140);
M5.Lcd.print("Current: ");
M5.Lcd.print(current);
M5.Lcd.print("A");
Serial.print("sending v1-> ");
Serial.println(v1);
voltage1->save(v1);
Serial.print("sending v2-> ");
Serial.println(v2);
voltage2->save(v2);
Serial.print("sending Current-> ");
Serial.println(current);
curr->save(current);
}
Error output:
Arduino: 1.8.12 (Windows 10), Board: "M5Stack-Core-ESP32, QIO, 80MHz, Default, 921600, None"
C:\Users\graff\OneDrive\Documents\Arduino\libraries\M5Stack\src\M5Display.cpp: In member function 'void M5Display::drawPngUrl(const char*, uint16_t, uint16_t, uint16_t, uint16_t, uint16_t, uint16_t, double, uint8_t)':
C:\Users\graff\OneDrive\Documents\Arduino\libraries\M5Stack\src\M5Display.cpp:543:3: error: 'HTTPClient' was not declared in this scope
HTTPClient http;
^
C:\Users\graff\OneDrive\Documents\Arduino\libraries\M5Stack\src\M5Display.cpp:545:7: error: 'WiFi' was not declared in this scope
if (WiFi.status() != WL_CONNECTED) {
^
C:\Users\graff\OneDrive\Documents\Arduino\libraries\M5Stack\src\M5Display.cpp:545:24: error: 'WL_CONNECTED' was not declared in this scope
if (WiFi.status() != WL_CONNECTED) {
^
C:\Users\graff\OneDrive\Documents\Arduino\libraries\M5Stack\src\M5Display.cpp:550:3: error: 'http' was not declared in this scope
http.begin(url);
^
C:\Users\graff\OneDrive\Documents\Arduino\libraries\M5Stack\src\M5Display.cpp:553:19: error: 'HTTP_CODE_OK' was not declared in this scope
if (httpCode != HTTP_CODE_OK) {
^
C:\Users\graff\OneDrive\Documents\Arduino\libraries\M5Stack\src\M5Display.cpp:559:3: error: 'WiFiClient' was not declared in this scope
WiFiClient *stream = http.getStreamPtr();
^
C:\Users\graff\OneDrive\Documents\Arduino\libraries\M5Stack\src\M5Display.cpp:559:15: error: 'stream' was not declared in this scope
WiFiClient *stream = http.getStreamPtr();
^
Multiple libraries were found for "WiFi.h"
Used: C:\Users\graff\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries\WiFi
Not used: C:\Program Files (x86)\Arduino\libraries\WiFi
Not used: C:\Users\graff\OneDrive\Documents\Arduino\libraries\WiFi
Multiple libraries were found for "SD.h"
Used: C:\Users\graff\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries\SD
Not used: C:\Program Files (x86)\Arduino\libraries\SD
Not used: C:\Users\graff\OneDrive\Documents\Arduino\libraries\SD
exit status 1
Error compiling for board M5Stack-Core-ESP32.
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
First of all you should do what your compiler wants:
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
This gives more details and if the solution is not working edit your question and replace the compiler output with the detailed Info.Include the missinglibs manually in your program
#include <WiFi.h>
#include <SD.h>
#include <M5Stack.h>
#include <Wire.h>
and checkthe dependencies you have in
#include "config.h"
as I could not compile due to missing file

How to include multiple directories in arduino library

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.

FirebaseArduino.h:20:18: fatal error: string: No such file or directory (Arduino)

I'm developing a project using FirebaseArduino library (Realtime database) on my Arduino Uno WiFi Rev2. When I ran my code, I got a mistake as following:
#include FirebaseArduino.h
#include WiFiNINA.h
Error message:
C:\Users\Documents\Arduino\libraries\firebase-arduino-USER\master\src/FirebaseArduino.h:20:18:
fatal error: string: No such file or directory
//FirebaseArduino.h lines 17 - 23
#ifndef FIREBASE_ARDUINO_H
#define FIREBASE_ARDUINO_H
#include <string> // Error
#include "Firebase.h"
#include "FirebaseObject.h"
// my code
#include <WiFiNINA.h>
#include <FirebaseArduino.h>
#define WIFI_SSID "SSID"
#define WIFI_PASSWORD "PWD"
#define FIREBASE_HOST "****"
#define FIREBASE_AUTH "****"
void setup() {
//conect wifi
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
while (WiFi.status() != WL_CONNECTED)
{
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Firebase.begin(FIREBASE_HOST, FAREBASE_AUTH);
}
String firebaseGet(String s)
{
String x = Firebase.getString(s);
yield();
delay(100);
return x;
delay(100);
}
void loop() {
String firebaseStatus = firebaseGet("****");
if (firebaseStatus == "ON")
{
//code to happen if the status is ON
}
else if (firebaseResult == "OFF")
{
//code to happen if the status is OFF
}
}
I found some possible problems:
1 - Arduino IDE version INCOMPATIBLE -- Tried to use 1.8.5, 1.6.12 and failed;
1.6.9 doesn't have INCOMPATIBLE problem. But it still cannot run.
2 - Should install old library of firebase -- still cannot run