Olimex Support Forum

DUINO => ARDUINO => Topic started by: Bumbum on November 19, 2021, 06:46:06 pm

Title: How to get started with the ESP32-Pro
Post by: Bumbum on November 19, 2021, 06:46:06 pm
Hello,

I try to get started, but I have some problems. I want to use a ESP32-Pro Board and program the ESP32 only from the Arduino IDE. I have installed the Arduino Bootloader on the PIC32, but then I get stuck. I cannot connect to the ESP32. How do I upload my first Sketch to the ESP32?

thank you and best regards
Bumbum
Title: Re: How to get started with the ESP32-Pro
Post by: Bumbum on November 24, 2021, 10:04:33 am
Hello,

I have done some research to provide some more informations about my problem. I have flashed the Arduino Bootloader to the PIC32MX270F256D on my Olimex ESP32pro board from the following URL:

https://github.com/OLIMEX/Arduino_configurations/tree/master/PIC

I have used a PICkit3 and the MPLAB X IDE. The flashing went fine. After this step I can program the PIC in the Arduino IDE. I have choosen the pic32-default-firmware from the examples. This software seems to handover the USB serial to the ESP32.

I have tested this and it seems to work. I have connect to the Olimex COM-port by a terminal and controlled the DTR and RTS line manually from my PC. I can measure either 0 V or 3,3 V on R21 and 0,6 V or 3,3 V on R47 which seems to be fine according to the schematics of the Olimex ESP32Pro.

I then try to upload a simply sketch with code to send "Hello World" over the Serial. For this I have selected the ESP32 Dev Module as Board and select the COM-port of the Olimex board. But then the Arduino IDE is not able to connect to the ESP32. I see the .... ___ animation until I get a timeout.

Can somebody help what I am doing wrong?

best regards
Bumbum
Title: Re: How to get started with the ESP32-Pro
Post by: LubOlimex on November 24, 2021, 03:01:31 pm
Wait, you downloaded one of these bootloaders:

https://github.com/OLIMEX/Arduino_configurations/tree/master/PIC/Bootloaders

to your ESP32-PRO board? Why?

Please use the resources from the ESP32-PRO repo instead:

https://github.com/OLIMEX/ESP32-PRO/tree/master/SOFTWARE/PIC32_part_bootloader_MPLAB
Title: Re: How to get started with the ESP32-Pro
Post by: Bumbum on November 24, 2021, 06:22:30 pm
Hello LubOlimex,

thank you for your answer. I have the link for the bootloader from the official documentation for Arduino to this board:

https://www.olimex.com/Products/Duino/_resources/Arduino_instructions.pdf

If it is wrong, Olimex should add the correct link there. I cannot find your link anywhere in this document.

Nevertheless, I have flashed this bootloader to the PIC with MPLAB X IPE but still get no connection to the ESP32 in the Arduino IDE.

Then I treid to upload the pic32-default-firmware in the Arduino IDE (which source is also shown on your link), but still get no connection. As board I selected "Olimex PIC boards/ESP32-PRO"

After this, the "Connection Animation" to the ESP32 stopps at "Connection...." and nothing more is happening.

What am I doing wrong again?

best regards
Bumbum
Title: Re: How to get started with the ESP32-Pro
Post by: JohnS on November 24, 2021, 06:31:55 pm
deleted
Title: Re: How to get started with the ESP32-Pro
Post by: LubOlimex on November 26, 2021, 04:56:38 pm
It seems to work out-of-the-box here. Probably something wrong in your drivers installation or Arduino IDE package installation. I will make you a video Monday.
Title: Re: How to get started with the ESP32-Pro
Post by: LubOlimex on December 01, 2021, 04:25:38 pm
You can find how it looks here in the 6 pictures that I uploaded here:

https://imgur.com/a/JDiY55X

Make sure it looks the same at your side.

This is ESP32-PRO without any modifications, taken directly from shop and plugged via microUSB cable to the PC.
Title: Re: How to get started with the ESP32-Pro
Post by: Bumbum on December 02, 2021, 08:09:26 am
Hello LubOlimex,

thank you, I can see the chipKIT device in my device-manager, selected the Olimex ESP32-EVB board in my Arduino IDE and the correct COM, but I am still not able to upload a programm. I also have tried to flash both bootloaders again, the one I tried first from the Olimex Arduino manual and the other one you have linked here. But this also does not help.

I guess my problem is here:

Quote from: LubOlimex on December 01, 2021, 04:25:38 pmThis is ESP32-PRO without any modifications, taken directly from shop and plugged via microUSB cable to the PC.

Because the Olimex manual told me to upload an other bootloader something is messed up. How can I get my Olimex Board to Factory defaults?

