ESP32: Use Arduino or ESP-IDF?

ESP_igrr
Posts: 2067
Joined: Tue Dec 01, 2015 8:37 am

Re: ESP32: Use Arduino or ESP-IDF?

Postby ESP_igrr » Tue May 12, 2020 8:57 am

The other thing to consider when using Arduino libraries is license requirements. Arduino libraries are distributed under LGPL, so when you link them into the application, you need to do a few extra steps to comply with the license requirements. Usually this means making the rest of your application's object files available for download, so that users can re-link them with a modified version of the LGPL library. Usually this makes it impossible to deploy an application protected by flash encryption and secure boot, if an LGPL component is included. Depending on the exact definition of "professional reason", this may or may not be an issue.

juuisle
Posts: 3
Joined: Sun May 10, 2020 5:24 pm

Re: ESP32: Use Arduino or ESP-IDF?

Postby juuisle » Wed May 13, 2020 6:58 am

Thank you very much, everyone. I now have more convincing reasons to put in my report.

I wrote software for the ESP32 to sample data with the ADC and send data to the MQTT Broker yesterday. It is written with ESP-IDF freeRTOS. This is a part of my university final year project (which is a garden eco-system that includes Sensors, Actuators (controlled by ESP32), and Web server (Flask), and a Mobile App (written in Flutter), etc)

My first intention was just used some magic arduino code to run this one and focus on the other parts Web, Mobile, because the last time I wrote code in C and freeRTOS was about 2 years ago. But thanks to the ESP-IDF example and good documentation, I was able to do it and attached to this code; I want to keep improving it. Now, I feel my code is very inefficient. Could anyone please take a look and give me some feedback. Especially, the wifi connection part, this one:

Code: Select all

 wifi_connect();  // Should I placed it in an xTaskCreate()? wifi_connect() is placed under wifi.c file.

    /* Similar to vanilla freeRTOS xTaskCreate function, but can run multiple cores */
    xTaskCreatePinnedToCore(moisture_sensor_task, "moisture-sensor", STACK_SIZE, NULL, (tskIDLE_PRIORITY + 5), NULL, 0);
    xTaskCreatePinnedToCore(mqtt_publish_task, "mqtt-publish-task", STACK_SIZE, NULL, (tskIDLE_PRIORITY + 5), NULL, 1);
I'm not sure if it should be scheduled in a new Task? Or write it like this is fine. This wifi thing seems to be a very heavy task. Here is the Github link with all code: https://github.com/juuisle/zocho-ten-sensor

Thank you very much,

username
Posts: 477
Joined: Thu May 03, 2018 1:18 pm

Re: ESP32: Use Arduino or ESP-IDF?

Postby username » Wed May 13, 2020 12:06 pm

You can leave it the way you posted it, its just fine.

I will mention this though. concerning blink.c. You might want to consider moving these to into main.c, before you do anything else.
I would also add after these, gpio_set_level(BLINK_GPIO, 0); with either a 0 or a one to set the pin state to where you want it at startup.

Code: Select all

    gpio_pad_select_gpio(BLINK_GPIO);
    /* Set the GPIO as a push/pull output */
    gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT);


In the way your using blink.c its not good coding practice to setup pins every time you call that function. So you want to set those pins up right away, and when you call that function it just sets the pin state.

abansal22
Posts: 105
Joined: Wed Apr 22, 2020 8:24 am

Re: ESP32: Use Arduino or ESP-IDF?

Postby abansal22 » Wed May 13, 2020 2:15 pm

ESP_Sprite wrote:
Tue May 12, 2020 7:53 am
Also, note it's not an exclusive choice. You can use most ESP-IDF features from Arduino and you can import the Arduino library into ESP-IDF. (There still are some small downsides to both solutions: you can't use the Arduino IDE in ESP-IDF and you can't use Menuconfig from Arduino, as stated above.)
I think, using arduino as a idf component works best. We can enjoy the ease of programming in arduino and also we can get the power of the esp idf. Right now I am using the esp idf 4.0, and arduino as a component. It works fine without any problems.

juuisle
Posts: 3
Joined: Sun May 10, 2020 5:24 pm

Re: ESP32: Use Arduino or ESP-IDF?

Postby juuisle » Wed May 13, 2020 8:11 pm

username wrote:
Wed May 13, 2020 12:06 pm
You can leave it the way you posted it, its just fine.

I will mention this though. concerning blink.c. You might want to consider moving these to into main.c, before you do anything else.
I would also add after these, gpio_set_level(BLINK_GPIO, 0); with either a 0 or a one to set the pin state to where you want it at startup.

Code: Select all

    gpio_pad_select_gpio(BLINK_GPIO);
    /* Set the GPIO as a push/pull output */
    gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT);


