Closed FStefanni closed 2 years ago
Thanks
What error message do you get and which ESP32 library version do you use. I can then try to create a workaround and test it.
Regards, Paul
Verzonden vanuit Mailhttps://go.microsoft.com/fwlink/?LinkId=550986 voor Windows
Van: Francesco @.> Verzonden: vrijdag 12 augustus 2022 17:01 Aan: @.> CC: @.***> Onderwerp: [paulvha/svm30] printf (Issue #2)
Hi,
the header printf.h of this libraries yelds to compiling errors with some newer version of ESP32, if none of its functions are used (basically, a warning which is used as error by default compiler configuration).
So I suggest to remove its inclusion from svm30.h, and include it explicitly only where it is truly needed.
Regards
— Reply to this email directly, view it on GitHubhttps://nam12.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fpaulvha%2Fsvm30%2Fissues%2F2&data=05%7C01%7C%7C2ac099fd29c84eb98aa108da7c73879e%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637959132878250765%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=5EdBcZVzaIf1CC2x7JLRajZFIoTpnLS5eb2EKX%2FOxiQ%3D&reserved=0, or unsubscribehttps://nam12.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAD2GBPGEKZGXPUXIWK4P2M3VYZRMNANCNFSM56L64XDQ&data=05%7C01%7C%7C2ac099fd29c84eb98aa108da7c73879e%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637959132878250765%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=aDk5FhmkfwxYxmHA6lsSyesx2NsqSeeqbS%2FqpfOFWWA%3D&reserved=0. You are receiving this because you are subscribed to this thread.Message ID: @.***>
Hi,
I use:
The warning is about unused variables (_pf_buffer_
), which is a warning treated as error.
Just to be able to compile, I simply removed the printf.h
header inclusion.
Regards
hi Francesco,
I had upgraded to Ubuntu version 22.00 and had to recover a large number of issues. So finally today I downloaded the ESP 2.0.4 , NOT the development version, selected the ESP32 Wrover module, and compiled the example1 from the version as it is. No error message, no warnings. I am using Arduino IDE 1.8.16.
Is there something else that you might have changed ?
regards, Paul
Creating esp32 image... Merged 2 ELF sections Successfully created esp32 image. python3 /home/paul/.arduino15/packages/esp32/hardware/esp32/2.0.4/tools/gen_esp32part.py -q /tmp/arduino_build_592772/partitions.csv /tmp/arduino_build_592772/example1_svm30_basic.ino.partitions.bin Using library svm30 at version 1.3.0 in folder: /home/paul/Arduino/libraries/svm30 Using library Wire at version 2.0.0 in folder: /home/paul/.arduino15/packages/esp32/hardware/esp32/2.0.4/libraries/Wire /home/paul/.arduino15/packages/esp32/tools/xtensa-esp32-elf-gcc/gcc8_4_0-esp-2021r2-patch3/bin/xtensa-esp32-elf-size -A /tmp/arduino_build_592772/example1_svm30_basic.ino.elf Sketch uses 285601 bytes (21%) of program storage space. Maximum is 1310720 bytes. Global variables use 17436 bytes (5%) of dynamic memory, leaving 310244 bytes for local variables. Maximum is 327680 bytes.
Hi,
yes, I add a bunch of warning flags (so they should only raise warnings, not compile errors). Please remember to comment the printf usages, otherwise the bug will not show.
To compile, I use arduino-cli
(here a script for your convenience, with the flags I use):
#!/usr/bin/env bash
arduino-cli compile \
-v --warnings all \
--build-property "compiler.cpp.extra_flags=-std=gnu++17 -Wall -Wextra -Werror=switch -Werror=return-type" \
-b esp32:esp32:esp32wrover \
example1_svm30_basic.ino
# EOF
Here the sketch, with printf
commented out:
/* example1 how to read information from SVM30
*
* By: paulvha@hotmail.com
* Date: September 20, 2019
* Version : 1.0
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*
* connected to MEGA2560
*
* SVM30 MEGA2560
* 1. SDL ----------- SDL
* 2. GND ----------- GND
* 3. VCC ----------- +5V
* 4. SDA ----------- SDA
*
* connected to UNO
*
* SVM30 UNO
* 1. SDL ----------- A5
* 2. GND ----------- GND
* 3. VCC ----------- +5V
* 4. SDA ----------- A4
*
*
* Sparkfun ESP32 thing
******************************************************************************************
* WARNING: THE SVM30 NEEDS BETWEEN 4.5V AND 5.5V (TYPICAL 5V). RUNNING ON 3v3 MAKES IT UNSTABLE.
* The SVM30 seems to have on-board pull-up resistors to +5V
* THE ESP32 PINS CAN HANDLE UP TO 3v3 ONLY AND AS SUCH YOU USE A BI-DIRECTIONAL LEVEL CONVERTER.
* e.g. https://www.sparkfun.com/products/12009
*****************************************************************************************
* SVM30 ESP32
* 1. SDL ----lll----- SCL (pin 22)
* 2. GND ----------- GND
* 3. VCC ----------- +5V/VUSB
* 4. SDA ----lll----- SDA (pin 21)
*
* Sparkfun ESP32
*
* Make sure :
* - use the VUSB pin to connect to the level converter (HV) and VCC of the SVM30
* - use the 3V3 pin to connect to the level converter (LV)
* - Select the Sparkfun ESP32 thing board before compiling
* - connect GND, SDA, SCL lines to the level converter and SVM30
* - The serial monitor is NOT active (will cause upload errors)
* - Press GPIO 0 switch during connecting after compile to start upload to the board
* - Press reset on the ESP32 thing after the sketch is loaded
*
*
* connected to ESP8266
******************************************************************************************
* WARNING: THE SVM30 NEEDS BETWEEN 4.5V AND 5.5V (TYPICAL 5V). RUNNING ON 3v3 MAKES IT UNSTABLE.
* THE ESP8266 PINS CAN HANDLE UP TO 3v3 ONLY AND AS SUCH YOU USE A BI-DIRECTIONAL LEVEL CONVERTER.
* e.g. https://www.sparkfun.com/products/12009
*****************************************************************************************
* SVM30 ESP8266
* 1. SDL ----lll---- SDL
* 2. GND ----------- GND
* 3. VCC ----------- VIN
* 4. SDA ----lll---- SDA
*
* Sparkfun ESP8266 thing
*
* Make sure :
* - connect with USB/Serial converter to serial connector for communication with PC (set to provide 3V3)
* - connect an EXTRA USB cable to the USB connector for providing 5V
* - use the VIN pin to connect to the level converter (HV) and VCC of the SVM30
* - use the 3V3 pin to connect to the level converter (LV)
* - connect GND, SDA, SCL lines to the level converter and SVM30
* - Select the Sparkfun ESP8266 thing board before compiling
* - The serial monitor is NOT active (will cause upload errors)
* - close the on-board DTR link during connecting after compile to start upload to the board
*/
/////////////////////////////////////////////////////////////
/* define driver debug
* false : no messages
* true : display driver debug messages
*//////////////////////////////////////////////////////////////
#define DEBUG false
/////////////////////////////////////////////////////////////
/* define number of seconds between display results
*
*//////////////////////////////////////////////////////////////
#define DELAY 10
///////////////////////////////////////////////////////////////
/////////// NO CHANGES BEYOND THIS POINT NEEDED ///////////////
///////////////////////////////////////////////////////////////
// function prototypes (sometimes the pre-processor does not create prototypes themself on ESPxx)
void read_id();
void read_featureSet();
void Errorloop(char *mess);
void read_values();
void read_baseline();
void KeepTrigger(uint8_t del);
#include <svm30.h>
// create instance
SVM30 svm;
void setup() {
Serial.begin(115200);
Serial.println(F("Hi there, this is example 1.\nReading information from the SVM30"));
// enable debug messages
svm.EnableDebugging(DEBUG);
svm.begin();
Serial.print(F("Driver version : "));
Serial.println(svm.GetDriverVersion());
// try to detect SVM30 sensors
if (svm.probe() == false) Errorloop((char *) "could not detect SVM30 sensors");
else Serial.println(F("SVM30 detected"));
// read and display the ID
read_id();
// read SGP30 feature set
read_featureSet();
}
void loop() {
// read measurement values
read_values();
// read SGP30 baseline
read_baseline();
// wait x seconds
KeepTrigger(DELAY);
}
/*
* @brief : keep triggering SGP30 while waiting
*
* @param del : number of seconds to wait
*
* source datasheet SVM30:
* The on-chip baseline compensation algorithm has been optimized
* for 1HZ sampling rate. The sensor shows best performance when
* used with this sampling rate.
*
*/
void KeepTrigger(uint8_t del)
{
uint8_t w_seconds = del;
unsigned long startMillis;
if (w_seconds == 0) w_seconds = 1;
while (w_seconds--)
{
startMillis = millis();
if (! svm.TriggerSGP30())
Errorloop((char *) "Error during trigger waiting");
// this gives 1Hz /1000ms (aboutisch)
while(millis() - startMillis < 1000);
}
}
/*
* @brief : read and display the values from the SVM30
*
*/
void read_values() {
struct svm_values v;
if (! svm.GetValues(&v))
Errorloop((char *) "Error during reading values");
Serial.print(F("CO2 equivalent : "));
Serial.print(v.CO2eq);
Serial.print(F(", TVOC : "));
Serial.print(v.TVOC);
Serial.print(F(", H2_signal : "));
Serial.print(v.H2_signal);
Serial.print(F(", Ethanol_signal : "));
Serial.print(v.Ethanol_signal);
Serial.print(F(", Humidity : "));
Serial.print((float) v.humidity/1000);
Serial.print(F(", temperature : "));
Serial.print((float) v.temperature/1000);
Serial.print(F(", absolute humidity : "));
Serial.print(v.absolute_hum);
}
/*
* @brief: read and display the id of the SGP30 and SHTC1 sensors
*/
void read_id() {
uint16_t buf[3]; // SGP30 needs 3 words, SHTC1 is 1 word
char id[15];
if ( ! svm.GetId(SGP30, buf))
Errorloop((char *) "could not read SGP30 id");
Serial.print(F("\nSGP30 id : "));
//sprintf(id, "%04x %04x %04x", buf[0], buf[1], buf[2]);
Serial.println(id);
if (svm.GetId(SHTC1, buf) == false)
Errorloop((char *) "could not read SHTC1 id");
Serial.print(F("SHTC1 id : "));
// only bit 5:0 matter (source: datasheet)
//sprintf(id, "%04x", buf[0] & 0x3f);
Serial.println(id);
}
/*
* @brief: read and display the product feature set of the SGP30 sensor
*/
void read_featureSet(){
char buf[2];
if ( ! svm.GetFeatureSet(buf))
Errorloop((char *) "could not read SGP30 feature set");
Serial.print(F("\nSGP30 product type : "));
Serial.print((buf[0] & 0xf0), HEX);
Serial.print(F(", Product version : "));
Serial.println(buf[1], HEX);
Serial.println();
}
/*
* @brief: read the baselines of the SGP30 sensor
* see example3 for extended information about baselines
*/
void read_baseline(){
uint16_t baseline;
if (! svm.GetBaseLine_CO2(&baseline))
Errorloop((char *) "could not read SGP30 CO2 baseline");
Serial.print(F(" CO2 equivalent baseline : 0x"));
Serial.print(baseline, HEX);
if (! svm.GetBaseLine_TVOC(&baseline))
Errorloop((char *) "could not read SGP30 TVOC baseline");
Serial.print(F(", TVOC baseline : 0x"));
Serial.println(baseline, HEX);
}
/**
* @brief : continued loop after fatal error
* @param mess : message to display
*/
void Errorloop(char *mess)
{
Serial.println(mess);
Serial.println(F("Program on hold"));
for(;;) delay(100000);
}
Here the output error:
In file included from ~/Arduino/libraries/svm30/src/svm30.h:63,
from /tmp/example1_svm30_basic/example1_svm30_basic.ino:119:
~/Arduino/libraries/svm30/src/printf.h:34:13: error: '_pf_buffer_' defined but not used [-Werror=unused-variable]
static char _pf_buffer_[_PRINTF_BUFFER_LENGTH_];
^~~~~~~~~~~
cc1plus: some warnings being treated as errors
Regards
the issue is fixed now in version 1.3.1. I added -Werror=all to the compiler options and got the same error. As the ESP32 library already has printf routines it is using those instead of the ones in printf.h. I have changed the printf.h file to include a check on ESP32.
regards, Paul
Hi,
I confirm that it now compiles under esp32, thank you.
Regards
Thanks.
I now better understand. As you say apparently the compiler option has been set for “ a warning to be treated as error”
I’ll have a look in the coming days.
Thanks again for the heads-up
Regards, Paul
Verzonden vanuit Mailhttps://go.microsoft.com/fwlink/?LinkId=550986 voor Windows
Van: Francesco @.> Verzonden: vrijdag 12 augustus 2022 17:41 Aan: @.> CC: @.>; @.> Onderwerp: Re: [paulvha/svm30] printf (Issue #2)
Hi,
I use:
The warning is about unused variables (_pfbuffer), which is a warning treated as error. Just to be able to compile, I simply removed the printf.h header inclusion.
Regards
— Reply to this email directly, view it on GitHubhttps://nam12.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fpaulvha%2Fsvm30%2Fissues%2F2%23issuecomment-1213249468&data=05%7C01%7C%7Cac32251acf3247b7260708da7c791ebb%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637959156886618635%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=TjVrAAAWGI2ClmGq%2BPHgVEa21xn7SG%2FcA6jGlSKwvdo%3D&reserved=0, or unsubscribehttps://nam12.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAD2GBPEQC7CQMK67IRUESCLVYZWCHANCNFSM56L64XDQ&data=05%7C01%7C%7Cac32251acf3247b7260708da7c791ebb%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637959156886618635%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=BEe%2F2vRDi0kJ3g9%2F3Q4nf5huRlFcoJnUsZU8c18N7ww%3D&reserved=0. You are receiving this because you commented.Message ID: @.***>
Hi,
the header
printf.h
of this libraries yelds to compiling errors with some newer version of ESP32, if none of its functions are used (basically, a warning which is used as error by default compiler configuration).So I suggest to remove its inclusion from
svm30.h
, and include it explicitly only where it is truly needed.Regards