Author Topic: Getting started with microcontrollers  (Read 7666 times)

0 Members and 2 Guests are viewing this topic.

Offline soldarTopic starter

  • Super Contributor
  • ***
  • Posts: 3166
  • Country: es
Getting started with microcontrollers
« on: March 14, 2024, 02:29:44 pm »
I have experience with older digital chips, soldering, some basic programming, but I have no knowledge or experience with MCUs and I would like to get started if i can do it very easily.

I see on Amazon tiny boards things like
DEVMO Digispark Kickstarter ATTINY85 General Micro USB Development Board Module Compatible with Arduino
Ximimark Digispark Kickstarter Mini ATTINY85 USB Development Board Module for Arduino IDE 1.00

Is this something I can plug into my Linux computer, do some simple programming and get it to do something practical?

Should I choose something else? Should I forget it?
All my posts are made with 100% recycled electrons and bare traces of grey matter.
 

Online MarkF

  • Super Contributor
  • ***
  • Posts: 2550
  • Country: us
Re: Getting started with microcontrollers
« Reply #1 on: March 14, 2024, 03:11:26 pm »
Unless you are looking for absolutely the smallest microcontroller out there, I would recommend one of the more basic Arduino boards as a general purpose starter.  With 8 pin micro's you're always going to be fighting the small pin count for driving peripherals.

Also, the Uno for example is often used as a programmer.  I actually got one to re-program my 3D printer and never used it since.  It would be a good platform to learn on.  Most of the micro's I've been using are Microchip PICs.  But then, I have 35+ years of programming experience on all kinds of platforms and languages and an E.E. degree.  I don't think I would recommend a PIC for a beginner unless you have a specific use case in mind.

I suggest one of these instead:
  https://store-usa.arduino.cc/products/arduino-uno-rev3?selectedStore=us
  https://store-usa.arduino.cc/products/arduino-nano?selectedStore=us
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11262
  • Country: us
    • Personal site
Re: Getting started with microcontrollers
« Reply #2 on: March 14, 2024, 03:16:44 pm »
Don't bother with those small boards. They use software USB implementation and generally annoying. Just get a real Arduino or a full clone.
Alex
 
The following users thanked this post: Ian.M

Offline calzap

  • Frequent Contributor
  • **
  • Posts: 448
  • Country: us
Re: Getting started with microcontrollers
« Reply #3 on: March 14, 2024, 04:01:03 pm »
I agree with previous comments.  Start with genuine Arduino.   It’s cheap, there are lots of tutorials, and the support network is vast.

Mike
 

Offline Picuino

  • Frequent Contributor
  • **
  • Posts: 730
  • Country: 00
    • Picuino web
« Last Edit: March 14, 2024, 04:18:41 pm by Picuino »
 

Offline RoGeorge

  • Super Contributor
  • ***
  • Posts: 6203
  • Country: ro
Re: Getting started with microcontrollers
« Reply #5 on: March 14, 2024, 04:42:03 pm »
Doesn't has to be genuine Arduino, that's about 10 times more expensive for the same microcontroller.  Any other clone would do it.  For the small, 8 bits, I like "Arduino nano" because has the same ATmega328 microcontroller as the Arduino UNO, but has more pins exposed, and what's the most important, nano has 0.1'' connector pins that can be fitted in a breadboard, which comes very useful for anything else than just blinking the onboard LED.

The green devboard on the right hand side is an Arduino nano plugged in a breadboard, together with a few other parts and two other breakout boards (not Arduino) controlled by the Arduino nano.


Pics from https://hackaday.io/project/7542-rogeorge-cell

Whatever model you buy, make sure it has a separate chip for USB to serial (another big IC on the board, apart from the microcontroller itself), because it makes the life easier in the long run.  CH340 is fine, doesn't have to be with FTDI because the FTDI chip alone is more expensive than the entire Arduino (because genuine FTDI chips have some extra features, but Arduino boards never make use of those extra features - they are not needed for an Arduino).

I've just look on Aliexpress and the price for an Arduino nano board is somewhere between $0.5 (some promotion, e.g. https://www.aliexpress.com/item/1005005702204423.html ) and $3...$5 a devboard Arduino nano with CH340G as USB bridge and ATmega328P microcontroller.



Another thing you may want to know, the word "Arduino" means 2 things, depending on the context.
- the Arduino IDE (software) - aka the editor, compiler and other software libraries needed to make use of the devboard
- the Arduino board (hardware) - the PCB where your microcontroller and programmer are

The funny thing is that the same "Arduino" software can work with many and various "Arduino" hardware for all kind of microcontrollers.  Arduino nano (or UNO) are based on the ATmega328 microcontroller from Atmel (now Microchip), and is one of the most popular MCU (Micro Controller Unit) used in the Arduino world.



Another interesting MCU might be ESP32.  ESP32 can be programmed with the Arduino IDE, has Wi-Fi, it is a bigger and more powerful MCU, and has some other goodies like for example it can be programmed directly in microPython (without Arduino).

There are many other boards with various MCU types and various prices.  Start with something that is $5-10 top at first, don't look for max memory or max speed - those parameters are irrelevant for learning microcontrollers.
« Last Edit: March 14, 2024, 05:07:38 pm by RoGeorge »
 

Offline mariush

  • Super Contributor
  • ***
  • Posts: 5029
  • Country: ro
  • .
Re: Getting started with microcontrollers
« Reply #6 on: March 14, 2024, 05:03:37 pm »
I agree with the others as well...  an arduino is a good start.

Also get some PIC16F or PIC18F chips and the programmer, a $40 microchip Snap - https://www.digikey.com/en/products/detail/microchip-technology/PG164100/9562532 or directly from microchip https://www.microchip.com/en-us/development-tool/pg164100 - or clones of Pickit 3 / 4 from eBay if you want cheaper ... but $40 is really not that much for something you may use for 10+ years.

You can program not only PIC microcontrollers but also atmega mcus (what was on original arduino) with the programmer, now that atmel is owned by Microchip.

I actually bought PICkit and some pics on purpose instead of arduino because it was more interesting to not follow the crowd and there's a wider variety of pic chips. It also forced me to actually search for some online tutorials and adapt them to my needs and pick up the language and microcontroller features faster.

 
 

Offline Picuino

  • Frequent Contributor
  • **
  • Posts: 730
  • Country: 00
    • Picuino web
Re: Getting started with microcontrollers
« Reply #7 on: March 14, 2024, 05:34:32 pm »
I love PIC microcontrollers because of their peripherals of all kinds and very complete. But I don't think it's a good option to start with. Rather for medium / advanced users.
 

Offline soldarTopic starter

  • Super Contributor
  • ***
  • Posts: 3166
  • Country: es
Re: Getting started with microcontrollers
« Reply #8 on: March 14, 2024, 05:43:08 pm »
Thanks for the replies. 

Some background: About 50 years ago I had a 6502 board and I did quite a bit with it, all programming in assembler.  Then about 30 Years ago, with PCs, Windows, etc I lost the ability to interface with the real outside world and i kept thinking how I could do it. About 25 years ago I bought a Velleman K8055 board,
https://www.velleman.eu/products/view/?country=uk&lang=en&id=351346
which I still have, but I never did much with it after my first playing around. It was programmed with Visual Basic or Visual Something, which I had to learn for the occasion and which I was told was not worth spending any effort on because it was already a dead language, discontinued by MS. I still have it but I do not remember anything about Visual Basic and it is probably not worth any effort. If anyone has any advice on this I like to hear it. All I can do for now is record several digital and analog inputs to a text file. I can know if someone rang my bell while I was away and at what time.

So for the last 20 years I have been thinking I should learn Arduino but I never got a round tuit. So here I am, 20 years later.

OK, so suppose I order the most popular and recommended choice, which seems to be the Arduino "classic" Uno Rev3 for $27.60 in Amazon (plus Danegeld)
https://www.amazon.com/Arduino-A000066-ARDUINO-UNO-R3/dp/B008GRTSV6/ref=sr_1_1_sspa

OK, I have it, I plug in a power supply (5V I assume) and I pug in the USB to my Linux Mint computer.  Now what? I assume i need to download some programming software. Yes?

Then what? Can you give me a step by step intro on how I would do a simple task?

Also, once programmed with USB I am assuming the Arduino is totally autonomous (as long as it has power). Yes?

While the USB is connected does it get power from there?

The main question is how is it programmed? What language does Arduino use? 
Where can I find simple tutorials with simple projects for learning and exercise?

Suppose I want to do a simple task like implement an AND function: read two switches and activate an output when both are closed. How would I do that?

I guess I'll go ahead and get the Arduino Uno R3. the worst that can happen is that it ends up doing nothing, just like the Velleman K8055.
All my posts are made with 100% recycled electrons and bare traces of grey matter.
 

Offline ozcar

  • Frequent Contributor
  • **
  • Posts: 322
  • Country: au
Re: Getting started with microcontrollers
« Reply #9 on: March 14, 2024, 07:17:41 pm »
...
Suppose I want to do a simple task like implement an AND function: read two switches and activate an output when both are closed. How would I do that?