best regards
Bumbum
Title: Re: How to get started with the ESP32-Pro
Post by: LubOlimex on December 02, 2021, 02:44:46 pm
Alright, I think the bootloader binary that is at the GitHub doesn't have the USB-serial program for the PIC32 on it. Basically you can program the PIC32 chip via Arduino but not the Arduino chip. So while you can see the PIC32 via the USB, the code send to the board is not transferred to the ESP32. To save some trouble I read the PIC32 of one of the working units and you can find it now here as ESP32-PRO-bootloader+serial-bridge.hex:

https://github.com/OLIMEX/ESP32-PRO/tree/master/SOFTWARE/PIC32_part_bootloader_MPLAB

Download this hex to the PIC32 board via your PIC programmer. Then try to program the ESP32 via Arduino IDE as you did previously. Follow again the pictures from my previous post. Let me know how it goes.
Title: Re: How to get started with the ESP32-Pro
Post by: Bumbum on December 02, 2021, 07:40:58 pm
Hello Lub,

thank you for your efforts. Unfortunately it is still not working. Here some pictures of my steps, maybe you see the problem:

MPAL IPE (https://ibb.co/BwZLWnc)

Device Manager (https://ibb.co/k10LXX4)

Arduino Upload Problem (https://ibb.co/rGZnfcB)

best regards
Bumbum
Title: Re: How to get started with the ESP32-Pro
Post by: LubOlimex on December 03, 2021, 09:25:40 am
One thing I immediately see is that the esptool is version v3.1 stable while it seems v3.0 developer version at your side. This means the ESP32 Arduino package that we used is different. I used 2.0, here you can see my packages and compare:

https://imgur.com/a/3tLxIhK

Edit: I will now try version 2.0.1 which seems to be the latest stable version.

I install the stable via the Board Manager, as detailed here:

https://docs.espressif.com/projects/arduino-esp32/en/latest/installing.html
Title: Re: How to get started with the ESP32-Pro
Post by: Bumbum on December 03, 2021, 10:56:17 am
Hello Lub,

I have updated my ESP-Board to 2.0.0 and are now able to upload code. Unfortunately it seems there is another problem, since I get no Serial output now:

Arduino Result (https://ibb.co/XkJRxfY)

best regards
Bumbum
Title: Re: How to get started with the ESP32-Pro
Post by: LubOlimex on December 03, 2021, 03:55:59 pm
Did you press "Enter" in the text box to send empty string? Try that.
Title: Re: How to get started with the ESP32-Pro
Post by: Bumbum on December 06, 2021, 08:03:00 pm
Hello Lub,

thank you for this hint. This was the last piece of the puzzle. What a journey until here. Now everything seems to work as expected. Thank you, I have learned a lot of your board.

best regards
Bumbum
Title: Re: How to get started with the ESP32-Pro
Post by: LubOlimex on December 07, 2021, 08:18:59 am
I thank you for your persistence, I will try to update the documentation to describe this process.

The difficulties are just the payoff for having both PIC32 and ESP32 in same design. It is much straight forward with boards that have just ESP32 or just PIC32, and we have a number of products with only each of them.

By the way, you can also program the PIC32 via Arduino. At the moment it has simple serial passthrough code (so you can program the ESP32 via USB), but for complex projects you can implement other extra code on top of the serial and utilize some of the PIC32 power. For final products, when final ESP32 software is downloaded you can even program the PIC32 with something else entirely. Programming the PIC32 via Arduino IDE requires the change of the state of PROG_EN1 jumper. When jumper is closed you can program the ESP32 via Arduino IDE, when it is open you can program the PIC32 via Arduino IDE.

The simple serial brodge for the PIC32 is this code: https://github.com/OLIMEX/ESP32-PRO/tree/master/SOFTWARE/PIC32_part_Arduino_IDE/PIC32_USB-Serial_Bridge/pic32-usb-serial

The hex we lastly made "ESP32-PRO-bootloader+serial-bridge.hex" contains both the bootloader and the bride code linked above.
Title: Re: How to get started with the ESP32-Pro
Post by: Bumbum on December 13, 2021, 08:46:42 am
Hello Lub,

thank you. On my journey until here I have learned a lot about the board and have understood the combination of the PIC and the ESP. But I have one question. I took a look on the PIC32-default-firmware example in the Arduino IDE. I guess this is the one you mention the serial bridge. I cannot see there in the code why I have to press "Enter" the first time (or receiving any data from PC-side) to activate the Serial communication.

Can you please explain why this step is neccessarry? I have fallen into the trap several times now during my development and wondered why I don't see any debug messages as I am used to with other Arduino projects. It is also illogical because the PIC is not restarted during a programming operation of the ESP32, yet you have to press Enter to restart communication after an update?

best regards
Bumbum
Title: Re: How to get started with the ESP32-Pro
Post by: Bumbum on December 13, 2021, 12:51:09 pm
Hello Lub,

I have done some more investigatin. I guess I have found the reason:

Serial.begin(1000000);

Is this neccessarry for programming the ESP32? If not, can you please make me a combined bootloader with serial-bridge with the following code? I guess this will solve all my problems:

int DTR=5; // PIC32 UART1 DTR pin
int RTS=4; // PIC32 UART1 RTS pin

bool dtr; // old DTR value
bool rts; // old RTS value

int baud=115200; //Default baudrate to start communication with

/* Read DTR/RTS signals sent from PC and toggle PIC32's DTR/RTS pins */
void readback()
{
  if (dtr != Serial.getDTR())
    {
      dtr = Serial.getDTR();
      if (dtr)
        digitalWrite(DTR, LOW);
      else
        digitalWrite(DTR, HIGH);

    }

  if (rts != Serial.getRTS())
    {
       rts = Serial.getRTS();

       if(rts)
          digitalWrite(RTS,LOW);
       else
          digitalWrite(RTS,HIGH);
    }
 
}


void setup() {

 //GPIO Setup:
 pinMode(DTR,OUTPUT);
 pinMode(RTS,OUTPUT);
 digitalWrite(RTS, LOW);
 digitalWrite(DTR, HIGH);
 delay(100);
 digitalWrite(RTS, HIGH);

 ANSELC = 0x00;
 LATC = LATC & (~0x04);
 TRISC |= 0x04;
// CNPUC = CNPUC & (~0x04);
 
 // Get USB DTR/RTS levels and store them for now
 dtr = Serial.getDTR();
 rts = Serial.getRTS();

 //Check for any level changes
 if (dtr) digitalWrite(DTR, LOW);
 else digitalWrite(DTR,HIGH);

 if(rts) digitalWrite(RTS, LOW);
 else digitalWrite(RTS,HIGH);

 //Set-up USB Serial port
 Serial.begin(baud);
 delay(100);
 //Setup UART1
 Serial0.begin(baud);
 delay(100);
}

void loop()
{
  /* First read the RTS/DTR levels of USB communication with PC
     Then toggle the RTS/DTR pins if any change */
     
     readback();
 
  while(Serial.available() || Serial0.available())
  {
    if (Serial.available())
    {
      Serial0.write(Serial.read());
    }
   
    if (Serial0.available())
    {
      Serial.write(Serial0.read());
    }
 
  }

  // Check if any baud changes on the USB side and change the UART1's baudrate
    if (Serial.getBaudRate() != baud)
    {
        baud = Serial.getBaudRate(); 
        Serial0.begin(baud);
               
    }
   
}

best regards
Andreas
Title: Re: How to get started with the ESP32-Pro
Post by: LubOlimex on December 14, 2021, 11:01:19 am
I have no idea why this happens and we will investigate. However, what you proposed doesn't fix it, I tested today.

Maybe the problem is either in the reset after programming or of the PIC32 pins are set improperly and affect bootstrap of ESP32.
Title: Re: How to get started with the ESP32-Pro
Post by: Bumbum on December 14, 2021, 05:50:50 pm
Hello Lub,

thank you for testing. Will you update this topic if you have found the reason?

best regards
Andreas
Title: Re: How to get started with the ESP32-Pro
Post by: LubOlimex on December 15, 2021, 08:15:54 am
For the moment, can you try using RTS or RTS/CTS flow control and let me know how it goes.
Title: Re: How to get started with the ESP32-Pro
Post by: LubOlimex on December 16, 2021, 09:35:03 am
I believe the firmware of the PIC32 that acts as serial bridge is made with RTS flow control in mind. You need to use another serial monitor software not the Arduino Serial Monitor (since I can't figure out how to change hardware flow control in Arduino Serial Monitor, maybe it is possible tho). Important! Opening Arduino IDE Serial Monitor and then closing it will probably bug the ESP32-PRO USB. My advice is to completly avoid opening or closing it when using ESP32-PRO. Just use another terminal (like PuTTY) and make sure to set RTS/CTS hardware flow control of the COM port.

Unfortunately, I don't think it would be good idea to try to fix that in the firmware of the PIC32 since this would also require changing the USB libraries for Arduino and changing those will make all other Arduino boards not working via USB.
Title: Re: How to get started with the ESP32-Pro
Post by: Bumbum on December 20, 2021, 02:01:08 pm
Hello,

sorry for my late reply. I have tested with Hyperterminal. If I set flow control to hardware it is working. After I connect I immediately receive data from the Olimex-Board. If I set flow control to "none" I get no data at all, also not after I press enter. I have to restart the Olimex board after this try to receive any data at all.

But I have not found an option to reconfigure the Arduino serial monitor to use hardware flow control. Can somebody help?

Using another terminal for debugging is of course no solution, it makes the problem even more complex. Just pressing enter in the Arduion Serial is way simpler then disconnecting from the terminal, flashing the board with the Arduino IDE and then reconnecting the terminal.

best regards
Bumbum