Hi,
I know this is a broad question. I am kind of lost in all the microcontroller offer. I came to understand there is Atmega328, ES32, STM and others.
I am into datalogging and controlling relays and sensors. Not much into wifi, bluetooth etc. I don't need speed either. 1hz sampling is more than enough. I need low power since my system usually rely on batteries. I also need good headroom for programming with Arduino IDE. 32k is not enough.
I am ready to go the Python route or C+ but I never been there and I am afraid of the learning curve. I am happy with Arduino IDE.
What microcontroller should I buy now that I know and have played with the arduino uno?
I'd recommend ESP32. Even if you don't need WiFi it has a very good price, plenty of memory and FreeRTOS under the hood. (You can ignore FreeRTOS for now and use it as regular Arduino, but it gives you a good way for future extension).
Second choice is BluePill (STM32)
I like, for now, the ESP32. I have so far, used the Uno, Mega, Due, STM32 BluePill, and the ESP32. Of the boards I've used the Due. The ESP32 has not left me with a want of what else is there? I've wanted more out of the Uno, Mega, and STM32. My issue with the Due is it's a unwanted step child, does not get the attention it deserved and does not stand against to the ESP32 feature set.
I do recommend getting a Uno with some sort of starter kit. Go through each exercise in the starter kit, took me 8 days, and then move on to your project.
If you have a particular shield in mind, to plug into an Uno, then I also recommend an Uno. If you don't intend to use a shield, but rather build circuits to your own design on breadboard and later on PCB or strip board, then you need an Uno like a fish needs a bicycle, as they say. For breadboard prototyping, a Nano or Pro Mini is a much better choice. For battery powered data logging, a 3.3V Pro Mini could be an even better choice.
I already went the learning kit way and read a basic cookbook about arduino programming. It is a good starting point to enter the arduino world. The problem is that my first sketch (assembling block of sketches together) finally grow into a big program that work as planned but it did return this message upon compiling: 83% memory used, stability problem may occur. Then I understand that I will be limited at a point by the 32k of Uno RAM.
Knowing this I rather commit my learning curve precious time to platform that will meet my actual but also futur requirement. This is why I asked for your input.
No particular shield in mind except RTC and SD card which are mandatory. I usually used the analog pin for halfbridge sensors. I use the digital pin to control relays that turn on and off some pumps and solenoids or start sensors heating elements. I also used digital pin for Serial data, SDI12 and I2C (new for me in arduino).
The feather M0 cortex is intresting but then I realized that the interesting part is not the packaging but the M0 cortex itself. I then saw the STM which I think work with the same chip. It also report to be low power (6 uA), it is cheaper compare to a nice package feather and can work at very low and high temperature. It is indeed interesting. But maybe it is hard to program? Is it compatible with arduino IDE? How much of the chip I loose If I don't programm using Python? Should I commit to Python?
The ESP32 also look good but then the wifi will waste my power budget unless I can turn it off? Again, maybe it is not that much compatible with the arduino IDE?
The Mega is interesting with 256k of RAM and the DUE but they are large. I would be happy with a Mega chip on a nano board at a STM price!
83% memory used, stability problem may occur. Then I understand that I will be limited at a point by the 32k of Uno RAM. :
83% of RAM or Flash memory? Flash memory is where the program is stored, and does not loose its contents when power is removed or reset is pressed. RAM memory is where program variables are stored when the sketch is running, and looses it's contents when power is removed or reset is pressed. Uno has 32K Flash and 2K RAM.
I suspect the message is about Flash memory. For a beginner to create a sketch this large is unusual, and I imagine the same sketch created by a more experienced programmer would be half the size or less, and if created by a very experienced programmer, perhaps only one tenth the size. In other words, as your coding skills improve, you learn ways to write less code that does more. This not only helps fit more code into a limited space, but makes your code so much easier for you to read, develop, debug and maintain in the future.
Not all M0 cortex are the same. They have the same ARM CPU core, but the rest of the "system on a chip" can be different. STM32 chips are made by a different manufacturer than SAMD21 chips, with different designs, but both contain that same M0 ARM core. Of the two, the SAMD21 chips probably have higher compatibility with Arduino sketches and IDE, because Arduino makes boards based on these chips. They don't make any boards based on STM32, so the compatibility of boards based on those chips is probably a little lower. But 95%+ sketches will probably run fine on either chip.
The memory warning is due to RAM not flash (and you can fill every last byte of flash without any stability issues or warning), you only have 2k of RAM - but there are very simple things that you may not be doing that waste huge amounts of ram - chief among them being not using the F() macro for constant strings...
Serial.print("Hi I am a constant string") uses one byte for each character, plus one for the null terminator at the end, because it has to get copied into RAM...
Serial.print(F("Hi I am a constant string")) only uses the flash.
It really adds up fast... Of course, that may not be what's happening for you, or you may already know about that but it's worth checking (and also checking how much flash you are using... so that you know what your needs are actually like.
And obviously, I'm a big fan of the AVR128DA parts - much newer parts, and cheap compared to similarly spec'ed "classic" AVRs, with better peripherals too, but the same friendly AVR core and tight link to the peripherals.
The Arduino IDE and language is based on C++. It is not compatible with Python. Some boards can be programmed with either, but if you use Python, you won't be using the Arduino language or IDE, so essentially you are not using the board as an Arduino.
Python has many advantages. It is an interactive, interpreted language, and a higher-level language than C++. This makes it easier to write code and debug that code, whether you are a beginner or an expert.
Python's drawback is that it is far less efficient. This does not matter so much on a quad core 2GHz PC with 8GB of RAM and a terabyte of storage. On a M0 single core ARM, it still might not matter so much, depending on your application. But in general, if the same sketch is coded in Python and in C++, by a coder proficient in both languages, the Python version will run 20~50 times slower and require considerably more RAM and Flash memory than the C++ version. That's why you don't see AVR based Arduino like Uno running Python code. They just don't have the resources and speed for it, whereas they can achieve the same tasks, and do them very efficiently, running C++ code.
I recompile the program to be sure. It is the flash which is full. So the program memory. The 2k RAM is also short (70% of the 2k).
I did reduce the code but I can surely do better. There are solution on this forum including the F(). Arduino was my first step in the microcontroller world. I can do a lot of hobby build with it. If things evolve to more serious matter, I rather commit to a better controller now since I have time to learn instead of doing it latter.
The more I read about this the more I come to think I will need to learn C++ programming and then many microcontrollers will open up!
What is the opinion about STM32 + CubeMx way?
I will probably go the ESP32 + STM32 way for now and compare how hard the transition will be with one and the other.
STM is not well supported in the Arduino IDE. Yes it can be done, heck I did it, but it's a pain. I abandoned doing the STM32 thing in Arduino and gave my STM32 BluePills and other STM32 hardware to a STEM program at the local university.
It might be worth considering one of Adafruit's M4 boards. They use the 120MHz ARM Cortex M4F, SAMD51 microcontroller with on-chip 512k flash and 192k RAM that's powerful enough to run CircuitPython. In fact the boards are designed with CircuitPython in mind with additional on-board flash memory. However, it's also possible to program them with the Arduino IDE using C/C++ as well.
They also come supplied with the slick UF2 (USB File Format) bootloader that acts like a memory drive and can perform either as a standard bootloader with the Arduino IDE, or allows for drag and drop uploading using UF2 files.
The SAMD51 itself is a very flexible architecture and uses a peripheral-to-peripheral highway called the event system. This allows peripherals (ADC, DAC, timers, etc...) and the DMA to communicate and run like a clockwork machine without CPU intervention.
Register level programming support on the SAMD51 is also very good and much less painful than the STM32.