Code: [Select]
void loop()
{
    digitalWrite(ledPin, digitalRead(buttonPin1) & digitalRead(buttonPin2);
}

Not hard, was it? OK, there is a bit of setup required which is missing there, but that is really just a bit of an extension of one of the many "official" examples - https://docs.arduino.cc/built-in-examples/digital/Button/
 

Offline Picuino

  • Frequent Contributor
  • **
  • Posts: 730
  • Country: 00
    • Picuino web
Re: Getting started with microcontrollers
« Reply #10 on: March 14, 2024, 07:17:51 pm »
You can power the board with the USB or, also, with a power supply of more than 7 volts.

The programming language is C with some C++, which are very standard languages and very popular in the microcontroller world.
 

Offline Picuino

  • Frequent Contributor
  • **
  • Posts: 730
  • Country: 00
    • Picuino web
Re: Getting started with microcontrollers
« Reply #11 on: March 14, 2024, 07:22:31 pm »
...
Suppose I want to do a simple task like implement an AND function: read two switches and activate an output when both are closed. How would I do that?

Code: (c) [Select]
void loop()
{
    digitalWrite(ledPin, digitalRead(buttonPin1) & digitalRead(buttonPin2);
}

Not hard, was it? OK, there is a bit of setup required which is missing there, but that is really just a bit of an extension of one of the many "official" examples - https://docs.arduino.cc/built-in-examples/digital/Button/

More readable and complete:


Code: [Select]
#define buttonPin1 3
#define buttonPin2 4
#define ledPin 5

void setup() {
    pinMode(buttonPin1, INPUT_PULLUP);
    pinMode(buttonPin2, INPUT_PULLUP);
    pinMode(ledPin, OUTPUT);
}

void loop() {
    boolean in1, in2, out;
    in1 = digitalRead(buttonPin1);
    in2 = digitalRead(buttonPin2)
    out = in1 & in2;
    digitalWrite(ledPin, out);
}
« Last Edit: March 14, 2024, 07:25:41 pm by Picuino »
 
The following users thanked this post: Old Printer

Online pcprogrammer

  • Super Contributor
  • ***
  • Posts: 3710
  • Country: nl
Re: Getting started with microcontrollers
« Reply #12 on: March 14, 2024, 07:27:44 pm »
OK, I have it, I plug in a power supply (5V I assume) and I pug in the USB to my Linux Mint computer.  Now what? I assume i need to download some programming software. Yes?

When connected to the computer via USB you don't have to power it with a separate supply. It uses the 5V from the USB connection.

Then what? Can you give me a step by step intro on how I would do a simple task?

There are lots of sites to help you with this. Like this one.

Also, once programmed with USB I am assuming the Arduino is totally autonomous (as long as it has power). Yes?

Yes once programmed the program remains in the internal flash memory of the MCU. Disconnect it from USB and connect another power supply to it and it will start your program.

While the USB is connected does it get power from there?

Yes. See above.

The main question is how is it programmed? What language does Arduino use? 
Where can I find simple tutorials with simple projects for learning and exercise?

The Arduino IDE available on Linux and Windows and probably MAC works with C++ but standard C also does the trick.

To program it, connect it to the computer via USB and use the tools from the IDE to program it. For this to work the Arduino has a preprogrammed boot loader. There is also an other way to program it with a so called USBASP dongle. With this you can program a blank MCU that does not have a preprogrammed boot loader in it.

Examples can be found al over the net.

Suppose I want to do a simple task like implement an AND function: read two switches and activate an output when both are closed. How would I do that?

This requires reading digital pins and writing to an other digital pin. There is a extensive reference online. Lots of samples can also be found on how to do this.

I guess I'll go ahead and get the Arduino Uno R3. the worst that can happen is that it ends up doing nothing, just like the Velleman K8055.

That is true. Take a look at this thread on how CharlotteSwiss started with Arduino.

Offline ozcar

  • Frequent Contributor
  • **
  • Posts: 322
  • Country: au
Re: Getting started with microcontrollers
« Reply #13 on: March 14, 2024, 08:09:35 pm »
...
Suppose I want to do a simple task like implement an AND function: read two switches and activate an output when both are closed. How would I do that?

Code: (c) [Select]
void loop()
{
    digitalWrite(ledPin, digitalRead(buttonPin1) & digitalRead(buttonPin2);
}

Not hard, was it? OK, there is a bit of setup required which is missing there, but that is really just a bit of an extension of one of the many "official" examples - https://docs.arduino.cc/built-in-examples/digital/Button/

More readable and complete:


Code: [Select]
#define buttonPin1 3
#define buttonPin2 4
#define ledPin 5

void setup() {
    pinMode(buttonPin1, INPUT_PULLUP);
    pinMode(buttonPin2, INPUT_PULLUP);
    pinMode(ledPin, OUTPUT);
}

void loop() {
    boolean in1, in2, out;
    in1 = digitalRead(buttonPin1);
    in2 = digitalRead(buttonPin2)
    out = in1 & in2;
    digitalWrite(ledPin, out);
}

More complete I will accept, but more readable I'm not so sure about.

Either the concise or verbose versions might require some trivial tweaking to take into account the way things are wired up (the official button example uses an external pulldown resistor for the buttton, not the internal pullup).  But then if the problem as stated was really all that was required you could save an input pin by just wiring the two switches in series.

 

Offline MarkT

  • Frequent Contributor
  • **
  • Posts: 367
  • Country: gb
Re: Getting started with microcontrollers
« Reply #14 on: March 14, 2024, 08:17:05 pm »
The Raspberry Pi Pico microcontroller board is worth considering as its very cheap, and has support under the Arduino toolchain for C++ as well as microPython.
There's also a version with WiFi and BLE called the Pico W.
 

Online MarkF

  • Super Contributor
  • ***
  • Posts: 2550
  • Country: us
Re: Getting started with microcontrollers
« Reply #15 on: March 14, 2024, 08:36:36 pm »
I didn't see that anyone pointed you to the Arduino IDE
   https://www.arduino.cc/en/software

Since you're using Linux, you can use either version: 
   Arduino IDE 2.3.2 (near the top)
or Arduino IDE 1.8.19 (near the bottom)

I've only used the older version because I'm still running Windows 7.
Either is okay.

As part of the IDE, there are many examples built-in.
I suggest you start with the Basics -> Blink to blink the on-board LED
just to verify you have the toolchain installed correctly and the Uno connected right.

The programming language is C/C++.

A peripheral that might be a lot of fun is a small OLED.
I used this Waveshare 1.5inch RGB OLED in several of my projects and Adafruit provided
an Arduino library to drive it.  (Although, I would suggest some changes if you get one because
their configuration maxes out the brightness.  Totally unnecessary and I suspect it will shorten its life.)
_______________________________________________________________________

@MarkT suggested the Raspberry Pi Pico.
If you want to go that route, I can point you to many hours of lectures from Cornell Univ.
 

Offline zilp

  • Regular Contributor
  • *
  • Posts: 206
  • Country: de
Re: Getting started with microcontrollers
« Reply #16 on: March 14, 2024, 09:22:52 pm »
I guess it should be noted that you don't have to use the arduino IDE/tools for developing for the "classic" arduinos (i.e., Atmega168/328 based ones). The underlying compiler is gcc for AVR, which you can use directly, and programming is done using avrdude, which you also can use directly. Both ot those also probably are available as packages from your distribution.
 

Online MarkF

  • Super Contributor
  • ***
  • Posts: 2550
  • Country: us
Re: Getting started with microcontrollers
« Reply #17 on: March 14, 2024, 11:05:08 pm »
I guess it should be noted that you don't have to use the arduino IDE/tools for developing for the "classic" arduinos (i.e., Atmega168/328 based ones). The underlying compiler is gcc for AVR, which you can use directly, and programming is done using avrdude, which you also can use directly. Both ot those also probably are available as packages from your distribution.

Why in the world would you want to do all that extra work?    :-//

Beginners don't want to learn all that on top of writing a little bit of code.

Isn't the whole purpose of the Arduino environment and it's libraries to hide everything and
have all the work done by it's libraries so that programmers don't have to think any more?    :-DD
 
The following users thanked this post: pcprogrammer

Online radiolistener

  • Super Contributor
  • ***
  • Posts: 3381
  • Country: ua
Re: Getting started with microcontrollers
« Reply #18 on: March 15, 2024, 01:50:01 am »
this board is too small and has small value.

It's better to buy bluepill or blackpill STM32 board for simple and cheap MCU learning and startup.

Here is also another blackpill borad which is better suited for Digital Signal Processing:
https://www.aliexpress.com/item/1005005303669884.html

it is more fast and has ADC and DAC and hardware support for floating point calculations
« Last Edit: March 15, 2024, 01:51:55 am by radiolistener »
 

Online pcprogrammer

  • Super Contributor
  • ***
  • Posts: 3710
  • Country: nl
Re: Getting started with microcontrollers
« Reply #19 on: March 15, 2024, 07:42:20 am »
The OP stated to be a beginner in the field of microcontrollers, so why advice the more complex ones to him.  :-//

The atmega328 used on the Arduino is reasonably simple to get started with even on a lower level, like directly using the peripherals. It is better to learn from this one first before stepping into the ones with more complex peripherals and less explicit documentation, let alone dual core processors.

Sure they can be used with the Arduino IDE but the hunt for libraries can be tricky and at first the programs will be similar to what will be done on the Arduino Uno and the additional speed won't matter.

Offline soldarTopic starter

  • Super Contributor
  • ***
  • Posts: 3166
  • Country: es
Re: Getting started with microcontrollers
« Reply #20 on: March 15, 2024, 08:06:20 am »
Thanks for all the replies. I think I will start by getting the Arduino Uno REV3 and go from there. I should have no problem interfacing hardware as I am very familiar with that kind of thing. The big hurdle is that I need to learn C and/or C++. I will have to find some tutorials and start practicing. We shall see if I can do it or if it proves to be more effort than I am willing to do.
All my posts are made with 100% recycled electrons and bare traces of grey matter.
 

Offline brucehoult

  • Super Contributor
  • ***
  • Posts: 4039
  • Country: nz
Re: Getting started with microcontrollers
« Reply #21 on: March 15, 2024, 09:31:40 am »
Thanks for all the replies. I think I will start by getting the Arduino Uno REV3 and go from there. I should have no problem interfacing hardware as I am very familiar with that kind of thing. The big hurdle is that I need to learn C and/or C++. I will have to find some tutorials and start practicing. We shall see if I can do it or if it proves to be more effort than I am willing to do.

You really don't need to know much at all of C/C++, at least at first. Just look at the provided examples in the Arduino IDE and copy and modify what they do.

They provide two functions, setup() and loop() which are, respectively, run once at the start of the program, and run repeatedly forever.

For the most part, all you have to do is declare a few global variables to represent the current state of your system, initialise them, and update them in loop().

You'll get a long way just doing arithmetic on your variables, assigning new values to them, calling library functions to read or set GPIO pins or get the current time, and a bit of if/then/else.

You're probably not going to have to write any of your own loops, or functions (at least until your programs gets large), or use arrays or any other complex data structures.

 

Offline paulca

  • Super Contributor
  • ***
  • Posts: 4055
  • Country: gb
Re: Getting started with microcontrollers
« Reply #22 on: March 15, 2024, 10:34:45 am »
Agree with others.  Those tiny boards with 8 pin chips are very limited in their application.

When I first used the ATTiny85 for example, I needed a small footprint to run 100 RGB LEDs.  However, once that 8 pin chip was in the bread board, I had to use the normal "Uno" board as the programmer.  You can run a programmer sketch or you can just pop the IC out of the Uno are jury rig it's programmer into the ATTiny.

Starting with Arduino 99% of the C/C++ code you will need for "single task projects" will be a matter of copy and paste or just ask ChatGPT.

The only time you will need to start learning C/C++ is when you want to combine several of those "single task projects" off of websites.  Even then, you will find hundreds of examples of people demostrating "super looping" for multi-tasking even if they don't call it that.

From those basic arduino platforms the sky is the limit.  Consider that the Arduino code framework is supported on a wide range of MCUs.

For practical, modern, IoT style projects the ESP8266 and ESP32 chips run the same Arduino core with very little adaption, but come with the likes of Wifi and Bluetooth support... for a "fiver".
"What could possibly go wrong?"
Current Open Projects:  STM32F411RE+ESP32+TFT for home IoT (NoT) projects.  Child's advent xmas countdown toy.  Digital audio routing board.
 
The following users thanked this post: Aldo22

Offline MrAl

  • Super Contributor
  • ***
  • Posts: 1440
Re: Getting started with microcontrollers
« Reply #23 on: March 15, 2024, 10:54:25 am »
I have experience with older digital chips, soldering, some basic programming, but I have no knowledge or experience with MCUs and I would like to get started if i can do it very easily.

I see on Amazon tiny boards things like
DEVMO Digispark Kickstarter ATTINY85 General Micro USB Development Board Module Compatible with Arduino
Ximimark Digispark Kickstarter Mini ATTINY85 USB Development Board Module for Arduino IDE 1.00

Is this something I can plug into my Linux computer, do some simple programming and get it to do something practical?

Should I choose something else? Should I forget it?


Hello there,

This is a question I see come up a lot on the web.

I've programmed all kinds of platforms including the 8008 CPU, 8080 CPU, Z80 CPU, and built dev boards for both the 8080 and Z80.  Also programmed for the 386 and 486 CPU's which were the basis of modern CPU's.  I've also programmed in various computer languages, and notably in C and C++ for the Windows platform.  I've also programmed various Arduino devices such as the Uno and Nano and Leonardo and Due and others that have a huge number of i/o pins.

After all that, I have to strongly recommend the Arduino Uno or the Arduino Nano as a starting device.  There are a lot of reasons for this mostly because there are a TON of examples that come with the IDE, and there is a wealth of online help and a forum just for those devices and Arduino in general.  It's hard to beat that.
The PIC chips are nice, but it's harder to get started with those probably because for a lot of projects you have to study the chip you want to use very carefully.  A big drawback I think is that the PIC chip online help forum is not nearly as consistent as the Arduino forum.  I programmed a lot with the PIC chips and one day I went to look up a new PIC chip that came out and the entire forum was GONE.  All those old notes and old posts were completely wiped out and replaced with a new forum so the old stuff was all gone.  That was a silly thing to do.  That probably came in with the acquisition that brought Atmel and Microchip together, but it was a very stupid thing to do.  The chips themselves are pretty good though, but will take more reading to understand properly.
I'd wait on that though if I was just getting into uC chips.

So first recommendation is the Uno, followed closely by the Nano, then after some experience you can start to move to other platforms.  It's good to know C and C++ but you can pick that up when you start with the Uno.  There are many examples you can study and ask about online.

I'd mention some of the applications I did but they are too numerous to list here.  It's just that you can do so, so, so, much with a microcontroller chip that you could not do with discrete logic chips or just analog.  If you come from that background, you will find an entirely new world of applications that you could create that you can get going in a few days or less.  It's like an entirely new paradigm in project creation and building.
 

Online pcprogrammer

  • Super Contributor
  • ***
  • Posts: 3710
  • Country: nl
Re: Getting started with microcontrollers
« Reply #24 on: March 15, 2024, 11:24:54 am »
Thanks for all the replies. I think I will start by getting the Arduino Uno REV3 and go from there. I should have no problem interfacing hardware as I am very familiar with that kind of thing. The big hurdle is that I need to learn C and/or C++. I will have to find some tutorials and start practicing. We shall see if I can do it or if it proves to be more effort than I am willing to do.

Check out this site. You can skip the IDE part but W3 school takes you through the process of creating programs in lots of languages.

Also some other sites here and here.

Offline Psi

  • Super Contributor
  • ***
  • Posts: 9953
  • Country: nz
Re: Getting started with microcontrollers
« Reply #25 on: March 15, 2024, 11:38:39 am »
Thanks for all the replies. I think I will start by getting the Arduino Uno REV3 and go from there. I should have no problem interfacing hardware as I am very familiar with that kind of thing. The big hurdle is that I need to learn C and/or C++. I will have to find some tutorials and start practicing. We shall see if I can do it or if it proves to be more effort than I am willing to do.

Arduino is good in that it hides all the hard things away by doing them for you. You can focus on learning how to program in C without having to deal with the low level hardware control stuff.
 

Greek letter 'Psi' (not Pounds per Square Inch)
 

Online tooki

  • Super Contributor
  • ***
  • Posts: 11550
  • Country: ch
Re: Getting started with microcontrollers
« Reply #26 on: March 15, 2024, 01:16:32 pm »
Thanks for all the replies. I think I will start by getting the Arduino Uno REV3 and go from there. I should have no problem interfacing hardware as I am very familiar with that kind of thing. The big hurdle is that I need to learn C and/or C++. I will have to find some tutorials and start practicing. We shall see if I can do it or if it proves to be more effort than I am willing to do.

Arduino is good in that it hides all the hard things away by doing them for you. You can focus on learning how to program in C without having to deal with the low level hardware control stuff.
Yep. Yet it doesn’t stop you from going deeper if and when you need to. (Arduino opponents often overlook the fact that you can choose to not use the Arduino functions whenever you like.)
 

Online tooki

  • Super Contributor
  • ***
  • Posts: 11550
  • Country: ch
Re: Getting started with microcontrollers
« Reply #27 on: March 15, 2024, 01:32:24 pm »
Thanks for all the replies. I think I will start by getting the Arduino Uno REV3 and go from there. I should have no problem interfacing hardware as I am very familiar with that kind of thing. The big hurdle is that I need to learn C and/or C++. I will have to find some tutorials and start practicing. We shall see if I can do it or if it proves to be more effort than I am willing to do.
Take it from me, someone who is NOT a gifted programmer: if I can learn Arduino (and thus C/C++) and make it do nice things (and from there, also learn to program in C/C++ on other MCUs, like PIC and STM32, in other IDEs), then practically anyone who can think logically can!

An Arduino Uno R3 or a Mega 2560 (essentially identical, but with way more IO pins) is a great way to start.

“Arduino” actually encompasses three things:
1. A family of microcontroller dev boards
2. The Arduino framework, i.e. the layer of Arduino commands (which are really just shortcuts) on top of more-or-less standard C++
3. The Arduino IDE, i.e. the text editor used to write and upload the code

None of these is mandatory — you can use Arduino boards with other IDEs and frameworks; you can use the Arduino framework with tons of non-Arduino boards; you can use the Arduino framework with other IDEs. (The only exception is that the Arduino IDE only supports the Arduino framework.) Beginners typically start using all three, then often migrate to more powerful boards, but still using the Arduino IDE. More advanced users then often migrate to another IDE.

I mostly use the Arduino framework running on ESP32 boards, using the PlatformIO IDE. :) But I’ve also played around with STM32 and Rpi Pico boards, all using the Arduino framework. At work I had to design a device around a PIC, and at school we had to use STM32, but without Arduino. Again, if I can learn it, so can you!
 

Online BTO

  • Frequent Contributor
  • **
  • Posts: 255
  • Country: au
Re: Getting started with microcontrollers
« Reply #28 on: March 15, 2024, 11:16:11 pm »
Hi mate,
I have exhausted the living crap out of studying the different boards AND I CAN ADVISE YOU PRETTY RELIABLY AS FOLLOWS

1. You're a beginner , so that needs to be kept in mind
(as others have stated you don't necessarily need to use Arduino IDE for programming) now while this is correct, You should start on Arduino IDE.

2. DECIDING WHICH BOARD TO GO FOR
Well, first this a question of .. What do you want to do ? However no beginner knows what they want to do , they usually just play with LED Strips for the most part , Sure, do that for a few days, then.. Move onto some more constructive that you'll actually learn from.

So as for the Boards,  Your first basic choices are... Do you want to go down the Raspberry Pi road (i would advise NO unless you can give me a reason why not.
so LET'S NOW TALK ABOUT THE OTHER DEV BOARD OPTIONS
You have a lot of choice, TeensyDuino, Arduino, Uno, Nano ,Mega, micro etc etc then all the other boards out there

HERE IS THE SUMMARY
You have 2 basic choices,
ARDUINO UNO
ESP32 WROOM

THE BETTER CHOICE IS THE ESP32 WROOM

This thing is so cheap it's not funny
On top of that , You have Dual core processing (You will thank me for this later)
You can do everything that you can do on Arduino, on an ESP32 Board
You can use the same language, write the same program (Except ESP32 has some MINOR Modifications)  Not a big deal, ok

3. Now you don't want to be someone that just flips through sketches and loads them all the time, You want to know how to have some basic programming skills


STEP 1 - Go to this link and the do the basic programming course with the ESP32 and Arduino IDE loaded , so you can follow along , that way you'll understand program structure
and how things work.

Start here
https://startingelectronics.org/software/arduino/learn-to-program-course/01-program-structure-flow/


STEP 2 - Your basic "Bare Minimum" Code for Arduino Is going to look like this
Here is a format that i use for myself and when teaching students.
Code: [Select]
/*
 GLOBAL FUNCTIONS AND VARIABLES

///////////////////////////////////////////////////////////////////////////////////////////
 PROJECT INFORMATION
-------------------------------------------------------------------------------------------
 CREATED BY :
 CREATED BY :
 DATE       :
 PROJECT    :
 VERSION    :
 LAST EDIT  :
///////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////
 WIRING INFORMATION
-------------------------------------------------------------------------------------------
   PIN #  - DESCRIPTION
///////////////////////////////////////////////////////////////////////////////////////////
*/
///////////////////////////////////////////////////////////////////////////////////////////
// Libraries to include
//-----------------------------------------------------------------------------------------
//#include <LIBRARY_NAME.h>             //DESCRIPTION OF LIBRARY
///////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////
// BEGIN SETUP
///////////////////////////////////////////////////////////////////////////////////////////
void setup()
{  //OPENS Void Setup

///////////////////////////////////////////////////////////////////////////////////////////
}  //CLOSES Void Setup
///////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////
// BEGIN LOOP
///////////////////////////////////////////////////////////////////////////////////////////
void loop()
{  //OPENS Void Loop

///////////////////////////////////////////////////////////////////////////////////////////
}  //CLOSES Void Loop
///////////////////////////////////////////////////////////////////////////////////////////


Now here is the basic structure for ESP32 (Considering that you'll now be playing with 2 Cores)

Code: [Select]
/*
 GLOBAL FUNCTIONS AND VARIABLES
///////////////////////////////////////////////////////////////////////////////////////////
 PROJECT INFORMATION
-------------------------------------------------------------------------------------------
 CREATED BY :
 CREATED BY :
 DATE       :
 PROJECT    :
 VERSION    :
 LAST EDIT  :
///////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////
 WIRING INFORMATION
-------------------------------------------------------------------------------------------
   PIN #  - DESCRIPTION
///////////////////////////////////////////////////////////////////////////////////////////
*/
///////////////////////////////////////////////////////////////////////////////////////////
// Libraries to include
//-----------------------------------------------------------------------------------------
//#include <LIBRARY_NAME.h>             //DESCRIPTION OF LIBRARY
///////////////////////////////////////////////////////////////////////////////////////////

/*/////////////////////////////////////////////////////////////////////////////////////////
 INITIATES THE TASKS
*///---------------------------------------------------------------------------------------
void Task1(void *pvParameters);  //Initiates Task1
///////////////////////////////////////////////////////////////////////////////////////////

/*/////////////////////////////////////////////////////////////////////////////////////////
 DEFINES THE TASK HANDLES
*///---------------------------------------------------------------------------------------
TaskHandle_t Task_1;  //Handle for Task1
///////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////
// BEGIN SETUP
///////////////////////////////////////////////////////////////////////////////////////////
void setup()
{  //OPENS Void Setup
/*/----------------------------------------------------------------------------------------
//SERIAL COMMUNICATION
-------------------------------------------------------------------------------------------
 Baud Rate Setup
*///---------------------------------------------------------------------------------------
  Serial.begin(115200);                           // Serial Monitor Baud Rate
  delay(10);
///////////////////////////////////////////////////////////////////////////////////////////
/*-----------------------------------------------------------------------------------------
  TASK CREATION
*///---------------------------------------------------------------------------------------
  xTaskCreate(Task1, "Task 1", 2000, NULL, 1, &Task_1);
  vTaskDelay(100);
///////////////////////////////////////////////////////////////////////////////////////////
}  //CLOSES Void Setup
///////////////////////////////////////////////////////////////////////////////////////////

/*/////////////////////////////////////////////////////////////////////////////////////////
 TASK EXECUTION - TASK 1
*//////////////////////////////////////////////////////////////////////////////////////////
void Task1(void *pvParameters)  //Initiates Task1
{ // OPENS Task1
  Serial.print(F("TASK 1 IS RUNNING ON CORE ")); 
  Serial.println(xPortGetCoreID());
  //vTaskDelay(1000);
  for(;;)
  { //OPENS  Task1 FOR Loop
    vTaskDelay(10); // REMOVE THIS LINE BEFORE INSERTING CODE
  } //CLOSES Task1 FOR Loop
} // CLOSES Task1
///////////////////////////////////////////////////////////////////////////////////////////
void loop()
{  //OPENS Void Loop
    vTaskDelay(10); // REMOVE THIS LINE BEFORE INSERTING CODE
}  //CLOSES Void Loop
///////////////////////////////////////////////////////////////////////////////////////////

Possibly the best advice i can give you is when starting ESP32 everyone is going to go on about "You have to pin the task to the core" using the function "xTaskCreatePinnedToCore"
THIS IS NOT CORRECT, Just use "xTaskCreate" as i have done here, Run it and play around with the serial monitor and noting how the rules work for the cores

OK, so this will get you started and understanding the basics

NOW, YOU'RE GOING TO ACTUALLY HAVE TO READ THE FREE RTOS USERMANUAL

chrome-extension://efaidnbmnnnibpcajpcglclefindmkaj/https://www.freertos.org/Documentation/Mastering-the-FreeRTOS-Real-Time-Kernel.v1.0.pdf

A QUICK CHEAT SHEET START

1. Jump straight to page 72 (Figure 4.7)   This will explain STATES OF A TASK to you
2. Now go back to page 54 , The beginning of the chapter of TASK MANAGEMENT and go to around page 93

You'll now have a very good understanding of what you're doing

3. Now make a coffee and set aside 3 days of hard study and read the entire manual.

SO HERE IS WHY
You're going to start with LED's (usually on Arduino) and when you want to blink them, you're going to be taught to use Delay as the function and a delay will be followed by a time period of the delay.   Now you'll always run into a problem BECAUSE OF HOW ARDUINO WORKS vs ESP32
the problem will be other things will be stopped and can't run until the delay time is up

The communities solution to this is to use "millis"  LOL    and.. for simple stuff. it works, (But then, for simple stuff, so does delay)
the point is, You're going to fail again. This is why FreeRTOS is better, You see, in ESP32 vTaskDelay  does not act as BLOCKING CODE (see that diagram that i showed you)
but in Arduino it does.  Write experimental code to prove this, it'll help your programming skills

Point is, ESP32 is better than Arduino

Now... To get you started, REACH OUT TO ME IF YOU HAVE ANY NEED FOR ANY OF THIS CODE
I'm going to give you a list of what i have As Test Sketches.  These were all created either for educational purposes of basic test purposes

- There is something called FastLED Pragma Message, it's an error that you can ignore, but i have code that can silence it

- Arithmetic Operations - This code helps you understand Arithmetic coding

- FOR Loops - This sketch let's you play with FOR Loops and understand how they work

- Increment Operators - This sketch let's you play with incremental operators to understand how to control the variables to do what you want to do.

- Relational Operators - This sketch let's your play around with relational operators to learn how they work

- Variables

- Test 2 LED Strips - A Sketch to test 2 LED Strips if they are working or not

- Basic Printline -  A Sketch to let you play with the output serial monitor for diagnostics

- FASTLED Multitasking - To be used with the FastLED library, a sketch to teach you multitasking on 1 core

- FastLED RGB Ordering - THIS ONE IS USEFUL - A Sketch that when you run it and you don't know the RGB ordering of the LED Strip that you just bought, this sketch will tell you the ordering of the strip,   saves you many many hours of wondering , why is the correct colour not coming up

- FOR Loops - A Sketch to help you understand FOR Loops

- Get Core ID - A sketch to help you understand which core is currently running a task

- While For Loops -  A Sketch (When you're ready and if you need to use it) that will teach you WHILE FOR loops

I won't post it all here now, but to get you doing your own code. Let me know and i'll pop it up
(Likely i'll create a new thread for it for everyone to see and you can grab the code from there.


FOR NOW MY ADVICE TO YOU IS ESP32 as a direct answer to your original question
and i wouldn't bother with those boards that you bought because those boards and arduino nano have more problems than you want to deal with
when you are starting off .


QUESTION EVERYTHING!!!
 

Online tooki

  • Super Contributor
  • ***
  • Posts: 11550
  • Country: ch
Re: Getting started with microcontrollers
« Reply #29 on: March 16, 2024, 01:25:20 am »
Let it be documented that I think BTO’s comment above could not be more wrong, in that basically everything stated is utter nonsense. Multicore programming is WAY beyond what anyone should be beginning with, and introducing that now is neither necessary nor helpful. RTOSes are in no way what one should be starting with!! The post above is a recipe for how to confuse a beginner, not help them.  :palm:  :palm:
« Last Edit: March 16, 2024, 01:28:28 am by tooki »
 
The following users thanked this post: pcprogrammer

Online pcprogrammer

  • Super Contributor
  • ***
  • Posts: 3710
  • Country: nl
Re: Getting started with microcontrollers
« Reply #30 on: March 16, 2024, 07:08:56 am »
And to add onto tooki, the readability of the code with all the "/////////" does not improve.

Adding comment sure but this is over the top  |O

So BTO  :-- :--

Online radiolistener

  • Super Contributor
  • ***
  • Posts: 3381
  • Country: ua
Re: Getting started with microcontrollers
« Reply #31 on: March 16, 2024, 07:21:10 am »
STEP 2 - Your basic "Bare Minimum" Code for Arduino Is going to look like this
Here is a format that i use for myself and when teaching students.
Code: [Select]
/*
 GLOBAL FUNCTIONS AND VARIABLES

///////////////////////////////////////////////////////////////////////////////////////////
 PROJECT INFORMATION
-------------------------------------------------------------------------------------------
 CREATED BY :
 CREATED BY :
 DATE       :
 PROJECT    :
 VERSION    :
 LAST EDIT  :
///////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////
 WIRING INFORMATION
-------------------------------------------------------------------------------------------
   PIN #  - DESCRIPTION
///////////////////////////////////////////////////////////////////////////////////////////
*/
///////////////////////////////////////////////////////////////////////////////////////////
// Libraries to include
//-----------------------------------------------------------------------------------------
//#include <LIBRARY_NAME.h>             //DESCRIPTION OF LIBRARY
///////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////
// BEGIN SETUP
///////////////////////////////////////////////////////////////////////////////////////////
void setup()
{  //OPENS Void Setup

///////////////////////////////////////////////////////////////////////////////////////////
}  //CLOSES Void Setup
///////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////
// BEGIN LOOP
///////////////////////////////////////////////////////////////////////////////////////////
void loop()
{  //OPENS Void Loop

///////////////////////////////////////////////////////////////////////////////////////////
}  //CLOSES Void Loop
///////////////////////////////////////////////////////////////////////////////////////////

You can help your students a lot to learn it just by making things much more easy with removing that spamming crap comments.  ;)

Here is how the same code should looks like:
Code: [Select]
//#include <LIBRARY_NAME.h>

void setup()
{
}

void loop()
{
}

as you can see its become small shiny and easy.
It's much more easy to read it and understand when there is no spamming crap comments. :)

if you want to add some large comment to document some details it's okay, but don't mix it with code. Just put that comment in one place, for example at the top of file and keep the code clean and free of spam.

For example:
Code: [Select]
/*

  HI THERE

                                                 
                                                 
        $$                              $$       
       $$$$$$                        $$$$$$     
       $$$$$$$$                    $$$$$$$$     
       $$$$$$$$$   $$$$$$$$$$$$$  $$$$$$$$$     
       $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$     
      !$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$     
       $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$     
       $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$     
       $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$     
       $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$     
      $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$     
      $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$   
     $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$   
     $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$   
    $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$   
    $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ 
    $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ 
    $$$$$$$$$55((((v55555555555(((((55$$$$$$$$$ 
    $$$$$$$$((((((((((((((((((((((((((!$$$$$$$$ 
    $$$$$$$((((( (((((((((((((((((.!(((($$$$$$$ 
    $$$$$$J((((    ((((((((((((((    (((5$$$$$$ 
    $$$$$$((((  $$ !(((((((((((( $$%  ((($$$$$$ 
    $$$$$&(((( $*$$ ((((((((((((  $$  (((#$$$$$ 
    $$$$$((((  $$$$ (((((((((((.$$$$$ (((($$$$$ 
    $$$$$((((  $$$$ ((((((((((( $$$$$ (((($$$$7 
     $$$$((((  $$$$ (((((((((((($$$$$ (((!$$$$   
     $$$$$(((( $$$$ (((((((((((( $$$  ((($$$$$   
    "$$$$$((((  $$ (((((((((((((  $  (((($$$$$( 
      $$$$(((((   ((((((($(((((((   '(((($$$$   
       $$$$((((((((((((((v(((((((((((((($$$$$   
        $$$$(((((((((((!(((!(((((((((((($$$$     
         $$$$((((((((((($$$((((((((((($$$$$     
          $$$$$v((((((((((((((((((((v$$$$       
            $$$$$$$$5!((((((((!F$$$$$$$         
  $$$$         A$$$$$$$$$$$$$$$$$$$$             
   $$$$            $$$$$$$$$$$$$                 
  v  $$$          $$$$$$$$$$$$$$$               
  v  5$v$         $$$$$$$$$$$$$$$$               
      $$v        $$$$$$$$$$$$$$$$$               
       $$$$      $$$$$$$$ $$$$$$$$               
       $$$v$$$$$v$$$$$$$$ $$$$$$$$               
        $$$$$$$$$$$$$$$$$ $$$$ $$$               
         $$$$$$$$$$$ $$$$ $$$$ $$$               
            $$$$ $$$ $$$$ $$$$ $$$               
                 $$$ $$$$ $$$$ $$$               
                 $$$ $$$$ $$$$ $$$               
                 $$$ $$$$ $$$$ $$$               
                 $$$ $$$$'$$$$ $$$               
               .v$$$v$$$$v$$$$v$$$vv             
            vvvvv$$$v$$$$v$$$$v$$$vvvvvv         
         vvvvvvvv$$$v$$$$v$$$$v$$$(vvvvvvv/     
        vvvvvvvv($$$v$$$$v$$$$v$$$$vvvvvvvvv     
      |vvvvvvvvv$$$$v$$$$v$$$$v($$$$vvvvvvvvv   
      vvvvvvvv$$$$$vv$$$$v$$$$vv($$$$vvvvvvvvv   
      vvvvvvvvv%%%%vv$$$$v$$$$vv%%%%Ivvvvvvvvv   
      vvvvvvvvvv%%%%$$$$vvv$$$$%%%%vvvvvvvvvvv   
      vvvvvvvvvvv%%%$$$%vvv%%$$%%%%vvvvvvvvvvv   
       vvvvvvvvvv%%%v%%%%v&%%%v%%%vvvvvvvvvv"   
         vvvvvvvv%%%v#%%%v%%%%v%%%vvvvvvvvv     
           vvvvvv%%%v7%%%v%%%%v%%%vvvvvv(       
              .vv%%%v7%%%v%%%%v%%%vvv           
                     (#%%v%%%#"                 
                                                 
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
OWNED BY:
REVIEWED BY:
APPROVED BY:
REJECTED BY:
THE IDEA BY:
CREATED BY :
ASSISTED BY :
ART BY:
COMMENTS BY:
CODED BY:
SPONSORED BY:
DONATED BY:
HATED BY:
LIKED BY:
IGNORED BY:
DATE:
TIME:
GPS POSITION:
PROJECT    :
CODE NAME:
SUB PROJECT:
VERSION    :
SUB VERSION:
FIRST EDIT:
SECOND EDIT:
THIRD EDIT:
LAST EDIT  :
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

*/
//#include <LIBRARY_NAME.h>

void setup()
{
}

void loop()
{
}

as you can see, you can add some text garbage, but still keep the code clean and simple if you don't mix it with that text garbage.  :)
« Last Edit: March 16, 2024, 10:50:06 am by radiolistener »
 

Offline zilp

  • Regular Contributor
  • *
  • Posts: 206
  • Country: de
Re: Getting started with microcontrollers
« Reply #32 on: March 16, 2024, 07:44:26 am »
I think that BTO's advice is bad for one simple reason: If you want to primarily learn programming, then doing so with microcontrollers just complicates things for no gain. If you just want to learn how to write software on top of an operating system, you can do that on Linux on your desktop/laptop, no need to fiddle around with additional hardware.

If you want to learn how to effectively use microcontrollers, though, then an operating system just obscures things. If you want to learn what microcontrollers can do, you will need to dig into datasheets and figure out how to set up registers so that the thing does what you want it to do. And for that purpose, I would think that a small AVR is a way better choice than an ESP32, simply because of its relative simplicity.

An RTOS is a useful abstraction for building embedded software that exceeds a certain level of complexity, but if you want to make effective use of microcontrollers, you need to know how you would do things without an operating system first (which in particular means that you understand how the RTOS does the things that it does).
 
The following users thanked this post: tooki

Offline soldarTopic starter

  • Super Contributor
  • ***
  • Posts: 3166
  • Country: es
Re: Getting started with microcontrollers
« Reply #33 on: March 16, 2024, 08:02:26 am »
Thanks all. I am going to order the Arduino Uno and try to get started with that.

I think I might try getting my 13 year old nephew interested in learning. If he takes to it then it would motivate me and be a learning experience for him. I will have to find some learning projects which would be interesting to him.
All my posts are made with 100% recycled electrons and bare traces of grey matter.
 

Online pcprogrammer

  • Super Contributor
  • ***
  • Posts: 3710
  • Country: nl
Re: Getting started with microcontrollers
« Reply #34 on: March 16, 2024, 08:26:51 am »
Here is how the same code should looks like:
Code: [Select]
//#include <LIBRARY_NAME.h>

void setup()
{
}

void loop()
{
}

I myself use "//------------------------------" between functions to make some distinction and add comments on input and return values.

Code: [Select]
//------------------------------------------------------------------
//Returns the current status of the pin
//port: 0 = GPIOA, 1 = GPIOB
//pin:  0 - 7

int readpin(int port, int pin)
{
}

//------------------------------------------------------------------
//Sets the pin
//state: 0 - 1
//port:  0 = GPIOA, 1 = GPIOB
//pin:   0 - 7

void setpin(int port, int pin, int state)
{
}


Less intrusive then the "///////////////////////////////////////////////////////////////////////" and still providing useful information.

Online radiolistener

  • Super Contributor
  • ***
  • Posts: 3381
  • Country: ua
Re: Getting started with microcontrollers
« Reply #35 on: March 16, 2024, 08:44:00 am »
I myself use "//------------------------------" between functions to make some distinction and add comments on input and return values.

This is c++ builder style. It leads to very bad code readability, especially if you're working on a large and complicated code.

For example most modern code editors allows to collapse functions body, but if your code is contaminated with these ----------------------------, your eyes will ripple and it will be difficult to read such code.


When you collapse bodies for my code it will looks like this:
Code: [Select]
//#include <LIBRARY_NAME.h>

void setup()
void loop()
void func1()
void func2()
void func3()

Clean, tiny, simple and easy to read and navigate.


But if you collapse bodies for code separated with -----, you will get this:
Code: [Select]
//#include <LIBRARY_NAME.h>

//========================================================================================================

void setup()

//========================================================================================================

void loop()

//========================================================================================================

void func1()

//========================================================================================================

void func2()

//========================================================================================================

void func3()

//========================================================================================================

what is better readable?  ;)
« Last Edit: March 16, 2024, 08:52:20 am by radiolistener »
 

Offline RoGeorge

  • Super Contributor
  • ***
  • Posts: 6203
  • Country: ro
Re: Getting started with microcontrollers
« Reply #36 on: March 16, 2024, 08:56:03 am »
OK, I have it [an Arduino UNO R3 board], I plug in a power supply (5V I assume) and I pug in the USB to my Linux Mint computer.  Now what? I assume i need to download some programming software. Yes?
Download and install the Arduino IDE (Integrated Development Environment) for Linux:  https://www.arduino.cc/en/software

Then what? Can you give me a step by step intro on how I would do a simple task?
Plug the UNO board into an USB port (it will get its power from USB, no need for external power supply), start the Arduino IDE, and inside the IDE select the type of board and the port where your UNO is connected.  If you manage to do that by simply inspecting the IDE menus, next step is to load an example (also from the IDE menus), compile, download it into the UNO board and enjoy.  If it is not clear how to do all that, start reading the getting started guide https://docs.arduino.cc/software/ide-v2/tutorials/getting-started-ide-v2/ or watch a video, depends of your learning style.

Also, once programmed with USB I am assuming the Arduino is totally autonomous (as long as it has power). Yes?
Yes.

While the USB is connected does it get power from there?
Yes.  There is also a jack barrel for an external power supply, read the User Guide for your specific type of Arduino board.

The main question is how is it programmed? What language does Arduino use? 
C (the most common), or a combination of C/C++ (Arduino IDE under the hood is using AVR-GCC and it supports mixed C/C++ code).  Can be programmed in AVR Assembler language, too.  In the microcontoller's datasheet there are often code excerpts in both assembler and C, for how to control the MCU, might be very educational (though, those code excerpts are not standalone/fully working examples for beginners).

Where can I find simple tutorials with simple projects for learning and exercise?
Inside the IDE itself there is a ton of C examples.  You can start from running the examples, then try to make little modification and run again.  Apart from those examples, there are all kind of Arduino getting started guides, tutorials, videos, books, etc.

Suppose I want to do a simple task like implement an AND function: read two switches and activate an output when both are closed. How would I do that?
- Read the board user guide, to find out the pinout.  Same pin can be either analog or digital, either input or output.  Your program tells it what you want it to be (there are some restrictions, but the idea is that it is all programable, not a fixed functionality like in classic microprocessors, or in digital TTL chips).  In an MCU a pin can be whatever you want it to be (well, with some restrictions).
- Choose 2 digital inputs to connect the switches.
- Choose another digital output for the LED.  On most Arduino boards, there is already an onboard LED connected to one of the pins.  Use that one, or choose some other pin and connect your own LED there, with a resistor.
- Now open the IDE, and write a program, where you read the digital input pins (the switches) and turn on the LED (write a digital 1 to the LED) when both switches are pressed.  You'll need to put all that inside an infinite loop, so the MCU forever reads the switches, evaluates if both are pressed, and turns the led ON or OFF accordingly.

So, in an MCU, your AND won't be a physical AND, like it would be when you wire a 74N08 gate.  In an MCU, this AND "gate" is in fact a program, a forever loop of reading the switches -> evaluate if both pressed -> update the LED status -> repeat.  For this approach, the response of the output LED (the "speed" of the AND "gate") is dictated by how often/how fast that program loop is running.
« Last Edit: March 16, 2024, 09:18:16 am by RoGeorge »
 

Online radiolistener

  • Super Contributor
  • ***
  • Posts: 3381
  • Country: ua
Re: Getting started with microcontrollers
« Reply #37 on: March 16, 2024, 09:10:03 am »
Where can I find simple tutorials with simple projects for learning and exercise?

Usually programming learning is started from hello world code. For MCU it is started from a simple LED blinking code. Then you can add more actions in your code and learn it step by step. For example you can add 10 LEDS instead of 1 and do moving light effect. Then you can add LCD display and show the text on it. Then add some temperature/pressure sensor like BME280, obtain it's data and show on the LDC display. etc

You can find code examples on github.
« Last Edit: March 16, 2024, 09:13:42 am by radiolistener »
 

Online Aldo22

  • Frequent Contributor
  • **
  • Posts: 694
  • Country: ch
Re: Getting started with microcontrollers
« Reply #38 on: March 16, 2024, 09:29:43 am »
A major advantage of ESPs is that they can be controlled via a web interface.
Basically, you don't need to buy any special displays, buttons, encoders or keypads, but you can control and view everything via a web browser.
This makes it quicker to test a code.
This may not be "Hello World" level, but for a somewhat larger project you will soon decide in favor of the ESP32 if you have the choice and the power consumption is not critical.

However, I would also learn C independently of the MCUs.

https://randomnerdtutorials.com/esp32-web-server-arduino-ide/
« Last Edit: March 16, 2024, 09:33:19 am by Aldo22 »
 

Online MarkF

  • Super Contributor
  • ***
  • Posts: 2550
  • Country: us
Re: Getting started with microcontrollers
« Reply #39 on: March 16, 2024, 10:52:46 am »
A major advantage of ESPs is that they can be controlled via a web interface.
Basically, you don't need to buy any special displays, buttons, encoders or keypads, but you can control and view everything via a web browser.


What's the point of using a microcontroller if you don't have any of these?
Isn't the point of having a MCU to control or gather data from a piece of hardware?   :-//

If all you want to do is learn how to program in C/C++, I would go so far as to say don't use a MCU.
Just write Linux or Windows programs.  You don't have to deal with the extra hardware.
Personally, I get the most satisfaction and immediate gratification from doing graphics.
Learning basic C is fairly easy. 
The general language is not all that different from others: Basic, Pascal, Ada, etc.

You're not going to see the real benefits of C++ until you have something with
multiple copies of some complex object.  Years ago, I wrote a MIDI sequencer where I had four keyboards.
Each keyboard performed the exact same functions, with the four summed together in the end.
You just declare four of them like you would four integers.

   
 

Online Aldo22

  • Frequent Contributor
  • **
  • Posts: 694
  • Country: ch
Re: Getting started with microcontrollers
« Reply #40 on: March 16, 2024, 11:20:44 am »
A major advantage of ESPs is that they can be controlled via a web interface.
Basically, you don't need to buy any special displays, buttons, encoders or keypads, but you can control and view everything via a web browser.


What's the point of using a microcontroller if you don't have any of these?
Isn't the point of having a MCU to control or gather data from a piece of hardware?   :-//

Of course you need sensors, motors, perhaps other modules etc., but they can be used or controlled “headless”.
I only spoke of “displays, buttons, encoders or keypads”.
For example, you can place a weather station with an ESP32 on the balcony and read its values using your smartphone in the kitchen. 
There is no need for a button or a display on the MCU.
 

Offline Picuino

  • Frequent Contributor
  • **
  • Posts: 730
  • Country: 00
    • Picuino web
Re: Getting started with microcontrollers
« Reply #41 on: March 16, 2024, 11:43:08 am »
An important point in the ESP32 and Arduino discussion is that the Arduino Uno R3 uses 5V voltages while the ESP32 uses 3.3V voltages.
The peripherals of each are different, the voltages very much determine what external elements you will be controlling.
 

Offline mariush

  • Super Contributor
  • ***
  • Posts: 5029
  • Country: ro
  • .
Re: Getting started with microcontrollers
« Reply #42 on: March 16, 2024, 11:43:47 am »
You don't need a web interface  ... apparently it's too hard to get a usb to serial cable and send commands to your microcontroller through serial... or get info through the serial connection... no, let's add unnecessary power consumption for the wireless, let's add a whole tcp/ip stack to deal with it etc etc etc.

For one way communication a simple infrared led and an IO pin would be enough... like multimeters work, see for example Uni-T UT61E data logging feature, basically an infrared led and an infrared sensor in the connector that plugs in the meter.  The bonus of having isolation between your computer and the device can often be worth it.

edit : the keyword I was looking for was optocouplers... one way connection could be one optocoupler, bi-directional connection would be two optocouplers .. a simple 4 pin connector or trrs jack or rj11/rj45 to a usb - serial converter chip on a cable would be enough to connect to a computer with isolation guaranteed.
« Last Edit: March 16, 2024, 11:53:06 am by mariush »
 
The following users thanked this post: pcprogrammer

Offline soldarTopic starter

  • Super Contributor
  • ***
  • Posts: 3166
  • Country: es
Re: Getting started with microcontrollers
« Reply #43 on: March 16, 2024, 12:09:57 pm »
OK, I have downloaded arduino-ide_2.3.2_Linux_64bit.AppImage , 190 MB and it runs. Now I need to receive the Arduino so i can plug it in..

I am beginning to gain confidence that I can do it ... even if I am doing it ten years later than I should have.

Thanks all for the encouragement.

All my posts are made with 100% recycled electrons and bare traces of grey matter.
 

Offline RoGeorge

  • Super Contributor
  • ***
  • Posts: 6203
  • Country: ro
Re: Getting started with microcontrollers
« Reply #44 on: March 16, 2024, 12:12:34 pm »
OK, so suppose I order the most popular and recommended choice, which seems to be the Arduino "classic" Uno Rev3 for $27.60 in Amazon (plus Danegeld)
https://www.amazon.com/Arduino-A000066-ARDUINO-UNO-R3/dp/B008GRTSV6/ref=sr_1_1_sspa

Better order this, at half the price you get 3 Arduino boards.

https://www.amazon.com/HiLetgo-ATmega328P-Controller-Development-Unsoldered/dp/B01DLIJQA2/ref=sr_1_11

I don't know this seller, the idea is to get a pack of a few boards.  Arduino 'nano' is the same as UNO R3, but better and cheaper.

The Arduino 'nano' includes all the features of the UNO R3 + some extra benefits that UNO R3 don't have.  'nano' boards are compatible with UNO R3, and they use the same microcontroller as UNO R3.

It is better to have more than one board, either as a spare, or to make two boards to talk to each other, one at each end of the communication wires, and such.  Even more, if you have 2 boards, you can use one board to debug the other one, I mean hardware debugging the other board, so to inspect/manually change the registers, its memory inside, the state of the bits peripheral ports, etc.

« Last Edit: March 16, 2024, 12:19:53 pm by RoGeorge »
 

Online pcprogrammer

  • Super Contributor
  • ***
  • Posts: 3710
  • Country: nl
Re: Getting started with microcontrollers
« Reply #45 on: March 16, 2024, 12:34:23 pm »
It is better to have more than one board, either as a spare, or to make two boards to talk to each other, one at each end of the communication wires, and such.  Even more, if you have 2 boards, you can use one board to debug the other one, I mean hardware debugging the other board, so to inspect/manually change the registers, its memory inside, the state of the bits peripheral ports, etc.

I was not aware that the ATmega328 used on the UNO and the nano support hardware debugging, but after looking at the datasheet it does have debugWIRE support. It needs to be enabled by programming a fuse bit and then uses the reset pin for the communication. When using breakpoints the FLASH is reprogrammed and can deteriorate faster than with normal use. Not the easiest to use since the IDE has to deal with this to.

The bigger ATmega or STM32 devices have better support for debugging via JTAG or SWD. Not sure if the Arduino IDE supports debugging.

For a beginner serial print is much easier for debugging. Just add it in the code and look at the serial monitor what is being send.

Offline zilp

  • Regular Contributor
  • *
  • Posts: 206
  • Country: de
Re: Getting started with microcontrollers
« Reply #46 on: March 16, 2024, 01:05:19 pm »
I am beginning to gain confidence that I can do it ... even if I am doing it ten years later than I should have.

Thanks all for the encouragement.

Given that you do know the electronics/logic side of things, and even have done assembly on an MCU-ish processor (by modern standards) ... I'll say that this will be easy. The area where there might be a lot to learn for you is probably more higher-level software abstractions, maybe modern communication systems (i.e., ethernet/IP), which is useful for complex systems, but you can do a lot even without that.

C in particular doesn't have that many concepts that would be completely foreign to an assembly programmer, it's mostly just a slightly more human-friendly way to write down the same thing, so chances are you'll primarily have to learn the syntax ... which shouldn't be that difficult if you are already familiar with the concepts represented by that syntax, and that especially so when that syntax heavily borrows from general math syntax that you are presumably also familar with. I mean, it's not really that hard to figure out what "a = b + c;" roughly does, right?
 

Offline Picuino

  • Frequent Contributor
  • **
  • Posts: 730
  • Country: 00
    • Picuino web
Re: Getting started with microcontrollers
« Reply #47 on: March 16, 2024, 01:34:02 pm »
A simple and small library for Arduino that allows multitasking is SCoop.
I recommend it when you intend to run several independent processes at the same time.
It has not been updated for many years, but it works well.

https://github.com/fabriceo/SCoop

Edit: Example

Code: [Select]

/*
 Multiple Blinks

 Demonstrates the use of the SCoop library in the same way than with original Scheduler.h
 
 Hardware required :
 * LEDs connected to pins 11, 12, and 13

 created 8 Oct 2012
 by Cristian Maglie
 Modified by
 Scott Fitzgerald 19 Oct 2012
 
 This example code is in the public domain
 
 http://arduino.cc/en/Tutorial/MultipleBlinks
 
 Modified by Fabrice Oudert 8 Jan 2013
 https://code.google.com/p/arduino-scoop-cooperative-scheduler-arm-avr/
 
*/

// Include Scheduler since we want to manage multiple tasks.
#include <SCoop.h>  // instead of original #include <Scheduler.h>

#if defined(SCoopANDROIDMODE) && (SCoopANDROIDMODE == 1)
#else
#error "to run this example with SCoop you must set de parameter SCoopANDROIDMODE to 1 at the begining of "SCoop.h"
#endif

int led1 = LED_BUILTIN;
int led2 = 12;
int led3 = 11;


void setup() {
  Serial.begin(9600);

  // Setup the 3 pins as OUTPUT
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);

  // Add "loop2" and "loop3" to scheduling.
  // "loop" is always started by default.
  Scheduler.startLoop(loop2);
  Scheduler.startLoop(loop3);
 
  Scheduler.start(); // this is needed with SCoop, not with Android original Scheduler
}

// Task no.1: blink LED with 1 second delay.
void loop() {
uint32_t timer1=0;

  digitalWrite(led1, HIGH);

  // IMPORTANT:
  // When multiple tasks are running 'delay' passes control to
  // other tasks while waiting and guarantees they get executed.
  Scheduler.delay(1000);

  digitalWrite(led1, LOW);

  Scheduler.delay(1000);

}

// Task no.2: blink LED with 0.1 second delay.
void loop2() {
uint32_t timer1=0;
  digitalWrite(led2, HIGH);
  Scheduler.delay(100);

  digitalWrite(led2, LOW);
  Scheduler.delay(100);
}

// Task no.3: accept commands from Serial port
// '0' turns off LED
// '1' turns on LED
void loop3() {
  if (Serial.available()) {
    char c = Serial.read();
    if (c=='0') {
      digitalWrite(led3, LOW);
      Serial.println("Led turned off!");
    }
    if (c=='1') {
      digitalWrite(led3, HIGH);
      Serial.println("Led turned on!");
    }
  }
}
« Last Edit: March 16, 2024, 01:40:45 pm by Picuino »
 

Offline RoGeorge

  • Super Contributor
  • ***
  • Posts: 6203
  • Country: ro
Re: Getting started with microcontrollers
« Reply #48 on: March 16, 2024, 01:48:19 pm »
When using breakpoints the FLASH is reprogrammed and can deteriorate faster than with normal use. Not the easiest to use since the IDE has to deal with this to.
...
Not sure if the Arduino IDE supports debugging.

I don't use Arduino IDE too often, IIRC the old Arduino IDE (v1.x) don't have hardware debugging support, while the new IDE (2.x) has hardware debugging support, but for newer boards.  It is possible to use hardware debugging on nano and/or UNO boards, though with some extra hoops.  Hardware debugging is out of the scope of a getting started/beginner topic, but it is possible with either a 'nano' or a  'UNO' type of Arduino boards (or other Arduino models based on ATmega328, or on any other MCU that supports HW debugging).

Regarding the wearing out the memory while setting hardware breakpoints (talking for debugWIRE interface only), there are 2 methods.  One way is to insert a BREAK assembly instruction in the executable code, so the flash will be rewritten to insert execution breakpoints.  Another method is to use only a single breakpoint at a time, breakpoint that is sitting in a special register, dedicated to debugWIRE debugging, so without writing/wearing the flash.

Don't know by heart if ATmega328 has dedicated breakpoint register for debugWIRE, without digging the datasheets right now, I guess it does support hardware breakpoints without rewriting the flash.  Even if it doesn't, the wear out of the flash reprogramming is not so dramatic, it can last for month, if not years of hobby level reprogramming and debugging (ab)use.

Anyway, an 'Arduino nano' board is less than $2-$5/pcs, so not a big deal to treat them almost as consumables.  Develop on one board, and once the software debugging is finished, program another new board that will go to the final project.


LATER EDIT - checked the datasheet for ATmega328P (the MCU used in either the Arduino nano and/or Arduino UNO R3), and the debugging breakpoints in mega328P seems to be possible only by inserting a BREAK instruction in the flash memory code (so changing the debugging breakpoints will require a flash write for that page of flash only):  see page 222 of 294 in https://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-7810-Automotive-Microcontrollers-ATmega328P_Datasheet.pdf
« Last Edit: March 16, 2024, 02:12:17 pm by RoGeorge »
 

Offline soldarTopic starter

  • Super Contributor
  • ***
  • Posts: 3166
  • Country: es
Re: Getting started with microcontrollers
« Reply #49 on: March 16, 2024, 05:04:10 pm »
Better order this, at half the price you get 3 Arduino boards.

https://www.amazon.com/HiLetgo-ATmega328P-Controller-Development-Unsoldered/dp/B01DLIJQA2/ref=sr_1_11

I don't know this seller, the idea is to get a pack of a few boards.  Arduino 'nano' is the same as UNO R3, but better and cheaper.

The Arduino 'nano' includes all the features of the UNO R3 + some extra benefits that UNO R3 don't have.  'nano' boards are compatible with UNO R3, and they use the same microcontroller as UNO R3.

It is better to have more than one board, either as a spare, or to make two boards to talk to each other, one at each end of the communication wires, and such.  Even more, if you have 2 boards, you can use one board to debug the other one, I mean hardware debugging the other board, so to inspect/manually change the registers, its memory inside, the state of the bits peripheral ports, etc.
Thanks. That looks very interesting. I think I will get both the Arduino Uno to get started and keep these nano in reserve so that I can dedicate them to particular project once it's developed and I can continue to play with the Uno.
All my posts are made with 100% recycled electrons and bare traces of grey matter.
 

Offline dobsonr741

  • Frequent Contributor
  • **
  • Posts: 674
  • Country: us
Re: Getting started with microcontrollers
« Reply #50 on: March 16, 2024, 05:21:14 pm »
Quote
The big hurdle is that I need to learn C and/or C++.

No need to learn C, learn Python instead. Worderfully simple, CircuitPython will get you going fast, with modern MCUs.

This is my recommendation: https://www.seeedstudio.com/XIAO-RP2040-v1-0-p-5026.html
You can upgrade yourself later on to Arduino IDE, and after that straight RP2040 C SDK, if you want to.
 

Online pcprogrammer

  • Super Contributor
  • ***
  • Posts: 3710
  • Country: nl
Re: Getting started with microcontrollers
« Reply #51 on: March 16, 2024, 07:24:56 pm »
Quote
The big hurdle is that I need to learn C and/or C++.

No need to learn C, learn Python instead. Worderfully simple, CircuitPython will get you going fast, with modern MCUs.

This is my recommendation: https://www.seeedstudio.com/XIAO-RP2040-v1-0-p-5026.html
You can upgrade yourself later on to Arduino IDE, and after that straight RP2040 C SDK, if you want to.

As if learning Python is any simpler than learning C.  :palm:

The Arduino IDE and all the examples that can be found, have you started quick on a simple target board like the UNO or nano.

As a beginner it is much easier to do things with Arduino without having to directly learn about a lot of other stuff, but also allows you to go quicker if you want to and dive deep into the internal interfaces in an MCU. And the latter is much simpler on an ATmega328 than on any of the more powerful MCU's like ESP32, RP2040, STM32 devices, PIC controllers and what more can be found.

Documentation also plays a big role into this. The datasheets for the ATmega series are rather good compared to for instance what STM32 devices bring to the table.

Offline dobsonr741

  • Frequent Contributor
  • **
  • Posts: 674
  • Country: us
Re: Getting started with microcontrollers
« Reply #52 on: March 16, 2024, 07:36:58 pm »
The question is what OP want: get successful real world applications of a microcontroller through a high level language, - or - to dive deep, to learn how to read datasheets, set register bits and do everything from scratch.

Both approach has merits, can be fun, let OP have choices.
 

Offline Doctorandus_P

  • Super Contributor
  • ***
  • Posts: 3365
  • Country: nl
Re: Getting started with microcontrollers
« Reply #53 on: March 17, 2024, 01:30:49 am »
"Arduino" has become very popular because it's easy to get started with, but very unfortunately it is quite a kludge and I don't like the platform much.

* The form factor of the "classic" arduino's is atrocious (I sort of like the "arduino nano" which is breadboard compatible).
* C & C++ programs start with a main( ) function (after startup code). and "arduino" have hidden that and added a ridiculous "setup() and "loop( )".
* The Java contraption they call an "IDE" is hardly worth that abbreviation. (Apparently it has gained some improvements in the last few years).
* How does hiding compiler messages make it "simpler"? Those messages are valuable.
* The whole framework is an ugly hodgepodge of mixed C and C++. If you study it, you learn from bad examples.

Also, for learning C or C++, using only a PC (with software) is a much better option than any uC board. When you use a decent IDE, it has an integrated debugger, and you can step though your code line for line effortlessly. This is a great extra tool during the learning process and helps with figuring out how the details work. Also, C and C++ are very much standardized languages (although the standards have evolved a lot over the last 50 years) I quite often design and debug algorithms on my PC, and only port them to an uC after the algorithm is debugged and working. If you know you want to port it later to a microcontroller, you can also do some extra tricks. For example, you can declare the special uC registers as simple variables. This does not get timers or uarts working, but if you start with the right names, you don't have to modify them when you port the code to an uC.

You can also use an RTOS such as FreeRTOS or ChibiOS. Often this is not really necessary for a small uC (think arduino), but for a bit more complex uC (ARM Cortex) it's a reasonable fit. Using an RTOS can give you some structure that helps with keeping the code better readable, and it also makes code re-use easier.
 

Offline Rick Law

  • Super Contributor
  • ***
  • Posts: 3442
  • Country: us
Re: Getting started with microcontrollers
« Reply #54 on: March 17, 2024, 01:54:02 am »
Thanks for all the replies. I think I will start by getting the Arduino Uno REV3 and go from there. I should have no problem interfacing hardware as I am very familiar with that kind of thing. The big hurdle is that I need to learn C and/or C++. I will have to find some tutorials and start practicing. We shall see if I can do it or if it proves to be more effort than I am willing to do.

Since you already have experience programming in assembler, learning C/C++ is easy.  I suggest starting with the Arduino IDE and load up one of their examples.  Something link Blink is a good one.  The sample C code is easy to understand for someone like you with assembler experience.  You will pick up C rather quickly.  Blinking an LED gives you immediate feedback.

Using C++ is a choice you can make later.  C (without the object oriented structure C++) works well enough to do every you can do with Arduino.  Some add-on stuff (for example, an LCD display) has their library written in C++.  If you are not already familiar with object oriented programming, that could be somewhat confusing.  You just define your copy of that LCD display object.  After that, just look at those object methods as function calls to functions specifically for that object.

I am not sure if you will have this confusion I had: One thing I found confusing when I start with Arduino (vs just a plain microprocessor) is the boot-loader.  I too moved from programming microprocessor in assembler decades ago, to playing with an Arduino (UNO first, mostly NANO now).  You grab a microprocessor (6502/8080, what not), there is no boot-loader.  You burn your EEPROM and the 8080/6502 will just start running what is in the boot rom/eeprom.  Took me some thinking to connect conceptually that the boot-loader is an area in flash reserved to emulate boot rom/eeprom.  This "boot rom" just starts the program already loaded in flashed, or communicated with the IDE to load a program into (the remaining areas of) flash.

If you get a NANO/UNO Arduino, they should have the arduino boot-loader, but I did have one experience of buying a 3-pack of NANOs that actually doesn't have the boot loader.  You would know the moment you try to use the Arduino IDE to flash one of the example programs to your arduino.  Make sure your first is an UNO with boot-loader.  If you have an Arduino UNO with boot loader that the IDE can talk to, it can download the bootloader flasher into the working UNO and make that UNO (or NANO) into a boot-loader flasher to flash the boot-loader onto another UNO/NANO.  UNO is easier since you can find a lot of info on how to hard-wire connect the working UNO to the UNO w/o bootloader.  NANO certainly can also do it, but lacking on-line helpful info, you have to be already familiar with how to hard-wire the pins of the flasher arduino and the other arduino to be flashed.  Having run into that problem, I now have a NANO dedicated to flashing boot-loader.

Good luck, starting may look intimidating, but for someone who can program 6502 with assembler, it should not be hard...
 

Online xrunner

  • Super Contributor
  • ***
  • Posts: 7518
  • Country: us
  • hp>Agilent>Keysight>???
Re: Getting started with microcontrollers
« Reply #55 on: March 17, 2024, 02:17:31 am »
Google "children using Arduino"

It really ain't that hard to learn.  :-+
I told my friends I could teach them to be funny, but they all just laughed at me.
 
The following users thanked this post: tooki

Offline Doctorandus_P

  • Super Contributor
  • ***
  • Posts: 3365
  • Country: nl
Re: Getting started with microcontrollers
« Reply #56 on: March 17, 2024, 02:26:59 am »
hp>Agilent>Keysight>Siglent  >:D
 

Online xrunner

  • Super Contributor
  • ***
  • Posts: 7518
  • Country: us
  • hp>Agilent>Keysight>???
Re: Getting started with microcontrollers
« Reply #57 on: March 17, 2024, 02:53:45 am »
hp>Agilent>Keysight>Siglent  >:D

I'm sure Tautech would agree but we digress ...  ;)
I told my friends I could teach them to be funny, but they all just laughed at me.
 

Online radiolistener

  • Super Contributor
  • ***
  • Posts: 3381
  • Country: ua
Re: Getting started with microcontrollers
« Reply #58 on: March 17, 2024, 04:23:31 am »
 

Online radiolistener

  • Super Contributor
  • ***
  • Posts: 3381
  • Country: ua
Re: Getting started with microcontrollers
« Reply #59 on: March 17, 2024, 04:26:08 am »
here is how to start programming in Rust for STM32 microcontrollers:
https://medium.com/digitalfrontiers/rust-on-a-stm32-microcontroller-90fac16f6342

 :)
 

Online tooki

  • Super Contributor
  • ***
  • Posts: 11550
  • Country: ch
Re: Getting started with microcontrollers
« Reply #60 on: March 17, 2024, 09:58:17 am »
"Arduino" has become very popular because it's easy to get started with, but very unfortunately it is quite a kludge and I don't like the platform much.

* The form factor of the "classic" arduino's is atrocious (I sort of like the "arduino nano" which is breadboard compatible).
So what? It works just fine for getting started, and there's a huge ecosystem of expansion boards ("shields") designed around that form factor.

* C & C++ programs start with a main( ) function (after startup code). and "arduino" have hidden that and added a ridiculous "setup() and "loop( )".
Pointless elitism that has zero merit from a technical standpoint.

The Arduino structure
Code: [Select]
setup()
  {
    //your code that runs once goes here
  }
loop()
  {
    //your code that runs repeatedly goes here
  }
is literally just shorthand for
Code: [Select]
main()
  {
    //your code that runs once goes here
 
   while(true)
     {
       //your code that runs repeatedly goes here
     }
  }

They compile to the exact same thing, and frankly, the setup()/loop() syntax is easier to understand, especially for a beginner. Remember, Arduino was literally designed as an educational tool for non-techies, and it does well at that goal.

* The Java contraption they call an "IDE" is hardly worth that abbreviation. (Apparently it has gained some improvements in the last few years).
The Arduino 1.x IDE is indeed very, very basic, but it works, and it works reliably. Experienced MCU programmers forget that configuring a "real" IDE and MCU project can be daunting, requiring MCU knowledge that a beginner doesn't possess. The Arduino IDE just works, allowing a beginner to focus on learning the concepts of MCU programming without getting bogged down with, discouraged by, or outright blocked by IDE/project configuration. Not to mention that before Arduino, most MCU toolchains were prohibitively expensive.

Arduino IDE 2.x is a big improvement, in that it now has autocomplete and hardware debugging support. But as I have explained already, one can also program Arduino using other IDEs, like the very popular PlatformIO.

* How does hiding compiler messages make it "simpler"? Those messages are valuable.
Where'd you get the idea that it hides compiler messages? It doesn't by default, and you can set the verbosity to even higher if you want.

A real issue is that compiler messages are often completely useless to a beginner -- and often are useless even to an experienced programmer. They often refer to things that are completely meaningless unless you are intimately familiar with the entire toolchain. Or how the error messages are often entirely wrong, in that the errors are symptoms of a syntax error somewhere earlier in the code, so the line numbers in the errors aren't actually where the error is!

* The whole framework is an ugly hodgepodge of mixed C and C++.
Given that C++ is designed to be mostly a superset of C, how is this a problem? Who cares?

If you study it, you learn from bad examples.
Of your entire rant, this is one of only 2 parts that has a kernel of truth: there are a LOT of examples of really bad code out there. It's a simple consequence of there being a lot of Arduino users, some of whom are only casual programmers. But IMHO that's a small price to pay in exchange for the value of the massive ecosystem that exists around it, and the community support available.

Also, for learning C or C++, using only a PC (with software) is a much better option than any uC board.
OP didn't say their goal was to learn C/C++. Their goal is to learn MCU programming, and they mentioned C/C++ as a hurdle, not a goal.

When you use a decent IDE, it has an integrated debugger, and you can step though your code line for line effortlessly. This is a great extra tool during the learning process and helps with figuring out how the details work. Also, C and C++ are very much standardized languages (although the standards have evolved a lot over the last 50 years) I quite often design and debug algorithms on my PC, and only port them to an uC after the algorithm is debugged and working. If you know you want to port it later to a microcontroller, you can also do some extra tricks. For example, you can declare the special uC registers as simple variables. This does not get timers or uarts working, but if you start with the right names, you don't have to modify them when you port the code to an uC.
This is the other part that has a kernel of truth: writing and debugging algorithms running on your computer is indeed much easier than on an MCU. I do the same thing. (Often, I just use www.onlinegdb.com rather than firing up Visual Studio or Xcode. Even if it didn't have debugging, which it does, the much shorter compile-run cycle saves tons of time compared to the compile-run-upload cycle of MCU programming.)

You can also use an RTOS such as FreeRTOS or ChibiOS. Often this is not really necessary for a small uC (think arduino), but for a bit more complex uC (ARM Cortex) it's a reasonable fit. Using an RTOS can give you some structure that helps with keeping the code better readable, and it also makes code re-use easier.
True, but as I've replied to the others who have suggested RTOS programming here: this isn't the time for that. Let people master the basics first!

(I also find it amusing that people bash Arduino for hiding the hardware beneath abstractions, supposedly preventing people from learning how things actually work, but then go on to suggest starting out with an RTOS, which... hides the hardware beneath abstractions!)






 
The following users thanked this post: brucehoult

Offline Picuino

  • Frequent Contributor
  • **
  • Posts: 730
  • Country: 00
    • Picuino web
Re: Getting started with microcontrollers
« Reply #61 on: March 17, 2024, 10:23:08 am »
Good luck, starting may look intimidating, but for someone who can program 6502 with assembler, it should not be hard...
That's what it might seem at first, but moving from the absolute flexibility of ASM to C is not so easy. You have to learn to submit to structured programming, forget GOTO/JMP and it's not immediate.
 

Offline brucehoult

  • Super Contributor
  • ***
  • Posts: 4039
  • Country: nz
Re: Getting started with microcontrollers
« Reply #62 on: March 17, 2024, 10:44:53 am »
"Arduino" has become very popular because it's easy to get started with, but very unfortunately it is quite a kludge and I don't like the platform much.

* The form factor of the "classic" arduino's is atrocious (I sort of like the "arduino nano" which is breadboard compatible).
So what? It works just fine for getting started, and there's a huge ecosystem of expansion boards ("shields") designed around that form factor.

I see nothing with which to disagree in this post. Saved me the effort.
 
The following users thanked this post: tooki

Offline brucehoult

  • Super Contributor
  • ***
  • Posts: 4039
  • Country: nz
Re: Getting started with microcontrollers
« Reply #63 on: March 17, 2024, 10:47:47 am »
Good luck, starting may look intimidating, but for someone who can program 6502 with assembler, it should not be hard...
That's what it might seem at first, but moving from the absolute flexibility of ASM to C is not so easy. You have to learn to submit to structured programming, forget GOTO/JMP and it's not immediate.

I'm not sure what language you're thinking of (maybe Java or Python?), but C is perfectly happy to let you write your whole program in one function, using labels, gotos, and shared variables.
 
The following users thanked this post: Rick Law

Online pcprogrammer

  • Super Contributor
  • ***
  • Posts: 3710
  • Country: nl
Re: Getting started with microcontrollers
« Reply #64 on: March 17, 2024, 10:56:25 am »
Good luck, starting may look intimidating, but for someone who can program 6502 with assembler, it should not be hard...
That's what it might seem at first, but moving from the absolute flexibility of ASM to C is not so easy. You have to learn to submit to structured programming, forget GOTO/JMP and it's not immediate.

C is in a lot of ways easier then ASM and has similar levels of flexibility. Working with data is much more of a hassle in ASM where you have to do much more to access something in an array of data than it is in C. It might be faster in ASM, but with modern compilers the optimization is very good. With for instance ARM ASM you have to know a lot about addressing modes, conditional execution and what more, that is all hidden in C.

Many will say that goto in C is a no no, but it works just the same as in ASM and if you want you can program however you like in C. Using structured programming makes it easier to read and able to be used by others, but it is not a must.

And what do you mean with it is not immediate. Loading a peripheral register with a value is just as immediate as in ASM, unless your compiler does special things. And with modern processor architectures with pipe lining and other optimization schemes even your ASM might not execute in the order you expect it.

As someone whom has done a lot of ASM programming for various targets like Z80, 6502, 8051 to name just a couple and loved it very much, C is actually a relief in how easy it is to program stuff and it is much easier to reuse code for another project or on another processor platform.

Offline Picuino

  • Frequent Contributor
  • **
  • Posts: 730
  • Country: 00
    • Picuino web
Re: Getting started with microcontrollers
« Reply #65 on: March 17, 2024, 11:10:33 am »
Good luck, starting may look intimidating, but for someone who can program 6502 with assembler, it should not be hard...
That's what it might seem at first, but moving from the absolute flexibility of ASM to C is not so easy. You have to learn to submit to structured programming, forget GOTO/JMP and it's not immediate.

I'm not sure what language you're thinking of (maybe Java or Python?), but C is perfectly happy to let you write your whole program in one function, using labels, gotos, and shared variables.

Yes, you can make a spaghetti program in C, but that's not the way.
 

Offline brucehoult

  • Super Contributor
  • ***
  • Posts: 4039
  • Country: nz
Re: Getting started with microcontrollers
« Reply #66 on: March 17, 2024, 11:39:17 am »
Good luck, starting may look intimidating, but for someone who can program 6502 with assembler, it should not be hard...
That's what it might seem at first, but moving from the absolute flexibility of ASM to C is not so easy. You have to learn to submit to structured programming, forget GOTO/JMP and it's not immediate.

I'm not sure what language you're thinking of (maybe Java or Python?), but C is perfectly happy to let you write your whole program in one function, using labels, gotos, and shared variables.

Yes, you can make a spaghetti program in C, but that's not the way.

It's not the way you should program in ASM either.
 

Offline Picuino

  • Frequent Contributor
  • **
  • Posts: 730
  • Country: 00
    • Picuino web
Re: Getting started with microcontrollers
« Reply #67 on: March 17, 2024, 12:14:46 pm »
From experience with other programmers, the move from assembler to C is easy when it comes to understanding pointers, for example, but costly when it comes to implementing structured programming. I'm just saying that the change is not so immediate.
And of course programming everything in a single function with global variables and gotos does not seem to me a logical choice.
« Last Edit: March 17, 2024, 12:16:52 pm by Picuino »
 

Offline ozcar

  • Frequent Contributor
  • **
  • Posts: 322
  • Country: au
Re: Getting started with microcontrollers
« Reply #68 on: March 17, 2024, 04:39:46 pm »
...

* C & C++ programs start with a main( ) function (after startup code). and "arduino" have hidden that and added a ridiculous "setup() and "loop( )".
Pointless elitism that has zero merit from a technical standpoint.

The Arduino structure
Code: [Select]
setup()
  {
    //your code that runs once goes here
  }
loop()
  {
    //your code that runs repeatedly goes here
  }
is literally just shorthand for
Code: [Select]
main()
  {
    //your code that runs once goes here
 
   while(true)
     {
       //your code that runs repeatedly goes here
     }
  }

They compile to the exact same thing, and frankly, the setup()/loop() syntax is easier to understand, especially for a beginner. Remember, Arduino was literally designed as an educational tool for non-techies, and it does well at that goal.


Saying that those are equivalent could lead to wrong assumptions.

The traditional AVR main() contains this:

Code: [Select]
setup();

for (;;)
{
loop();
if (serialEventRun) serialEventRun();
}

Cores for other processors do other messing around on return from loop().
 
The following users thanked this post: tooki

Offline abeyer

  • Frequent Contributor
  • **
  • Posts: 292
  • Country: us
Re: Getting started with microcontrollers
« Reply #69 on: March 17, 2024, 10:36:17 pm »
if you want to add some large comment to document some details it's okay, but don't mix it with code. Just put that comment in one place, for example at the top of file and keep the code clean and free of spam.

For example:
...

There may be cases for using these comments, but please don't just use them to duplicate details stored in your vcs, and which will invariably get out of sync and not be correct. If you absolutely must have things like version, last changed, etc... in the text of your code, use your vcs and automation to populate them (and thus ensure they stay correct) rather than manually entering them.
 

Offline abeyer

  • Frequent Contributor
  • **
  • Posts: 292
  • Country: us
Re: Getting started with microcontrollers
« Reply #70 on: March 17, 2024, 10:51:04 pm »
As if learning Python is any simpler than learning C.  :palm:

The OP here might be an exception here as he isn't a beginner and comes in with a background in asm already... but python is 100% easier for beginners to get started/get productive with, and I say that having both formal and informal experience teaching multiple languages to university and adult learners. Things like manual memory management, pointers, and the associated operators are all fiddly bookkeeping details you have to keep straight in your head, and trying to do that while also learning the basic mechanics and logic of programming in general is an extra burden. It's not insurmountable, if someone wants to start with C/C++ it's certainly possible, plenty of people have learned that way, and you will end up with a deeper understanding of some things. But it's disingenuous and not helpful to underestimate the additional challenges. Some people may want that, and more power to them, but they should make that choice with their eyes open.
 
The following users thanked this post: tooki

Online radiolistener

  • Super Contributor
  • ***
  • Posts: 3381
  • Country: ua
Re: Getting started with microcontrollers
« Reply #71 on: March 18, 2024, 01:14:48 am »
Here is nice startup code for novice. This is a code example for LED blinking.
It is written in Rust language for STM32 bluepill arduino board.
Code: [Select]
// std and main are not available for bare metal software
#![no_std]
#![no_main]

extern crate stm32f1;
extern crate panic_halt;
extern crate cortex_m_rt;

use cortex_m_rt::entry;
use stm32f1::stm32f103;

// use `main` as the entry point of this application
#[entry]
fn main() -> ! {
    // get handles to the hardware
    let peripherals = stm32f103::Peripherals::take().unwrap();
    let gpioc = &peripherals.GPIOC;
    let rcc = &peripherals.RCC;

    // enable the GPIO clock for IO port C
    rcc.apb2enr.write(|w| w.iopcen().set_bit());
    gpioc.crh.write(|w| unsafe{
        w.mode13().bits(0b11);
        w.cnf13().bits(0b00)
    });

    loop{
        gpioc.bsrr.write(|w| w.bs13().set_bit());
        cortex_m::asm::delay(2000000);
        gpioc.brr.write(|w| w.br13().set_bit());
        cortex_m::asm::delay(2000000);
    }
}

You can find more details on how to compile it and upload into microcontroller here:
https://jonathanklimt.de/electronics/programming/embedded-rust/rust-STM32F103-blink/

As you can see, it is very easy, you can play with it and extend its functionality. That way you can learn programming for microcontrollers.
« Last Edit: March 18, 2024, 01:19:37 am by radiolistener »
 

Offline dobsonr741

  • Frequent Contributor
  • **
  • Posts: 674
  • Country: us
Re: Getting started with microcontrollers
« Reply #72 on: March 18, 2024, 01:34:50 am »
Still too much boilerplate needed in rust (unwrap, unsafe to name a few), and secret handshakes with the hardware the novice would not know what are they and where is it coming from (apb2enr, set bit, etc.)

IMO circuitpython is the simplest, and saves a lot of semicolons!

Code: [Select]

import time
import board
import digitalio

led = digitalio.DigitalInOut(board.LED)
led.direction = digitalio.Direction.OUTPUT

while True:
    led.value = True
    time.sleep(0.5)
    led.value = False
    time.sleep(0.5)
« Last Edit: March 18, 2024, 01:40:44 am by dobsonr741 »
 
The following users thanked this post: tooki

Offline brucehoult

  • Super Contributor
  • ***
  • Posts: 4039
  • Country: nz
Re: Getting started with microcontrollers
« Reply #73 on: March 18, 2024, 05:47:20 am »
Still too much boilerplate needed in rust (unwrap, unsafe to name a few), and secret handshakes with the hardware the novice would not know what are they and where is it coming from (apb2enr, set bit, etc.)

Agreed on this part.

The fewer lines (and tokens!) in the minimal "blink an LED" program the better!

Quote
IMO circuitpython is the simplest, and saves a lot of semicolons!

Code: [Select]

import time
import board
import digitalio

led = digitalio.DigitalInOut(board.LED)
led.direction = digitalio.Direction.OUTPUT

while True:
    led.value = True
    time.sleep(0.5)
    led.value = False
    time.sleep(0.5)

You lost me here.

Looking at my keyboard, the writing is completely worn off the A, S, C, and L keys and 90% gone on D, E, O and the Windows/Mac CMD keys. The semicolon key is not visibly worn at all, and I'm working in C, C++, Java, C# all day long.

Python take a slow processor and makes it MUCH slower. A 16 MHz AVR running native code is acceptable for lots of stuff and (~50x faster than a 6502), but saddle it with an interpreted language and it's going to be a lot slower than a 1970s micro. Still ok for many things, but that also cuts out a lot of possibilities.

Still faster than a 6502 or z80 running BASIC, probably, but I learned how to POKE 6502 instructions into RAM and run them on probably my 2nd or 3rd day with the machine, it was THAT necessary. Can CircuitPython even do that? On a Harvard machine like an AVR?

Your Python example is not significantly simpler than Arduino C++ code:

Code: [Select]
void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
  digitalWrite(LED_BUILTIN, HIGH);
  delay(500);
  digitalWrite(LED_BUILTIN, LOW);
  delay(500);
}

In fact the Python has 13 more "words" than the C++. And 6 fewer punctuation characters. At best I'd call it a draw, but I think the cognitive advantage might even lie with C++ here. The use of semicolons and { } is highly stylized and learned in minutes.
« Last Edit: March 18, 2024, 10:02:00 pm by brucehoult »
 
The following users thanked this post: pcprogrammer

Online pcprogrammer

  • Super Contributor
  • ***
  • Posts: 3710
  • Country: nl
Re: Getting started with microcontrollers
« Reply #74 on: March 18, 2024, 07:58:41 am »
Indeed the separation between functions and actions is much clearer in C than in Python, where it is based on the number of indents, for as far as I'm aware. Have not done much in Python to be honest, and there is a reason for it. To me the learning curve for Python seems much steeper than for plain C. Why because you have to dive into the standard functions much more to get things done. In C I can get everything I want done with just the basic syntax. No need for any external library.

Having the memory handling done for you might be easier, but it still needs you to think about what to put in it and how to do this. I tried ones to do something with Python and wanted to put some data in an array, but not in the first location. Turns out you have to set up the array first to be fully filled or use dedicated functions for it or something like that.

In C I find this to be much easier and clearer. Declare an array with some dimensions and write to the location you want with the standard array indexing. Sure you can write outside the array and do stupid things, but I expect you can do stupid things in any language.

But to each his own.

Offline brucehoult

  • Super Contributor
  • ***
  • Posts: 4039
  • Country: nz
Re: Getting started with microcontrollers
« Reply #75 on: March 18, 2024, 08:25:59 am »
Having the memory handling done for you might be easier

You can easily have this is C too.

Simply:

- apt install libgc-dev   (or the equivalent on your OS)

- in your program #include <gc.h> and call GC_malloc() instead of malloc()

- add -lgc to your gcc/linker options

That's it!

You can also build it to simply replace the standard malloc() and make free() a NOP.

The Boehm GC for C has been developed and used and battle-tested on almost every kind of computer for over 35 years since 1988. It has been used in many big programs such as Inkscape, GNU Java, and Guile, Mono. Probably tons more that don't advertise it.

I use it in basically all of my personal C/C++ programs.

In 2006 I ported it to Qualcomm's BREW mobile phone OS, for use in the AlcheMo Java compiler (on ARM7TDMI chips).

It's not appropriate for chips such as the AVR with 2K of RAM, but it's fine on anything that can run CircuitPython/MicroPython!

I don't know why more people don't know about and use it.
 

Online radiolistener

  • Super Contributor
  • ***
  • Posts: 3381
  • Country: ua
Re: Getting started with microcontrollers
« Reply #76 on: March 18, 2024, 02:04:24 pm »
Still too much boilerplate needed in rust (unwrap, unsafe to name a few), and secret handshakes with the hardware the novice would not know what are they and where is it coming from (apb2enr, set bit, etc.)

yes, python looks more simple and short, but it produce slow and unsafe code. This is not a good choice for microcontrollers.
The gem of Rust is that it produce fast and safe code and don't allows to use things which leads to undefined behavior.

If Rust looks complicated, it's better to choice C language.
Microcontrollers have too small amount of memory and lack of processing speed, so using slow and bloat language is definitely not a smart choice...
« Last Edit: March 18, 2024, 02:10:41 pm by radiolistener »
 

Offline Picuino

  • Frequent Contributor
  • **
  • Posts: 730
  • Country: 00
    • Picuino web
Re: Getting started with microcontrollers
« Reply #77 on: March 18, 2024, 02:19:32 pm »
The advantage of C is that it is the most widely accepted language with the most compilers for microcontrollers.
Rust does not have the acceptance of C for now.
 

Online radiolistener

  • Super Contributor
  • ***
  • Posts: 3381
  • Country: ua
Re: Getting started with microcontrollers
« Reply #78 on: March 18, 2024, 03:45:50 pm »
Rust is a natural choice for creating programs for microcontrollers, mobile devices and PC.

By the way, Rust is now supported for linux kernel development, you can use it instead of C now.
Quote
With 6.1, however, there is something fundamentally different. For the first time in Linux's history, in addition to C, you'll be able to use another language, Rust, for kernel development.

Why? As Wedson Almeida Filho of Google's Android Team said, "We feel that Rust is now ready to join C as a practical language for implementing the kernel. It can help us reduce the number of potential bugs and security vulnerabilities in privileged code while playing nicely with the core kernel and preserving its performance characteristics."

Specifically, as Alex Gaynor and Geoffrey Thomas explained at the 2019 Linux Security Summit, almost two-thirds of Linux kernel security holes [PDF] come from memory safety issues. And where do they originate? Inherent weaknesses in C and C++. Rust, on the other hand, dodges these issues by using far safer application programming interfaces (APIs). Rust is simply safer than C.

Recently, the US National Security Agency (NSA), which is in charge of securing code as well as breaking it, suggested that one of the best things you can do for your program's security is to use memory-safe languages such as Rust instead of C.

Rust is a modern replacement for old C. So, there is a sense to start your new projects in Rust. :)
« Last Edit: March 18, 2024, 03:49:25 pm by radiolistener »
 

Offline Rick Law

  • Super Contributor
  • ***
  • Posts: 3442
  • Country: us
Re: Getting started with microcontrollers
« Reply #79 on: March 18, 2024, 05:46:21 pm »
Recall the OP's question is "Getting started with microcontrollers."

Given the ecosystem Arduino has, information and example are readily available - possibly exceeding competing ecosystems by many folds.  That made the Arduino ecosystem a prime choice for "getting started".

Once one got started, one can always switch to more feature filled, stronger, or more powerful systems.  For the getting started phase, the easiest and simplest (in getting going and in getting additional info/help) is probably the most suitable.
 
The following users thanked this post: voltsandjolts, tooki, radiohomebrewer2000

Online tooki

  • Super Contributor
  • ***
  • Posts: 11550
  • Country: ch
Re: Getting started with microcontrollers
« Reply #80 on: March 18, 2024, 06:30:12 pm »
Here is nice startup code for novice. This is a code example for LED blinking.
It is written in Rust language for STM32 bluepill arduino board.
Code: [Select]
// std and main are not available for bare metal software
#![no_std]
#![no_main]

extern crate stm32f1;
extern crate panic_halt;
extern crate cortex_m_rt;

use cortex_m_rt::entry;
use stm32f1::stm32f103;

// use `main` as the entry point of this application
#[entry]
fn main() -> ! {
    // get handles to the hardware
    let peripherals = stm32f103::Peripherals::take().unwrap();
    let gpioc = &peripherals.GPIOC;
    let rcc = &peripherals.RCC;

    // enable the GPIO clock for IO port C
    rcc.apb2enr.write(|w| w.iopcen().set_bit());
    gpioc.crh.write(|w| unsafe{
        w.mode13().bits(0b11);
        w.cnf13().bits(0b00)
    });

    loop{
        gpioc.bsrr.write(|w| w.bs13().set_bit());
        cortex_m::asm::delay(2000000);
        gpioc.brr.write(|w| w.br13().set_bit());
        cortex_m::asm::delay(2000000);
    }
}

You can find more details on how to compile it and upload into microcontroller here:
https://jonathanklimt.de/electronics/programming/embedded-rust/rust-STM32F103-blink/

As you can see, it is very easy, you can play with it and extend its functionality. That way you can learn programming for microcontrollers.
”Very easy” my ass. Even passively understanding what that code does requires preexisting knowledge that a beginner will not possess. Heck, I’m not a beginner and I have no clue what most of that code does!

I see that reply as the kind of didactic disconnect so many naturally gifted programmers have: it’s in no way useful to a learner. It’s not simple, and merely declaring it is doesn’t make it so! 
 
The following users thanked this post: Avelino Sampaio

Online pcprogrammer

  • Super Contributor
  • ***
  • Posts: 3710
  • Country: nl
Re: Getting started with microcontrollers
« Reply #81 on: March 18, 2024, 07:01:11 pm »
It feels a bit like everybody needs to show how knowledgeable they are by bringing far to complex stuff to the table for a beginner.

Like Rick Law wrote this is about getting started with microcontrollers and for that Arduino based on the ATmega328 is the simplest one can get.

Forget faster or dual core or wifi connectivity or what ever programming language out there and just follow your already chosen path with the UNO. In time and when you feel like it, it is always an option to step up to something faster or more complex with a more "mature" IDE if needed.

Online tooki

  • Super Contributor
  • ***
  • Posts: 11550
  • Country: ch
Re: Getting started with microcontrollers
« Reply #82 on: March 18, 2024, 10:34:42 pm »
It feels a bit like everybody needs to show how knowledgeable they are by bringing far to complex stuff to the table for a beginner.

Like Rick Law wrote this is about getting started with microcontrollers and for that Arduino based on the ATmega328 is the simplest one can get.

Forget faster or dual core or wifi connectivity or what ever programming language out there and just follow your already chosen path with the UNO. In time and when you feel like it, it is always an option to step up to something faster or more complex with a more "mature" IDE if needed.
Hear, hear!
 

Offline soldarTopic starter

  • Super Contributor
  • ***
  • Posts: 3166
  • Country: es
Re: Getting started with microcontrollers
« Reply #83 on: March 18, 2024, 11:12:31 pm »
Recall the OP's question is "Getting started with microcontrollers."

Given the ecosystem Arduino has, information and example are readily available - possibly exceeding competing ecosystems by many folds.  That made the Arduino ecosystem a prime choice for "getting started".

Once one got started, one can always switch to more feature filled, stronger, or more powerful systems.  For the getting started phase, the easiest and simplest (in getting going and in getting additional info/help) is probably the most suitable.

It feels a bit like everybody needs to show how knowledgeable they are by bringing far to complex stuff to the table for a beginner.

Like Rick Law wrote this is about getting started with microcontrollers and for that Arduino based on the ATmega328 is the simplest one can get.

Forget faster or dual core or wifi connectivity or what ever programming language out there and just follow your already chosen path with the UNO. In time and when you feel like it, it is always an option to step up to something faster or more complex with a more "mature" IDE if needed.

Yeah. It feels like some posts are more trying to scare me away. I am trying to not pay attention to them or i will just give up.

I have ordered the Arduino Uno R3 and when i get it I will get started with IDE 2.3.2 and ask questions from there. Often too many choices is a bad thing. 
All my posts are made with 100% recycled electrons and bare traces of grey matter.
 
The following users thanked this post: xrunner, tooki, pcprogrammer, radiohomebrewer2000

Offline Rick Law

  • Super Contributor
  • ***
  • Posts: 3442
  • Country: us
Re: Getting started with microcontrollers
« Reply #84 on: March 18, 2024, 11:43:14 pm »
...
I have ordered the Arduino Uno R3 and when i get it I will get started with IDE 2.3.2 and ask questions from there. Often too many choices is a bad thing. 

Good idea... That is simple.  I can give you a step-by-step, but I suspect you may just want to figure it out yourself.

Oh, this silly Arduino thing is not educational, so no sense wasting time "discovering" wading through the confusion.  Arduino call program source code a "sketch"...
 

Online MarkF

  • Super Contributor
  • ***
  • Posts: 2550
  • Country: us
Re: Getting started with microcontrollers
« Reply #85 on: March 19, 2024, 03:16:16 am »
I have ordered the Arduino Uno R3 and when i get it I will get started with IDE 2.3.2 and ask questions from there. Often too many choices is a bad thing.

You can open the examples from the IDE file menu and compile them without any hardware.
It will give you a jump on learning your way around the IDE and you can see how the example code
is laid out.  You can also start learning C and the Arduino calls to read and write to the I/O ports.

Then when your hardware comes, you just plug it in and download the programs you've been learning.

Don't let the fanboys and their favorite programming language of the month scare you off.
C/C++ is still the most used language in industry (except for financial institutions) and they are slow to change.
I my 40 years of software development we used Assembly, Fortran, a brief year of Ada, and then C/C++.
Python seems to have a niche in the academic scene.

And there are about as many ways to write and document your code as there are programmers.
Unless you're working in a large group.  My largest group of programmers contained 14 people and we had
very strict guidelines to follow for number of lines of code per module, documentation, design reviews, etc.
Even down to variable names we were forbidden to use.  I see no reason for any of it to be brought up or
discussed here when someone is just learning a new language and MCUs.
« Last Edit: March 19, 2024, 03:26:22 am by MarkF »
 

Online radiolistener

  • Super Contributor
  • ***
  • Posts: 3381
  • Country: ua
Re: Getting started with microcontrollers
« Reply #86 on: March 19, 2024, 04:56:02 am »
Heck, I’m not a beginner and I have no clue what most of that code does!

Are you kidding? Common dude, the code is pretty clean.
It may scary for you just because it uses some new syntax which is not familiar for you, but that can be learned within several hours.

Just look, the structure is very transparent:

First we declare which libraries and featrues we will use:
Code: [Select]
// std and main are not available for bare metal software
#![no_std]
#![no_main]

extern crate stm32f1;
extern crate panic_halt;
extern crate cortex_m_rt;

use cortex_m_rt::entry;
use stm32f1::stm32f103;

Then we have main code:
Code: [Select]
#[entry]
fn main() -> ! {
...
}

which consists of two parts, first part is initialization:
Code: [Select]
    // get handles to the hardware
    let peripherals = stm32f103::Peripherals::take().unwrap();
    let gpioc = &peripherals.GPIOC;
    let rcc = &peripherals.RCC;

    // enable the GPIO clock for IO port C
    rcc.apb2enr.write(|w| w.iopcen().set_bit());
    gpioc.crh.write(|w| unsafe{
        w.mode13().bits(0b11);
        w.cnf13().bits(0b00)
    });

and the second part is main loop:
Code: [Select]
loop{
        gpioc.bsrr.write(|w| w.bs13().set_bit());
        cortex_m::asm::delay(2000000);
        gpioc.brr.write(|w| w.br13().set_bit());
        cortex_m::asm::delay(2000000);
    }

There is even no need to know Rust to read the code and say what it does, it self explaining...

The only thing which may be not obvious are these manipulations for GPIO port configuration. But this is not Rust specific thing, this is MCU specific details, which will be the same for any language. You're needs to read MCU datasheet in order to learn it.
« Last Edit: March 19, 2024, 05:10:40 am by radiolistener »
 

Online pcprogrammer

  • Super Contributor
  • ***
  • Posts: 3710
  • Country: nl
Re: Getting started with microcontrollers
« Reply #87 on: March 19, 2024, 06:55:06 am »
Are you kidding? Common dude, the code is pretty clean.

Sure I can read it but it looks cluttered with all the objects needed to do  a simple thing. A bit like java with all the dot extensions to call a simple thing.

Like "cortex_m::asm::delay(2000000);" when in C with your own function "delay(2000000);" is enough. But here you need to select the top class, sub class and then the function you want to use.

And "safe" is just a word. Nothing is really safe. Mistakes are easily made even for experienced programmers and the "safe" flies out of the window.

Further more here we are most likely advising someone who has retired and wants to play with microcontrollers. Don't think "safe" code is high on his priority list.

Offline brucehoult

  • Super Contributor
  • ***
  • Posts: 4039
  • Country: nz
Re: Getting started with microcontrollers
« Reply #88 on: March 19, 2024, 08:52:54 am »
Are you kidding? Common dude, the code is pretty clean.

Sure I can read it but it looks cluttered with all the objects needed to do  a simple thing. A bit like java with all the dot extensions to call a simple thing.

Like "cortex_m::asm::delay(2000000);" when in C with your own function "delay(2000000);" is enough. But here you need to select the top class, sub class and then the function you want to use.

It's crazy!  Will this code work on a board with an AVR, PIC, MIPS, RISC-V, ESP32 with XTensa?

I think no, it's got to be rewritten.

The Arduino code works on EVERYTHING, without any modification.

How many lines of code have to be changed if you want to toggle something other than pin 13?  I see four. It should be one. On Arduino you don't even have to know which pin the built in LED is actually on -- there'a a macro for that.

Quote
And "safe" is just a word. Nothing is really safe. Mistakes are easily made even for experienced programmers and the "safe" flies out of the window.

Completely agree.

In the 80s I was a big fan of bondage and discipline languages such as Ada, Pascal, and here we have Rust. I'm not now.

Sure, they make it harder to make certain kinds of coding errors. But they totally fail to address the other 90%, 98%, whatever it is. Not to mention specification errors, architectural design errors, algorithm errors.

Or even something as simple as writing..

Code: [Select]
loop{
    gpioc.bsrr.write(|w| w.bs13().set_bit());
    cortex_m::asm::delay(2000000);
    gpioc.bsrr.write(|w| w.bs13().set_bit());
    cortex_m::asm::delay(2000000);
}

I'm completely converted from bondage and discipline languages as the panacea to Test Driven Incremental Development. Write a little bit, test a little bit, write a little bit more. Keep lots of tests around to detect regressions.

Once you're doing that, even a typeless language can be used reliably, though I definitely prefer a language where you can write user-defined problem domain types on things such as function arguments and class members and critical local variables, firstly as DOCUMENTATION for the human, but the compiler also checks them if you supply them. And infers the types of everything else as much as possible.
 
The following users thanked this post: tooki, pcprogrammer

Offline paulca

  • Super Contributor
  • ***
  • Posts: 4055
  • Country: gb
Re: Getting started with microcontrollers
« Reply #89 on: March 19, 2024, 01:04:29 pm »
what is better readable?  ;)

Hey, give em a break.  They (MCU coders) are doing absolutely fine learning the 1980s.  Let's not have TOO high expectations, eh?
"What could possibly go wrong?"
Current Open Projects:  STM32F411RE+ESP32+TFT for home IoT (NoT) projects.  Child's advent xmas countdown toy.  Digital audio routing board.
 

Offline soldarTopic starter

  • Super Contributor
  • ***
  • Posts: 3166
  • Country: es
Re: Getting started with microcontrollers
« Reply #90 on: March 19, 2024, 02:40:10 pm »
If I may interrupt for a moment....

I see ELEGOO UNO R3 Board ATmega328P with USB Cable(Arduino-Compatible) for Arduino which looks exactly the same and is $10 cheaper. Is it a clone that I can use exactly the same? Can I get this Elegoo board and use it just the same?

https://www.amazon.com/ELEGOO-Board-ATmega328P-ATMEGA16U2-Compliant/dp/B01EWOE0UU/ref=sr_1_2_sspa
All my posts are made with 100% recycled electrons and bare traces of grey matter.
 

Online pcprogrammer

  • Super Contributor
  • ***
  • Posts: 3710
  • Country: nl
Re: Getting started with microcontrollers
« Reply #91 on: March 19, 2024, 02:56:16 pm »
Yep it is much the same. The main processor is the ATmega328P and that is what is needed.

The bonus on this one is the 16U2 MCU they use for the communication with the PC. So yes you can save yourself some money.

Offline soldarTopic starter

  • Super Contributor
  • ***
  • Posts: 3166
  • Country: es
Re: Getting started with microcontrollers
« Reply #92 on: March 19, 2024, 03:03:56 pm »
Yep it is much the same. The main processor is the ATmega328P and that is what is needed.

The bonus on this one is the 16U2 MCU they use for the communication with the PC. So yes you can save yourself some money.
Thanks. From some of the posts I had understood that the Arduino includes some kind of boot firmware or something like that which makes it work with the IDE on the computer and I want to make sure this will also work. If it works exactly the same then I will get it but if I need to tinker with it before I even get started then I would rather pay $10 more and save myself the trouble.
All my posts are made with 100% recycled electrons and bare traces of grey matter.
 

Online pcprogrammer

  • Super Contributor
  • ***
  • Posts: 3710
  • Country: nl
Re: Getting started with microcontrollers
« Reply #93 on: March 19, 2024, 03:07:35 pm »
It states 100% compatibility.  :-+

Even 2 dollar nano's bought on Aliexpress have the bootloader. Not sure if you can still get them for 2 dollar though. Have not looked at AVR (ATmega and ATtiny) boards for quite some time.

Online Aldo22

  • Frequent Contributor
  • **
  • Posts: 694
  • Country: ch
Re: Getting started with microcontrollers
« Reply #94 on: March 19, 2024, 03:18:54 pm »
@soldar: Maybe a starter kit wouldn't be bad for the absolute beginning. There's a lot of cheap stuff to get you started playing.

e.g. (not tested)
https://www.aliexpress.com/item/1005006060347174.html
 

Offline Rick Law

  • Super Contributor
  • ***
  • Posts: 3442
  • Country: us
Re: Getting started with microcontrollers
« Reply #95 on: March 19, 2024, 05:23:58 pm »
It states 100% compatibility.  :-+

Even 2 dollar nano's bought on Aliexpress have the bootloader. Not sure if you can still get them for 2 dollar though. Have not looked at AVR (ATmega and ATtiny) boards for quite some time.

I tend to agree that likely you will not have compatibility issues.  In over a dozen rounds of UNO/NANO purchases, I've yet to come across one with boot-loader that has compatibility problem.  You do need to set your IDE to the right board (Arduino UNO), the right CPU (ATMega328), and perhaps the right COM port -- I think COM may be auto detect.  Not sure if you would need driver for the UNO's serial port as well.

I did get a pack that didn't have the boot-loader, just once shopping based of CPA (Cheapest Price Available) but just once.  With NANO, the more likely problem you may run into are the ATMega318's.  The ATMega318 is the little brother of ATMega328.  Price has come down so much that the 318 NANOs is rare, but I suppose the chip-shortage might have brought it back to life.  Buying on-line from a store an ocean away is like life, and life is like a box of chocolates -- you never know what you'll get...

Once you get past that (connect/compile/download), you may think "why would I waste money on a kit" when I can buy the components a lot cheaper.  Depending on what you try, you will gather up your own collection of components.  You know, a bread-board, some LED's, some ballast resistors, some more coffee, or whatever.  The difficulty is not just in getting the hardware, the difficulty may be getting the associated software (that really works) -- such as the software for an SD card reader module, or running a specific LED display.
 

Online MarkF

  • Super Contributor
  • ***
  • Posts: 2550
  • Country: us
Re: Getting started with microcontrollers
« Reply #96 on: March 19, 2024, 05:47:41 pm »
Yep it is much the same. The main processor is the ATmega328P and that is what is needed.

The bonus on this one is the 16U2 MCU they use for the communication with the PC. So yes you can save yourself some money.
Thanks. From some of the posts I had understood that the Arduino includes some kind of boot firmware or something like that which makes it work with the IDE on the computer and I want to make sure this will also work. If it works exactly the same then I will get it but if I need to tinker with it before I even get started then I would rather pay $10 more and save myself the trouble.

What you're looking for is clearly stated in the middle of the Amazon page.

2079122-0

The bootloader is a small piece of code in any MCU that allows you to download your program without the need for additional hardware (for example a PICKIT 3 for downloading programs into Microchip PIC microcontroller).
 

Online pcprogrammer

  • Super Contributor
  • ***
  • Posts: 3710
  • Country: nl
Re: Getting started with microcontrollers
« Reply #97 on: March 19, 2024, 07:28:02 pm »
But in case something goes wrong and you need to reload a bootloader it is also not that hard.

An USBASP can be used to load a new one. (Search for USBASP programmer) Or a spare nano or UNO can be programmed to act as one and be used to do the same thing.



This video tells how to do it, or this instructable takes you through the steps. And of course Arduino itself also comes to the rescue.

Offline zilp

  • Regular Contributor
  • *
  • Posts: 206
  • Country: de
Re: Getting started with microcontrollers
« Reply #98 on: March 19, 2024, 07:30:26 pm »
Thanks. From some of the posts I had understood that the Arduino includes some kind of boot firmware or something like that which makes it work with the IDE on the computer and I want to make sure this will also work. If it works exactly the same then I will get it but if I need to tinker with it before I even get started then I would rather pay $10 more and save myself the trouble.

As others have already said, you will almost certainly get one with the bootloader installed, especially so given that the article description seems to say so, and also, just in general, clones are fine. After all, they aren't complicated, they are mostly the MCU with a crystal and a USB/serial bridge in a standardized form factor.

But also, even if the bootloader were missing, that's really not a hard thing to fix, especially with an electronics background. avrdude not only supports the bootloader protocol, but also various bit-banging adapters for the "native" AVR programming scheme, so, if you have some PC/laptop with a serial or parallel port, it's just a matter of wiring up a few pins and writing the bootloader to the chip that way.

Really, I think you are over-thinking this. Just buy one. Most likely, things will just work ... and in the unlikely case that something doesn't work, it won't be that hard to fix, especially with the help of this forum, and you would even learn something along the way. It's not like you will spend a month tinkering to get things working. Even in the worst case, you absolutely for certain will get this running in an afternoon at most, and most likely in minutes.
 

Online tooki

  • Super Contributor
  • ***
  • Posts: 11550
  • Country: ch
Re: Getting started with microcontrollers
« Reply #99 on: March 19, 2024, 09:27:29 pm »
Heck, I’m not a beginner and I have no clue what most of that code does!

Are you kidding? Common dude, the code is pretty clean.
It may scary for you just because it uses some new syntax which is not familiar for you, but that can be learned within several hours.

Just look, the structure is very transparent:



There is even no need to know Rust to read the code and say what it does, it self explaining...

The only thing which may be not obvious are these manipulations for GPIO port configuration. But this is not Rust specific thing, this is MCU specific details, which will be the same for any language. You're needs to read MCU datasheet in order to learn it.
I didn’t say it was “scary”. I just said I don’t know what it means. As I said: I am not a naturally gifted programmer. What seems obvious to you may not be obvious to me, and just declaring that it’s obvious doesn’t actually make it so.

No, the code is not transparent or self-explanatory. Heck, it’s not even transparent or self-explanatory even with the knowledge of what the code does! The only reason it is transparent and self-explanatory to you is because you are already very familiar with the language and the MCU. As I said before: complete didactic disconnect.


The fact that programming that requires knowing the MCU intimately is precisely why Arduino is successful for hobbyists and beginners and everything else is not: Arduino does not demand that you familiarize yourself with the MCU intimately before you can get anything done. You clearly don’t see or understand the value of getting a beginner going with a low barrier to entry. Early successes are encouraging, and make the learner experience that they can get it to do something.

Arduino’s C/C++ code, especially the basics, are truly self-explanatory, and that also helps the learner learn both the syntax and the functions.
 

Online tooki

  • Super Contributor
  • ***
  • Posts: 11550
  • Country: ch
Re: Getting started with microcontrollers
« Reply #100 on: March 19, 2024, 09:42:44 pm »
Yep it is much the same. The main processor is the ATmega328P and that is what is needed.

The bonus on this one is the 16U2 MCU they use for the communication with the PC. So yes you can save yourself some money.
Thanks. From some of the posts I had understood that the Arduino includes some kind of boot firmware or something like that which makes it work with the IDE on the computer and I want to make sure this will also work. If it works exactly the same then I will get it but if I need to tinker with it before I even get started then I would rather pay $10 more and save myself the trouble.
Having the bootloader is a key element of an Arduino board. They’re never intended to ship out without one.


The only complication clone boards have over the genuine Arduinos is the USB-serial bridge: genuine ones (which use a second Atmega MCU with custom firmware as the bridge) don’t need any USB-serial driver on a Mac or Linux, and on Windows the driver is installed with the IDE if I recall correctly. The clones use one of a number of USB-serial bridge ICs (CH340, CP2102N, FT232, etc.), which all work fine, but typically require the user to install a driver manually. Once you’ve done that, the clones work identically to the originals.
 

Offline zilp

  • Regular Contributor
  • *
  • Posts: 206
  • Country: de
Re: Getting started with microcontrollers
« Reply #101 on: March 20, 2024, 12:22:28 am »
The only complication clone boards have over the genuine Arduinos is the USB-serial bridge: genuine ones (which use a second Atmega MCU with custom firmware as the bridge) don’t need any USB-serial driver on a Mac or Linux, and on Windows the driver is installed with the IDE if I recall correctly. The clones use one of a number of USB-serial bridge ICs (CH340, CP2102N, FT232, etc.), which all work fine, but typically require the user to install a driver manually. Once you’ve done that, the clones work identically to the originals.

Drivers for all the usual USB UARTs are in the vanilla Linux kernel, so that's a complete non-issue on Linux.
 
The following users thanked this post: tooki

Offline brucehoult

  • Super Contributor
  • ***
  • Posts: 4039
  • Country: nz
Re: Getting started with microcontrollers
« Reply #102 on: March 20, 2024, 12:52:46 am »
If I may interrupt for a moment....

I see ELEGOO UNO R3 Board ATmega328P with USB Cable(Arduino-Compatible) for Arduino which looks exactly the same and is $10 cheaper. Is it a clone that I can use exactly the same? Can I get this Elegoo board and use it just the same?

https://www.amazon.com/ELEGOO-Board-ATmega328P-ATMEGA16U2-Compliant/dp/B01EWOE0UU/ref=sr_1_2_sspa

The ELEGOO stuff is great. I have a number of their Uno and Mega2650 boards, in preference to official Arduino. They also have very good bundles with sensors and servos and misc electronic components for people who don't already have that stuff.

It works exactly the same as the official board in every respect. Will take 2 minutes to make it work.
 

Online radiolistener

  • Super Contributor
  • ***
  • Posts: 3381
  • Country: ua
Re: Getting started with microcontrollers
« Reply #103 on: March 20, 2024, 04:26:37 am »
You clearly don’t see or understand the value of getting a beginner going with a low barrier to entry. Early successes are encouraging, and make the learner experience that they can get it to do something.

Yes, I don't see any barriers here to entry for beginners. The only barrier here is a mind lock like "it looks unclear and not familiar for me, so I don't  want to look into it and don't want to learn it". This is not a barrier, but just an unwillingness to learn something new.
 

Offline MrAl

  • Super Contributor
  • ***
  • Posts: 1440
Re: Getting started with microcontrollers
« Reply #104 on: March 20, 2024, 05:30:08 am »
Yep it is much the same. The main processor is the ATmega328P and that is what is needed.

The bonus on this one is the 16U2 MCU they use for the communication with the PC. So yes you can save yourself some money.
Thanks. From some of the posts I had understood that the Arduino includes some kind of boot firmware or something like that which makes it work with the IDE on the computer and I want to make sure this will also work. If it works exactly the same then I will get it but if I need to tinker with it before I even get started then I would rather pay $10 more and save myself the trouble.
Having the bootloader is a key element of an Arduino board. They’re never intended to ship out without one.


The only complication clone boards have over the genuine Arduinos is the USB-serial bridge: genuine ones (which use a second Atmega MCU with custom firmware as the bridge) don’t need any USB-serial driver on a Mac or Linux, and on Windows the driver is installed with the IDE if I recall correctly. The clones use one of a number of USB-serial bridge ICs (CH340, CP2102N, FT232, etc.), which all work fine, but typically require the user to install a driver manually. Once you’ve done that, the clones work identically to the originals.

Hi,

This isn't the same thing, but I've gotten Nano's with bad boot loaders.  One time I could program the boot loader in myself over the old one and it worked after that, but one never worked so I had to use the miniUSB programmer to program that one board, but only that one.
The miniUSB programmer is not expensive either and it's good to have one, or another Arduino set up to program another Arduino.

On the topic of the Arduino itself again...
I think the boards like the Uno and Nano have a really nice number of i/o pins which makes them quite useful
I was really surprised at the number of i/o pins on the Mega, quite a board!
I was a little disappointed that the Due only works on 3.3 volts.  Most of the stuff I had at the time was 5 volts so it takes a lot more to get the i/o pins to interface with 5 volts using a Due.  Since there are a lot of i/o pins on that board too, it takes a lot of logic level shifters.  I did not like that idea because it detracts from the simplicity of the Arduino concept.
 

Online radiolistener

  • Super Contributor
  • ***
  • Posts: 3381
  • Country: ua
Re: Getting started with microcontrollers
« Reply #105 on: March 20, 2024, 07:00:03 am »
I would suggest to use STM32 board with SWD in-circuit debugger, it allows to program the chip and debug it inside circuit step-by-step with no need to have some bootloader in the microcontroller.

For example, this board supports SWD: https://www.aliexpress.com/item/1005006110046576.html
You're don't needs bootloader and serial port to program it. Just use some cheap Chinese ST-LINK USB-SWD interface.

With using SWD you can stop your program in microcontroller at any moment of time and discover it's state (registers/memory/peripherals) in debugger. It don't needs bootloader. This is very useful, especially if you're newbie and want to discover what happens inside microcontroller when you run your program.
« Last Edit: March 20, 2024, 07:58:53 am by radiolistener »
 

Online xrunner

  • Super Contributor
  • ***
  • Posts: 7518
  • Country: us
  • hp>Agilent>Keysight>???
Re: Getting started with microcontrollers
« Reply #106 on: March 20, 2024, 11:27:28 am »
I would suggest to use STM32 board with SWD in-circuit debugger, it allows to program the chip and debug it inside circuit step-by-step with no need to have some bootloader in the microcontroller.

Baloney. That's like telling a newly licensed driver that they need to buy a OBD scanner to be able to analyze what's going on with their car if something confusing happens while driving.

Newbies - please don't listen to this person. Get an Arduino UNO and try some basic setups like lighting some LEDs or reading a temperature sensor. I've used them for more then ten years - Nano, Uno, Due, and the new Uno R4 and I've never once needed to debug any program step-by-step.

Just get one and have fun.  :-+
I told my friends I could teach them to be funny, but they all just laughed at me.
 
The following users thanked this post: tooki, pqass, pcprogrammer, Aldo22

Online radiolistener

  • Super Contributor
  • ***
  • Posts: 3381
  • Country: ua
Re: Getting started with microcontrollers
« Reply #107 on: March 20, 2024, 12:30:29 pm »
Baloney. That's like telling a newly licensed driver that they need to buy a OBD scanner to be able to analyze what's going on with their car if something confusing happens while driving.

No. That's like telling a newly licensed driver that they need to buy parking radar for better learning to parking. Yes, they can do that without parking radar, but it will be much more complicated for them, because they don't get enough feedback what is going on around vehicle while they trying to parking in a limited space with poor visibility.

The same thing with in-circuit debugging for microcontrollers. It allows newbies to see what is going on in the microcontroller when they trying to do something. And it helps to understand it more easy why something going wrong and how to fix it. It will helps newbies a lot.

Newbies - please don't listen to this person. Get an Arduino UNO and try some basic setups like lighting some LEDs or reading a temperature sensor. I've used them for more then ten years - Nano, Uno, Due, and the new Uno R4 and I've never once needed to debug any program step-by-step.

In my opinion this is bad recommendation.
Well... I didn't wanted to talk my thoughts about arduino due to my negative attitude towards their libraries and IDE, but it appears that it needs to be explained.

Arduino is a bloated and very expensive marketing platform. When you use it, you're paying ten's times higher price and get very slow and very expensive MCU with a small features. Yes, they provide you with their branded IDE and libraries designed for noobs which allows to simplify copy-paste coding with no knowledge at all. But when you use it, you will not learn microcontrollers and you will get stick with arduino market. That's the issue.

I know guys who using arduino for about 10 years and still don't know how to deal with microcontrollers with no arduino platform (to be clear I'm talking not about you or someone in this thread). They are ready to pay hundred dollars for arduino development board just because they don't know how to deal with non arduino boards which cost just ten dollars and can provide you 100-1000 times higher performance, much more hardware features. This looks like crazy for me.

