Since Arduino uses C++ for its programming with libraries that are specific to Arduino, is it possible to compile your sketch and have it run as a C++ program on a Raspberry Pi? I saw there was RasPiArduino for the Raspberry Pi 1/2 but it doesn;t seem to support 3. I am looking to run a program I made on my Arduino boards on my Raspberry Pi with a few modifications.(Note: I posted a similar question before but all anyone focused on was the specific example and not the question as a whole.) What would I need to change for it to run, and what would I need to carry over to run my Arduino programs on the Raspberry Pi?

  • 1
    The first link is invalid. but it doesn't seem to support 3 What makes you think it's not supported? Is it explicitly stated somewhere? If it works on a Pi 2 it's likely it also works on a Pi 3. – Dirk Mar 7 '19 at 16:23

You are absolutely correct that Arduino sketches are C(++) with a set of custom libraries

In principle if one replaces or provides a wrapper for each imported/used library with an API compatible raspberry pi port of that library , then the code will compile as is. There is an additional complication that Arduino provides void main() entry point for you as part of the core library application bootstrap, this function does much platform specific initialization and must also be ported.

However this is only half the picture. An arduino sketch is a baremetal application: the entire CPU , every peripheral, and all of physical memory is freely available to you. Many libraries provide functionality that is impossible to directly port in a user space application running on Linux, although equivalent functionality may be found, certain design patterns common in Arduino sketches and baremetal plat forms- things like busy waits, while loop on a status bit, random delays etc. Will not be directly portable or will behave unpredictably . Your application may break and require architectural redesign to function on Linux.

  • Do you know any good resources on simple libraries to use? I am still kind of new to C++ and I am not really a programmer but I need to do some programs to build my device. – Michael H. Mar 8 '19 at 15:35

There something called cross-compilation toolchain. You might want to look into that. One example Link: https://crosstool-ng.github.io/

Cross-compilation toolchain helps in creating binaries that run for different platform than the platform where toolchain runs.

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.