Arduino vs “Real World”: advice - Page 1
Forum section: electronics / general

author: PerranOak
author_rank: Frequent Contributor
timestamp: April 07, 2022, 03:48:39 pm
content: Is there an easy way to get from an Arduino project to a standalone microcontroller project?For example: I have used Arduino libraries, etc. to get a small oled display to work - all is well.How do I go about translating this success into a microcontroller project without having to go back to the data sheet and start again as if I’d never done the Arduino job?Can I examine the Arduino stuff and extract some already developed routines and so on?This is a general question. I’ve only ever done one or the other (Arduino or standalone) and never translated Arduino advances into microcontroller success.Cheers.

author: ejeffrey
author_rank: Super Contributor
timestamp: April 07, 2022, 04:21:00 pm
content: What do you actually want to do to "translate into a micro-controller project"? Are you trying to get away from the arduino hardware or software? Are you trying to add features or require performance that the arduino runtime environment doesn't support? Do you want to move to a different microcontroller family? You can put an AVR on your own PCB and continue to load an arduino sketch on it if you want to. If you ditch the arduino runtime you will have to go looking at datasheets to figure out how to set up and talk to the peripherals. You should still be able to apply whatever you learned about talking to the OLED display regardless of what hardware or software you use. You can also flash a bare metal program onto arduino hardware if you want. Or you can stay in the arduino IDE and write code that bypasses much of the runtime. The arduino runtime is just some startup code and some libraries, you can mostly do whatever you want. If you start reconfiguring peripherals the arduino library calls that use them will likely stop working but that's not a problem.

author: Lindley
author_rank: Regular Contributor
timestamp: April 07, 2022, 05:08:56 pm
content: We would say your completed Arduino project IS a standalone microcontroller project, if its not then what is the difference as you see it ?Think you might really mean how to avoid the use of the Arduino libraries ? but all they are is what other people have already coded for you to use with the minimal work.There is nothing to stop you writing all the code needed to output to the Oled, we used to do it on the earlier GLCDs.The first step is to look at the Oleds datasheet and understand how to initialise it and then output the display data.For a real programming challenge then look at doing it but using Assembly code, where you will really see the advantages of a languages like C++ with so many free libraries.

author: eugene
author_rank: Frequent Contributor
timestamp: April 07, 2022, 06:02:50 pm
content: As Lindley notes, you don't need to use any particular Arduino library. If you want to transition from the full Arduino experience to 'bare metal' programming, then do it in small steps. Rewrite one of your programs without one or more libraries. If you don't even know where to begin, then look at the source code for the library. If you have the library installed on your computer, then the source code is somewhere on your hard drive.Once you've figured out how to program your Arduino without libraries it is an easy jump to abandon the setup() and loop() format to write more traditional programs.Be forewarned that eventually you will need to read some datasheets. There is no way to write meaningful software for microcontrollers without studying the details of the hardware. If you really want to avoid that then you probably don't want to stray too far from the Arduino ecosystem.

author: rstofer
author_rank: Super Contributor
timestamp: April 07, 2022, 09:12:23 pm
content: It depends on your uC target platform. If it's just an ATmega328 on a different PCB, you can continue to use the Arduino libraries if the hardware pinout is identical. All you are doing is swapping out the PCB.If you plan to port the code to a different AVR then you can probably transmorgify the Arduino libraries by changing some pinouts and such. But, yes, you need to marry the datasheets.If you plan to start with an entirely different family of uCs then you are on your own. Some chips will have factory support libraries and all you have to do is learn how to work with them. More library data than actual hardware data. An example might be I2C (or SPI) for your oLed. Just figure out how the new library function compares to the Arduino library (call parameters) and change your high level code to fit.Finally, you really want to get buried in the details, pick a chip that has hardware I2C or SPI and write everything from scratch. You will absolutely be spending time in the multi-thousand page User Manuals (or datasheets). This is going to take a while.You never mentioned what you are actually trying to do or why you want to do it. That's important!Today, if I needed a bit more horsepower than the ATmega328, I would head to the Teensy 4.1 - it's blistering fast (around 600 MHz) and there are Arduino 'like' libraries that may make porting the code appear trivial - and FAST! This thing is awesome:https://www.pjrc.com/store/teensy41.htmlOr, rewrite everything in microPython for the Pi Pico - my new favorite toy (and, maybe, favorite language. We'll see...).

