Hello everyone. I need to implement 2 sensors using I2C in my Uno. The sensors are: MLX90614 (contactless temperature sensor) VL53L0X (TOF sensor) Both are connected in I2C bus in my Arduino Uno. The code for MLX90614 is:
<pre>#include <Wire.h> #include <Adafruit_MLX90614.h> Adafruit_MLX90614 mlx = Adafruit_MLX90614(); void setup() { Serial.begin(115200); mlx.begin(); } void loop() { Serial.print(mlx.readObjectTempC()); Serial.println(); delay(800); }
and the code for sensor VL53L0X is:
<pre>#include "Adafruit_VL53L0X.h" Adafruit_VL53L0X lox = Adafruit_VL53L0X(); void setup() { Serial.begin(115200); while (! Serial) { delay(1); } if (!lox.begin()) { Serial.println(F("Failed to boot VL53L0X")); while(1); } } void loop() { VL53L0X_RangingMeasurementData_t measure; lox.rangingTest(&measure, false); if (measure.RangeStatus != 4) { Serial.println(measure.RangeMilliMeter); } else { Serial.println(" out of range "); } delay(800); }
Both codes work separately, but when I try to join them, they did not work:
<pre>#include "Adafruit_VL53L0X.h" #include <Adafruit_MLX90614.h> #include <Wire.h> Adafruit_VL53L0X lox = Adafruit_VL53L0X(); Adafruit_MLX90614 mlx = Adafruit_MLX90614(); void setup() { Serial.begin(115200); mlx.begin(); while (! Serial) { delay(1); } if (!lox.begin()) { Serial.println(F("Failed to boot VL53L0X")); while(1); } } void loop() { if (Serial.available()) { String ch; ch = Serial.readString(); ch.trim(); if(ch=="read_temperature") { Serial.print(mlx.readObjectTempC()); Serial.print("\n"); } if(ch=="read_distance") { VL53L0X_RangingMeasurementData_t measure; lox.rangingTest(&measure, false); if (measure.RangeStatus != 4) { Serial.println(measure.RangeMilliMeter); } } } }
Any ideas? Thanks.
void setup() { Serial.begin(115200); mlx.begin(); while (! Serial) { delay(1); } if (!lox.begin()) { Serial.println(F("Failed to boot VL53L0X")); while(1); } }
void setup() { Serial.begin(115200); while (! Serial) { delay(1); } mlx.begin(); if (!lox.begin()) { Serial.println(F("Failed to boot VL53L0X")); while(1); } }
if (Serial.available()) { }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)