They are not newbie, but they stuck with these arduino products and don't know how to deal with non arduino boards at all. And they even don't want to learn something else. That's looks like some kind of disease, and I often see the same symptoms from many peoples, and they all have one thing in common - they started with arduino... :) 

This is not a joke, I really see that behavior, even in this thread several peoples demonstrated that "arduino" symptom... And this is not only my discovery. All my colleagues who professionally working with MCU also had exactly the same opinion about arduino...

I think the root of cause for that is that they started with a wrong way. In my opinion their main mistake is using arduino as a first platform. They started with arduino and this formed in them an attraction to this arduino market and a reluctance to learn anything else.

This is some kind of fast food, there are some peoples who like to eat fast food and just don't want to eat healthy and delicious food. They prefer to eat some fast food which cause cancer simply because it is full of chemical flavor enhancers... It become so crazy, that people consciously refuses healthy food and voluntarily eating fast food... And the things are even worse many of them well understand that this is bad for their health, but no longer able to abandon the chosen path...

Exactly the same issue with arduino. Of course this is your choice, but note, if you start with arduino it will learn you how to use arduino products, but not how to use microcontrollers.  ;)

Note that the faster way to code something and the best way to do it are different things.

PS: in my opinion spending money on Nano, Uno, Due and other marketing arduino stuff is a big waste of money. It's better to spend a little bit more time to learn with some STM32 board. You will get much faster MCU and much more hardware features at much cheaper price and you will not be tied to the arduino market platform.

