AdafruitMotorHAT in C++ using wiringPi

MatAff New Member Posts: 18 ✭✭

I ran into a problem with using the AdafruitMotorHat in C++ and just wanted to leave a comment here on how I managed to get it to work, it in case anyone else runs into the same problem in the future.

Firstly, Adafruit only tends to provide code in Python. So to use the AdafruitMotorHat in C++ threebrooks wrote a C++ library to use it. I've been using this on the Pi and it works great. This library can be found here:

When I tried to use this library on the Up board I got the following error.

Oops: Unable to determine board revision from /proc/cpuinfo
 -> No "Hardware" line
 ->  You'd best google the error to find out why.

After much digging I found the problem was with the wiringPi library, which is only build to support the Raspberry Pi. (The author is quite explicit about this).

See for general download and installation instructions.

To use this for the Up board, we need to make a change to one of the files: wiringPi.c

In wiringPi.c find the following function and comment out the exit statement. The library does various checks to ensure it's running on a Pi (which it's not, but close enough I guess!). I've left the other warnings in place. You will see them when you run the motors. You could comment the other print statements out as well, but I like to remind myself this has not been properly fixed.

static void piGpioLayoutOops (const char *why)
  fprintf (stderr, "Oops: Unable to determine board revision from /proc/cpuinfo\n") ;
  fprintf (stderr, " -> %s\n", why) ;
  fprintf (stderr, " ->  You'd best google the error to find out why.\n") ;
//fprintf (stderr, " ->\n") ;
  exit (EXIT_FAILURE) ;

After making this fix, run the conveniently provided build script.


Hopefully in future there will be a more elegant way to use some version of the AdafruitMotorHat or wiringPi libraries. But for now this at least gets it running!