Arduino programming

Arduino is an open-source electronics prototyping platform based on flexible, easy-to-use hardware and software. It’s intended for artists, designers, hobbyists, and anyone interested in creating interactive objects or environments. So very interesting stuff..

The microcontroller on the board is programmed using the Arduino programming language and the Arduino development environment. Arduino programming environment is lean and relatively easy to use. Quite a few examples are at your finger tip. It is relatively easy to get started.

arduino316

Arduino Development Using NetBeans IDE article tells that that the Arduino IDE lacks some key features most modern IDEs have and it is actually fairly straight forward to add Arduino support in the NetBeans IDE. Other possible IDE to use is Ecplipse.

17 Comments

  1. SEOMaster says:

    This is a superb post Tomi Engdahl’s ePanorama blog .
    But I was wondering how do I suscribe to the RSS feed?

    Reply
  2. what is programming says:

    what is programming…

    Arduino programming ” Tomi Engdahl’s ePanorama blog is a big world, I am looking for someone who can elaborate on what is programming….

    Reply
  3. Vernon Brotemarkle says:

    Hey, with the abundance of crappy blogs around it’s great to see that there are still some filled with great content! Is there any way I can be emailed when you create a new post? thank you!

    Reply
  4. Toolduino « Tomi Engdahl’s ePanorama blog says:

    [...] Toolduino is a simple software tool that lets you easily interact with Arduino hardware. With this software you can easily can test the circuits you create. The Arduino must be running [...]

    Reply
  5. Arduino UNO review « Tomi Engdahl’s ePanorama blog says:

    [...] The Uno is the latest in a series of USB Arduino boards, and the reference model for the Arduino platform. The Uno differs from all preceding Arduino boards with USB connection in that it does not use the FTDI USB-to-serial driver chip (like Arduino Dueminanove board I already own). [...]

    Reply
  6. Arduino Goes ARM « Tomi Engdahl’s ePanorama blog says:

    [...] tells that now the open source Arduino platform has a new member — the ARM-based Arduino Due announced at the Maker Faire in New [...]

    Reply
  7. Duemilanove 2009 Atmega 328P SCM Board « Tomi Engdahl’s ePanorama blog says:

    [...] board is not the newest Arduino design (UNO) for this kind of board, this board is based on older Duemilanove. In this case I don’t consider the older design any way worse than the newer one, there are [...]

    Reply
  8. Tomi Engdahl says:

    Code Craft-Embedding C++: Hacking the Arduino Software Environment
    http://hackaday.com/2015/12/31/code-craft-embedding-c-hacking-the-arduino-software-environment/

    The Arduino software environment, including the IDE, libraries, and general approach, are geared toward education. It’s meant as a way to introduce embedded development to newbies. This is a great concept but it falls short when more serious development or more advanced education is required. I keep wrestling with how to address this. One way is by using Eclipse with the Arduino Plug-in. That provides a professional development environment, at least.

    The code base for the Arduino is another frustration. Bluntly, the use of setup() and loop() with main() being hidden really bugs me. The mixture of C and C++ in libraries and examples is another irritation. There is enough C++ being used that it makes sense it should be the standard. Plus a good portion of the library code could be a lot better. At this point fixing this would be a monumental task requiring many dedicated developers to do the rewrite. But there are a some things that can be done so let’s see a couple possibilities and how they would be used.

    The Main Hack

    As mentioned, hiding main() bugs me. It’s an inherent part of C++ which makes it an important to learning the language.

    Zapping setup() and loop()

    Now that I have control over main() I can address my other pet peeve, the setup() and loop() functions. I can eliminate these two function by creating my own version of main(). I’m not saying the use of setup() and loop() were wrong, especially in light of the educational goal of Arduino. Using them makes it clear how to organize an embedded system. This is the same concept behind C++ constructors and member functions.

    Global Instantiation

    One issue with C++ is the cost of initialization of global, or file, scope class instances. There is some additional code executed before main() to handle this

    Program Class

    My approach is to create a Program class with a member run() function. The setup for the entire program occurs in the class constructor and the run() function handles all the processing. What would normally be global variables are data members.

    Redbot Line Follower Project

    The Redbot project is an interesting vehicle for demonstrating code techniques. The current test of the motor routines demonstrates how to override the existing Arduino main(). Even if you don’t like my approach with Program, the flexibility of using your own main() may come in handy for your own projects.

    Reply
  9. Tomi Engdahl says:

    Learn Functional Reactive Programming on Your Arduino
    http://hackaday.com/2016/05/25/learn-functional-reactive-programming-on-your-arduino/

    Juniper is a functional reactive programming language for the Arduino platform. What that means is that you’ll be writing your code using anonymous functions, map/fold operations, recursion, and signals. It’s like taking the event-driven style that you should be programming in one step further; you write a=b+3 and when b changes, the compiler takes care of changing a automatically for you. (That’s the “reactive” part.)

    If you’re used to the first-do-this-then-do-that style of Arduino (and most C/C++) programming, this is going to be mind expanding. But we do notice that a lot of microcontroller code looks for changes in the environment, and then acts (more or less asynchronously) on that data.

    http://www.juniper-lang.org/tutorial.html

    Reply
  10. Tomi Engdahl says:

    Using Modern C++ Techniques with Arduino
    http://hackaday.com/2017/05/05/using-modern-c-techniques-with-arduino/

    C++ has been quickly modernizing itself over the last few years. Starting with the introduction of C++11, the language has made a huge step forward and things have changed under the hood. To the average Arduino user, some of this is irrelevant, maybe most of it, but the language still gives us some nice features that we can take advantage of as we program our microcontrollers.

    Modern C++ allows us to write cleaner, more concise code, and make the code we write more reusable. The following are some techniques using new features of C++ that don’t add memory overhead, reduce speed, or increase size because they’re all handled by the compiler. Using these features of the language you no longer have to worry about specifying a 16-bit variable, calling the wrong function with NULL, or peppering your constructors with initializations. The old ways are still available and you can still use them, but at the very least, after reading this you’ll be more aware of the newer features as we start to see them roll out in Arduino code.

    C++11 introduced a series of fixed width integer types aliases that will give you the number of bits (in multiples of 8) you want. There are both signed and unsigned versions. If you use int16_t for a variable you know it’s 16 bits, regardless of which Arduino is being targeted.

    The concept of an anonymous namespace has been around for a while in C++, but it came to prominence with the introduction of C++11. In C++11, the anonymous namespace is now the preferred way to specify a variable, function, or class that is accessible only in the current file

    Anonymous namespaces take the place of declaring things static. Anything you may have declared as static or const, or written as a #define can now put into an anonymous namespace and have the same effect – anything defined in inside cannot be accessed outside of the ‘.cpp’ file that the namespace is in. In the Arduino IDE, though, if you add a tab and give the new tab a name that doesn’t end in ‘.cpp’ or ‘.h’ then the file is given an extension of ‘.ino.’ When you click the ‘Verify’ button, all the ‘.ino’ files are concatenated into a single ‘.cpp’ file.

    Reply
  11. Tomi Engdahl says:

    Building an OBD Speed Pulse: Behold the ICE
    http://hackaday.com/2017/05/09/obd-speed-pulse-part-2-behold-the-ice/

    I am a crappy software coder when it comes down to it. I didn’t pay attention when everything went object oriented and my roots were always assembly language and Real Time Operating Systems (RTOS) anyways.

    So it only natural that I would reach for a true In-Circuit-Emulator (ICE) to finish of my little OBDII bus to speed pulse generator widget. ICE is a hardware device used to debug embedded systems. It communicates with the microcontroller on your board, allowing you to view what is going on by pausing execution and inspecting or changing values in the hardware registers. If you want to be great at embedded development you need to be great at using in-circuit emulation.

    Not only do I get to watch my mistakes in near real time, I get to make a video about it.

    Walk through the process of using an In-Circuit Emulator in the video

    I have the In-Circuit-Serial-Programming (ICSP) pins routed to a pin header on my board so that I can program the part directly.

    On this connector you’ll find the Reset line, which means with this header I can use a true ICE utilizing the debugWIRE protocol. Since the vast majority of designs that use an AVR chip do not repurpose the reset pin for GPIO, it is a perfect pin to use for ICE. All of the communications during the debug process will take place on the reset pin.

    As a hardware engineer by trade I would always reach for an ICE to kick off the implementation; only after the Beta release would the ICE start to gather dust in the corner.

    In the case of the ATmega, the debugging capabilities are built into the microcontroller itself. This is a much more straightforward implementation than the early days when we had to have a second isolated processor running off-board with its own local RAM/ROM.

    One note mentioned in the video is that a standard Arduino’ish board needs to have the filter capacitors removed from the RESET line to allow the high speed data on the line for its debugWIRE usage.

    ICEyness

    The ICE allows us to download and single step our code while being able to observe and overwrite RAM and I/O Registers from the keyboard.

    Reply
  12. Tomi Engdahl says:

    Templates Speed Up Arduino I/O
    http://hackaday.com/2017/05/11/templates-speed-up-arduino-io/

    It is easy to forget, but the Arduino does use C++. Typically, the C++ part is in the libraries and the framework and most people just tend to code their main programs using a C-style just using the library objects like C-language extensions. [Fredllll] recently created a template library to speed up Arduino I/O and he shared it on GitHub.

    If you’ve ever done anything serious with the Arduino, you probably know that while digitalWrite is handy, it does a lot of work behind the scenes to make sure the pin is setup and this adds overhead to every call. [Fredllll’s] template versions can switch a pin’s state in two cycles. You can cut that in half if you don’t mind bothering the state of other pins on the same port.

    https://github.com/fredlllll/FredUtil-Arduino/blob/master/fredOptimization.h

    Reply
  13. Tomi Engdahl says:

    Arduino I/O Speed Breakdown
    https://hackaday.com/2010/01/06/arduino-io-speed-breakdown/

    [Jee Labs] has worked out how long it takes for an Arduino to perform various I/O operations. Predictably, analogRead() takes the longest, followed by analogWrite(). Arduino really falls behind when it comes to digital pin I/O: digitalWrite() takes a whopping fifty times longer than a direct bit write to a port register! This is something to take into consideration when you are looking to do some beefy I/O with an Arduino.

    Reply
  14. Tomi Engdahl says:

    Pin I/O performance
    In AVR, Hardware, Software on Jan 6, 2010 at 00:01
    http://jeelabs.org/2010/01/06/pin-io-performance/

    Reply
  15. Tomi Engdahl says:

    Building an Arduino sketch from scratch
    http://thinkingonthinking.com/an-arduino-sketch-from-scratch/

    Unix programmers have been building software for many years with the command line and the GCC toolchain. When developing for embedded systems, where clock cycles and memory usage counts, some familiarity with GCC is often needed.

    The GCC tools come in different forms. For example, there is a variant for Atmel AVR microcontrollers which is an important part of the Arduino IDE. Also, you’ll find GCC versions for ARM which e.g. the Teensy 3 requires.

    The Arduino IDE will install all the the AVR GCC tools for you.

    Learning the secrets of compilers and build tools takes some practice.

    Imagine this blink.ino Arduino sketch

    To compile this sketch with g++, you must include the Arduino.h header and include a main() function.

    With the arduino.h header, you get functions to work with pins and ports. Also, you get function prototypes for the main parts of your sketch

    void setup(void);
    void loop(void);

    Now, blink.cpp is valid for compilation.

    As we used the pinMode and digitalWrite functions of Arduino core libraries, we need to package some of these libraries into our blink.o binary.

    Repeating these steps manually for every project would quickly become furstrating. To automate builds and configurations, there are Makefiles.

    https://github.com/arduino/Arduino/blob/master/hardware/arduino/avr/cores/arduino/Arduino.h

    Reply

Leave a Comment

Your email address will not be published. Required fields are marked *

*

*