If you're planning to learn microcontrollers for professional use, I strongly don't recommend to start with arduino.
But if you're don't planning to code for microcontrollers professionally, and just want to play with some electronic stuff for a short period of time, arduino platform may be the best solution for you, because it allows to use it with no knowledge at all, but at the price of much higher cost.
« Last Edit: March 20, 2024, 01:13:33 pm by radiolistener »
 
The following users thanked this post: BILLPOD

Offline zilp

  • Regular Contributor
  • *
  • Posts: 206
  • Country: de
Re: Getting started with microcontrollers
« Reply #108 on: March 20, 2024, 01:10:32 pm »
They are not newbie, but they stuck with these arduino products and don't know how to deal with non arduino boards at all. And they even don't want to learn something else.

There you have the reason why. People who don't want to learn, won't learn. I doubt that that has much to do with arduino, other than that arduino allows people to get things done to some degree without learning much.

And that especially so given that arduino has very little actual lock-in. I mean, it's all Free Software anyhow, and the hardware can be used just fine without an arduino specific software, too, so there really aren't any barriers to learning more, other than that people just don't want to.

PS: in my opinion spending money on Nano, Uno, Due and other marketing arduino stuff is a big waste of money.

Now, that might be true for genuine arduino boards, but especially for the ones you mention the market is flooded with clones, so those really don't have to be expensive. I mean, really, the arduino nano ist just the small-ish AVR equivalent of a blue pill for STM32: A standardized pinout board that is breadboard-compatible and that is cheap and convenient, if you buy clones, and that is perfectly usable without any of the arduino software (and on the flip side, my understanding is that you can use blue pill boards with the arduino IDE/framework stuff, too ...).
 

