Huskylens Code to Nano ESP 32 Code

How do I fix this error?

#include <GSheet32.h>
GSheet32 Sheet("AKfycbxMZikdFlL1r2JCWe0Bjsl8Fc4Kca_lnL86yJtv1er4dG-oyWTEpbEcoH_8C7wPFm4R");

const char* ssid = "Tradition1871"; 
const char* password = "your WiFi password";



/***************************************************
 HUSKYLENS An Easy-to-use AI Machine Vision Sensor
 <https://www.dfrobot.com/product-1922.html>
 
 ***************************************************
 This example shows the basic function of library for HUSKYLENS via Serial.
 
 Created 2020-03-13
 By [Angelo qiao](Angelo.qiao@dfrobot.com)
 
 GNU Lesser General Public License.
 See <http://www.gnu.org/licenses/> for details.
 All above must be included in any redistribution
 ****************************************************/

/***********Notice and Trouble shooting***************
 1.Connection and Diagram can be found here
 <https://wiki.dfrobot.com/HUSKYLENS_V1.0_SKU_SEN0305_SEN0336#target_23>
 2.This code is tested on Arduino Uno, Leonardo, Mega boards.
 ****************************************************/

#include "HUSKYLENS.h"



#define MYPORT_TX 11
#define MYPORT_RX 10

HUSKYLENS huskylens;
HardwareSerial mySerial(2)// RX, TX
//HUSKYLENS green line >> Pin 10; blue line >> Pin 11
void printResult(HUSKYLENSResult result);

const int BlockedButton = 8;
const int NotBlockedButton = 9;

int BlockedButtonState = 0;
int NotBlockedButtonState = 0;


void setup() {
    
    Serial.begin(115200);
    mySerial.begin(9600, SERIAL_8N1, MYPORT_RX, MYPORT_TX);
    pinMode (BlockedButton, INPUT);
    pinMode (NotBlockedButton, INPUT);
    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);
    }
      Serial.begin(115200);
  Sheet.connectWiFi(ssid, password);
  Sheet.clearData(); // function to delete all data in the sheet
  // Add // if you don't want it to be used
}

void loop() {
    BlockedButtonState = digitalRead (BlockedButton);
    NotBlockedButtonState = digitalRead (NotBlockedButton);
    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);
        }    
    }
      Sheet.sendData("C","D","E","F","G");
}


void printResult(HUSKYLENSResult result){
    if (result.command == COMMAND_RETURN_BLOCK ){
        if (BlockedButtonState == HIGH && NotBlockedButtonState == LOW ){
            Serial.println(String()+F("Block:xCenter=")+result.xCenter+F(",yCenter=")+result.yCenter+F(",width=")+result.width+F(",height=")+result.height+F(",ID=")+result.ID+F("saved_button=1 ")+F("scored_button=0 "));
        }
        else if (NotBlockedButtonState == HIGH && BlockedButtonState == LOW ){
            Serial.println(String()+F("Block:xCenter=")+result.xCenter+F(",yCenter=")+result.yCenter+F(",width=")+result.width+F(",height=")+result.height+F(",ID=")+result.ID+F("saved_button=0 ")+F("scored_button=1 "));
          }
        else if (BlockedButtonState == LOW && NotBlockedButtonState == LOW){
            Serial.println(String()+F("Block:xCenter=")+result.xCenter+F(",yCenter=")+result.yCenter+F(",width=")+result.width+F(",height=")+result.height+F(",ID=")+result.ID+F("saved_button=0 ")+F("scored_button=0 "));
          }
          
    }
    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!");
    }
}
C:\Users\randolwd472\Documents\Arduino\libraries\HUSKYLENS\examples\HUSKYLENS_ALMOST_THERE_FRIDAY\HUSKYLENS_ALMOST_THERE_FRIDAY.ino:40:1: error: expected ',' or ';' before 'void'
 void printResult(HUSKYLENSResult result);
 ^~~~
C:\Users\randolwd472\Documents\Arduino\libraries\HUSKYLENS\examples\HUSKYLENS_ALMOST_THERE_FRIDAY\HUSKYLENS_ALMOST_THERE_FRIDAY.ino: In function 'void loop()':
C:\Users\randolwd472\Documents\Arduino\libraries\HUSKYLENS\examples\HUSKYLENS_ALMOST_THERE_FRIDAY\HUSKYLENS_ALMOST_THERE_FRIDAY.ino:80:13: error: 'printResult' was not declared in this scope
             printResult(result);
             ^~~~~~~~~~~
C:\Users\randolwd472\Documents\Arduino\libraries\HUSKYLENS\examples\HUSKYLENS_ALMOST_THERE_FRIDAY\HUSKYLENS_ALMOST_THERE_FRIDAY.ino:80:13: note: suggested alternative: 'result'
             printResult(result);
             ^~~~~~~~~~~
             result

the compiler said it

so find line 40 where there is void printResult... look at the code line just above and you'll see that there is a missing semi colon..

HardwareSerial mySerial(2)// RX, TX


HardwareSerial mySerial(2); // RX, TX

OMG thank you so much it actually worked!!!!!!!!! I've been at this for literal months. You are amazing.

the compiler was pretty straight to the point :slight_smile:

Strange though, I'm just now looking at where it said the error was, and it was two lines below where the error actually was; it showed void printResult(HUSKYLENSResult result);, but the error was really where you said it was, HardwareSerial mySerial(2)// RX, TX.

I just found out that I have another problem, though. It isn't an error in the program; it's just that for some reason the serial monitor isn't displaying the Huskylens's output. I first thought that it was because I'm trying to display it on a Google sheet, but I opened that up too, and there's nothing showing up. The project goal is to get the Huskylens to track a soccer ball for goalie training (I'm using a small object to start off with; it can't track fast things), and there are 2 push-buttons that input if the goalie has blocked the ball or not. It displayed the data on the serial monitor just fine when I used the Mega board and the starter code with the modifications at the bottom for the push-button, but when I added the GSheet32 thing and used the ESP32, I had to modify the code into what you see above, and now the serial monitor is continuously printing out dashes every second on the same line, and the Google sheet is doing nothing (I have the Apps Script written, and the code thingy for it is on line 2). Do you know what I did wrong?

I found another forum that I'm going to continue on. I think I also saw your name there. It's called "Serial monitor not working with Nano ESP32"

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.