Can not compile on Arduino Nano ESP 32



  • Hi,
    I'm trying to compile one of the example on Arduino Nano ESP32. (MySensors version 2.3.2)
    Am I doing something wrong?

    ***Compiling debug version of 'SoilMoistSensor' for 'Arduino Nano ESP32 (nano_nora)'

    esp32-hal-uart.c: In function uartSetPins

    esp32-hal-uart.c: 153:9: warning: 'return' with no value, in function returning non-void
    return
    ^~~~~~
    esp32-hal-uart.c:149: note declared here
    bool uartSetPins(uint8_t uart_num, int8_t rxPin, int8_t txPin, int8_t ctsPin, int8_t rtsPin)
    ^~~~~~~~~~~

    mysensors.h:61: In file included from
    SoilMoistSensor.ino:73: from

    MyHwESP32.cpp: In function bool hwInit()

    MyHwESP32.cpp: 30:48: error: no matching function for call to 'USBCDC::begin(long unsigned int, SerialConfig)
    MY_SERIALDEVICE.begin(MY_BAUD_RATE, SERIAL_8N1)

    USB.h:21: In file included from
    HardwareSerial.h:201: from
    arduino.h:184: from
    SoilMoistSensor.ino: from
    USBCDC.h:70: note candidate void USBCDC begin(long unsigned int)
    void begin(unsigned long baud=0)
    ^~~~~
    USBCDC.h:70: note candidate expects 1 argument, 2 provided

    SoilMoistSensor.ino: In function void loop()

    SoilMoistSensor.ino: 143:17: error: call of overloaded 'sleep(uint32_t&)' is ambiguous
    sleep(SLEEP_TIME)

    unistd.h:23: In file included from
    unistd.h:4: from
    pthread.h:25: from
    pthread.h:21: from
    gthr-default.h:48: from
    gthr.h:151: from
    atomicity.h:35: from
    basic_string.h:39: from
    string:52: from
    stdexcept:39: from
    array:39: from
    tuple:39: from
    functional:54: from
    Error compiling project sources
    HardwareSerial.h:49: from
    arduino.h:184: from
    Debug build failed for project 'SoilMoistSensor'
    SoilMoistSensor.ino: from***



  • @ctodor said in Can not compile on Arduino Nano ESP 32:

    USBCDC

    Can you please attach your sketch?



  • @eiten
    It is the SoilMoistSensor.ino skecth from MySensor example.

    *// Enable debug prints to serial monitor
    #define MY_DEBUG
    //#define MY_GATEWAY_ESP32

    // Enable and select radio type attached
    //#define MY_RADIO_RF24
    //#define MY_RADIO_NRF5_ESB
    #define MY_RADIO_RFM69
    //#define MY_RADIO_RFM95

    #include <math.h> // Conversion equation from resistance to %
    #include <MySensors.h>

    // Setting up format for reading 3 soil sensors
    #define NUM_READS (int)10 // Number of sensor reads for filtering
    #define CHILD_ID 0

    MyMessage msg(CHILD_ID, V_LEVEL);
    uint32_t SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)

    long buffer[NUM_READS];
    int idx;

    /// @brief Structure to be used in percentage and resistance values matrix to be filtered (have to be in pairs)
    typedef struct {
    int moisture; //!< Moisture
    long resistance; //!< Resistance
    } values;

    const long knownResistor = 4700; // Constant value of known resistor in Ohms

    int supplyVoltage; // Measured supply voltage
    int sensorVoltage; // Measured sensor voltage

    values valueOf[NUM_READS]; // Calculated moisture percentages and resistances to be sorted and filtered

    int i; // Simple index variable

    void setup()
    {
    // initialize the digital pins as an output.
    // Pin 6,7 is for sensor 1
    // initialize the digital pin as an output.
    // Pin 6 is sense resistor voltage supply 1
    pinMode(6, OUTPUT);

    // initialize the digital pin as an output.
    // Pin 7 is sense resistor voltage supply 2
    pinMode(7, OUTPUT);
    

    }

    void presentation()
    {
    sendSketchInfo("Soil Moisture Sensor Reverse Polarity", "1.0");
    present(CHILD_ID, S_MOISTURE);
    }

    void loop()
    {

    measure(6,7,1);
    Serial.print ("\t");
    Serial.println (average());
    long read1 = average();
    
    measure(7,6,0);
    Serial.print ("\t");
    Serial.println (average());
    long read2= average();
    
    long sensor1 = (read1 + read2)/2;
    
    Serial.print ("resistance bias =" );
    Serial.println (read1-read2);
    Serial.print ("sensor bias compensated value = ");
    Serial.println (sensor1);
    Serial.println ();
    
    //send back the values
    send(msg.set((int32_t)ceil(sensor1)));
    // delay until next measurement (msec)
    sleep(SLEEP_TIME);
    

    }

    void measure (int phase_b, int phase_a, int analog_input)
    {
    // read sensor, filter, and calculate resistance value
    // Noise filter: median filter

    for (i=0; i<NUM_READS; i++) {
    
    	// Read 1 pair of voltage values
    	digitalWrite(phase_a, HIGH);                 // set the voltage supply on
    	delayMicroseconds(25);
    	supplyVoltage = analogRead(analog_input);   // read the supply voltage
    	delayMicroseconds(25);
    	digitalWrite(phase_a, LOW);                  // set the voltage supply off
    	delay(1);
    
    	digitalWrite(phase_b, HIGH);                 // set the voltage supply on
    	delayMicroseconds(25);
    	sensorVoltage = analogRead(analog_input);   // read the sensor voltage
    	delayMicroseconds(25);
    	digitalWrite(phase_b, LOW);                  // set the voltage supply off
    
    	// Calculate resistance
    	// the 0.5 add-term is used to round to the nearest integer
    	// Tip: no need to transform 0-1023 voltage value to 0-5 range, due to following fraction
    	long resistance = (knownResistor * (supplyVoltage - sensorVoltage ) / sensorVoltage) ;
    
    	delay(1);
    	addReading(resistance);
    	Serial.print (resistance);
    	Serial.print ("\t");
    }
    

    }

    // Averaging algorithm
    void addReading(long resistance)
    {
    buffer[idx] = resistance;
    idx++;
    if (idx >= NUM_READS) {
    idx = 0;
    }
    }

    long average()
    {
    long sum = 0;
    for (int cnt = 0; cnt < NUM_READS; cnt++) {
    sum += buffer[cnt];
    }
    return (long)(sum / NUM_READS);
    }*



  • Your board seems to use USBCDC to communicate with the PC. So in the file /hal/architecture/ESP32/MyHwESP32.cpp, line 30, you have to change MY_SERIALDEVICE.begin(MY_BAUD_RATE, SERIAL_8N1); to MY_SERIALDEVICE.begin(MY_BAUD_RATE);.
    Furthermore, as ESP32 implements the function sleep(uint32_t) iself, you need to change line 147 in the sketch from sleep(SLEEP_TIME); to sleep(SLEEP_TIME, false);.

    Hope this helps!

    Regards, Ei



  • As an additional info, sleep will not work on the ESP in version 2.3.2. Try the developement branch from the github if you need sleep, there I implemented this.



  • @eiten Thx for the info.
    "Try the developement branch from the github": can you give me the url?



  • @ctodor of course:
    https://github.com/mysensors/MySensors/tree/development does contain sleep code for ESP. You can download the library here as a zip file.





  • @ctodor did you succeed?



  • @eiten
    Sorry for the late response, but I didn't had time to work on it until today.

    Yes, I was able to compile but not to upload. After "uploading", the Arduino NANO ESP 32 disconects from the PC.
    I must reset the board in order to be able to upload another sketch.



  • OK, so I suppose the build flags are incorrect. Do you use PlatformIO? Then, you could try:

    build_flags = 
    	-D ARDUINO_USB_MODE=1
    	-D ARDUINO_USB_CDC_ON_BOOT=1
    

    If you are on the Arduino IDE, you have to set Tools -> USB-Mode -> CDC-Mode. Ore something similar, I don't have the Arduino IDE installed ATM. IIRC, monitor speed must be set to 460800.



  • @eiten Yep, I was able to upload the sketch after I've set Tools -> USB-Mode -> CDC-Mode.
    Thank you for your help.

    Well, I think I rushed with the conclusion.
    Somehow, the bord is now in infinite boot loop:

    0;255;3;0;14;Gateway startup complete.
    0;255;0;0;18;2.3.2
    ESP-ROM:esp32s3-20210327
    Build:Mar 27 2021
    rst:0x8 (TG1WDT_SYS_RST),boot:0x2b (SPI_FAST_FLASH_BOOT)
    Saved PC:0x4200d223
    SPIWP:0xee
    mode:DIO, clock div:1
    load:0x3fce3808,len:0x44c
    load:0x403c9700,len:0xbe4
    load:0x403cc700,len:0x2a68
    entry 0x403c98d4

    repetes over and over



  • That's strange. Is it exactly the code from above? It seems, it is in gateway mode, but in your sketch, you commented out the gateway option...



  • @eiten You are right. It is not the same sketch. The previuos sketch seems to work fine (I used it just to make sure I am able to compile and upload).
    Now I'm trying to upload a sketch where the ardunio runs as gateway and this is what a need , a gateway that receives messages from a few magnetic door sensors.
    But please, don't waste your time with me. I think I'm going to write my simple protocol to do such a simple task.

    Thank you very much for your effort.



  • @ctodor You are very welcome


Log in to reply
 

Suggested Topics

44
Online

11.4k
Users

11.1k
Topics

112.6k
Posts