Recommended books to learn about embedded? - Page 1
Forum section: electronics / general

author: Winfried
author_rank: Contributor
timestamp: January 22, 2022, 08:51:57 pm
content: Hello,I'm only getting started with microcontrollers.Since they're so tiny and affordable, I'm especially interested in ESP-based controllers, while a lot of books deal with Arduino and RaspberryPi.What books would you recommended to get started, preferably in high-level languages like Python or Lua, if available?Thank you.

author: cfbsoftware
author_rank: Regular Contributor
timestamp: January 22, 2022, 11:25:31 pm
content: I know next to nothing about Python or ESP but can recommend Elektor magazine and its publications. You might find something here of interest to you:https://www.elektor.com/espressif/books

author: nctnico
author_rank: Super Contributor
timestamp: January 22, 2022, 11:34:15 pm
content: 'Making embedded systems' by White is a nice start. It is C oriented but also goes deep into how the hardware and software interact. The latter is very important when writing software for a system with limited resources (compared to a PC).

author: rstofer
author_rank: Super Contributor
timestamp: January 23, 2022, 03:05:00 am
content: Why not start with the Arduino? There are thousands of projects on the Internet and both a hardware description and code is provided.You can eventually walk away from using the Arduino libraries and write your code for bare metal. The ATmega328P isn't the most powerful chip around but it's an easy start.Using the familiar Arduino infrastructure and similarly functioning libraries, the Teensy 4.1 is a VERY FAST CPU with a flattened learning curve if undertaken after working with the Arduino.https://www.pjrc.com/store/teensy41.htmlThe Arduino isn't the be-all end-all of uCs but it's a great place to start.Here's a starter kit that comes with everything you need to get going with the Arduino including the code to drive all the peripherals:https://www.amazon.com/ELEGOO-Project-Tutorial-Controller-Projects/dp/B01D8KOZF4It also includes an Arduino UNO clone so there's nothing else to buy. There's a lot of education in that kit.Amazon has many other kits along the same lines. There is also a really good starter kit for the Raspberry Pi.https://www.amazon.com/Freenove-Raspberry-Processing-Tutorials-Components/dp/B06W54L7B5The compatible Raspberry Pi is extra. The code files are an education in themselves. Plus, you do all the development on the same uC as you are using to experiment. In that regard, it is a lot more convenient than the Arduino starter kit which requires a PC for device programming.

author: Simon
author_rank: Unknown
timestamp: January 23, 2022, 09:11:36 am
content: Quote from: rstofer on January 23, 2022, 03:05:00 amGod NO! The arduino was intended for "makers" and "artists". It was not meant for serious work. Sadly the world missed the point and thought they had gotten their hands an a way to program a micro like a PC.If you truly want to learn embedded then step away from the arduino. Sure it's an inviting prospect to be able to do stuff in minutes but as soon as you have a need for the real hardware you will find you need to learn to do it properly. I wrote one program in arduino, and then looked to convert it to bare metal.If you can hack understanding the hardware then do, and code properly. My issue was learning to code and learning the chip all in one go. Once I had my first success just having to worry about how the code is written I was willing to play with the hardware.Micro controllers are powerful in their own right. Their power comes from their peripherals, much of these are underused in the arduino because the peripherals are so different between chips that there is no way of writing standard libraries that will work on each chip using it to it's full whilst having common code and portability.For example in the name of compatibility the ADC library will always give a 10 bit result even on chips with a 12 bit ADC, they have to go and do this in the background to make sure you get a consistent result. If you want the full 12 bit you have to add code to get back what was taken away.Full use of interrups? forget it.Arduino is so removed from the hardware that it sets you on a path to programming that is not reconcilable with how you would program in bare metal or via other less ruinous abstraction systems.

author: MarkF
author_rank: Super Contributor
timestamp: January 23, 2022, 10:38:00 am
content: I agree with Simon.If you want to learn microcontrollers and how the software interacts with hardware,stay awayfrom all things Arduino. Or using any libraries you might find. They will only remove you from understanding how the microcontroller works.More and more, I'm seeing people begging for a library to perform some function. Then, they are begging for someone to explain how is works. And after that, they are begging for someone to debug the library for them. Sometimes, you just don't have a choice. You can spend all your time searching for a library and learn nothing or write your own library and gain some insight. To this day, I avoid libraries at all costs.Also, you language of choicewill be'C'. Unless, you want to delve into assembly language. Which I strongly discourage. Todays microcontrollers are fast enough that it is rare you would need to go to such lengths. Coming from someone who started programming by toggling machine code into the front panel of a PDP-11/55 and watching lights blink.My first introduction to microcontrollers was a module from DLP Designs that contained a PIC16F877A. I would suggest starting with one of the 8-bit PIC16's and learning how to use the peripherals. One of the newer ones with a builtin oscillator. The PIC16's are simple enough that the learning curve is not too steep. Also, the initial cost is low: just the MCU in a DIP package and the programmer.Take a look at a recent thread starting with my comments and working back:https://www.eevblog.com/forum/beginners/looking-for-practice-building-circuits-that-use-microcontrollers/msg3931733/#msg3931733

