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

0 Members and 1 Guest are viewing this topic.

Online soldarTopic starter

  • Super Contributor
  • ***
  • Posts: 3173
  • 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.
 

Offline 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: 11263
  • 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 »
 

Online 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.
 

Online soldarTopic starter

  • Super Contributor
  • ***
  • Posts: 3173
  • 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

Offline 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.
 

Offline 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.
 

Offline 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: 3386
  • 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 »
 

Offline 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.

Online soldarTopic starter

  • Super Contributor
  • ***
  • Posts: 3173
  • 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.
 

Offline 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.


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf