Page 1 of 1

ESP32 very slow with MICROPYTHON !!! ??

Posted: Thu May 19, 2022 1:29 pm
by ixbo
Hello always the same witch is a little surprised by the ESP32 with MicroPython I know that it's a language interpreted !

The time to put to 1 and return to 0 is about 10us (2*5us) , compare with a dsPIC4013 I often use in ASSEMBLER, the same thing is 70ns , about 142 time less (dsPic is old....!!)

On ESP32 the instruction "utime.sleep_us(1)" take 16us instead of 1 !!!!!!! it's important to know it !

I will generate a pulse of 10us for HC_SR04 a ultrasonic sensor, yes i can use simply pulsehigh 2 time, but is there an another way to generate a accurate time , perhaps with timer .....?

Or perhaps it will be better that I use ARDUINO's language for better performance ? what do you think about that ?

I'am frustrated by the performance of ESP32 (...with Micropython!)

Thank s very much

Best regard

Re: ESP32 very slow with MICROPYTHON !!! ??

Posted: Thu May 19, 2022 7:39 pm
by scruss
The approach for MicroPython is completely different from PIC assembler. Don't hand-roll everything. I've used that library successfully. You don't need to care how long the pulses are that you're sending. It returns the distance directly as a floating point value in centimetres.

You can measure a pulse accurately with machine.time_pulse_us()

The ESP32 port has four hardware timers, too.

Not entirely true.

Posted: Fri May 20, 2022 9:26 am
by pythoncoder
Different platforms provide their own support for fast operation. In addition to the suggestions of @scruss, ESP32 has RMT. The RP2 has the amazingly flexible PIO. Many platforms have PWM which can be used to provide stable, precise clocks with programmable frequency and duty cycle. STM32 has flexible hardware timers.

Also see the native and viper code emitters. Platforms such as STM32 and RP2 support inline assembler code.

The list goes on...

Re: ESP32 very slow with MICROPYTHON !!! ??

Posted: Sat May 28, 2022 8:32 am
by ixbo
Hello thanks for you answers....
Yes i know that the pulse width is not very important it must be > 10us but it was a surprise for me to see that an ESP32 witch is a super microcontroleur was so slow , in fact it's micropython that create this slowness...

I very happy of your answers
Best regards

Re: ESP32 very slow with MICROPYTHON !!! ??

Posted: Sat May 28, 2022 12:00 pm
by karfas
ixbo wrote:
Sat May 28, 2022 8:32 am
In fact it's micropython that create this slowness...
What did you expect from an interpreted, highly dynamic language like (micro)python? Even CPython isn't famous for its performance. It's not a surprise for me that simple function calls require a few ns.

For really time critical applications both micropython as well as the ESP32 are most likely not the right tools for the job.

Re: ESP32 very slow with MICROPYTHON !!! ??

Posted: Sun May 29, 2022 9:58 am
by ixbo
Hello thanks for your answer

I do not expect anything ,it's just a surprise for me I use most frequently ASSEMBLER with dsPIC4013 (MICRCHIP) with this language I know excatly for each instruction what happen....and speed of my code.
With these sort of language I' m very far to know what happen but it's VERY VERY rapid to make a program !
(for example I have done a drone all the code written in ASSEMBLER , all computing in 32 bit (dsPIC is 16 bit !, about 60000 lines ! , yes it's a little crazy !!! , perhaps little is not the good word !!l)

Thanks very much
Best regards

Assembler is lovely. In small doses.

Posted: Mon May 30, 2022 5:36 pm
by pythoncoder
The key to optimisation is to identify the bottlenecks and optimise only those. The beauty of MicroPython is that it enables you to do exactly that, using the techniques mentioned above.

I too have written substantial programs in Assembler, but only when there was absolutely no choice. Given a choice I'd choose an interpreted language for those parts where speed is not an issue, dropping down to C, Assembler, or specialist hardware support where necessary. How can you do that on a microcontroller? MicroPython...

Re: ESP32 very slow with MICROPYTHON !!! ??

Posted: Tue May 31, 2022 9:55 am
by andypiper
scruss wrote:
Thu May 19, 2022 7:39 pm
[*]Look at Awesome MicroPython.
Aside: we really should get that page linked more prominently from the MicroPython website and docs, I should get to work on this issue.