author: Simon
author_rank: Unknown
timestamp: January 23, 2022, 10:44:10 am
content: My experience has been AVR and now ARM. I don't see a huge amount of complexity in the ARM chips compared to the AVR when it comes to the peripherals themselves. Just ignore all the fancy stuff and treat it like an AVR on steroids. The only complication is the clock system that is complex or rather, poorly explained and you need to know that you need to introduce wait states in the non volatile memory controller when you speed up the CPU as the flash memory can only go so fast.Interrupts are a little more complex as the interrupt controller is part of the ARM CPU and requires some delving into ARM documentation but again once you head is around it you are done.

author: Simon
author_rank: Unknown
timestamp: January 23, 2022, 10:46:53 am
content: is C++ really worthwhile on an MCU? I have set myself the goal to learn it but really that is just so that I can keep up with other peoples code if I do use external code.Using third party code is valid particularly where you want to something standard and it's not worth buggering about but like converting a number to ascii but even then I ended up writing my own and it was faster than the standard library on AVR.

author: MarkF
author_rank: Super Contributor
timestamp: January 23, 2022, 11:00:57 am
content: Quote from: Simon on January 23, 2022, 10:44:10 amThat has been my experience with the PIC18 and PIC32 series microcontrollers I've used. The internal oscillator configuration is a nightmare.

author: Simon
author_rank: Unknown
timestamp: January 23, 2022, 11:20:46 am
content: It's made worse in the case of say the SAMC (and I assume the similar SAMD) by the fact that they explain it poorly in datasheets. There really is a market out there for people to write books on these chips that actually explain how to use them rather than just list features and functionality in a way that is little more informative than some sort of computer self generated text.For example synchronized registers are not well explained and I do not know if they were the cause of the trouble I had setting up a counter with a pre-scaler. enable, pre-scaler and mode are all in CTRLA, if you don't set the mode first if you want to be in the non default mode then you can't write to registers only available in that mode. But equally if you write to the pre-scaler before enabling the counter the pre-scaler has no effect so I found myself writing to the mode bit, then writing in one go the mode again, the pre-scaler and the enable. No clue whatsoever in the datasheet and all down to trial and error. At one point it looked like I had it working and the chip was just running at 49.5MHz instead of 48MHz but I persevered in experimenting and realized that it was merely coincidence and that the prescaler was having no effect.That is the downside of ARM based stuff, while the peripheral functionality may not be any more complicated it's just harder work getting some things to work.

author: nctnico
author_rank: Super Contributor
timestamp: January 23, 2022, 12:10:52 pm
content: Quote from: rstofer on January 23, 2022, 03:05:00 amI'd start with something like the Teensy right away. Using a slow and limited processor gets in the way quickly. IMHO the Arduino is severely outdated right from the start. Starting off with a more capable microcontrollers allows to use Micropython and go from there. Micropython already supports the Teensy 3.1; support for version 4.1 is likely to follow (some people have already created ports for the processor used on the Teensy 4.1)

author: Simon
author_rank: Unknown
timestamp: January 23, 2022, 01:30:43 pm
content: Arduino does include ARM based devices. But as I said above it's just throwing more features away because the mega328 does not have them as well. I think the language is irrelevant, it's about understanding the environment you are programming on of direct hardware access and manipulation rather than just writing high level code as you would on a larger standardized platform that has an OS.I draw the line between things that would have some sort of OS and things that don't. If there is no OS then don't go looking for anything that tries to give you anything like that sort of standard functionality because it will be at the expense of the power of the chip and still you will not have portability.I do rather wonder when I see terminology such as "driver" applied to code from manufacturers.

author: Jeroen3
author_rank: Super Contributor
timestamp: January 23, 2022, 03:17:12 pm
content: Lol,arduinois not evil.When dealing with the ESP controller you actually need something like it, otherwise you're going nowhere.Quote from: Winfried on January 22, 2022, 08:51:57 pmI would not focus on the combination of those. But as separete topics. Find a book about microcontrollers processors, find a book about python.Like The Definitive Guide to ARM Cortex -M3 and Cortex -M4 Processors.I don't know of any python books, but it has reasonabledocumentation.Though C and C++ are the most commonly used, so you may need some knowledge about that first.One key thing to remember is that is doesn't matter where you program, learning to program can be with any language. The concepts remain mostly the same.The ESP32 contains many domains... C++, gnu toolchains, python, wifi, bluetooth, web standards, operating systems. Probably more.It's a very complicated product, but it's made very accessible (hence it's popularity) because you can use it with the Arduino libraries!The concept of the wireless microcontroller wasn't new, but it never really took off in the tinker markets due to the remaining complexity of utilizing them.

author: alexanderbrevig
author_rank: Frequent Contributor
timestamp: January 23, 2022, 03:34:00 pm
content: Data sheets, YouTube, blogs, forums and stack overflow is all you need. I have not found any good books,In truth I gave up on the prospect some years ago, tht any such book exists unless part- and tool-chain specific.Good luck!C++ is definitely worth it. Forth and Rust are fun tooI'll choose another part of their tool chain does not support C++, unless a client pays me my C surcharge of coursePS: I don't like Arduino because of personal experiences and affiliations, but I am here because of Arduino. My first project was to reimplement an Arduino project, with a custom PCB and only port manipulation. I learned a lot those weeks! It's been many years since i touched Arduino now though. (Disclaimer: I am part of the Wiring team, and have done consulting for Arduino)

author: rstofer
author_rank: Super Contributor
timestamp: January 23, 2022, 05:45:25 pm
content: The thing about the Arduino kit isn't the Arduino, it's the external devices and how to interface them. How many times do we see threads complaining that the user can't get I2C working or generally misunderstands SPI? Just having a working knowledge of these external protocols and the gadgets that hang off of them is quite useful before getting buried in bare metal.It's a matter of the learning curve. Starting bare metal with the Teensy 4.1 is going to be problematic. Getting the first project running is going to be exponentially more difficult than the same project on an Arduino.Once the external devices are understood, porting that understanding to a Teensy is pretty easy.OP, you didn't state where you are with 'electronics' learning. Are you learning electronics in concert with embedded systems? If so, I would double down on my recommendation of the Arduino kit. Even if you only use it for a month to learn the basics, it's an easier start than the Teensy. BTW, I go back to the beginning with Teensy boards and I like the 4.1 a lot.If you decide to walk away from Arduino, consider the Raspberry Pi kit. Among other things to learn (if you don't already know them) is how to build projects in C on Linux. You will pick up some decent skills with Linux just getting the provided projects to run. And, yes, I prefer C for everything related to uCs. There is some merit to Python because it is the most used language (or so the users say) and it has applications well beyond mere uCs. You wouldn't waste your time if you were to learn Python as well as C. Note that the Starter Kit includes code for C and Python (as well as Scratch and Java). Try them all! Learn as much coding as you can!Starting from nowhere, I think it's best to keep it simple and with as much handholding as possible. There's plenty of time later to get fancy.

author: Simon
author_rank: Unknown
timestamp: January 23, 2022, 05:47:12 pm
content: Quote from: Jeroen3 on January 23, 2022, 03:17:12 pmIf they are coming up with a new ecosystem for industrial applications sure. The problem for them is that they have run out of steam. Anyone can make a clone board and now that they have given their shoddy software away for free for so long people expect it to stay that way. If they have a proper commercial proposition for industrial controls then that is not the same as Arduino. I would not trust the current Arduino ecosystem anywhere near my stuff. Jeez, I had to fudge my code so that 80/100 = 1 stopped happening! keep that shite out of my sight thanks. The only code I want to debug is my own.

author: alexanderbrevig
author_rank: Frequent Contributor
timestamp: January 23, 2022, 06:22:07 pm
content: I know it's off topic but Simon. You must have had a particularly bad experience with Arduino. It's just C++ though, so no way80/100 == 1Given the sheer amount of people successfully using it, it can't be that bad... Maybe give it another go some weekend? Teach it to a kid in the family perhaps?

author: SiliconWizard
author_rank: Super Contributor
timestamp: January 23, 2022, 06:23:01 pm
content: It is bad, but not THAT bad indeed.

author: rstofer
author_rank: Super Contributor
timestamp: January 23, 2022, 06:41:36 pm
content: Quote from: Simon on January 23, 2022, 01:30:43 pmHow does FreeRTOS fit into your definition? Is it an OS? Arguably, yes but it is clearly targeting embedded systems.As to ARM, I started with the LPC2106 and graduated to the LPC2148. These are well documented chips by NXP but quite old at this point. I finally got to the mbed LPC1768 and used their online toolchain to build what looks to the CPU as a 100 step per inch plotter but accumulates steps and sends command strings to a LaserJet over TCP/IP. Given the mbed network library, this is almost trivial.. Big queue on input, some crunching (accumulating steps), big queue on output and a bit of network code (state machine). I really like this chip/board. mbed.org is owned by ARM.I would look for mbed compatible ARM boards given the opportunity. The libraries are worth the effort. The project and the libraries can be downloaded to a local machine if desired.https://os.mbed.com/https://os.mbed.com/platforms/https://os.mbed.com/platforms/mbed-LPC1768/FWIW, the LPC1768 User Manual is only 840 pages and there will be a test later.. That's actually brief in comparison to later chips.Of course, the Datasheet is another 93 pages...

author: Simon
author_rank: Unknown
timestamp: January 23, 2022, 06:45:08 pm
content: Quote from: alexanderbrevig on January 23, 2022, 06:22:07 pmIt was a kid that had me using it. The work experience student did a project on it and suddenly the machine he did it for was going for a demo with the customer so I had to write a load of code from scratch in a hurry in Arduino to replicate what he was trying to do. in the course of doing it I found that yes a lot of his code would not work but also hit the same problems he had due to it being the arduino. I had an topic thread on why can't I call millis or micros (can't remember which was the main problem) and it turns out that because of cross compatibility even a 32 bit ARM sporting 16kB of RAM is not allowed to do what an 8bit AVR sporting 2kB of RAM can't because we tried to make a one size fits all and if we just taught people to program embedded rather than a PC the universe would break.