author: brucehoult
author_rank: Super Contributor
timestamp: April 07, 2022, 11:53:22 pm
content: Quote from: PerranOak on April 07, 2022, 03:48:39 pmYes.What, exactly, do you have now? And what do you want to change about it?There are dozens of boards now that can be described as "Arduino", some made by the actual Arduino company, some by others. Some have one of the original AVR microcontroller family, others have ARM or RISC-V or other CPUs.Let's assume that now you're using an Arduino Uno, with the AVR ATMega328 microcontroller.Maybe you'd like to use something smaller and/or cheaper than the Uno. No problem, you can get an Arduino Pro Mini which has exactly the same microcontroller but is much smaller and cheaper, especially if you get a Chinese clone.Do you need all the capacity of the ATMega328? Or is your code simple enough that you can you get away with less program space and RAM? If so then you could use an even cheaper board with e.g. An ATTiny85 or ATTiny88 e.g.https://www.amazon.com/ATTINY88-Development-Digispark-ATmega328-Compatible/dp/B07VFLSY7HMaybe you'd like to design your own circuit board? You can buy a bare ATMega328 chip and run it will just a few external components. There are plenty of web pages on that. Or for tasks that use few IO pins and not a lot of code or data, the ATTiny85 doesn't need any external components at all. You can program either one using the Arduino IDE and your existing Uno to provide the appropriate power and signals to the bare chip.QuoteGreat! If it works how you need, fast enough etc, then why change anything?QuoteWhat about it do you think you need to change?QuoteOf course! All the source code is there, in your Arduino IDE directory.QuoteIf it works and is fast enough and doesn't use more code and data space than you can afford ... then why change anything?

