Firebeetle 2 ESP32-E I2C connection cannot working if I also use UART
Hello. I'm using Firebeetle 2 ESP32-E. Why I2C connection for HuskyLens cannot working if I also use UART connection for DFPlayer Pro DF1201S? Any suggestion?
Here is my code:
#include <SoftwareSerial.h>
#include "HUSKYLENS.h"
#include <DFRobot_DF1201S.h>
HUSKYLENS huskylens;
SoftwareSerial PSerial(25, 26);
DFRobot_DF1201S DF1201S;
float PERSON, LABCOAT;
void printResult(HUSKYLENSResult result);
//HUSKYLENS green line >> Pin 10; blue line >> Pin 11
void setup() {
Serial.begin(115200);
Wire.begin();
while (!huskylens.begin(Wire))
{
Serial.println(F("Begin failed!"));
Serial.println(F("1.Please recheck the \"Protocol Type\" in HUSKYLENS (General Settings>>Protocol Type>>I2C)"));
Serial.println(F("2.Please recheck the connection."));
delay(100);
}
PSerial.begin(9600);
DF1201S.setVol(100);
while(!DF1201S.begin(PSerial))
{
Serial.println("Init failed, please check the wire connection!");
delay(100);
}
}
void loop() {
PERSON = 0;
huskylens.writeAlgorithm(ALGORITHM_OBJECT_RECOGNITION);
huskylens.requestBlocksLearned();
while (huskylens.available()) {
HUSKYLENSResult result = huskylens.read();
if (result.command == COMMAND_RETURN_BLOCK){
if (result.ID == 1){
PERSON = 1;
}
}
}
while ((PERSON == 1)) {
huskylens.writeAlgorithm(ALGORITHM_OBJECT_CLASSIFICATION);
LABCOAT = 0;
huskylens.requestBlocksLearned();
while (!(LABCOAT == 1)) {
HUSKYLENSResult result = huskylens.read();
if(result.ID == 1){
huskylens.clearCustomText();
huskylens.customText("Using Lab Coat", 230, 35);
DF1201S.playFileNum(1);
LABCOAT = 1;
}
else {
huskylens.clearCustomText();
huskylens.customText("Not Using Lab Coat", 230, 35);
DF1201S.playFileNum(2);
LABCOAT = 0;
}
}
}
Serial.print(LABCOAT);
}
Download the complete code:https://drive.google.com/file/d/1J7GdBRk3V-jkLjal5alMt99SpFTx5bqe/view?usp=sharing
jennapls try this code. This code has been verified successfully.
Here is my code:(HUSKYLENS →IIC,DFRobot_DF1201S→HardWare UART)
#include <SoftwareSerial.h>#include "HUSKYLENS.h"#include <DFRobot_DF1201S.h>
HUSKYLENS huskylens;//SoftwareSerial PSerial(25, 26);DFRobot_DF1201S DF1201S;
float PERSON, LABCOAT;
void printResult(HUSKYLENSResult result);
//HUSKYLENS green line >> Pin 10; blue line >> Pin 11//DF1201S TX,RX——> ESP32-E TX,RXvoid setup() { Serial.begin(115200); while(!DF1201S.begin(Serial)) { Serial.println("Init failed, please check the wire connection!"); delay(1000); } DF1201S.setVol(20); Serial.print("VOL:"); /*Get volume*/ Serial.println(DF1201S.getVol()); /*Enter music mode*/ DF1201S.switchFunction(DF1201S.MUSIC); /*Wait for the end of the prompt tone */ delay(2000); /*Set playback mode to "repeat all"*/ DF1201S.setPlayMode(DF1201S.ALLCYCLE); Serial.print("PlayMode:"); /*Get playback mode*/ Serial.println(DF1201S.getPlayMode()); Wire.begin(); while (!huskylens.begin(Wire)) { Serial.println(F("Begin failed!")); Serial.println(F("1.Please recheck the \"Protocol Type\" in HUSKYLENS (General Settings>>Protocol Type>>I2C)")); Serial.println(F("2.Please recheck the connection.")); delay(100); } //PSerial.begin(9600);
}void loop(){ if (!huskylens.request()) Serial.println(F("Fail to request data from HUSKYLENS, recheck the connection!")); else if(!huskylens.isLearned()) Serial.println(F("Nothing learned, press learn button on HUSKYLENS to learn one!")); else if(!huskylens.available()) Serial.println(F("No block or arrow appears on the screen!")); else { Serial.println(F("###########")); while (huskylens.available()) { HUSKYLENSResult result = huskylens.read(); printResult(result); } } Serial.println("Start playing"); /*Start playing*/ DF1201S.start(); delay(3000); }
void printResult(HUSKYLENSResult result){ if (result.command == COMMAND_RETURN_BLOCK){ Serial.println(String()+F("Block:xCenter=")+result.xCenter+F(",yCenter=")+result.yCenter+F(",width=")+result.width+F(",height=")+result.height+F(",ID=")+result.ID); } else if (result.command == COMMAND_RETURN_ARROW){ Serial.println(String()+F("Arrow:xOrigin=")+result.xOrigin+F(",yOrigin=")+result.yOrigin+F(",xTarget=")+result.xTarget+F(",yTarget=")+result.yTarget+F(",ID=")+result.ID); } else{ Serial.println("Object unknown!"); }}
jenna