author: Simon
author_rank: Unknown
timestamp: January 23, 2022, 06:50:45 pm
content: Quote from: rstofer on January 23, 2022, 06:41:36 pmMy programming experience is limited and while I have heard of it I don't know how much it does. Does it take care of your peripheral setup and work across different devices? no I don't think so. I would not call it an OS, it's a task scheduler, it just makes coding easier when you need to manage lots of tasks to the point you need a scheduler like an OS does but I think that is as far as it goes? Basically Arduino should be scrapped for proper bare metal learning, if you want anything like it promises you go the next level up I believe to something like a raspberry pi ? Where you don't do embedded you code in a Linux OS.QuoteYes I had a little look. Saw lots that seems to be in C++ so I have left it alone for now as I need to learn C++ first.

author: Simon
author_rank: Unknown
timestamp: January 23, 2022, 06:53:42 pm
content: But again with ARM we are talking a vast ecosystem from chips that run at 48MHz and are resource limited but cheap to chips that are just CPU's using external memory. Lets not forget that ARM was meant to be a PC processor originally. It was only the quest for cost saving and meticolous design that produced such a low power processor that suddenly while failing to get used in it's intended application it found its way into the embedded world only to be re-extracted later as a stand alone processor.

author: Simon
author_rank: Unknown
timestamp: January 23, 2022, 07:17:09 pm
content: Quote from: SiliconWizard on January 23, 2022, 06:23:01 pmi know, but after all the other contortions I had to go through to get the damn thing to work, I just gave up. Christ you can't even officially split programs into multiple files unless you call them a library which is not technically a library just source code.

author: netmonk
author_rank: Contributor
timestamp: January 23, 2022, 08:06:19 pm
content: I would not advice Arduino or against it.I'm still a beginner myself and far from all the experimented and professionals around.But what i can state is that there are some bias in the thread.Learning is mostly motivated with rewards. Experimented peoples have already learnt and their pleasure source is somewhere else most of the time.When you are learning new skill, it's more efficient to start small with high rewards so that the will to continue and go more difficult is keept.Of course the way to start small is not the most efficient way to achieve mastering from the master's POV, but going straight bare metal on a mcu should not be the starting point but the target.So this beeing said, what is better from a starter point of view- playing with arduino on esp 32, succeeding measuring room temperature and sending data over the internet over sunday afternoon of dirty coding- trying to spend the next 6 months understanding interruptions/timer/ low level i2c-spi communication and getting too early frustrated leading to total loss of interestAnd if you ever find a good book, then tell me. Already asked two years ago here and still no answer.

author: Simon
author_rank: Unknown
timestamp: January 23, 2022, 08:26:08 pm
content: The question is that the OP wants to understand embedded. What do we mean by embedded? Now if you are a novice in both programming and embedded environments sure the Arduino will step you into it more gently, you "just" need to follow the instructions and start to understand how to program and not worry too much about the hardware. Oh but this is supposed to be embedded, embedded means at least to me that you are working close to the hardware. These are not so powerful chips. You have chosen them specifically because of what they can do.I need to do CAN bus at some point. The best MCU that I can see is the SAMC, it has 2 CAN bus controllers built in, yet costs the same as just two CAN bus controllers, so you get the MCU for free. It will work at up to 5V which is still where a lot of automotive sits, oh. Arduino does not have a board that is based on it. They have the SAMD only.Embedded means to me using things like interrupts to make the most of your hardware. These are unsupported in Arduino with the exception of pin interrupts. Sure you can go around writing your own code to access them but then excuse me? what were you using the arduino for?Sure start with an arduino, I did, but do not expect to do anything too clever with it if you want to work in a production environment. Oh and by the way, have you noticed the chip shortage? Because I am not an arrogant berk I was happy to use a chip I had not used before, the SAMD because we already had a prototype done by the local school using the arduino. Custom hardware design based on an arduino board. But the SAMD chips are all sold, I can't possibly imagine why. So I have had to pick something else and go cold turkey because from having something I could fall back on having got the damn thing to work, I now cannot as I am forced to use another chip.If your skillset involves being put out of work the day you cannot buy a chip that the arduino runs on then uh, good luck.

author: Jester
author_rank: Frequent Contributor
timestamp: January 23, 2022, 08:43:01 pm
content: I think you will get up to speed more quickly by putting something together, even if it starts with a blinky light. The easiest way to do that is with an Arduino just to get started. After you write a few Arduino programs that do what you want them to do, you can move on to an actual bare metal type project, and make a blinky light from scratch. Start simple even a 8 pin PIC on a breadboard. My first embedded project was with a 6800 around 1980ish in assembler, about 10x perhaps 100x the effort and time compared to Arduino. IMO C is a great language and worth learning. Start small and build from there.

author: commie
author_rank: Frequent Contributor
timestamp: January 23, 2022, 09:18:49 pm
content: Quote from: MarkF on January 23, 2022, 10:38:00 amHeck, may I introduce you to paper tape and maybe once you have a grasp of that we can move onto cassette tape for input or a RS232 terminal. Di-spite what everyone is telling you, there are alternative programming languages like Bascom AVR which are encredibly easy to use (compared to 'c') and just as powerful.