In the way your using blink.c its not good coding practice to setup pins every time you call that function. So you want to set those pins up right away, and when you call that function it just sets the pin state.
Thank you very much, this is a great suggestion. I have renamed it to gpio.h. This new file can be used to control the pin state.

bkgoodman
Posts: 45
Joined: Fri Feb 17, 2017 12:41 pm

Re: ESP32: Use Arduino or ESP-IDF?

Postby bkgoodman » Tue May 19, 2020 2:13 pm

I just felt compelled to share my experience with the two:

I wanted to make a simple device that could speak to Amazon IoT via MQTT/SSL on ESP32. I started with Arduino IDE. It took me two weeks to find the right libraries, get them configured properly, debug some problems with the libraries off-the-shelf, and modifiy them to get them to work. During this, I also wanted to try it on ESP8622. This required installing more/different libraries, afterwhich broke my original ESP32 project. (I then had to either uninstall IDE, and find/re-install appropriate libraries, etc). I then needed to build this on a different computer, and was unable to get the exact build environment to get it to work properly. I blame this on Arduino's real lack of decent library management, namespace (library) collisions,requirement of so many ill-fitting third-party libraries, wild incompatibility between different libraries and hardware platforms. Arduino 2.0 may fix some of this - but has a cloud-based provisioning model which requires you to pay for other hardware types - so without paying I couldn't even evaluate how this works - but it was clearly not the direction I wanted to go.

After being completely frustrated with this - I downloaded ESP-IDF - and basically had the project working in about an hour.

When I then wanted to extend functionality - new peripherals, hardware devices - all the libraries were built-in, documented, had sample-code, and able to be integrated within minutes.

In short, I can't express how frustrated I am with Arduino, and how great ESP-IDF has been.

username
Posts: 477
Joined: Thu May 03, 2018 1:18 pm

Re: ESP32: Use Arduino or ESP-IDF?

Postby username » Tue May 19, 2020 2:38 pm

In short, I can't express how frustrated I am with Arduino, and how great ESP-IDF has been.
Simular issues here. I started out with Arduino only because I was new to espressif. As time moved on and I started moving on from simple hello world, toggling GPIO and so on to adding peripherals and making products I was constantly hit with issues. Namely I2C and SPI. where it would work for a few hours then just hang...

I then moved to ESP-IDF and never had one issue with I2C or SPI or anything quite frankly. Not to mention the code size was quite smaller than with Arduino.

reganb
Posts: 1
Joined: Sat Apr 10, 2021 11:02 pm

Re: ESP32: Use Arduino or ESP-IDF?

Postby reganb » Sun Apr 11, 2021 10:47 pm

Reading the above posts, it sounds like I can use the Arduino library in an eclipse project where all the other code is using the ESP-IDF plugin, right?

1 - Do I just import the Arduino library into the eclipse project and then I can use the arduino functions/objects as well as all the ESP-IDF stuff?

2 - will importing the Arduino library adversely impact any existing ESP-IDF code that was written by team members for other project functionality?

Im sorry but I am very new to this, and I am working on a team project and I am trying to code an adroid app in android studio that uses bluetooth BLE to connect to the ESP32 and I am having problems getting it to bond and connect. Finding anything to help me get the connection working is really tough, and most of the code examples Im finding with searches are done using arduino, so it seems like my chances of getting this working would be a lot better if I could try some of the arduino code examples im seeing. However, the other team members have coded all of the ESP32 hardware interfaces and logic using the ESP-IDF Eclipse Plugin and I cant adversely impact any of their code by bringing in the arduino library (if doing so causes problems with their code).

username
Posts: 477
Joined: Thu May 03, 2018 1:18 pm

Re: ESP32: Use Arduino or ESP-IDF?

Postby username » Mon Apr 12, 2021 11:14 am

Did you know that there are many examples in you ESP-IDF examples folder?
You can also see those examples here are well.
https://github.com/espressif/arduino-es ... /libraries
https://github.com/espressif/esp-idf/tr ... r/examples

hichol
Posts: 1
Joined: Sun May 09, 2021 12:25 pm

Re: ESP32: Use Arduino or ESP-IDF?

Postby hichol » Sun May 09, 2021 12:47 pm

I have one question does ESP-IDF gives me better performance than Arduino, for example native sample code Face Detection it works but performance is so bad I can't use it other then prove of concept, ESP-IDF is going to improve on performance face detection, I mean frame rate of 1 or 2fps and most time it's less than that with Arduino.
Anyway I thank you guys for all the excellent work you done, brought us the high technology so low cost.

Who is online

Users browsing this forum: Baidu [Spider] and 116 guests