I would like to see pyXod. Xod that used Python code instead of C++.
I’m just a hobbyist, not a professional programmer or anything. I like micropython for programming microcontrollers, I find it easy to understand and it’s possible to get a lot done with not many lines of code.
I started with C and that was okay. I tried to learn C++ once, but gave up pretty quickly. The syntax is way too complex for me, C++ code might as well be in Swahili as far as I’m concerned.
Anyway, just my two cents worth.
Ні @mogplus8 ! That’s an interesting thought… In a way, it might make ARM controllers easier. Are you using micro Phyton to program stm32 only or other boards? Tell us what environment you are using and where you got the information about working with it
I’ve used Micropython on a Weact Black Pill, which has an STM32F411 processor, and it runs a treat. I’ve also used it on a few different ESP32 boards, also with no problem. I’ve never tried the wifi or bluetooth functionality of the board though as my project doesn’t need it. It also works really well on Raspberry Pi Pico, and supports its Programmable I/O feature nicely.
I use Thonny for programming. I’ve tried a few other IDEs; Pycharm, VS code with RT-thread extension (not great) and MicroPico extension, (which is very good but only for RPi Pico), and Arduino Micropython). They are all good, but Thonny is the simplest and most reliable imho. Pycharm is good but it’s a professional level IDE, and does way more than I need, so I found a lot of the extra functionality got in the way rather than helping. My programs are pretty simple!
There is a lot of information on the net about Micropython, lots of terrific forums and more documentation than you can poke a stick at. It’s available for many different platforms too. If you go to micropython.org/downloads they are all listed there.
There is another popular version too, called Circuitpython, which I believe is managed by Adafruit. I had a look at it once, but I was already well into Micropython by then, and Circuitpython didn’t seem to be as comprehensive as Micropython. But to be honest, I didn’t look that hard.
Hello @mogplus8. It’s an interesting experience, you even intrigued me. I will definitely try to visit Thonny and try something new. I would like to request you to share your experience with stm32 through XOD ide. I saw you spent a long time trying to get stm32 to work with xod ide. What are the successes, and what can you advise in this regard? The ESP32 is currently working great for me in the XOD ide. And I haven’t tried stm32 yet. Sincerely, Nazar.
That was a while ago. I think it’s about two or three years since I last played with xod. I really like the concept of xod, for all sorts of reasons. To be honest, I don’t remember exactly why I gave up on it, maybe to do with trying to write code in C++ without really knowing C++? I’m an old school programmer (I used to program in Cobol on IBM mainframes) so I ended up going back to what I know.
Sorry I can’t be more help. :-
PS. I tried another tool similar to xod around the same time, but I’m not sure if it’s still being maintained. It’s called Embrio. The website is embrio.io. It had some good ideas too.
Just as an example, consider the following.
I am using the RMT module in an ESP32 to generate a PPM output stream. (It’s for a radio control transmitter). PPM consists of a series of pulses between 1000us and 2000us, with a much longer “sync” pulse to terminate the “frame”. The space between pulses is always 300us. A frame of eight pulses plus sync pulse is fixed at 22,500us.
In Python it can be done very simply. This is the code.
from esp32 import RMT
from machine import Pin
rmt = RMT(0, pin=Pin(18, Pin.OUT), clock_div=80)
chanPulse = [1000,2000,1000,2000,1000,2000,1000,2000] # eight channel receiver
for i in range(200):
duration = ()
for val in chanPulse:
duration = duration + (val, 300)
syncPulse = 22500 - sum(duration) - 300
duration = duration + (syncPulse, 300)
rmt.write_pulses(duration, True)
So how does it work.
- import some libraries. This is like the #include directive in C.
- define the rmt object, giving the output pin and frequency (the clock runs at 80MHz so the value of 80 gives a 1MHz frequency for the rmt object.
- chanpulse contains a list of output pulse widths in microseconds. These can be modified anywhere else in the program before writing the output stream to the output pin (18 in this case). Note this is a Python “list”, defined with square brackets. It is ordered and mutable.
- For this test the program writes out 200 frames. The final program would of course loop forever. In Python this is typically written as “While True:” which is equivalent to the “void loop() {” construct in C.
- RMT requires the input to be a Python “tuple”, defined with round brackets, and is of the form n1, 300, n2, 300, etc. where n1, n2, etc are the pulsewidths from chanpulse, and 300 is the 300us “space” between the pulses. Tuples are ordered and immutable.
- write the frame to the rmt object, in one simple statement.
This is the output.
I had a look at the code required to do this in C or C++, with the idea or maybe having a go at creating a xod module to do the same thing. But pages and pages of reading through technical descriptions soon convinced me that it would be a project that would take me days or weeks, and would require me to once more dive into the quagmire of C++. For anybody interested the documentation is here. Good luck.
Of course, Python has its own learning curve, and its own quirks, foibles and limitations, and its own way of thinking about problems and programming solutions. But for me, the effort of learning it has paid off handsomely. I wouldn’t go back to C unless I had a very, very good reason to, and C++ will be a closed book to me forever.
The other consideration of course is performance. Python is an interpretive language, and not a “bare metal” language like C or C++. It won’t run on an Arduino Uno. But with current microcontrollers like the STMF4xx and ESP32xx processors, the performance difference is negligible for all but the most compute intensive applications.
Just my two cents worth.
Your code really looks pretty self-explanatory. Looking at this, I thought about how to implement a chain of microsecond pulses through nodes running on C++. For starters, I would work on an Arduino uno and try to modify the node from Mr. @wayland’s library: wayland/rectangular-waveform — XOD Eventually, I would also create an array of values and a “for” loop (in C++) in this node. However, this is not actually the shortest path…
Hi Nazar,
I had a brief look at this module. I created a new project that contained just the example and tried to run it on a Teensy 4.1, but in the list of boards there was no Teensy, and no ESP32 either. So I’m guessing I have to install something else to run it on either of those. Or a Blackpill, or Pi Pico, or…
If we talk about this library(wayland/rectangular-waveform — XOD) in particular, then it was created by itself for arduino, in particular, arduino uno, nano and others. As for the addition of the esp32 board in xod ide, here are the instructions according to which I did it…Access ESP32 non-volatile storage using XOD - Hackster.io. There at the beginning there is a description of how to add the esp32 to the list of boards. By the way, I intend to try working with the Pi Pico in XOD IDE. I wonder if everything will work fine in xod for this board.