author: MarkF
author_rank: Super Contributor
timestamp: January 23, 2022, 11:59:38 pm
content: Quote from: commie on January 23, 2022, 09:18:49 pmGet real. The last time I wrote a Basic program was in the 80s along with my punch cards and teletype terminal.Let's throw in a little Fortran and Pascal while we're at it. Oh, don't forget good old Ada.If you want to play around in your basement, write your little Basic programs till your hearts content.But, you will be hard pressed to find Basic being used in industry now days.Besides, C isn't any harder to program in than Basic is. If you stay away from the fancy C++ stuff, it's just minor syntax and name differences.It's all in what your goal is.If you want to quickly throw together a program to see some lights blink, get an Arduino. Then try to write 8-bit parallel data to one of those cheap LCD displays (without a shift register). Depending on which Arduino you have, you will quickly realize you have a mess and need to start packing bits because the MCU doesn't have an 8-bit port. Then when you want to start doing some real complex stuff, you will need to start over with all new hardware and setup another software development environment with new software tools to learn.On the other hand... If you want to understand how the MCU works, you won't get there by placing layer upon layer of libraries between your code and the MCU hardware. It's just NOT that hard to learn how write a blinky program on a low end microcontroller. I would even venture to say it's easier. For example, a PIC blinky program in no more that 5 or 6 lines of C code.THE CHOICE IS YOURS. Neither one is bad.

author: nctnico
author_rank: Super Contributor
timestamp: January 24, 2022, 12:19:42 am
content: Quote from: MarkF on January 23, 2022, 11:59:38 pmFamous last words... you couldn't be further from the truth. Where people go wrong with C is usually pointers and index/buffer overflows. In fact, C is much harder to program in than Basic if you want a piece of software that is rock solid. Especially where it comes to dealing with types and memory. At least C++ allows to pass variable by reference and therefore offers a way to avoid the use of pointers.And maybe Basic is no longer used today but it is replaced by other scripting languages like Lua and Python. Those languages provide some protection against common problems like buffer overflows and so on. Or at least provide ways to detect and recover gracefully instead of continuing with invalid data.

author: Cerebus
author_rank: Super Contributor
timestamp: January 24, 2022, 03:11:52 am
content: Quote from: Simon on January 23, 2022, 07:17:09 pmFundamentally and completely wrong.Done using only controls presented in the IDE user interface, specifically that little triangle on the right and the "New Tab" item it leads to, which then asks you for a filename for the new file. Note that the whole thing has built successfully.If you're going to condemn a whole platform condemn it it for things that are actually wrong with it, not for things you you couldn't figure out how to do even when they were right in front of you.

author: uer166
author_rank: Super Contributor
timestamp: January 24, 2022, 03:41:31 am
content: Here's something few people would suggest, but I find it helped me understand things with a bit of a different mindset, and allowed me to greatly improve the reliability of my systems. It's a free PDF:https://www.safetty.net/publications/pttes.It explores ways to make time triggered systems in a down-to-earth tone even beginners can understand.

author: commie
author_rank: Frequent Contributor
timestamp: January 24, 2022, 10:18:27 am
content: Quote from: MarkF on January 23, 2022, 11:59:38 pmBascom AVR is not a interpreter, it is a full compiler supporting upto 5 dimensional arrays and 64bit double floats.

author: Simon
author_rank: Unknown
timestamp: January 24, 2022, 06:28:40 pm
content: Quote from: Cerebus on January 24, 2022, 03:11:52 amfind me the official instructions, there are non. I got into suc a mess because it does not work like it does in C. Its just a painful mess.

author: nctnico
author_rank: Super Contributor
timestamp: January 24, 2022, 06:31:35 pm
content: Painfull mess is a strong term. IMHO it didn't work as you expected and it was easier for you to go bare metal. That is fine. OTOH Arduino works for a lot of people and that is also fine.I would qualify Altium as a painfull mess but nevertheless it works for a whole lot of people.

author: Simon
author_rank: Unknown
timestamp: January 24, 2022, 06:46:51 pm
content: You miss the point, there is no official support for multiple files. Have a google. You will quickly find threads on forums that never come up with an actual solution other than: "I don't recommend this but this is what I do"I ended up using the same method as our work experience student, just use header files and include them.

author: Cerebus
author_rank: Super Contributor
timestamp: January 24, 2022, 07:18:12 pm
content: Quote from: Simon on January 24, 2022, 06:46:51 pmIf there is no "official support" for multiple files, why does it compile and build from them fine? Pure accident? Why does it have a multi-tab interface for having lots of program documents open at once if it's unsupported? Somebody just thought it looked bare without tabs and they just happened to allow building projects with multiple files after they'd added tabs just for the appearance of it? Pull the other one...

author: eugene
author_rank: Frequent Contributor
timestamp: January 24, 2022, 07:24:10 pm
content: Quote from: Winfried on January 22, 2022, 08:51:57 pmWhat is your background? How much experience do you have with electronics and programming?Is there a reason you want to look past Raspberry Pi and Arduino? Have you already traveled that road are looking for something new?Do you already have a ESP32 development board? Most people are attracted to the ESP32 because of all the peripherals, but the complexity makes it harder to learn. (It also seems poorly documented, but that might be just my opinion.) I recently completed a project with an ATTINY after working with sophisticated MCU's on a whole range of platforms. Working with the simple 8 bit architecture was like an ice-cold beverage on a hot summer day.

