##困っていること
Arduino IDE (Windows10 PC)にて,ESP32に書き込むプログラムのコンパイルをしています.
プログラムと,ヘッダーファイルを末尾に添付します.
このプログラムをコンパイルすると,次のエラーが出てきてしまいます.
原因が分からずこまっています.
text
1sketch\Test3.ino.cpp.o:(.literal._Z5setupv+0x14): undefined reference to `ESP32_BME280_I2C::ESP32_BME280_I2C_Init(unsigned char, unsigned char, unsigned char, unsigned char, unsigned char, unsigned char)' 2 3sketch\Test3.ino.cpp.o:(.literal.startup._GLOBAL__sub_I_bme280i2c+0x8): undefined reference to `ESP32_BME280_I2C::ESP32_BME280_I2C(unsigned char, unsigned char, unsigned char, unsigned int)' 4 5sketch\Test3.ino.cpp.o:(.literal._Z7bme_getv+0x1c): undefined reference to `ESP32_BME280_I2C::Read_All(double*, double*, double*)' 6 7sketch\Test3.ino.cpp.o: In function `setup()': 8 9C:\Users\PLC\Documents\Arduino\Program\Test3\Test3/Test3.ino:48: undefined reference to `ESP32_BME280_I2C::ESP32_BME280_I2C_Init(unsigned char, unsigned char, unsigned char, unsigned char, unsigned char, unsigned char)' 10 11sketch\Test3.ino.cpp.o: In function `_GLOBAL__sub_I_bme280i2c': 12 13C:\Users\PLC\Documents\Arduino\Program\Test3\Test3/Test3.ino:48: undefined reference to `ESP32_BME280_I2C::ESP32_BME280_I2C(unsigned char, unsigned char, unsigned char, unsigned int)' 14 15sketch\Test3.ino.cpp.o: In function `bme_get()': 16 17C:\Users\PLC\Documents\Arduino\Program\Test3\Test3/Test3.ino:35: undefined reference to `ESP32_BME280_I2C::Read_All(double*, double*, double*)' 18 19collect2.exe: error: ld returned 1 exit status 20 21exit status 1 22 23ボードESP32 Dev Moduleに対するコンパイル時にエラーが発生しました。 24
##プログラム
c++
1#include "ESP32_BME280_I2C.h" 2 3const uint8_t Address = 0x76; 4const uint8_t sda = 12; 5const uint8_t scl = 14; 6const uint32_t frequency = 30000; 7 8ESP32_BME280_I2C bme280i2c(Address, scl, sda, frequency); 9 10void setup(){ 11 Serial.begin(115200); 12 delay(1000); //Take some time to open up the Serial Monitor 13 14 //Example Indoor navigation 15 uint8_t t_sb = 0; //stanby 0.5ms 16 uint8_t filter = 4; //IIR filter = 16 17 uint8_t osrs_t = 2; //OverSampling Temperature x2 18 uint8_t osrs_p = 5; //OverSampling Pressure x16 19 uint8_t osrs_h = 1; //OverSampling Humidity x1 20 uint8_t Mode = 3; //Normal mode 21 22 bme280i2c.ESP32_BME280_I2C_Init(t_sb, filter, osrs_t, osrs_p, osrs_h, Mode); 23 delay(1000); 24} 25 26void loop(){ 27 bme_get(); 28 delay(5000); 29} 30 31//************** BME280 measure ************************* 32void bme_get(){ 33 double temperature, pressure, humidity; 34 35 bme280i2c.Read_All(&temperature, &pressure, &humidity); 36 37 char temp_c[10], hum_c[10], pres_c[10]; 38 sprintf(temp_c, "%2.2lf", temperature); 39 sprintf(hum_c, "%2.2lf", humidity); 40 sprintf(pres_c, "%4.2lf", pressure); 41 42 Serial.println("-----------------------"); 43 Serial.print("Temperature = "); Serial.println(temp_c); 44 Serial.print("Humidity = "); Serial.println(hum_c); 45 Serial.print("Pressure = "); Serial.println(pres_c); 46 Serial.println("-----------------------"); 47 Serial.flush(); 48}
##Header
c++
1/* 2 ESP32_BME280_I2C.h - for Arduino core for ESP32 3 Beta version 1.2 4 5License MIT [Modified person is Mgo-tec.] 6Reference SWITCH SCIENCE page URL: 7http://trac.switch-science.com/wiki/BME280 8Reference library: 9https://github.com/adafruit/Adafruit_BME280_Library 10Original License is BSD [Copyright (c) 2012, Adafruit Industries] 11BSD License: 12Redistribution and use in source and binary forms, with or without 13modification, are permitted provided that the following conditions are met: 141. Redistributions of source code must retain the above copyright 15notice, this list of conditions and the following disclaimer. 162. Redistributions in binary form must reproduce the above copyright 17notice, this list of conditions and the following disclaimer in the 18documentation and/or other materials provided with the distribution. 193. Neither the name of the copyright holders nor the 20names of its contributors may be used to endorse or promote products 21derived from this software without specific prior written permission. 22THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY 23EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY 26DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 29ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32*/ 33 34#ifndef ESP32_BME280_I2C_h_ 35#define ESP32_BME280_I2C_h_ 36 37#include "Arduino.h" 38#include "Wire.h" 39 40class ESP32_BME280_I2C 41{ 42public: 43 ESP32_BME280_I2C(uint8_t bme280_address, uint8_t scl, uint8_t sda, uint32_t freq); 44 45 void ESP32_BME280_I2C_Init(uint8_t Stanby_t, uint8_t filter, uint8_t overS_T, uint8_t overS_P, uint8_t overS_H, uint8_t mode); 46 void WriteRegister(uint8_t reg_address, uint8_t data); 47 void ReadCalibration(void); 48 double Read_Temperature(); 49 double Read_Pressure(); 50 double Read_Humidity(); 51 52 void Read_All(double *temp, double *press, double *hum); 53 double ReadAltitude(double SeaLevel_Pres, double pressure); 54 55 int32_t compensate_T(int32_t adc_T); 56 double compensate_T_double(int32_t adc_T); 57 58 uint32_t compensate_P(int32_t adc_P); 59 double compensate_P_double(int32_t adc_P); 60 61 uint32_t compensate_H(int32_t adc_H); 62 double compensate_H_double(int32_t adc_H); 63 64 uint16_t read16bit(uint8_t reg); 65 uint8_t read8bit(uint8_t reg); 66 67private: 68 uint8_t _bme280_addres; 69 uint8_t _scl, _sda; 70 uint32_t _freq; 71 72 int32_t _t_fine; 73 74 uint16_t _dig_T1; 75 int16_t _dig_T2; 76 int16_t _dig_T3; 77 78 uint16_t _dig_P1; 79 int16_t _dig_P2; 80 int16_t _dig_P3; 81 int16_t _dig_P4; 82 int16_t _dig_P5; 83 int16_t _dig_P6; 84 int16_t _dig_P7; 85 int16_t _dig_P8; 86 int16_t _dig_P9; 87 88 uint8_t _dig_H1; 89 int16_t _dig_H2; 90 uint8_t _dig_H3; 91 int16_t _dig_H4; 92 int16_t _dig_H5; 93 int8_t _dig_H6; 94}; 95 96#endif
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。