17 Replies Latest reply on Feb 7, 2020 3:58 PM by colporteur

    What is your favorite tool for learning to program Arduino?

    makerkaren

      Learning any new programming language is difficult if you don't already know any programming. From what I've been heard, Arduino is loosely based on C, but is...kinda weird. Arduino hardware is one of the most popular and common dev boards with a microcontroller. So naturally, it would be useful for an electronics newb to learn how to program them.

       

      While learning electronics, I've had my hands on multiple Arduino Starter Kits. These come with sample circuits and the corresponding code to make them work. That code can be tweaked to make each circuit do something slightly different. But here's the point of difficulty: What if you want to make your own circuit, and can't find code similar to what you want. What do you do? Where do you look?

       

      So if you've played around with Arduino, what did you do to learn the language?

      What are your favorite tools for learning to code with Arduino?

      Do you like watching videos? Have you found good tutorials?

       

      Post links, sources, and sage advice in the comments below.

       

      ~Karen

        • Re: What is your favorite tool for learning to program Arduino?
          mayermakes

          Watching videos and then building my own projects was my way, I have books on arduino but tbh I never even looked into them. Learning by doing worked best for me. Also with every project my set condition is that I have to do something I haven't coded before. This drives me automatically to improve my skill set.

          4 of 4 people found this helpful
          • Re: What is your favorite tool for learning to program Arduino?
            michaelkellett

            You could stay with Arduino - and you'll become an expert on getting round all the daft quirks of Arduinos.

             

            On the other hand you could learn C - and this will give you access to a whole load of other processors and boards. And if you can do C you can quickly learn to do Arduino.

             

            Which way you go depends on where you want to end up - Arduino is good for a quick hack without understanding much of what is going on, C and a (for example) ST Nucleo board can take you to serious places.

             

            For example - you can talk to sensors quite easily using I2C on an Arduino, using C on a Nucleo board you can write code that is capable of testing if the I2C interface on sensor actually meets the I2C spec.

             

            How you learn is a matter of taste - I learn by reading and hate videos - for others it's the opposite.

             

            The best book to learn C was/is "The C Programming Language", 2nd Edition (by Kernighan & Ritchie", but it's a little dated now (not been updated for latest C standards). You'll need to read other stuff according to which tools and parts you use.

             

            MK

            4 of 4 people found this helpful
            • Re: What is your favorite tool for learning to program Arduino?
              jc2048

              Michael got there before me, but I'm the same: I learnt C directly from K&R. Still have my copy and use it regularly.

               

               

              Something like the UNO is, essentially, programmed in C, it's just that the UI, headers, and libraries hide it from you to some extent [because you're assumed to be a beginner and it might frighten you having to deal with a compiler, or something like that].

               

              As a small example of using it more like how you would program a traditional microcontroller, though I lazily used the Arduino timing-delay functions, this is the test program I used for my latest blog. It was hacked together from previous bits and pieces, so there's no real style or elegance to it.

               

              /* jfet output-characteristic control program */

              #include <arduino.h>

              #define START_VOLTAGE 0
              #define END_VOLTAGE 14

              void setup() {
                PORTC = 0x00;
                DDRC = DDRC | 0x2F;    // set output pins
              }

               

              void loop() {
                int i;

                while(1) {
                  for(i = START_VOLTAGE; i <= END_VOLTAGE; i=i+2) {
                    PORTC &= 0xFFF0;
                    PORTC |= i & 0x000F;
                    delayMicroseconds(10000);
                    noInterrupts();
                    PORTC |= 0x20;
                    delayMicroseconds(1000);
                    PORTC &= ~0x20;
                    delayMicroseconds(20);
                    interrupts();
                    }   
                  }
              }

               

              The Atmel register names for the processor registers (that you can find on the datasheet) are available to use, it's just that all of that is quietly arranged in the background [I assume that the compiler gets called with an appropriate header file for the particular board that you've selected added in]. In this code, I've gone straight for the port register, rather than use the Arduino library functions that normally save you from knowing anything about controlling IO pins directly. Controlling the pins directly is much faster, but the downside is loss of generality [this would only work on a board with that particular Atmel processor on]. The pins marked A0-A3 on the board are really the pins of Port C of the processor, so you also need to be able to read the circuit diagram of the board to be able to do this.

              6 of 6 people found this helpful
              • Re: What is your favorite tool for learning to program Arduino?
                dubbie

                I moved to Arduino for work purposes. I was a University lecturer in Embedded Systems for many years and worked through several different systems. I taught myself Pascal from a book to do my PhD on Mobile Robots, then in my first job I used a Hewlet Packard 64000 networked development system (10 MBytes network disk the size of a filing cabinet) to do first 8085 and then 8088/6. PCs came along so I moved to assembler - that was in the days when you could see the assembler code for MS-DOS. Pascal became out of fashion so I had to move to C (same book as everyone above) taught myself - sort of, then I used TurboC for the first time. What a revelation. So fast, so flexible, so easy and it made programmes for PCs. Time moves on, PCs get networked, Hardware Abstraction Levels get implemented in Windows and doing embedded systems with large classes of students becomes difficult. I moved to Microchip PICs because they were cheap, flexible and we could make our own programmers (one for each student). Students were no longer restricted to being in a lab so we could set work that was more challenging and exciting. Then Microchip stared making MPLAB more difficult to access and use over a network, plus the C compiler we used, CCS, became expensive and Microchip C became ANSI standard (all the functions to make things easy for students disappeared) then I encountered Arduino. Just brilliant. Mostly like C, lots of help on the internet for any level of user, we made our own UNO PCB clones, at very low cost, such that we could even give them away to prospective students at Open Days. The projects we could set students massively increased in complexity and in my last year I was able to set a piece of work equivalent to what I did in my PhD. Just amazing. I'm retired now but Arduino is still my preferred system - it's cheap and (mostly) works. Just right for messing about.

                 

                Dubbie

                • Re: What is your favorite tool for learning to program Arduino?
                  Fred27

                  My initial reaction was "why assume Arduino is the best way to start" but thought that might come across as a bit negative so I hesitated to reply. It seems I'm not the only one though, so I'll chime in.

                   

                  Learning vanilla C and the bit manipulation that goes with microcontrollers seems the best grounding. There are also many microcontrollers with great IDEs that allow things like hardware breakpoints and inspecting variables / registers. Manufacturers often provide good examples of how to use the peripherals on the device. One of these would seem like a much better choice. It's always baffled me that the worst example of microcontroller development is the one people are pushed towards towards for no other reason that other people have.

                   

                  I hope that doesn't seem to negative and isn't out of scope for your question.

                  • Re: What is your favorite tool for learning to program Arduino?
                    neuromodulator

                    The Arduino enviroment is just a set of C++ libraries. These libraries are available for other platforms as well, for instance for Espressif's ESP32/ESP8266 or even STM32's. The Arduino library is a pretty high level hardware abstraction layer, and depending on what you wanna do you, you may want to go lower level or not. The library is pretty straightforward to use, online documentation should suffice to learn what you need. Now even thought the Arduino library is written in C++, it only uses a tiny part of the language, so unless you want to learn C++, you can live without learning much about it, and as a matter most people that program Arduinos are not aware  that they call methods of objects (like in Serial). MCU's are usually programmed in C, so unless you know C, you probably should learn it, and as others have pointed out C's K&R book is one of the best, although a bit dated. I still think that the book will get you in the right mindset on how to program in C, and updating your knowledge to the latest C standards should be pretty painless.

                    1 of 1 people found this helpful
                    • Re: What is your favorite tool for learning to program Arduino?
                      rsc

                      Hmmm,

                      If you really want to know how a microprocessor works, learn the assembly code.  I wrote C and assembly code for Atmel processors many years before the Arduino surfaced.  The best part of the Arduino code is the bootloader.  Before that, you needed an ISP  programmer or similar tools to do anything.  The Mbed group had the clever idea of letting you program without buying/installing the compiler software.  Mbed and Arduino has made it a lot simpler to program these days.

                      Scott

                      2 of 2 people found this helpful
                      • Re: What is your favorite tool for learning to program Arduino?
                        BigG

                        makerkaren  wrote:

                         

                        Learning any new programming language is difficult if you don't already know any programming. From what I've been heard, Arduino is loosely based on C, but is...kinda weird. Arduino hardware is one of the most popular and common dev boards with a microcontroller. So naturally, it would be useful for an electronics newb to learn how to program them.

                         

                        If you read the Arduino.cc intro, it tells us that "the Arduino programming language (based on Wiring), and the Arduino Software (IDE), based on Processing." So for someone learning that is fine, however as soon as you move into more complex stuff then you need to understand c++ if you want to create your own libraries etc. These days as you build it ends up being interchangeable between the Wiring language and the c++.

                         

                        In the early years I noticed on forums and on blogs that many people who called themselves professional embedded software programmers never liked the IDE or the programming method or syntax. In my experience it required an unlearn process to relearn a different methodology, in particular the way you approached debugging, for example. They classed Arduino as something just for hobbyists, dismissing it without stopping to think what Arduino was delivering as a system for prototyping.

                         

                        In my experience I found that Arduino was great system to learn from as it hid most of the complex stuff such as the compiling process and the way it uploaded the program onto the device (unlike Eclipse IDE, for example). On the other hand it was unforgiving if you did not get your software logic right or if you over used the run time memory resource available as it was quite difficult to work out where you got things wrong. I believe both of these things are being addressed so it can only get better.

                         

                        Looking ahead though, I think people starting out now have another viable alternative, which is circuit Python. "Horses for courses", as they say.

                         

                        makerkaren  wrote:

                         

                        While learning electronics, I've had my hands on multiple Arduino Starter Kits. These come with sample circuits and the corresponding code to make them work. That code can be tweaked to make each circuit do something slightly different. But here's the point of difficulty: What if you want to make your own circuit, and can't find code similar to what you want. What do you do? Where do you look?

                         

                        The market has moved on and things have significantly improved recently. There is now a ton of stuff out there within the supply chain in terms of new sensor breakout boards with software libraries through to companies offering low cost prototype PCB's together with easy to use online software to design PCB's. I learn by example, as I am not a linear learner. I need to have a problem to solve first. I also need to understand all the building blocks first, so books and structured lectures or course notes never worked for me. This meant I had to do the whole syllabus before it clicked. As such, I find that a combination of YouTube (videos played back at high speed) and online examples work for me. I recall in the early years that Jeremy Blumm was the go to source for demonstrating different examples clearly and simply. I believe he has now published a new book. For now, I find Adafruit's learning tutorials to be an excellent starting point. So similarly, this is a case of "horses for courses".



                        3 of 3 people found this helpful
                        • Re: What is your favorite tool for learning to program Arduino?
                          beacon_dave

                          "What if you want to make your own circuit, and can't find code similar to what you want. What do you do? Where do you look?"

                           

                          Have you got a copy of 'Arduino Cookbook' by Michael Margolis ?

                          https://learning.oreilly.com/library/view/arduino-cookbook/9781449399368/

                          It's basically page after page of sample circuits and code.

                          4 of 4 people found this helpful
                          • Re: What is your favorite tool for learning to program Arduino?
                            colporteur

                            After looking through the responses to your post, I thought I would ask a few questions.

                             

                            What programming language(s) are you wanting to learn?

                             

                            What is your educational/experience background?

                             

                            What do you have available for resources? Hardware, cash and time are some considerations for this question.

                            • Re: What is your favorite tool for learning to program Arduino?
                              sjmill01

                              So if you've played around with Arduino, what did you do to learn the language?

                              I had C experience back from back in the day.  I used a "teach yourself C in 24hrs" book.  It was tough on me because I wasn't use to pointers.  However, Arduino is much more straight forward.

                               

                              To teach my son, we just talked through the examples that come with the IDE. 

                               

                              Programming is like whittling for me.  I start out with minimum functionality for the goal, then I keep adding features.

                               

                              What are your favorite tools for learning to code with Arduino?

                              Simply the examples that come with the libraries.  I started with "blink" that is under File-->Examples and go from there.

                               

                              Do you like watching videos? Have you found good tutorials?

                              I only watch videos for inspiration versus learning code.  I just always have Google or Bing open as I code.  If I get stuck, I search.  Usually someone on Stack Exchange has already asked and answered it.  By far, it is my biggest reference for coding in all languages.

                               

                              The biggest thing that got me to learn code was that I always driven by an idea for a project.  I never knew how to get there when I started.  I'd write a few sentences on what I wanted to do and then I learned as I needed.  When I'd research for one thing, I'd learn 10 other things that would come in handy in the future.

                               

                              Post links, sources, and sage advice in the comments below.

                              I rarely use a favorite website to source knowledge.  I use a question in google.  But, for Arduino, I've been known to peek at this one:

                              https://www.arduino.cc/reference/en/

                               

                              I code at work and then come home and code for fun.  The tens of thousands of lines of code in my code worlds all just come down to these fundamentals:

                               

                              data types

                              for loop

                              Do/While loops

                              If...then

                              concatenation of a string variable

                              Call a method that has a return value

                               

                              On the Arduino, start with the Blink example and use these to take pin inputs in clever ways and show things to the serial monitor.  It's downhill from there.  Questions will pop in your head to do the next cool thing from where you are.  Jump to google and ask those questions and you'll evolve your Google-foo to conquer any challenge.

                               

                              -Sean

                              4 of 4 people found this helpful
                              • Re: What is your favorite tool for learning to program Arduino?
                                rsc

                                This is the book I used in my "Intro to Microprocessors" class.

                                1 of 1 people found this helpful