author: eugene
author_rank: Frequent Contributor
timestamp: January 24, 2022, 07:38:31 pm
content: Quote from: Simon on January 24, 2022, 06:46:51 pmFor the record, you can add as many *.c, *.cpp, and *.h files to the project as you want. Just put them all in the same folder as your main *.ino file. As always, *.h files need to be #included explicitly, but any cpp file will be compiled and linked with the main sketch. This means you should not have extraneous files in the folder, but that's just the way the toolchain works. Like any tool, if you can't figure out how to use it, then it will likely frustrate you. OTOH, learn how and you can exploit all the hardware of any Arduino compatible board completely within the Arduino environment. I've accomplished incredible feats with Teansies and just couple hours of coding.

author: alexanderbrevig
author_rank: Frequent Contributor
timestamp: January 24, 2022, 08:30:37 pm
content: Sorry Winfried. We are derailing.I want to back Simon up on somethng actually. For the longest time (and maybe still?) enums and typedefs (and #defines got moved too I think) did not propagate correctly. So if you used either of those, the solution was/is to either move the files into a library folder (where the preprocessor won't do anything) or do everything with those types in the main tab. Finally, you could hack the base main.cpp to include (forward) declarations there.This all stems from the fact Arduino is C++, but spares the user from having to do function declarations they way they should be done. So, the preprocessor creates those for you, and in that process it will mess up and f.ex move the declaration above where you define a parameter type.I would and still have recommend newbies to at least have a try with Arduino. Have a try with a raspberry pi. Have a try with a PIC, and play around with some ARM chip (not using Arduino). If a beginner can get through all that, she may stay for the adventure and fun to come.

author: rstofer
author_rank: Super Contributor
timestamp: January 24, 2022, 09:48:39 pm
content: Quote from: Simon on January 23, 2022, 05:47:12 pmWere you printing? 80. / 100. is 1 if the format specifier doesn't allow decimal placesQuoteThe output is 1 with no decimal point and no decimal digits. There are probably other situations where rounding occurs automagically. Underlying the Arduino IDE/toolchain is avr-binutils, avr-gcc, and avr-lib. They are not specific to Arduino. I imagine it gets the right answer. I guess we would have to see the surrounding context to figure why you got a rounded answer.All bets are off if you have a problem with Arduino libraries but getting math wrong should be obvious to a lot of users.https://forum.arduino.cc/t/arduino-language-vs-c-c/65526/2https://www.nongnu.org/avr-libc/

author: Simon
author_rank: Unknown
timestamp: January 25, 2022, 06:42:14 am
content: I've never read anything about rounding, new one on me. Integer math is integer math, it does the division, no decimal place, you only get the remainder if you ask for it.

author: Simon
author_rank: Unknown
timestamp: January 25, 2022, 06:45:53 am
content: Quote from: alexanderbrevig on January 24, 2022, 08:30:37 pmYea, so you have to "randomly" declare some stuff yourself. Because it's an attempt at simplifying something, trying to do it the way that something normally works anyway actually causes problems I found.I have no problems with multiple files in a proper IDE, as soon as I try to use the arduino like a proper IDE things fall over. I look for the official method and all I find is people saying that "this is what I do". Nowhere is there official ways of doing it. Computers are methodical. They will do exactly as told, so just tell us what you told the damn computer to do!For a large program, by the time you have made it work in arduino it looks nothing like a properly set out program in a proper IDE.

author: Simon
author_rank: Unknown
timestamp: January 25, 2022, 08:36:07 am
content: Using the Arduino does not get you things like this:https://www.eevblog.com/forum/microcontrollers/hd44780u-and-derivatives-bus-timings/msg3965054/#msg3965054That display is updating on an interrupt. The Arduino based prototype takes 25ms to update and that means other stuff cannot happen unless it is on an interrupt which gets messy. This takes one half step in sending data every 100µs leaving thousands of cycles in between to do the rest of the program. Can't do that with arduino. Not because the arduino is too crap to do that but because being a system with "libraries" written to cater for any chip used you cannot leverage on the hardware. The Arduino is mostly CPU and a lot of the hardware is underused whilst the rest is badly used because they have no choice on a system that is common to an ATmega328 and a SAMD21. That is not embedded programming.If you want to work on a higher level system that does not involve bare metal then sure, that is valid too. But then pick your system and find a book on that. It does not help these days that every term is misused and abused to sound cool and it's really difficult to have a conversation with someone and be sure we are talking about the same thing.

author: Jester
author_rank: Frequent Contributor
timestamp: January 25, 2022, 03:14:56 pm
content: ]QuoteArduino is a double edged sword. Super easy to get started with little knowledge, however because so much is hidden in a wrapper if you do have some C experience and expect normal C behaviour you don’t always get what you expect and further you don’t know when Arduino will be Arduino and when Arduino will act like actual C. I seem to recall that %f is not supported in Arduino, I tried using it in sprintf() and it did not work. Not to mention the /100 reduction in speed on I/O unless you work around the normal Arduino I/O.That being said if your just starting out it’s a great way to get “started”