author: westfw
author_rank: Super Contributor
timestamp: April 08, 2022, 02:22:18 am
content: QuoteProbably. Almost all of the libraries are Open Source Software of some kind, so you can look at the source code (you probably already have a copy somewhere in the Arduino directory hierarchies, or you can find them in their original repositories on github and etc.One of the things you'll need to check is whether the OSSW license used is compatible with the way you intend to distribute your project. If your project is going to be OSSW as well, you should pick a compatible license (which is always fun if you have libraries with multiple different licenses.) If you intend your project to be proprietary, you may NOT want to look at source code that has "copyleft" provisions (that would force you to make your project open source as well.) In extreme cases, you might avoid looking at such code at all, going straight back to the datasheets. Most microcontroller-size projects rarely reach that degree of ... contention. But it's a thing to be aware of.QuoteYou can actually use a lot of Arduino library source code without any changes. It's not like there is an "Operating System" that provides special functions. You'd have to copy all of the layers used (a display might use I2C or SPI libraries in addition to its own code, and they might use digitalWrite() occasionally. (replacing digitalWrite() is easy, though.)It's pretty much reasonable to copy/add all the library source code into an Atmel Studio AS7 "project", try a compile, and then either suck in more code or write replacements to fix any errors that occur.

author: Doctorandus_P
author_rank: Super Contributor
timestamp: April 09, 2022, 04:38:03 am
content: First thing to do is to ditch the horrible arduino contraption they misleadingly call an "ide".It is not even a decent editor.There are a bunch of different ways to get a better compile environment . One of the oldest I can remember was a makefile that extracts all the "arduino" stuff and lets you compile from the commandline.Today it makes more sense to use something like platformio.Once you've set up a decent IDE that can compile the arduino stuff, you can follow function call throughout your code.One of the first things to learn is that "arduino" is not a programming language. The language used is a bit of a mix of C and C++, and unfortunately that makes it a mediocre choice for learning either of those languages.Your program starts with a function called "main( )".Find that function with help of your decent IDE and then start reading code.It's one of the reasons why I dislike "arduino". It tries to hide too much, and this makes it a bad platform to learn from.A lot of the "arduino" libraries are utter garbage. I once tried it with a library for the max7219, and it was too slow to get any decent update rate of the display. Looking at the code it turned out that whenever you want to write to one of the cascaded displays, it updated all of them, with the result that 5 cascaded displays write 5x as slow as they should. I assume that quite a lot of such libraries are written by people with not much programming experienceThere probably also are decent libraries among the "arduino stuff", There are quite a bunch of libraries that were developed independently of "arduino", and later wrapped up to work on that platform.For the more complicated libraries, starting from scratch with nothing but a datasheet and a C or C++ compiler is possible, but quite time consuming.If you want to dive deeper then "just using arduino libraries" then starting with some "arduino library" you're interested in, and first make it work in a decent IDE. Then combine it with an EUR 7 Logic Anlayser and reading parts of the datasheets.

author: brucehoult
author_rank: Super Contributor
timestamp: April 09, 2022, 09:52:00 am
content: Quote from: Doctorandus_P on April 09, 2022, 04:38:03 amSure, the editor is no emacs, but it's serviceable and far better than notepad or vi. If someone is happy with it then leave them be. It's easy enough to use an external editor and have the IDE check for modifications to files.Meanwhile the *IDE* part of it is quite useful in managing different projects, boards, programmers, toolchains etc.QuoteFor anyone who knows how to deal with makefiles this is indeed trivial. For beginners the IDE works.Quoteplatformio is nice for big serious projects, sure. But not necessary.QuotePerhaps you meant "Wiring", not "Arduino".Wiring does qualify as a language in that it is a deliberate simplified compatible subset of both c++ and Java. To run Wiring code as c++ a preprocessor is used to automatically add some #includes and to scan the program for functions and add prototypes for all of them at the start, so the order of functions doesn't matter. To run Wiring code as Java a preprocessor is used to add some imports to the start and to wrap all the code in a class so that the user's global functions become methods of the class.The Java compatibility has been forgotten or ignored by most users for a long time now, and c++ features that are not part of Wiring are commonly used in current Arduino code.Wiring uses a different library than the standard c or c++ libraries, but that is to the user's benefit, and it is actually designed for making it easy to write code that runs on a machine with very limited program and data memory.How often do we get threads on this board when someone wants to format a couple of integers into a string and uses sprintf() of similar and their program code size suddenly blows up by 30 KB because the PC-oriented C library drags in code for formatting floating point numbers, 64 and even 128 bit integers and so forth?That doesn't happen with the Arduino libraries. If you print a string you get the code to print a string, and nothing else. If you print a 16 bit integer you get the code to print a 16 bit integer, and nothing else.The same goes for a number of other aspects of the library, but avoiding the printf() trap is a major benefit.Quotemain() is part of the Arduino library not the user's code for very good reason -- it vastly enhances the portability of sketches.At its heart it is simply...Code:void main(){setup();while(1)loop();}... but in fact it is likely to do board-specific setup without having to bother the user to know about it or remember to do it.For example, on the "Arduino" board I use most often...Code:void freedom_e300_specific_initialization(void){write_csr(mtvec, &trap_entry);if (read_csr(misa) & (1 << ('F' - 'A'))) { // if F extension is presentwrite_csr(mstatus, MSTATUS_FS); // allow FPU instructions without trappingwrite_csr(fcsr, 0); // initialize rounding mode, undefined at reset}freedom_e300_clock_setup();}/** \brief Main entry point of Arduino application*/int main( void ){// Compute F_CPU inverse, used for millis and micros functions.calc_inv(F_CPU/1000, &f_cpu_1000_inv);calc_inv(F_CPU/1000000, &f_cpu_1000000_inv);freedom_e300_specific_initialization();setup();do {loop();if (serialEventRun)serialEventRun();} while (1);return 0;}QuoteRubbish. Nothing is hidden. Details are wrapped, but all the source code is there if you want it.QuoteSure, but that applies to any platform used by amateurs. If Arduino didn't exist the amateurs would be using something else and putting out low quality libraries for it instead. Or, more likely, they would be giving up on trying to get anything to work on a microcontroller in the first place.In short, don't be such a gate-keeping elitist snob.

author: Doctorandus_P
author_rank: Super Contributor
timestamp: April 09, 2022, 10:43:04 am
content: Quote from: brucehoult on April 09, 2022, 09:52:00 amIt definately is not.I never used emacs and I barely dabbed a toe in Vi.Vi is a very good editor though. I can't do very much with it but that does not mean it's a bad editor.For the rest of your post...Your only intention seems to be to ridicule everything I wrote and I know out of experience thaty trying to communicate with such people is senseless and a waste of time.So you you I'll just remain to be a gate keeping elitish snob.

author: brucehoult
author_rank: Super Contributor
timestamp: April 09, 2022, 10:54:08 am
content: Quote from: Doctorandus_P on April 09, 2022, 10:43:04 amYou mean: correct the misconceptions and misinformation.

author: DiTBho
author_rank: Super Contributor
timestamp: April 09, 2022, 12:10:10 pm
content: Quote from: Doctorandus_P on April 09, 2022, 04:38:03 amYup, and, Worse Than the Worst the Gameduino2 library

author: Siwastaja
author_rank: Super Contributor
timestamp: April 10, 2022, 06:36:36 am
content: If you have a working Arduino code which does what it needs to do and is well tested, there is absolutely no reason why you could not use the exact same binary in production, even without the Arduino board (just the same microcontroller as-is).It's just thatusually, products are made by at least somewhat experienced people, who usually just do notneedan Arduino, and it would only be a hindrance for them.But you totally can do it, if the Arduino libraries are good enough for the task at hand. And many projects are really simple. But I might not hire a designer who could only do Arduino, because the next project might be too challenging.Especially if you are a lone wolf selling a few gadgets, you can choose your projects in such way they are easily doable by you with Arduino or whatever. (In the past, maybe BASIC STAMP). You can totally run a business that way.

author: rteodor
author_rank: Frequent Contributor
timestamp: April 10, 2022, 08:33:16 am
content: Aaaah ...portability. The bordeline disorder in between idealism and wishful thinking.Portability is a lot like moving from one place to another.Move to the nex city: easy. Move to the next country: not that hard. Move 2 continents away: uf, another alphabet another laws, another aproach to life and death and so on.Also think what you want to take with you. If you want to take the landscape and house with you well .... not possible. But most likely you can take the dog and clothes with you.If there is another architechture that is supported by Arduino IDE and the libraries are well written then you are just "moving to the next city" so may get away with minor or no changes.If you want to take the "whole" project with you it is like taking the whole house. Libraries and applications if they are well written are easy to port.Your question is too generic and so is my response.

author: DiTBho
author_rank: Super Contributor
timestamp: April 10, 2022, 10:39:50 am
content: Quote from: rteodor on April 10, 2022, 08:33:16 amLOL, I love this definition

author: brucehoult
author_rank: Super Contributor
timestamp: April 10, 2022, 11:19:02 am
content: Quote from: rteodor on April 10, 2022, 08:33:16 amIn the last seven years I've moved from my comfortable South Pacific island to live and work in two such wacky and weird cultures on two different continents as Russia and the USA for several years each. And then back home. In my 50s, btw. Portability is both desirable and doable. where I literally have edible and delicious bananas growing in my back yard, near my Starlink dishhttps://hoult.org/rusk/8.jpghttps://hoult.org/rusk/21.jpg

author: rob77
author_rank: Super Contributor
timestamp: April 10, 2022, 09:19:52 pm
content: vi is a really nice editor, vim is powerful one. only a person who don't know how to use it would say it's a bad editor.with vim extensions you can easily create a powerful text mode IDE (file browser + multi file editing + syntax highlighting + make integration) and you can even work remotely through ssh session over low bandwidth networksbtw..how do you create a random string ? ask a first time user to close vi

author: brucehoult
author_rank: Super Contributor
timestamp: April 10, 2022, 10:01:37 pm
content: Quote from: rob77 on April 10, 2022, 09:19:52 pmI used vi from 1982 (on a Zilog System 8000) until 1997, when I learned emacs.It's better than ed, I'll give it that.Here is Bill Joy on vi in 1984:"I think as mode-based editors go, it's pretty good. One of the good things about EMACS, though, is its programmability and the modelessness. Those are two ideas which never occurred to me.""The fundamental problem with vi is that it doesn't have a mouse and therefore you've got all these commands. In some sense, its backwards from the kind of thing you'd get from a mouse-oriented thing. I think multiple levels of undo would be wonderful, too. But fundamentally, vi is still ed inside. You can't really fool it.""It's like one of those pinatas—things that have candy inside but has layer after layer of paper mache on top. It doesn't really have a unified concept. I think if I were going to go back—I wouldn't go back, but start over again."The quote which really places the date of this interview:"I think the Macintosh proves that everyone can have a bitmapped display. The fundamental tension in UNIX that I think AT&T doesn't understand is that everyone is going to have a bitmap. Bitmap display is media compatible with dot matrix or laser printers. With a mouse to point with, you've got sort of a baseline of facilities around which you can build a document environment. I think you also need a full-page display. I think we'll have to wait for Big Mac from Apple, maybe two years away, to get full-page display."

author: eugene
author_rank: Frequent Contributor
timestamp: April 10, 2022, 10:19:06 pm
content: Bill Joy quote is great.When I first started using unix I thought it was a huge improvement over VAX/VMS. I hated learning vi, but once I did I was a vi fanboi. That was 40 years ago....I guess I can see how IT guys like that it's useful when editing config files over ssh, but otherwise, why bother?

author: SiliconWizard
author_rank: Super Contributor
timestamp: April 10, 2022, 10:22:52 pm
content: I know there are some aficionados out there, but I certainly do not miss console-based editors. Eek. If I need quick editing of config files through ssh or such, I'll use nano. Otherwise, I use editors with a real GUI.vi or vim are not bad editors. They are just very anachronistic. And that's from someone who uses command-line stuff quite a bit.

author: rob77
author_rank: Super Contributor
timestamp: April 10, 2022, 10:50:08 pm
content: Quote from: eugene on April 10, 2022, 10:19:06 pmvim is my daily driver editor (vim on console, gvim in graphics or windows), probably i would switch if there was a better alternative...can you suggest any good editor with syntax highlight , block mode and regex support which exists for both console and gui and exists natively for both linux and windows while having the same set of commands/control so you don't have to use/learn 2 editors ?

author: DiTBho
author_rank: Super Contributor
timestamp: April 10, 2022, 10:50:58 pm
content: Quote from: brucehoult on April 10, 2022, 10:01:37 pmLOL

author: rob77
author_rank: Super Contributor
timestamp: April 10, 2022, 11:00:44 pm
content: Quote from: brucehoult on April 10, 2022, 10:01:37 pmyeah 1984 .. that's totally relevant... have you noticed that the vi used nowadays is a different piece of software ? VIm - vi iMproved

author: DiTBho
author_rank: Super Contributor
timestamp: April 10, 2022, 11:05:24 pm
content: Quote from: rob77 on April 10, 2022, 10:50:08 pmmaybeTextadeptwith Lua scriptingIt can be compiled to run in both graphical(gtk) and text-based(ncurses) user interface environments.It doesn't offer too many features, but everything is controlled by Lua, therefore you have to learn it to create your own scripts in order to add more features.

author: nctnico
author_rank: Super Contributor
timestamp: April 10, 2022, 11:09:10 pm
content: Quote from: rob77 on April 10, 2022, 10:50:08 pmNot console but Eclipse and VSCode do all the rest you mention.

author: rob77
author_rank: Super Contributor
timestamp: April 10, 2022, 11:20:42 pm
content: Quote from: DiTBho on April 10, 2022, 11:05:24 pmthat looks good (even if it's just replacing vimscript with Lua, while the concept is similar), but it's not really a better alternative because all the features of vim i use would need to be separately installed from separate sources (regexp from 3rd part git..etc...). furthermore it's not even part of linux distros, so it would have to be either compiled or installed from 3rd party repos, which is a no-go on many systems

author: westfw
author_rank: Super Contributor
timestamp: April 11, 2022, 05:19:51 am
content: QuoteSounds like EMACS to me, although I'm not sure what you mean by "block mode."It's pretty amazing that the editor I started to work with some 40 years ago is still in existence, much less still my favorite editor. (although I occasionally miss the TECO minibuffer.)

author: brucehoult
author_rank: Super Contributor
timestamp: April 11, 2022, 07:25:41 am
content: Quote from: westfw on April 11, 2022, 05:19:51 amIndeed it does sound like emacs. And any OS where it's not installed by default there is a package manager one-liner to get it.I think they are talking about the commands with "r" (rectangle) inserted between the C-x and the action e.g. k, d, M-w, y, o using point and mark to define a rectangle. And C-x SPC to highlight that rectangle.

author: Bassman59
author_rank: Super Contributor
timestamp: April 11, 2022, 05:10:06 pm
content: Quote from: westfw on April 11, 2022, 05:19:51 amEvery once in a while, I look for something to replace emacs and its vhdl-mode. I've looked at VSCode, Eclipse, Atom, you name it. And I always go back to emacs.

author: brucehoult
author_rank: Super Contributor
timestamp: April 11, 2022, 10:02:30 pm
content: Quote from: rob77 on April 10, 2022, 11:00:44 pmI'm not complaining that the code is badly written, or that it doesn't have enough features. I'm complaining that the basic model of how you interact with it is totally broken.The guy who *wrote* it even agreed with that, and that emacs is a better design than his editor, 40 years ago.

author: SiliconWizard
author_rank: Super Contributor
timestamp: April 11, 2022, 10:13:24 pm
content: https://en.wikipedia.org/wiki/Editor_war(Now I agree with Bruce here that emacs has a better model, but I haven't used it in ages. I do prefer using a modern, fully GUI-based editor, making reasonable usage of the mouse. Now I admit there aren't many that are as powerful.)But it's funny to see that the "war" is still on. Kinda.

author: DiTBho
author_rank: Super Contributor
timestamp: April 11, 2022, 10:23:45 pm
content: Anyway, none of the editors around comes with what I really need. Thus I am hackingnedit. It's xmotif-based, for me it's simpler than gtk*

author: SiliconWizard
author_rank: Super Contributor
timestamp: April 11, 2022, 10:40:24 pm
content: Quote from: DiTBho on April 11, 2022, 10:23:45 pmWell, pretty much same here. I have written my own editor a long time ago, and have maintained it ever since. Still the one I use the most. It has features that can't be found in any other, although those might be purely personal and not appeal to anyone else much. It's been very stable too, so I have full trust. It's "unfortunately" Windows-only. When I need an editor on other platforms, I mostly use Geany.

author: brucehoult
author_rank: Super Contributor
timestamp: April 11, 2022, 11:12:49 pm
content: Quote from: SiliconWizard on April 11, 2022, 10:13:24 pmNot a bad summary.I note that in the "Benefits of vi" the 2nd one (model interface) is one of the primary anti-vi arguments, and the 3rd (it loads faster) hasn't been noticeably true since the days of ... Core 2 Duo? Most of the rest are arguments why you should know enough vi to get by on a strange system until you can load emacs, not arguments for why you would use it if you have a choice.They missed that the name is shorter.QuoteIf you have a GUI and mouse then emacs' basic operation is exactly the same as any modern GUI editor, from moving around, inserting and deleting, copy and paste.Emacs copy & paste operations are a bit different from the Mac / Windows ones, mostly because it predates them.On MacOS every text editing box implements basic emacs keystrokes in addition to the Mac ones. This is also true of the web browser text field I'm typing this in -- I can use C-a and C-e to go to the start and end of the line, C-k to cut from the cursor to the end of the line, C-y to paste that back etc. I didn't do something to enable that, it's just ubiquitous.Integrating vi's modal text editing commands into a modern GUI app doesn't make sense, even in principle.I can fully understand why people such as system admins constantly using a large number of minimally-configured machines or VMs or docker images to look at logs and config files and make small edits would use vi a lot. Especially when you want to guard against accidental edits, so the modal nature works to your advantage.

author: rob77
author_rank: Super Contributor
timestamp: April 12, 2022, 05:17:08 am
content: Quote from: SiliconWizard on April 11, 2022, 10:13:24 pmKindai'm saying VIm is powerful and it's great, but i'm not saying it is superior to any other editor. yet some emacs guys are arguing that emacs is the best

author: Bassman59
author_rank: Super Contributor
timestamp: April 12, 2022, 06:32:10 pm
content: Quote from: rob77 on April 12, 2022, 05:17:08 amEmacs is the best because Emacs is the best!Yes, that's a tautology.

author: chucksticks
author_rank: Newbie
timestamp: April 12, 2022, 08:15:38 pm
content: QuoteSounds like you need to set some requirements. Maintainability, portability, scalability? Otherwise, why take the risks of trying something new?