Forum >Replies by anonymous
userhead anonymous
Replies (2)
  • You Reply: Hi!

    It's basically the example code delivered with the library. The only thing I added is Servo library declaration and servo initialization. No servo movement commands yet. That's enought for the problem to appear. Marked changes to the example with "//<---".
    Code: Select all
    #include "HUSKYLENS.h"
    #include "SoftwareSerial.h"
    #include <Servo.h>                    //<---
    
    Servo myServo1;                       //<---
    
    HUSKYLENS huskylens;
    SoftwareSerial mySerial(10, 11); // RX, TX
    void printResult(HUSKYLENSResult result);
    
    void setup() {
        Serial.begin(115200);
        mySerial.begin(9600);
        myServo1.attach(5);              //<---
        while (!huskylens.begin(mySerial))
        {
            Serial.println(F("Begin failed!"));
            Serial.println(F("1.Please recheck the \"Protocol Type\" in HUSKYLENS (General Settings>>Protocol Type>>Serial 9600)"));
            Serial.println(F("2.Please recheck the connection."));
            delay(100);
        }
    }
    
    void loop() {
        huskylens.request();
        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);
            }    
        }
    }
    
    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!");
        }
    }
  • You Reply: So far I have managed to identify that it is the request() function that is causing this behavior. If I remove the huskylens.request() call from the code, the odd behavior of servos stops. Of course now the communication with Huskylens does not work anymore.

    request function has rather compact body:
    protocolWriteRequest();
    return processReturn();

    Unfortunately I'm not able to locate protocolWriteRequest() function body, so this is the point I'm stuck at. Any hints appreciated. :)

    EDIT: Solved (or rather went around it) by moving to I2C. Still, would love to understand what the problem is. :)