Online radiolistener

  • Super Contributor
  • ***
  • Posts: 3381
  • Country: ua
Re: Getting started with microcontrollers
« Reply #109 on: March 20, 2024, 01:26:01 pm »
A standardized pinout board that is breadboard-compatible and that is cheap and convenient, if you buy clones, and that is perfectly usable without any of the arduino software

that is also true for external modules, I'm often using arduino format sensors and modules with STM32 microcontrollers and with no arduino software.

But STM32 dev boards also compatible with breadboard. For example, bluepill with STM32F103C8T6 well fit on breadboard.

So, this is not unique specific of arduino dev boards.

And I don't see any advantage of using arduino dev boards with no arduino software.
Their microcontrollers are slower and had less hardware features than STM32 dev boards.
« Last Edit: March 20, 2024, 01:38:05 pm by radiolistener »
 

Online radiolistener

  • Super Contributor
  • ***
  • Posts: 3381
  • Country: ua
Re: Getting started with microcontrollers
« Reply #110 on: March 20, 2024, 01:48:11 pm »
I mean, really, the arduino nano ist just the small-ish AVR equivalent of a blue pill for STM32

No, that is mistake.

Arduino Nano uses ATmega328P which is 8-bit 16 MHz MCU with 32k FLASH and 2k RAM.

