Code: Select all#undef max //ADDED
#define max(a,b) ((a)>(b)?(a):(b)) //ADDED!!! Added because Max/Min functions not working in header
#undef min //ADDED
#define min(a,b) ((a)<(b)?(a):(b)) //ADDED!!! Added because Max/Min functions not working in header
Within my Arduino program, I'm using HardwareSerial instead as such to use the ESP32 Hardware UART2
Code: Select all#include <HardwareSerial.h>
#include <HuskyLensProtocolCore.h>
#include <HUSKYLENS.h>
#include <HUSKYLENSMindPlus.h>
#include <DFRobotHuskyLens.h>
#include <M5Stack.h>
HUSKYLENS huskylens;
#define RXD2 17 //Oops Switched my wires!!
#define TXD2 16 //Oops Switched my wires!!
int ID1 = 1;
void setup() {
M5.begin();
Serial.begin(115200);
Serial2.begin(9600, SERIAL_8N1, RXD2, TXD2); //Communication with Huskylens
while (!huskylens.begin(Serial2))
{
Serial.println(F("Failbus!"));
delay(100);
}
huskylens.writeAlgorithm(ALGORITHM_LINE_TRACKING);
}
void loop() {
M5.update();
int32_t error;
if (!huskylens.request(ID1)) {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
{
HUSKYLENSResult result = huskylens.read();
printResult(result);
// Calculate the error: where it needs to move for center
error = (int32_t)result.xTarget - (int32_t)160;
}
delay(100);
}
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!");
}
}
This yielded successful data transmission, at least with the line tracking part