author: rstofer
author_rank: Super Contributor
timestamp: January 25, 2022, 04:56:40 pm
content: Quote from: Jester on January 25, 2022, 03:14:56 pmThat's been my point all along. Everybody needs to start somewhere and embedded, by definition, deals with external gadgets and the Arduino Starter Kit has a lot of gadgets. More important, it includes working code in 4 languages and full explanations. No, an Arduino won't likely be a solution to a commercial project but it is a great place to start.Starting with ARM from bare metal just seems like a very steep learning curve with little chance of success. Nevertheless, Google comes up with a lot of books for starting with STM32 - search string: 'stm32 book' (no quotes).

author: Simon
author_rank: Unknown
timestamp: January 25, 2022, 05:05:15 pm
content: Question is how much do you do with arduino before switching? I did just one program as I was dense to how C worked. once I have got my head around what was purely C and what may be hardware I went in search of more and rewrote my first program in bare metal.Doing more than getting to grips with writing some code an the arduino will not help as once you do proper embedded you work in an entirely different way. You don't have to bare metal an ARM, just do an AVR. To do anything clever with a micro you will need to understand the chip and bare metal it or use some other abstractioan system that caters to your MCU in full.i am writing my first bare metal project on ARM now. Firstly what i need to do the arduino is incapable of and it's not even hard, secondly all the problems I am having are with my limited experience and skills in C, nothing to do with the IDE or abstraction. As i have to work closely to the hardware I could not do it any other way.Deadline is 5 weeks away, usable MCU's that run arduino are out of stock but I have 1000 SAMC21 chips that I asked to be ordered back in October. Next date any of those come out of a fab is November this year - apparently, so by hook or by crook I am bare metalling this little bastard!

author: alexanderbrevig
author_rank: Frequent Contributor
timestamp: January 25, 2022, 05:14:52 pm
content: Good luck on your project!We need to stop saying Arduino is C. It is C++Saying Arduino can't handle something is dangerous. SAMC is already supported so one could just add the firmware you're making, reset registers to default values, the call your software from setup and claim victory.There is nothing magical with Arduino, neither does it lock you down to using the abstractions.For me, the little magic is broken. I still enjoy giving magic powers to others though. People blinking their first LED is magical.

author: Simon
author_rank: Unknown
timestamp: January 25, 2022, 05:21:30 pm
content: what board has the SAMC? The problem is that the working of the arduino is different to bare metal programming. If I'm going to put some bare metal stuff in then I may as well just bare metal it. I'm either bare metal or not.I'd not wnat to mess too much with the arduino with my own code. By the time I work out if what i wnat to do is OK, I will have done it bare metal in less time.

author: rstofer
author_rank: Super Contributor
timestamp: January 25, 2022, 05:51:25 pm
content: Quote from: Simon on January 25, 2022, 05:05:15 pmPerhaps just as long as it takes to work through the experiments in the Starter Kit. Maybe use it on some future mechatronics projects, maybe not. But it is worth the time and effort to work through the experiments. Learn a language, learn a device/paradigm, learn something about electronics and IO, then move on. Maybe a month's work...QuoteAnd if the project is sizeable, you probably need to learn Linux and, in particular 'make'. Then there is the absolute nightmare of getting OpenOCD and JTAG to work or some variant of ICSP. You aren't using a development board with USB programming, are you? That might not qualify as 'bare metal'.QuoteAnd the Starter Kit deals with programming in C (in general) although it will be targeting Arduino. C is a project in itself. I started with a PIC16F877 and still like the PIC16F628 (if I am FORCED to use PICs) but my favorite among the AVRs is the ATmega128. But I wrote the code in C on Linux, used 'make' to control the build and AVRdude to do the ICSP programming. It worked extremely well. I like the larger AVRs but, you know, I can do the same thing using an Arduino board as the target and not one bit of Arduino code. In fact, the Arduino IDE uses AVRdude to do the device programming. I don't need the IDE, I don't need the setup()/loop() structure, I can do anything the chip can do using any IDE I want along with 'make' and the avr-gcc tools. I would just use the board to hold the chip long enough to program it.QuoteDon't know if an RTOS is part of your solution but here's a paper:http://ww1.microchip.com/downloads/en/appnotes/atmel-42382-getting-started-with-freertos-on-atmel-sam-flash-mcus_applicationnote_at04056.pdfThe secondary reason for using an RTOS is to segment the code. Tasks don't need to know what other tasks are doing, they are self-contained entities. You build your project by concentrating on the task code, not the overall structure. Structure comes from FreeRTOS.It is rumored that IBM used to figure 100 lines of debugged code per day per programmer. You should have plenty of time.

author: rstofer
author_rank: Super Contributor
timestamp: January 25, 2022, 06:11:20 pm
content: SAM C21 development board (just for writing code) that, ...wait for it..., has Arduino headers:https://nl.farnell.com/microchip/atsamc21-xpro/evaluation-board-xplained-pro/dp/2492013I didn't check stock, heck, I can't even read the page!There's a bunch in stock at Mouser:https://www.mouser.com/c/?marcom=187817120Development boards can be worth their weight in gold (when the price of gold is depressed).

