ต้องการใช้ sensor 2 ตัว ในESP32 สร้างชิ้นงานผมเลยต้องการประกาศขา SDA SCL เพิ่มมาใหม่
#include <Wire.h>
#include "MAX30105.h"
#include "heartRate.h"
#define I2C_SDA 33
#define I2C_SCL 32
TwoWire I2Cone = TwoWire(0);
MAX30105 MAX;
const byte RATE_SIZE = 4; //Increase this for more averaging. 4 is good.
byte rates[RATE_SIZE]; //Array of heart rates
byte rateSpot = 0;
long lastBeat = 0; //Time at which the last beat occurred
unsigned long delayTime;
float beatsPerMinute;
int beatAvg;
void setup() {
Serial.begin(115200);
Serial.println(F("BME280 test"));
I2Cone.begin(I2C_SDA, I2C_SCL, 100000);
bool status1 = MAX.begin(0x57, &I2Cone);
if (!status1) {
Serial.println("Could not find a valid BME280_1 sensor, check wiring!");
while (1);
}
Serial.println("-- Default Test --");
delayTime = 1000;
Serial.println();
MAX.setup(); //Configure sensor with default settings
MAX.setPulseAmplitudeRed(0x0A); //Turn Red LED to low to indicate sensor is running
MAX.setPulseAmplitudeGreen(0); //Turn off Green LED
}
void loop() {
max30102();
delay(delayTime);
}
void max30102() {
long irValue = MAX.getIR();
if (checkForBeat(irValue) == true)
{
//We sensed a beat!
long delta = millis() - lastBeat;
lastBeat = millis();
beatsPerMinute = 60 / (delta / 1000.0);
if (beatsPerMinute < 255 && beatsPerMinute > 20)
{
rates[rateSpot++] = (byte)beatsPerMinute; //Store this reading in the array
rateSpot %= RATE_SIZE; //Wrap variable
//Take average of readings
beatAvg = 0;
for (byte x = 0 ; x < RATE_SIZE ; x++)
beatAvg += rates[x];
beatAvg /= RATE_SIZE;
}
}
Serial.print("IR=");
Serial.print(irValue);
Serial.print(", BPM=");
Serial.print(beatsPerMinute);
Serial.print(", Avg BPM=");
Serial.print(beatAvg);
if (irValue < 50000)
Serial.print(" No finger?");
Serial.println();
}
โค้ดที่ได้ลองทำ ผมไปดูจากเว็บมาเลยลองดัดแปลงเอาโค้ดของ sensor มาใส่รวมกันดู แต่มีปัญหาส่วนนี้
Arduino: 1.8.8 (Windows 10), Board: "DOIT ESP32 DEVKIT V1, 80MHz, 921600, None"
C:\Users\acer\Documents\Arduino\testmax\1\1.ino: In function 'void setup()':
1:18:41: error: invalid initialization of non-const reference of type 'TwoWire&' from an rvalue of type 'TwoWire'
bool status1 = MAX.begin(0x57, &I2Cone);
^
In file included from C:\Users\acer\Documents\Arduino\testmax\1\1.ino:1:0:
C:\Users\acer\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6\libraries\Wire\src/Wire.h:68:5: note: after user-defined conversion: TwoWire::TwoWire(uint8_t)
TwoWire(uint8_t bus_num);
^
In file included from C:\Users\acer\Documents\Arduino\testmax\1\1.ino:2:0:
C:\Users\acer\Documents\Arduino\libraries\SparkFun_MAX3010x_Sensor_Library-master\src/MAX30105.h:50:11: note: initializing argument 1 of 'boolean MAX30105::begin(TwoWire&, uint32_t, uint8_t)'
boolean begin(TwoWire &wirePort = Wire, uint32_t i2cSpeed = I2C_SPEED_STANDARD, uint8_t i2caddr = MAX30105_ADDRESS);
^
1:26:3: error: 'delayTime' was not declared in this scope
delayTime = 1000;
^
C:\Users\acer\Documents\Arduino\testmax\1\1.ino: In function 'void loop()':
1:36:9: error: 'delayTime' was not declared in this scope
delay(delayTime);
^
Multiple libraries were found for "MAX30105.h"
Used: C:\Users\acer\Documents\Arduino\libraries\SparkFun_MAX3010x_Sensor_Library-master
Not used: C:\Users\acer\Documents\Arduino\libraries\SparkFun_MAX3010x_Pulse_and_Proximity_Sensor_Library-1.1.1
Not used: C:\Users\acer\Documents\Arduino\libraries\SparkFun_MAX3010x_Pulse_and_Proximity_Sensor_Library-1.1.1
Not used: C:\Users\acer\Documents\Arduino\libraries\SparkFun_MAX3010x_Pulse_and_Proximity_Sensor_Library-1.1.1
Not used: C:\Users\acer\Documents\Arduino\libraries\SparkFun_MAX3010x_Pulse_and_Proximity_Sensor_Library-1.1.1
exit status 1
invalid initialization of non-const reference of type 'TwoWire&' from an rvalue of type 'TwoWire'
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
อาจจะเป็นเพราะผมเอามารวมกันแล้วเกิดปัญหาขึ้น พอจะสามารถหาวิธีการแก้ปัญหาหรือแนวทางให้หน่อยได้ไหมครับ