ESP32: Use Arduino or ESP-IDF?

ESP_igrr
Posts: 1656
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: 181
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: 20
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: 10
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: 181
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.

Who is online

Users browsing this forum: No registered users and 36 guests