While bluepill uses STM32F103C8T6 which is 32-bit ARM core running at 72 MHz with 64k or 128k FLASH and 20k RAM.

In addition, STM32F103C8T6 has SWD interface and a lot of peripherals, include 12-bit ADC, PWM, CAN, I2C,SPI,Serial, etc.

This is like attempt to compare ZX Spectrum with Raspberry Pi  :D


Someone may say that ZX Spectrum is better for newbie than Raspberry Pi because Basic-48 is more easy to learn and newbie don't needs so many features from Raspberry Pi, but I would recommend to use Raspberry Pi for learning computers...  :)
« Last Edit: March 20, 2024, 02:00:09 pm by radiolistener »
 

Offline dobsonr741

  • Frequent Contributor
  • **
  • Posts: 674
  • Country: us
Re: Getting started with microcontrollers
« Reply #111 on: March 20, 2024, 01:55:04 pm »
+1 for debugging in the Arduino IDE.

It was missing for a long long time, now it’s there. It’s there for a reason, and because it’s valuable. Printf/println debugging is a huge waste of time.

So the recommendation in year 2024, IMO, is to start with an Arduino supported M0 CPU, that has debugging support. Not for the first led blinky, but down the road it will save time and allows OP to make better progress and understanding.

A perfect example if $47 is not upsetting: https://store-usa.arduino.cc/products/arduino-zero?selectedStore=us

There are alternatives at lower cost, just not that neat single package as Zero.
« Last Edit: March 20, 2024, 01:59:18 pm by dobsonr741 »
 

Offline Picuino

  • Frequent Contributor
  • **
  • Posts: 730
  • Country: 00
    • Picuino web
Re: Getting started with microcontrollers
« Reply #112 on: March 20, 2024, 02:14:50 pm »
Setting up an 8-bit peripheral usually takes no more than a setup to 2 or 3 8-bit registers. It is relatively simple to understand and memorize so that you know what you are doing.

In the case of 32-bit microcontrollers it is a very different story. The number of bits to set is multiplied several times to make it quite difficult for someone who is just starting out.

The memory of the Arduino Uno R3 is more than enough to do all kinds of projects that someone starting out might need.
If at some point you want to upgrade to a more powerful board (for the same price as the UNO R3), you can switch to the Arduino UNO R4, with a 32-bit microcontroller, much more memory and input/output pins running at 5V.

I see that this topic is being completely ignored and it is fundamental. It has nothing to do with working with 5V or 3.3V. All external boards have to change to adapt to different working voltages.

 
The following users thanked this post: tooki

Offline Picuino

  • Frequent Contributor
  • **
  • Posts: 730
  • Country: 00
    • Picuino web
Re: Getting started with microcontrollers
« Reply #113 on: March 20, 2024, 02:21:14 pm »
https://store.arduino.cc/products/uno-r4-minima
Price: €18,00
Clock speed    48 MHz
Memory    256 kB Flash, 32 kB RAM
Circuit operating voltage    5 V
Input voltage (VIN)    6-24 V
DC Current per I/O Pin    8 mA       <--- much less than Atmega328P (typical for 32-bit microcontrollers)
 

Online radiolistener

  • Super Contributor
  • ***
  • Posts: 3381
  • Country: ua
Re: Getting started with microcontrollers
« Reply #114 on: March 20, 2024, 02:34:30 pm »
Setting up an 8-bit peripheral usually takes no more than a setup to 2 or 3 8-bit registers. It is relatively simple to understand and memorize so that you know what you are doing.