author: ralphrmartin
author_rank: Frequent Contributor
timestamp: January 25, 2022, 07:54:55 pm
content: Despite people writing Arduino off as a toy, I'd answer the original question by suggesting a book that will take you quite a way beyond the basics:https://www.elektor.com/freertos-for-esp32-arduino-e-bookYou will find that you can do quite sophisticated multitasking using the combination of Arduino and Freertos, given a moderately powerful processor.One thing Arduino has going for it is plenty of libraries for driving displays, sensors and so on, and there's no point reinventing wheels.

author: alexanderbrevig
author_rank: Frequent Contributor
timestamp: January 25, 2022, 08:27:11 pm
content: Three reasons for reinventing the wheel:Learning about embedded (which is the subject of this thread)Implementing it better/correct (power requirements, DMA needs etc)Providing abstractions that are insufficient for your needs (maybe you need it to accept network endianness, or maybe play nice with FreeRTOS whatever)

author: alexanderbrevig
author_rank: Frequent Contributor
timestamp: January 25, 2022, 08:41:29 pm
content: Oh, OP you may want to check these reviews by Jack Ganssle who is a known name in embedded:http://www.ganssle.com/bkreviews.htm,he has also written a few books:http://www.ganssle.com/book.htmI will warn you about premature optimization though. The older books tend to go on and on about them.Compilers are amazing these days, and if you're using C++ they are all zero cost (except virtual methods [runtime speed] and exceptions [memory/stack]). If you find you need to optimize, try a few compiler flags before rewriting for loops from postfix to prefix in-/decrements.

author: Simon
author_rank: Unknown
timestamp: January 25, 2022, 09:09:34 pm
content: Quote from: rstofer on January 25, 2022, 06:11:20 pmYes, I have 2, right pain in the ass to work with those 2 row headers. Of course they have an arduino footprint, Arduino is cool, it's what everyone wants so marketing put it in the specs. It also means that you can use arduino shields with it which, ahem, ahem, takes you away from that arduino rubbish and into the land of the living!Is there an arduino board file for it? will it work with the IDE?Oh and don't forget "internet of things"

author: Simon
author_rank: Unknown
timestamp: January 25, 2022, 09:12:52 pm
content: Quote from: ralphrmartin on January 25, 2022, 07:54:55 pmthat is the only reason I have ever willingly used it. I would use it to make a quick jig in the lab but nothing more. It's the reason anyone uses it. Well now I have my own display "library" and it runs faster with less risk of issues.As for libraries, out demo/prototype showed a load of garbage on the screen the other day, no idea why but then i am sure those libraries don't come with a warranty

author: Simon
author_rank: Unknown
timestamp: January 25, 2022, 09:14:53 pm
content: One day when I have the time I may look at rtos, just don't have the time now.

author: alexanderbrevig
author_rank: Frequent Contributor
timestamp: January 26, 2022, 12:56:18 am
content: The toolchain supports the chip, one could add a custom board file. Name it likeSimonHatesArduino, then be sure to use one of my many unmaintained libraries:https://playground.arduino.cc/Profiles/AlphaBeta/#PlaygroundContributionsto get the ultimate crappy experience, I meanIn fact, several of my libraries would probably qualify as things one should not touch. I wrote them for teaching fellow students how to program hardware. I barely knew how myself...

author: eugene
author_rank: Frequent Contributor
timestamp: January 26, 2022, 02:35:46 am
content: Quote from: rstofer on January 25, 2022, 06:11:20 pmIsn't an Arduino (or compatible) simply a development board once you realize that you're not required to used the IDE or any specific library?Quote from: Simon on January 25, 2022, 09:09:34 pmPoor Simon. It must be very difficult to be you.

author: rstofer
author_rank: Super Contributor
timestamp: January 26, 2022, 03:43:09 am
content: Quote from: eugene on January 26, 2022, 02:35:46 amYes it is! In fact, there is every good reason to buy the DIP version of the Arduino (as opposed to the SMD version) and use the Arduino board to program the device before it is installed in some other board.

author: Simon
author_rank: Unknown
timestamp: January 26, 2022, 08:07:50 am
content: Quote from: rstofer on January 26, 2022, 03:43:09 amYes it is! In fact, there is every good reason to buy the DIP version of the Arduino (as opposed to the SMD version) and use the Arduino board to program the device before it is installed in some other board.Been there done that. Then used the AVRISP

author: Simon
author_rank: Unknown
timestamp: January 26, 2022, 08:10:41 am
content: Quote from: eugene on January 26, 2022, 02:35:46 amPoor Simon. It must be very difficult to be you.It's doable it's "OK" but what happened to those good old lab things with a breadboard?All you can do with those pins is put a ribbon cable on it, you can't even plug that board into another without making it hard work. But I gladly bought 2 as they are a good controlled environment to develop basic code on. My current project has an LCD on it so now I can just send messages to the screen.