The issue is that I have code using an Arduino library and need to convert it into C++ so I can use it with a raspberry pi on ROS (Robot operating system). Does anyone know the best way to change it over or know of good resources?

I know that Arduino is essentially C++ but I am uncertain about how to make Arduino libraries into C++.

  • Arduino libraries already are C++. – Majenko Jun 7 '19 at 18:52
  • Thank you! So I do not need to rewrite anything to use Arduino code in C++? Or do I just need to call the library differently? – Ally Jun 7 '19 at 18:54
  • Depending on the library you may need to reimplement standard Arduino API calls, like digitalWrite, etc. Or just implement your own copies of whatever functions are needed using whatever ROS provides. – Majenko Jun 7 '19 at 18:58
  • The Arduino API is just a collection of C++ functions and classes. If a library needs one of those functions or classes then just implement it (if ROS doesn't already provide it. No idea what or who ROS is). – Majenko Jun 7 '19 at 19:01
  • Ok, that helps. I am trying to get a grasp on the differences between Arduino and generic C++. (ROS is Robot Operating system and works only on Linux so Arduino doesn't work with it so I am transforming code to work with it on a Rasberry pi). – Ally Jun 7 '19 at 19:05

The sometimes-called "Arduino Language" is C++, but with some upfront work - primarily supplying file inclusions - done for you if you don't.

The Arduino compiler is a GNU C++ compiler. If you write or supply standard C++ to the Arduino IDE, it will compile it.

| improve this answer | |

The Arduino compiler is a GNU C++ compiler HOWEVER there is no c runtime library (which is not part of the compiler).

Probably more significant to the question is that the Arduino compiler supplies support for the ATMEL hardware. This is incompatible with the Raspberry Pi.

The Arduino is a real time microcontroller and has unrestricted access to its hardware, the Pi usually runs a multi-tasking OS, the hardware is not directly accessible from user space, so many tasks need to be written differently; often this means relying on a OS supplied kernel driver.

Any practicable Arduino program would require extensive changes to work on the Raspberry Pi. The effort involved is likely to be more than writing a Raspberry Pi program from scratch.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.