I don't agree. Most of usual arithmetic operations requires to work with 32 integers. It's not easy for newbie to do 32-bit arithmetic with several 8-bit operations in a row and using carrier flag. It's much more easy to do it with a single 32-bit operation, like it happens on STM32.

In the case of 32-bit microcontrollers it is a very different story. The number of bits to set is multiplied several times to make it quite difficult for someone who is just starting out.

No, this is not difficult. When you needs to add two 32-bit integer on 32-bit MCU, you're just use one add operation, it is much more easy to understand than a sub-routine which consists of several 8-bit operations in a row which is required on 8-bit MCU.

The memory of the Arduino Uno R3 is more than enough to do all kinds of projects that someone starting out might need.

ZX Spectrum had 48K memory which was more than enough for 3D games like Elite or Saboteur with a huge map. But this doesn't means that ZX Spectrum is better for newbie than Raspberry Pi for learning computers and programming languages.

If at some point you want to upgrade to a more powerful board (for the same price as the UNO R3), you can switch to the Arduino UNO R4, with a 32-bit microcontroller, much more memory

With STM32 you can more easy switch to more powerful core like STM32F7 which can run at 216 MHz with 462 DMIPS and use external 8MB RAM and 16 MB FLASH with graphics display support, hardware floating point and many other things.

and input/output pins running at 5V.
I see that this topic is being completely ignored and it is fundamental. It has nothing to do with working with 5V or 3.3V. All external boards have to change to adapt to different working voltages.

Regarding to 5V GPIO, bluepill already has a lot of 5V tolerant pins and can work with 5V signals with no issue.
For example, I control 2x16 LCD with 5V interface directly connected to STM32 bluepill with no issue.

As you can see 5V tolerant GPIO is not an issue for STM32 boards.
 

Online radiolistener

  • Super Contributor
  • ***
  • Posts: 3381
  • Country: ua
Re: Getting started with microcontrollers
« Reply #115 on: March 20, 2024, 02:50:56 pm »
https://store.arduino.cc/products/uno-r4-minima
Price: €18,00
Clock speed    48 MHz
Memory    256 kB Flash, 32 kB RAM
Circuit operating voltage    5 V
Input voltage (VIN)    6-24 V
DC Current per I/O Pin    8 mA       <--- much less than Atmega328P (typical for 32-bit microcontrollers)

https://www.aliexpress.com/item/1005005303669884.html
Price: 3.39 USD
Clock speed: 170 MHz
Memory: 128kB FLASH, 32kB RAM

Note that this is full 32-bit ARM core running at 170 MHz with hardware multiplier and floating point support, hardware DSP acceleration, 2 x 12-bit DAC and 12-bit ADC.

It has USB OTG FS port and 18 GPIO pins, more than in your example... ;)

https://www.aliexpress.com/item/1005006632336183.html
Price: 12.40 USD
Clock speed: 480 MHz
Memory: 2048kB FLASH, 1MB RAM

2 x 12-bit DAC, 3 x 16-bit ADC, FPU floating point unit, USB OTG and 82 GPIO



« Last Edit: March 20, 2024, 02:59:31 pm by radiolistener »
 

Offline brucehoult

  • Super Contributor
  • ***
  • Posts: 4039
  • Country: nz
Re: Getting started with microcontrollers
« Reply #116 on: March 20, 2024, 02:52:26 pm »
Setting up an 8-bit peripheral usually takes no more than a setup to 2 or 3 8-bit registers. It is relatively simple to understand and memorize so that you know what you are doing.

I don't agree. Most of usual arithmetic operations requires to work with 32 integers. It's not easy for newbie to do 32-bit arithmetic with several 8-bit operations in a row and using carrier flag. It's much more easy to do it with a single 32-bit operation, like it happens on STM32.

A newbie?  They are going to write "a = a + b" and a thing called a C compiler will turn that into the necessary four AVR instructions. Instructions which the newbie will never see or be aware of.

I don't know what to make of you. Maybe you're a troll. Or maybe you're special. Either way, newbies should be paying zero attention to you.
 
The following users thanked this post: tooki, pcprogrammer

Online radiolistener

  • Super Contributor
  • ***
  • Posts: 3381
  • Country: ua
Re: Getting started with microcontrollers
« Reply #117 on: March 20, 2024, 03:04:39 pm »
A newbie?  They are going to write "a = a + b" and a thing called a C compiler will turn that into the necessary four AVR instructions. Instructions which the newbie will never see or be aware of.

Yes, C compiler hide it, but if you attach with debugger you will see that STM32 doing it with a single instruction, while 8-bit CPU requires several instructions to calculate 32-bit integers.

And you will need to know it in order to understand why 32-bit MCU do it much faster even if you configure both 32-bit and 8-bit MCU for the same clock frequency...
 

Online radiolistener

  • Super Contributor
  • ***
  • Posts: 3381
  • Country: ua
Re: Getting started with microcontrollers
« Reply #118 on: March 20, 2024, 03:17:06 pm »
I don't know what to make of you. Maybe you're a troll. Or maybe you're special. Either way, newbies should be paying zero attention to you.

There is nothing special. I just wonder why you're stick with these old very outdated and slow MCU for a high price, while there is much more cheap, much more fast and much more easy to debug MCU are available.

This is I would ask if you're a troll, but I understand that you seriously believe in this nonsense that these ancient and very expensive 8-bit controllers with no in-circuit debugging are better than modern 32-bit ARM cores... So, I just smile when someone trying to prove that this ancient 8-bit junk is better than modern 32-bit ARM controllers "because 8-bit is more easy for newbie"...  :D

As I mentioned before, this is the same as to saying that ZX Spectrum is better for newbie than Raspberry Pi, because ZX Spectrum has 8-bit registers, while Raspberry Pi has 64-bit registers which "is quite difficult for someone who is just starting"  :-DD To be clear, that is complete bullshit...  :)


For newbie STM32 will be more easy, because it allows him to easy debug the code inside the chip and it helps a lot even for professional developers to investigate what is going wrong and quickly fix it.

Much more fast core of STM32 and more memory also helps newbie, because it don't require to spend time on code optimizations, which definitely requires more knowledge and experience.
« Last Edit: March 20, 2024, 03:38:35 pm by radiolistener »
 
The following users thanked this post: dobsonr741

Offline aliarifat794

  • Regular Contributor
  • *
  • Posts: 50
  • Country: bd
Re: Getting started with microcontrollers
« Reply #119 on: March 20, 2024, 03:43:38 pm »
Starting with ARduino Uno will be better.
 

Online radiolistener

  • Super Contributor
  • ***
  • Posts: 3381
  • Country: ua
Re: Getting started with microcontrollers
« Reply #120 on: March 20, 2024, 04:01:24 pm »
Starting with ARduino Uno will be better.

Yeah, that's what I'm talking about...  :horse:  The mice wept, pricked themselves, but couldn't stop eating the cactus  :-DD

« Last Edit: March 20, 2024, 04:13:00 pm by radiolistener »
 

Online pcprogrammer

  • Super Contributor
  • ***
  • Posts: 3710
  • Country: nl
Re: Getting started with microcontrollers
« Reply #121 on: March 20, 2024, 04:20:34 pm »
A newbie?  They are going to write "a = a + b" and a thing called a C compiler will turn that into the necessary four AVR instructions. Instructions which the newbie will never see or be aware of.

Yes, C compiler hide it, but if you attach with debugger you will see that STM32 doing it with a single instruction, while 8-bit CPU requires several instructions to calculate 32-bit integers.

And you will need to know it in order to understand why 32-bit MCU do it much faster even if you configure both 32-bit and 8-bit MCU for the same clock frequency...

A proper IDE with debugging also hides it. It just shows you the C code being debugged and you can look at the variables. Only when you use command line debugging in gdb you can see that, but that is not for newbies.

I have to say you are full of bullshit blurting in this thread about what a newbie should learn right away. Some can and will. Others take it slow and may go further and some will just stick with Arduino. Let them be.

Yes an ARM32 based MCU is faster than an AVR based MCU, but most of the time you don't need that speed.

Online radiolistener

  • Super Contributor
  • ***
  • Posts: 3381
  • Country: ua
Re: Getting started with microcontrollers
« Reply #122 on: March 20, 2024, 04:51:11 pm »
A proper IDE with debugging also hides it. It just shows you the C code being debugged and you can look at the variables. Only when you use command line debugging in gdb you can see that, but that is not for newbies.

if you hide it completely, you will be unable to see that modifying 32-bit variable is not atomic operation on 8-bit MCU. So, you will not realize why accessing it from second thread or from interrupt with no synchronization can lead to incorrect value. While on 32-bit MCU such operation will be atomic (if stored at aligned address). So, hiding these details is a trap for you.

I have to say you are full of bullshit blurting in this thread about what a newbie should learn right away. Some can and will. Others take it slow and may go further and some will just stick with Arduino. Let them be.

This is okay if you have personal preference to use ancient and expensive MCU.
But please don't talk that using them is more easy.

If you're think that I didn't worked with old MCU, you're wrong. I wrote code in C/asm for very different platforms include 8080, Z80, 8048, 8051, PIC, AVR, MSP430, STM8, STM32, x86/x64, etc. Some of them had JTAG/SWD and some don't, so I know what I'm talking about and can compare which one is more easy.

Yes an ARM32 based MCU is faster than an AVR based MCU, but most of the time you don't need that speed.

They are not only much more faster, but they also much more easy to debug with JTAG/SWD.
And they provide you with much more features.
And they are much more cheap.

But some peoples still using old ancient MCU and still believes that it is better and more easy  :)
That is what I'm talking about.
« Last Edit: March 20, 2024, 05:54:20 pm by radiolistener »
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9890
  • Country: us
Re: Getting started with microcontrollers
« Reply #123 on: March 20, 2024, 06:34:09 pm »
You won't have to chase bugs if you don't put them in to start with.

I tend to use printf() or equivalent for debugging.  On any bare hardware project, the first thing I do is get the UART working.  Next, I add conversion functions like itoa() and a few string functions.

By all means, start with the Arduino UNO R3 and one of the Starter Kits at Amazon.  Like this one:

https://www.amazon.com/ELEGOO-Project-Tutorial-Controller-Projects/dp/B01D8KOZF4
« Last Edit: March 20, 2024, 06:39:06 pm by rstofer »
 
The following users thanked this post: tooki

Online pcprogrammer

  • Super Contributor
  • ***
  • Posts: 3710
  • Country: nl
Re: Getting started with microcontrollers
« Reply #124 on: March 20, 2024, 07:08:46 pm »
This is okay if you have personal preference to use ancient and expensive MCU.
But please don't talk that using them is more easy.

I did not say that the AVR based MCU's are my personal preference. They are simpler in many ways than ARM, or other newer more fancy MCU's, and they all have there usage.

For a newbie learning to understand the AVR based ones definitely is easier just because the core is simpler and the peripherals are simpler. You yourself state to have learned it on the old 8 bit processors, and so do a lot of us here on the forum. These processors where and are simple to understand, even though math with bigger numbers is more complex. But we learned from them because most of us started using assembler. All the high level languages hide all of that. Take Basic, a very simple and easy to learn language, A = B + C could be done with big or even fractional numbers and it just works. The same applies for C, it hides stuff for you and in most cases there is no need to debug, because it just works. For many this is enough.

And that is what Arduino brings to a lot of people, and as said before that is good for them. Lets them play with fun stuff. For the more complex projects it might not suffice, for the more experienced programmer it might feel restrictive, but that is not the issue here.

This is about Soldar who wants to play with microcontrollers and does not want a big hurdle in front of him to keep him from doing so. And sure a bluepill board or an ESP32 can just as easily be used with the Arduino IDE, but might be more problematic for a beginner.

And the cost of it all is not your problem. If a person feels fine with a more expensive board that is his prerogative. True real Arduino boards are expensive and so are ST discovery boards. Fortunately there are many clones available, but they may have their pitfalls with cloned MCU's that do not function completely the same. And that is something you don't want as a beginner.

So lets just leave it at that and stop polluting this thread with personal believes about what you think he or any other newbie should do.

Offline brucehoult

  • Super Contributor
  • ***
  • Posts: 4039
  • Country: nz
Re: Getting started with microcontrollers
« Reply #125 on: March 20, 2024, 10:08:53 pm »
A newbie?  They are going to write "a = a + b" and a thing called a C compiler will turn that into the necessary four AVR instructions. Instructions which the newbie will never see or be aware of.

Yes, C compiler hide it, but if you attach with debugger you will see that STM32 doing it with a single instruction, while 8-bit CPU requires several instructions to calculate 32-bit integers.

If newbies are using a debugger, it will be a source-level debugger.

Quote
And you will need to know it in order to understand why 32-bit MCU do it much faster even if you configure both 32-bit and 8-bit MCU for the same clock frequency...

Supercharged V12's go faster at the same RPM than 4 cylinders, but 90% of people drive 4 cylinder. They get the job done.
 
The following users thanked this post: tooki

Online radiolistener

  • Super Contributor
  • ***
  • Posts: 3381
  • Country: ua
Re: Getting started with microcontrollers
« Reply #126 on: March 21, 2024, 03:56:08 am »
For a newbie learning to understand the AVR based ones definitely is easier just because the core is simpler and the peripherals are simpler.

I don't agree with this. Less resources, less performance don't means that learning will be more easy.

I'm strongly sure STM32 is better platform for beginners.
And choice for STM32 platforms will helps to make life more easy for beginners i future...

For example. ZX Spectrum 48 "core is much more simpler and peripherals are simpler", but does it means that newbie programmer these days should use ZX Spectrum 48 instead of Raspberry Pi 4 for learning?


I know some guys who will try to prove that ZX Spectrum 48 is the only option which newbie programmer should start with and Raspberry Pi 4 is too complicated for newbie. The same as you're trying to impose your opinion that Arduino is the only option which newbie should start with. But is that true? What do you think?

Many newbies starting learning with Raspberry Pi and have better progress than these who started with ZX Spectrum 48. Despite the fact that Raspberry Pi core/peripherals are much more complicated than ZX Spectrum 48, it still helps to learn with Raspberry Pi more easy than with ZX Spectrum 48. Isn't it?  ;)


AVR was nice controllers for programming in asm 25 years ago. I remember 2004... they sent me large stickers "My microcontroller can beat your microcontroller", that was funny :) So they had good marketing even 20 years ago, but that is just marketing and ideology. These days it's architecture become very ancient and learning it will become a breaker to learn modern controllers like STM32.

I know peoples which cannot learn STM32 just because they started with AVR with Arduino and now unable to learn STM32. And since modern market is full of different STM32 and other ARM contorllers, they feel like failures and are forced to buy very expensive and slow controllers, simply because they are used to them. That's real world...  :-//

So lets just leave it at that and stop polluting this thread with personal believes about what you think he or any other newbie should do.

Note, that I didn't talked what newbie should do. This is your pollution's here with categorical statement "newbie should start with arduino UNO or nano with no alternative"  ;)

I just explained why your idea that "newbie should start with arduino" is not good, and provided info that there are other ways which is better if you want to learn microcontrollers for professional purposes.

As I already stated, this is your choice what you should use.

I just wonder, why you're trying to hide info that there are other solutions?
Why you're impose this limited arduino solution as the only and uncontested way that a beginner should do?
« Last Edit: March 21, 2024, 05:06:01 am by radiolistener »
 

Online tooki

  • Super Contributor
  • ***
  • Posts: 11550
  • Country: ch
Re: Getting started with microcontrollers
« Reply #127 on: March 21, 2024, 04:58:20 pm »
You clearly don’t see or understand the value of getting a beginner going with a low barrier to entry. Early successes are encouraging, and make the learner experience that they can get it to do something.

Yes, I don't see any barriers here to entry for beginners. The only barrier here is a mind lock like "it looks unclear and not familiar for me, so I don't  want to look into it and don't want to learn it". This is not a barrier, but just an unwillingness to learn something new.
Anything that stands in the way of getting things done — including lack of knowledge — is a barrier.

Nothing has zero barriers to entry. But some have more than others. If you don’t see this, then you’re blind.

And what you’re pushing for in subsequent replies is the exact opposite of what any sane beginner would do. You clearly have ZERO clue about how to educate, so I sincerely hope you are never in a position to be training beginners.

I suspect, however, that trying to get you to understand this is as pointless as discussing “analog vs digital” with you, in that the fact that the entire rest of the planet disagrees with you isn’t sufficient to make you reconsider your viewpoint.

So to any beginners who are reading this: ignore basically everything radiolistener has said in this thread.
 
The following users thanked this post: pcprogrammer

Online pcprogrammer

  • Super Contributor
  • ***
  • Posts: 3710
  • Country: nl
Re: Getting started with microcontrollers
« Reply #128 on: March 21, 2024, 05:55:47 pm »
Supercharged V12's go faster at the same RPM than 4 cylinders, but 90% of people drive 4 cylinder. They get the job done.

I would state that they also consume less energy (the 4 cylinder types), but that analogy does not necessarily apply to the MCU world. The older types can consume more per MHz than the newer ones.

Quote from radiolistener.
Quote
I just wonder, why you're trying to hide info that there are other solutions?
Why you're impose this limited arduino solution as the only and uncontested way that a beginner should do?

We are not hiding this, we are just stating that a lot of the other solutions are more complex to start with.
If a beginner wants to dive into the deep end with and STM32, ESP32, RP2040 or whatever is out there that is perfectly fine. And with the Arduino IDE the simple things will be most likely just as simple, but the moment you want to go a bit deeper it gets more complicated.

An STM32 timer has much more possibilities than the ones on the ATmega MCU's, and the documentation is less clear for the STM32's. That is what we are trying to put out there.

The comparison between ZX spectrum and Raspberry PI is very lame and bares no weight here. Both these systems run on an OS. Basic for the first one and mostly Linux for the latter. This makes things a lot easier. Go and try to program the Raspberry PI bare metal, without any prior knowledge. It will be much harder than doing it on a ZX spectrum. The needed information is much easier to find for a Z80 based system.

But as others have already concluded you are pulling our chains and that is what is called trolling. I have seen this behavior of you in other threads too and a lot of the more active members state to take everything you write with a grain of salt, or negate the advice to do the exact opposite. So you saying "don't use the Arduino with ATmega", actually means "use it as much as you can".  >:D

Offline dobsonr741

  • Frequent Contributor
  • **
  • Posts: 674
  • Country: us
Re: Getting started with microcontrollers
« Reply #129 on: March 21, 2024, 07:19:28 pm »
Quote
try to program the Raspberry PI bare metal

Respectfully disagree, bare metal raspberry pi is simple with Circle: https://github.com/rsta2/circle
 

Online pcprogrammer

  • Super Contributor
  • ***
  • Posts: 3710
  • Country: nl
Re: Getting started with microcontrollers
« Reply #130 on: March 21, 2024, 07:49:39 pm »
Quote
try to program the Raspberry PI bare metal

Respectfully disagree, bare metal raspberry pi is simple with Circle: https://github.com/rsta2/circle

Well that is not the intention of how I meant it. Here the work has been done by others to facilitate you to program somewhat bare metal.

My view point is to work from nothing else but the documentation available on the raspberry pi. Then it ain't simple anymore. Having to deal with multiple cores and the correct startup sequences, etc.

Everything is simple when someone else already did the hard work.

Offline dobsonr741

  • Frequent Contributor
  • **
  • Posts: 674
  • Country: us
Re: Getting started with microcontrollers
« Reply #131 on: March 21, 2024, 08:19:00 pm »
Newton said “If I have seen further it is by standing on the shoulders of Giants” February 5, 1676. Applies to us and open source. I always consider it, unless there is a corporate policy opposing a certain type of open source license.
 

Online radiolistener

  • Super Contributor
  • ***
  • Posts: 3381
  • Country: ua
Re: Getting started with microcontrollers
« Reply #132 on: March 21, 2024, 08:50:22 pm »
And what you’re pushing for in subsequent replies is the exact opposite of what any sane beginner would do. You clearly have ZERO clue about how to educate, so I sincerely hope you are never in a position to be training beginners.

I had some experience to train beginners, and they had very good progress and thanked me for the training. I success to learn even these who was unable to learn from other teacher who are professionals in education. This is nice to see their progress, it's like your own progress. But education someone eat a lot of my energy, so I think you're right - this is really not my mission to teach others. Even 2-3 hours per day for 5 students make me sucked all the energy out of me and I just collapsed at home and slept for hours. Teaching others takes too much of my energy, so I don't like it.  :)

I suspect, however, that trying to get you to understand this is as pointless as discussing “analog vs digital” with you, in that the fact that the entire rest of the planet disagrees with you isn’t sufficient to make you reconsider your viewpoint.

I well understand your point of view, but unfortunately when you can understand other point of view it don't means that he also can understand your point of view. That's the world we are living in. When you can see someones mistake, it don't means that he also can see their own mistakes... That is why I don't like to train someone, especially if he don't have enough knowledge or desire to learn... :-//

The comparison between ZX spectrum and Raspberry PI is very lame and bares no weight here. Both these systems run on an OS. Basic for the first one and mostly Linux for the latter. This makes things a lot easier. Go and try to program the Raspberry PI bare metal, without any prior knowledge. It will be much harder than doing it on a ZX spectrum. The needed information is much easier to find for a Z80 based system.

I have no idea, why you're decided that someone needs to learn computers from programming bare metal for low level hardware?  :-//

When you bought ZX Spectrum, do you started programming in Z80 machine codes or in Basic within the Basic interpreter?

The same for Raspberry Pi, why beginner should start programming bare metal for low level hardware instead of C or Python in the Linux environment? I think there is no such requirement and beginner can start programming in C or Python in the Linux environment. That is expected way.

And I think there is much more easy to find information about programming in C or Python for Linux, than for programming in Basic for ZX Spectrum.  :)
« Last Edit: March 21, 2024, 09:27:44 pm by radiolistener »
 

Online radiolistener

  • Super Contributor
  • ***
  • Posts: 3381
  • Country: ua
Re: Getting started with microcontrollers
« Reply #133 on: March 21, 2024, 10:00:56 pm »
But as others have already concluded you are pulling our chains and that is what is called trolling.

Usually the trolls themselves who blame others for trolling. I just ignore it.  :)

I have seen this behavior of you in other threads too and a lot of the more active members state to take everything you write with a grain of salt, or negate the advice to do the exact opposite.

I don't trolling, but sometimes I can say something with a kind of sarcasm or as a joke. It should be obvious.

