HUSKYLENSGeneral

I want to use huskylens and esp32 in conjunction. !

userHead Account cancelled 2020-07-10 12:37:26 5593 Views8 Replies
I am trying to program an esp32 board that can use Wi-Fi and Bluetooth inexpensively.
"HUSKYLENS.h" gives an error. Is there a library for esp32?

There is an ADC module, but shouldn't it be received as an analog value to receive coordinate values?
2020-10-06 10:18:58 I also had to comment out lines 709-715 in HUSKYLENS.h to get it working on an ESP8266. These lines relate to writing the new firmware version - shouldn't be any different between the ESP8266 and the ESP32, so I'm guessing it's something with this release of the Arduino library. It was getting an error that the data variable had not been initialized. Hopefully it doesn't break anything userHeadPic jat5
2020-08-25 21:42:26 thanx userHeadPic hajnyondra
2020-08-23 23:56:48 Hey all, just wanted to send this because I may have found a workaround in the meantime for people using an ESP32 based platform (instead of waiting for a revision and such). As a general note, I'm using the M5Stack ESP32 Core written with Arduino IDE 1.8.21 platform

Most of the issues appeared to be usage of the SoftwareSerial library so I just commented those out in the headers.
DFRobotHuskyLens.h lines 63-69 commented out
HUSKYLensMindPlus.h lines 63-69 commented out

I removed these library files from the library (I didn't need them anyway, I'll handle my own motion but for whatever reason wouldn't compile even if I didn't include them)
DFMobile.h removed
DFMobile.cpp removed

And for whatever reason the min/max functions weren't compiling/working in the HUSKYLENS.h header so I added the below at line 18 in HUSKYLENS.h
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
Arrow:xOrigin=192,yOrigin=108,xTarget=184,yTarget=66,ID=1

Hope this helps someone/somewhere/somehow in the meantime! Note I'm no developer and barely know what I'm doing half the time, so no promises

EDIT:
To the OPs ADC question, I don't know of any Analog interface and don't see anything of that nature in the library. The 4-pin interface is Serial or I2C as far as I'm aware (I haven't tested the I2C side)
userHeadPic dicidan969
2020-08-18 01:32:11 The whole thing doesn't work just because in library is softwereserial.
Just remove it and do a hardware serial insted (I don't know how to edit the library)
userHeadPic bmdevine
2020-08-16 23:26:28 And will it be possible in the future? userHeadPic bmdevine