A note on C, C++, and Arduino programming

I see a lot of questions on the Web about how Arduino code relates to C and/or C++.  In a nutshell,  Arduino code IS basically C/C++ code.  Arduino uses a set of standard libraries to hide some of the functionality behind the curtain, making things easier for the newcomer to get started in the hobby.  For example, rather than setting specific bits on a “Port” to identify a pin as an output, coding something like DDRC.1 = 1;   after looking up which “port register” and which bit in the register controls the pin you want, you simply can code something like:  pinMode(8, OUTPUT);

This can also save time and effort for more experienced developers as well.  Arduino is not just for newbies.  There are tradeoffs, however.  For example, using the Arduino library to set pin modes takes longer, in terms of CPU processing time, than setting them more directly.  BUT, because Arduino basically IS C, you can often (but not always) just drop in the direct code you need, and still use the Arduino libraries for the rest.  And if you someday want to go straight to AVR C programming, skipping the Arduino IDE’s and libraries entirely, there are ways of doing that to with your Arduino board.

You may have noticed that I said Arduino is basically C/C++.  Well, which is it?  Aren’t they two different, if related languages?  Yes, they are.   C++ is mostly a superset of C, adding object oriented programming concepts.  C++ started as “C with classes”   but C is no longer completely a proper subset of C++, as the two languages evolved a bit differently over time.  These days, languages usually have both the core language itself and a set of standard libraries.  These libraries have already coded frequently used routines in an efficient manner,  so you don’t have to keep reinventing the wheel.  As I understand it, Arduinos support C++ core language features and the common C libraries, such as math.h, but NOT the standard C++ libraries.  So while you can use objects and other core C++ language features, you can’t draw from the C++ library.  At least this is my understanding.  Please let me know if I’ve gotten something wrong.

Initial musings on robotic vehicles

I finally started working on my first robotic vehicle about 2 months ago.  It’s built around the RP5 tracked chassis and the Romeo controller board, both from DFRobot.  I chose the RP5 because it’s low-cost, the tracks make it a bit more capable for traveling over small objects, and it was fully assembled.  I chose the Romeo because it’s an Arduino-compatible board with support for driving the motors built in (no need for a motor controller board) and lots of convenient 3-pin headers (pwr, gnd, and signal) tied to the Arduino pins, making it really easy to connect sensors and other items.

My goal for the first robot is for it to run indoors, using dead reckoning to navigate (as best it can) to a series of pre-specified waypoints, while avoiding obstacles along the way.  I wanted to build capability in stages.  Here’s what I’ve found out so far:

  1. It is trivial to use available kit parts, like the RP5 and the Romeo, to quickly get up a vehicle that moves around, whether in a straight line, by moving and turning for preset time periods, or moving at random.
  2. It is surprisingly easy to add a sensor and instigate obstacle avoidance.
  3. It is 1-2 orders of magnitude harder to add position sensing and navigation.

Having said that, I’m well along the way to getting navigation working, it’s been fun, and given me the opportunity to learn or relearn a lot of basic C along the way (my previous C experience being limited to 1 course about 25 years ago).  I find it’s much easier to learn a technical subject if you’ve got a hands-on project you’re working on, and that even a simple robot touches on a lot of the basics of the C language.

 

Hello world!

My first blog post ever!  I’ve played around with programming and software development (both as a hobby and professionally) since starting on GE time-sharing system via a teletype in 7th grade (you youngsters can look that up!).  I really like python as my programming language of choice, but this blog will mainly be about my entry into microcontrollers and robotics, hence C and Arduino code.

This blog will mainly focus on my initial forays into robotics, but will touch on other items from time to time as well.

 

4JFAEQ26CG4F