For example when I talked about Rust in this thread, it was a bit of a joke and a bit of serious suggestion. These who follow this suggestion won't regret it, but I understand that it looks scary for newbies and very small amount of them will not be afraid and will follow this path. And they will be rewarded. And I think you're know why  ;)

The rest, who will accept your recommendation for Arduino Uno with a high probability will not be able to find themselves in programming for microcontrollers. I think this is not their mission in our world, so I’m not worried about those who take your advice, but those who take up learning Rust, I worry about them and I would like to support them :)
« Last Edit: March 21, 2024, 10:03:38 pm by radiolistener »
 

Offline kevin.gibbs

  • Contributor
  • Posts: 34
  • Country: us
    • Teardown it!
Re: Getting started with microcontrollers
« Reply #134 on: March 26, 2024, 03:31:34 pm »
If you want very simple solutions like reading inputs and activating outputs, your knowledge of assembler is enough. The code will take only a few lines after basic standard microcontroller configuration (stack placement, interrupt configuration). You will be more comfortable using the C language for more complex functions. It is probably better to start getting acquainted with it on Arduino examples.
Teardown, research, create!
 

Offline paulca

  • Super Contributor
  • ***
  • Posts: 4055
  • Country: gb
Re: Getting started with microcontrollers
« Reply #135 on: March 27, 2024, 10:15:09 am »
I think there is a lot of debate here which is people not realising they are standing in different parts of the map and shouting about their perspective of what they see as the same thing, when it isn't.

Learning MCU development as a "Bare Metal" exercise is a valid pursuit to learn about how MCUs work.  In some cases it's the only option.

However.  Times are changing.  MCUs are now getting larger, faster, cheaper and in the emerging "hobbiest" markets were cost is far less of an issue due to very low volumes and no "bean counters", so the hobbiest can afford some pretty serious MCU hardware.

The Arduino Framework certainly wasn't the first "Generic Dev Framework" for MCUs, but it is certainly the first one that the world will remember.

Whether you guys like it or not, it splits the software model in two.  Actually, if you don't start accepting it and get onboard with the idea, you will either detrimentally harm the development or screw yourself out of a job further down the road.

The split is now between:
Framework and Library code <-->  Application code.

This is a natural split point in software as it tends to be different types/classes of developers who do well in lower level, generic framework and library code and those who do better at understanding and implementing what customers actually want.

In the big iron world the splits/layers/components/dependencies split dozens and dozens of times.

You can even see it in STM32.  They have several layers of frame works and abstractions.

The difference in my humble opinion is that Arduino and it's surrounding eco-system have functioning hardware integrations and devices for thousands of devices.  STM32 ... their HAL barely works on it's own, but comes with support for exactly zero devices. 

Even with that, in STM32 the HAL and LL libs are so broken and different between models and ranges that you stand about as chance of getting a "Plug and play" hardware driver as you do getting blood out of a stone.

If you approach this from the point of view of an Application developer, their first and only question is, "How do I make it work to solve this problem and meet the customer needs?".  They do not care HOW, they just want to get something working.

In my opinion, Arduino is the place to start.  If you don't like the hand-holding, over caring framework:
* You don't have to use it.
* It only costs you about $5 to switch to an STM32.

STM32 is better if you want to explore the still stuck in the 1990s MCU land.  This is where the industry still is basically.

While you and I can drop $30 on an STM32 H750 to run a pretty heating dashboard in 2Mb of RAM.  The product industry cannot.  Not when their competitor can run it with nearly as many features on an F411 costing a tenth the price.

Summary:  Regardless of the hardware, if you want to develop applications first and foremost, then a practical, easy to learn application dev framework is the way to go.  Aka Arduino.  Even if you are running Arduino Framework on Atmel/MC 8bit micros or on STM32H7 32bit dual cores or ESP32s.  If however you want to learn the low level reality of spending months trying to fit all your requirements into 16K or RAM and a 50Mhz CPU, using ASM macros and compiler tricks all day... and still contribute to some of the most buggy and annoying sofware in the world..... don't (use a app dev framework).
"What could possibly go wrong?"
Current Open Projects:  STM32F411RE+ESP32+TFT for home IoT (NoT) projects.  Child's advent xmas countdown toy.  Digital audio routing board.
 
The following users thanked this post: Avelino Sampaio, Aldo22

Offline Rick Law

  • Super Contributor
  • ***
  • Posts: 3442
  • Country: us
Re: Getting started with microcontrollers
« Reply #136 on: March 28, 2024, 12:43:57 am »
Thanks for the replies. 

Some background: About 50 years ago I had a 6502 board and I did quite a bit with it, all programming in assembler.  Then about 30 Years ago, with PCs, Windows, etc I lost the ability to interface with the real outside world and i kept thinking how I could do it. About 25 years ago I bought a Velleman K8055 board,
https://www.velleman.eu/products/view/?country=uk&lang=en&id=351346
which I still have, but I never did much with it after my first playing around.
... ...

The OP, in this follow up reply (reply #8 on this tread) says he did 6502 assembler on a 6502 experiment board.  So he knows how to develop program with limited feature, limited resources, and limited assistance (50 yr ago, no google search for help).

His having worked with an microprocessor based experiment board, Arduino UNO will be both familiar (UNO as experiment board)  and welcoming with more assistance than anyone could expect some 30/50yrs ago.

Once he starts with an infrastructure to load and run something on an MCU of any sort, I think he can move forward from there.  Discussion about features and resources with different varieties of MCUs may be interesting, but that surely doesn't have much impact during his getting starting phase.


 

Offline brucehoult

  • Super Contributor
  • ***
  • Posts: 4039
  • Country: nz
Re: Getting started with microcontrollers
« Reply #137 on: March 28, 2024, 01:45:54 am »
The OP, in this follow up reply (reply #8 on this tread) says he did 6502 assembler on a 6502 experiment board.  So he knows how to develop program with limited feature, limited resources, and limited assistance (50 yr ago, no google search for help).

Indeed so, which is why AVR is a great place to start.

AVR is much easier to program in asm than 6502, is at least 50 times faster and often 150x -- 16x clock speed, 1 cycle/instruction vs 3-4 average, not to mention that, say, adding two local variables in registers vs two local variables in ZP is 1 instruction vs 4 (and 11 clock cycles) for 8 bit and 2 instructions vs 7 (and 2 clock cycles vs 20). Also setting up things such as GPIO on AVR is not much different to setting up GPIO on a 6522 VIA. You can't say that about STM Arm chips.

PLUS you've got the whole programming in C using the Arduino environment thing IF YOU WANT IT.
 

Offline John Celo

  • Contributor
  • Posts: 20
  • Country: lt
Re: Getting started with microcontrollers
« Reply #138 on: March 28, 2024, 01:55:15 am »
I sometimes see ESP32 and similar microcontrollers suggested to beginners based on their specs alone, while neglecting some important aspects.

Namely, ESP32 has very slow build times (even after the first build where it caches *some things*), complicated toolchain and, in part, thanks to it's very large flash (8mb!), it takes quite a long time to reprogram the flash too.

The end result is that it is gathering dust, because it not fun to use a device that compiles and flashes so slowly.
And that's after getting ESP-IDF working with debugger, breakpoints and live variables.

Only after flashing ESP32 with micropython/circuit python did I start having to have fun with it, because the frustrating slowness of the toolchain gets sidestepped. And you can REPL it and iterate quickly and, well, actually have fun!

I'd rather use an anemic Arduino Nano, because it compies and flashes quickly, than a powerful device with a slow, complicated toolchain and massive flash that takes half a minute to reflash.

It's more than just raw specs. Turns out that I don't need a powerful specs to read sensors, blink leds, control an i2c/spi displays or some motor driver modules.

I've ordered STM32 board and an STLink programmer and I'm curious to see how pleasant or unpleasant, slow or fast the toolchain and overall development experience is going to be.

Needless to say, I wouldn't recommend MCUs to beginners based on specs alone, certainly not ESP32s (unless they explicitly want wireless perhaps)
« Last Edit: March 28, 2024, 01:58:16 am by John Celo »
 

Online pcprogrammer

  • Super Contributor
  • ***
  • Posts: 3710
  • Country: nl
Re: Getting started with microcontrollers
« Reply #139 on: March 28, 2024, 06:44:41 am »
I've ordered STM32 board and an STLink programmer and I'm curious to see how pleasant or unpleasant, slow or fast the toolchain and overall development experience is going to be.

You most likely won't be disappointed. The compiler is fast (gnu arm tool chain) and since the flash memories are not that big the programming is also fast. But figuring out how to setup the peripherals based on the datasheets is a bit more of a chore. On the one side due to the complexity and capabilities they offer, and on the other side due to the somewhat crappy documentation.  >:D

Offline paulca

  • Super Contributor
  • ***
  • Posts: 4055
  • Country: gb
Re: Getting started with microcontrollers
« Reply #140 on: March 28, 2024, 10:21:37 am »
I'd rather use an anemic Arduino Nano, because it compies and flashes quickly, than a powerful device with a slow, complicated toolchain and massive flash that takes half a minute to reflash.

Wow.  Half a minute.  You won't get very far in the big iron world with a total round trick of under 30s.

In Eclipse/IntelliJ and most serious IDEs it will be compiling the build constantly in the background.  So it seems almost instant, almost, not quite, but you can make a change and hit "Run tests" and it will actually start running the tests within 10 seconds or so.  Depends on how fast your machine is and how much memory you are playing with.

However.  Once that application component is "pushed" to the repo, the build pipelines will pick it up.  Some will reuse the checkedout, prebuilt workspace and pick up from the last build, but these are usually rare and discouraged outside of "DEV" environments.  For obvious reasons(?) generally the build workspace is wiped clean and all code and dependencies downloaded fresh for each build.

In these cases a moderately sized ... say ... SpringBoot based REST API Micro-Service, with less than 1000 lines of actual code, might take 10-15 minutes to complete.  That will be about 5 minutes to download everything, like the code, the dependant jars, and resolve the external dependency tree an download it.  (This is all similar to how PlatformIO or ESPHome remote serverside builds work in MCU land, just triggered off a Git push to a branch.)  It will take about 3-5 minutes to run the build.  Then another 5 minutes or so to build the docker images and deploy it to an environment.

Even for projects which are written in non-compiled code, such as python, it still takes 30-60s to build the docker image and another minute or two to deploy them.

Granted deployment isn't always required or necessary outside of CICD/CD you can usually run the code directly in a local dev environment and point against other pre-loaded docker services on your local machine.

For a bit of exposure to this 'real' world, try this simple task.

Compile Firefox from source on Linux. 

If you have done this, I would implore you to "STFU and dry your eyes.", you have it easy.
"What could possibly go wrong?"
Current Open Projects:  STM32F411RE+ESP32+TFT for home IoT (NoT) projects.  Child's advent xmas countdown toy.  Digital audio routing board.
 

Online radiolistener

  • Super Contributor
  • ***
  • Posts: 3381
  • Country: ua
Re: Getting started with microcontrollers
« Reply #141 on: March 28, 2024, 10:27:34 am »
Compile Firefox from source on Linux. 

I wanted to compile it, but unfortunately download source code was failed due to not enough GB of free disk space. When I started download archive I didn't expected that archive will eat several GB of free disk space, but it also require even more space to unzip it...   :D
« Last Edit: March 28, 2024, 10:33:03 am by radiolistener »
 

Offline paulca

  • Super Contributor
  • ***
  • Posts: 4055
  • Country: gb
Re: Getting started with microcontrollers
« Reply #142 on: March 28, 2024, 10:35:16 am »
Compile Firefox from source on Linux. 

I wanted to compile it, but unfortunately download source code was failed due to not enough GB of free disk space. When I started download archive I didn't expected that archive will eat several GB of free disk space, but it also require even more space to unzip it...   :D

LOL, wait till you are multiple hours into the compile and it fails because it consumed >10Gb of disk.




May I add, for people like me the appeal of MCUs is their simplicity.

A platform for which you can "saturate the stack" from the very, very bottom to the very, very top.  Full 100% round-trip stack dev.  100% bespoke code.

Anyone who has tried (and it's worth doing for fun), "Bare metal" programming a modern PC will tell you it's damned complicated.  MCUs, even dual core ones are so incredibly simple in comparison you can actually get real, useful, functional code written for them.... bare metal.

Even to start to come up to something like 1980s DOS level of computing, bare metal on a modern AMD64 architecture is going to take you weeks and involve some of the most nasty low-level, detailed hardware/firmware and concurrency project you have ever encountered.

So for this I agree with those steering people away from Arduino, STM32-HAL, ESP32-IDF and others.  If you want the above go bare-metal datasheet and register macros.  Have fun.

However, my point still stands that if you want a "hobby platform" as a "maker" and your primary focus is on "making stuff" and "making stuff work", then you can take the above as optional.  Use the biggest, easiest, most convienient app dev framework for whatever hw platform you choose.

There is no need to pick one.   When we get Windows vs. Linux debates, it's pointless the answer to "Which is best?", is "Both".  Next!

I have limited experience in Arduino (including baremetal cross compiled avr toolchain), STM32-HAL, ESP32 (with arduino and IDF).

I have half a dozen H7 STMs with >1Mb static RAM, but I also have some F0's with 4K.  I have big Uno boards and I have custom PCB ATTiny85s.

No one size, platform, language, technology stack fits all.  The more the merrier.  More tools in the box with some knowledge in how to use them makes it far more likely you have the right one for the job at hand.
"What could possibly go wrong?"
Current Open Projects:  STM32F411RE+ESP32+TFT for home IoT (NoT) projects.  Child's advent xmas countdown toy.  Digital audio routing board.
 

Online pcprogrammer

  • Super Contributor
  • ***
  • Posts: 3710
  • Country: nl
Re: Getting started with microcontrollers
« Reply #143 on: March 28, 2024, 10:41:52 am »
There is no need to pick one.   When we get Windows vs. Linux debates, it's pointless the answer to "Which is best?", is "Both".  Next!

Wrong, the answer is "Neither".  :-DD


Offline brucehoult

  • Super Contributor
  • ***
  • Posts: 4039
  • Country: nz
Re: Getting started with microcontrollers
« Reply #144 on: March 28, 2024, 05:00:35 pm »
Compile Firefox from source on Linux. 

I wanted to compile it, but unfortunately download source code was failed due to not enough GB of free disk space. When I started download archive I didn't expected that archive will eat several GB of free disk space, but it also require even more space to unzip it...   :D

LOL, wait till you are multiple hours into the compile and it fails because it consumed >10Gb of disk.

What kind of computer are you guys using?

Back when I actually worked for Mozilla in 2009, Firefox took around 10 minutes to build on my quad core i7-860. I imagine on my current *laptop* it would be 2 or 3 minutes.

And SSDs today cost 6c/GB, 10c/GB for a really good one. If you're still on 3.5" hard disks, 4TB ones are $70 ... less than 2c/GB.
 

Offline paulca

  • Super Contributor
  • ***
  • Posts: 4055
  • Country: gb
Re: Getting started with microcontrollers
« Reply #145 on: March 28, 2024, 05:19:28 pm »
Requirements¶
Memory: 4GB RAM minimum, 8GB+ recommended.

Disk Space: At least 30GB of free disk space.

Operating System: A 64-bit installation of Linux. It is strongly advised that you use a supported distribution; see Supported Build Hosts. We also recommend that your system is fully up-to-date.
"What could possibly go wrong?"
Current Open Projects:  STM32F411RE+ESP32+TFT for home IoT (NoT) projects.  Child's advent xmas countdown toy.  Digital audio routing board.
 

Offline paulca

  • Super Contributor
  • ***
  • Posts: 4055
  • Country: gb
Re: Getting started with microcontrollers
« Reply #146 on: March 28, 2024, 05:30:55 pm »
Back when I actually worked for Mozilla in 2009, Firefox took around 10 minutes to build on my quad core i7-860. I imagine on my current *laptop* it would be 2 or 3 minutes.

2009.  Interesting.  My experience was around 2002 when it had only just been renamed to firefox from Mozilla (after Netscape died)

So, the last hardware I compiled it on would have been a PiledriverFX room heater octo-core with 4Gb RAM.  It took hours.  Although i did recall it being faster than vanilla Mozilla was (Mozilla at the time was trying to become a bonafide baremetal OS entirely).

The other monster when compiling a full Linux distro from source was "Open Office"  or previously "Star Office" or previously "Sun office".  It was another overnight compile with 10s of Gb of disc space used.

Back then I even had 3 old PCs all running "distcc" to speed up "OS Wide" make clean install scripts, with 100s for packages compiled.

Last time I did a full OS build though was 4 or 5 years ago. An instance of Gentoo Linux.  I recall the base system took less than an hour, the X11 layer about an hour and KDE 2 hours.  Firefox I didn't install and I accepted the "binary dist" chrome on advice at the time.

So maybe you are right and Firefox is no longer an "compile overnight" monster.
"What could possibly go wrong?"
Current Open Projects:  STM32F411RE+ESP32+TFT for home IoT (NoT) projects.  Child's advent xmas countdown toy.  Digital audio routing board.
 

Online radiolistener

  • Super Contributor
  • ***
  • Posts: 3381
  • Country: ua
Re: Getting started with microcontrollers
« Reply #147 on: March 28, 2024, 05:55:44 pm »
What kind of computer are you guys using?

Back when I actually worked for Mozilla in 2009, Firefox took around 10 minutes to build on my quad core i7-860. I imagine on my current *laptop* it would be 2 or 3 minutes.

And SSDs today cost 6c/GB, 10c/GB for a really good one. If you're still on 3.5" hard disks, 4TB ones are $70 ... less than 2c/GB.

On PC I have 5-10 GB free space on 1TB drive. When I realize that this is not enough space, I tried to download it to a fast 16GB flash drive, but it appears that it also not enough to unzip the source even if archive is downloaded to a separate disk.
« Last Edit: March 28, 2024, 05:59:14 pm by radiolistener »
 

Offline brucehoult

  • Super Contributor
  • ***
  • Posts: 4039
  • Country: nz
Re: Getting started with microcontrollers
« Reply #148 on: March 28, 2024, 06:22:47 pm »
So just for fun I tried it.

I expect 2009 Firefox would build in 2 or 3 minutes now, but 15 years later 2024 Firefox took 11m18s to build on my laptop [1]. CPU time was 204m54s User plus 8m24s System.

That's a "non-artifact" build, which is their current term for compiling all the C / C++ / Rust rather than downloading pre-built object files and only building the Javascript (etc?) implementing the UI.

Downloading and unpacking the source took around 20 or 30 min (depends on your internet speed of course), ending up using 9336 MB of disk. Fully built it's now using 26058 MB of disk. Let's call it $2.50 worth of SSD.

[1] Lenovo Legion Pro 5i (2023), i9-13900HX, 32 GB RAM, 1 TB SSD, 4060 GPU, cost $1750 inc tax&delivery
 

Offline paulca

  • Super Contributor
  • ***
  • Posts: 4055
  • Country: gb
Re: Getting started with microcontrollers
« Reply #149 on: March 28, 2024, 07:11:08 pm »
Parallelism is highly important of course.  The kernel is usually the master of this.  Given enough distcc instances and cores it will go faster and faster and faster with so many non-dependant targets to compile.  I just wish Make could cope with parallel targets including linking.

When working with LFS (Linux From Scratch) the metric was known as BinUtils.  A base system would take 24.5 BinUtils to compile.

So you referenced it by the first thing you compiled.... err binutils.  How long it took and then all other compile times where ratios to that.

EDIT:  Up to the day.  On a personal project, if I commit a code change and push it, gitlab will launch pipelines to build the python library, then build the docker image for that section of project and push it to a registry.

A single character typo can result in a wait of 5 minutes or more.

This was only implemented as a learning project, as it is how things are done when you have a few dozen developers and not one.  However, as I am one dev on this project, I am winding all of that back to simple "build.sh", "deploy.sh" scripts.  No need.  Sledge hammer to crack a nut.  CNC machine to mount a shelf.
« Last Edit: March 28, 2024, 07:14:41 pm by paulca »
"What could possibly go wrong?"
Current Open Projects:  STM32F411RE+ESP32+TFT for home IoT (NoT) projects.  Child's advent xmas countdown toy.  Digital audio routing board.
 

Online tooki

  • Super Contributor
  • ***
  • Posts: 11550
  • Country: ch
Re: Getting started with microcontrollers
« Reply #150 on: March 28, 2024, 07:19:52 pm »
I sometimes see ESP32 and similar microcontrollers suggested to beginners based on their specs alone, while neglecting some important aspects.

Namely, ESP32 has very slow build times (even after the first build where it caches *some things*), complicated toolchain and, in part, thanks to it's very large flash (8mb!), it takes quite a long time to reprogram the flash too.
That's a good point; long compile times are a downside. At least in PlatformIO, the caching makes a huge difference. On the other hand, I don't find the upload speed to be a huge burden. First off, most ESP32's come with 4MB flash; 8MB and 16MB are options. But if I'm not sorely mistaken, unused flash doesn't get uploaded. So if you're only making a small application, it will upload quickly.

I have been known to do some initial programming on AVR to get program flow or whatever working, then move it to ESP32 later. That and the aforementioned doing parts in onlinegdb.com to debug algorithms or whatever.
 

Offline radiohomebrewer2000

  • Contributor
  • Posts: 35
  • Country: us
Re: Getting started with microcontrollers
« Reply #151 on: March 31, 2024, 12:02:56 pm »
Soldar,
Have you gotten your Arduino UNO R3 yet?
Have you played with it yet?

I am curious.

I think you made a good choice.  I got an authentic Arduino UNO 3 about 12 years ago as part of a Make ultimate pack.  Most of that stuff I did not use.  I still use the solderless breadboard and the jumper wires from it.  However, I could have done without it.  Or gotten the cheaper pack.

I do like the Arduino Nano better because it fits on a solderless breadboard.  Once your design works, build on a solderable breadboard that works like a solderless breadboard with the same number of points.  However, there are these Arduino Nano sockets you can buy to plug your Nano in.  Here is a description you can search:  Nano Controller Terminal Adapter Expansion Board Nano IO Shield Simple Extension Plate for Arduino Nano AVR ATMEGA328P.  I use this so you can unplug it to make an update to your Nano's sketch.

Blink is good to start with especially since it is already on the Arduino I got.   The tutorial for getting started at Arduino.cc is good.  And the Arduino IDE is good too.  Sure, it is not as good as Eclipse of Visual Studio for an IDE, but it works.  One of things I did after getting Blink to upload and work was to modify the sketch (program) to blink faster or slower or some kind of pattern using the delay function.  This is to prove changes I make are being uploaded successfully.

And when you are ready, you can try other microcontrollers like ESP32 and programming languages like assembly, C, C++, Python, Rust, etc.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf