Forum >Replies by dicidan969
userhead dicidan969
Replies (3)
  • You Reply: That's a great point. We could try verifying the Serial connectivity outside of the example sketch. That way we can confirm the hardware is working properly with communication. Even with a failure of the huskylens.begin function, we should still see normal strings

    Maybe just have a barebones sketch with Serial communications and gradually start adding content until you start to see problems
  • You Reply: The latter sounds like a Baud rate mismatch on the serial port(s). Is the device set to "AutoDetect" and you're using the default entries in the example code, with the serial monitor Baud set to 115200?
    Code: Select all
      Example HuskyLens_Get_Started
    SoftwareSerial mySerial(10, 11);     // RX, TX  pins to wire signal wires to the arduino
    ...
        Serial.begin(115200);       // This is the Serial Monitor port for your PC connection and such
        mySerial.begin(9600);     // This is specific for the Huskylens to talk directly to the Arduino
        while (!huskylens.begin(mySerial)) {
    ...
    
    I'm not sure on the first issue or if it's related or not. It could be related if both ports are talking across the same lines or something weird, not sure. Are you also using pins 10 & 11 as the example code? Maybe someone else may have some insight
  • You Reply: 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)