Search code examples
c++arduinoraspbian

Is it possible to use an Arduino Sketch as a C++ program?


I know some modifications will need to be made but can I convert an Arduino Sketch and compile it to run on a Raspbian System as a C++ program? I am looking to use a modbus library from Arduino to output data.


Solution

  • Yes you kind of can use your arduino sketch into Raspbian but you must use some libs. I recommend you look at this site, the only change is the pinout. WiringPi lib is a PIN based GPIO access library written in C for the BCM2835, BCM2836 and BCM2837, so you can use almost every function like arduino but in Raspberry. Also the way it will be compiled and executed will change. I recommend you learn a little bit of linux and how to compile C++/C code by command line.

    There is some example:

    #include <iostream>
    #include <wiringPi.h>
    
    using namespace std;
    
    
    /* Defines */
    #define LED  2
    
    int main (int argc, char *argv[]) {
      if (wiringPiSetup() == -1) {
        cout << "Unable configure wiringPi! Exiting..." << endl;
        return 1;
      }
    
      pinMode(LED, OUTPUT);
    
      while (1 < 2) {
        digitalWrite(LED, HIGH);
        delay(500);
        digitalWrite(LED, LOW);
        delay(500);
      }
    
      return 0;
    }