How to export a compiled C++ project as executable for Raspberry Pi 3 (ARM, Raspberry Pi OS 32 bit)

151 views Asked by At

I have a Raspberry Pi 4B with Raspberry Pi OS x32. I use Code::blocks and gcc-compiler for the development. I wrote a simple C++ project that contains only one source file and use some libraries. The code is below:

#include <iostream>
#include <chrono>
#include <thread>
#include <wiringPi.h>

using namespace std;

void switchOnLeds(int delay, int firstLed, int lastLed);
void digitalWrite(int pin, bool statement);
void simpleDelay(int cycles);
int calculateOperationTime();
bool lastStatement = false;
const int DELAY_PIN = 14;    //Pin only to delay    

int main()
{
    cout << "In this program I try to control the LED strip without SPI-wire. The LED strip must be connected with the Pin 11/GPIO 17. It is 6 pin on the left side from up. Pin 23/GPIO 11 must be free and not connected" << endl;
    int firstLed = 0;
    int lastLed = 0;
    wiringPiSetup () ;
    for (int i = 0; i < 10; i++){
        cout << "Enter first LED number: " << endl;
        cin >> firstLed;
        cout << "Enter second LED number: " << endl;
        cin >> lastLed;
        int delay = calculateOperationTime();
        cout << "Start to test with delta time: " << delay << "LEDs between " << firstLed << " and " << lastLed << " must be switched on" <<endl;
        switchOnLeds(delay, firstLed, lastLed);
    }
    return 0;
}

void switchOnLeds(int delay, int firstLed, int lastLed) {
    const auto BIT_0_HIGH_VOLTAGE_TIME = (250);    //nanoseconds to start transfer the logical 0 for ws2811 in fast mode
    const auto BIT_0_LOW_VOLTAGE_TIME = (1000);    //nanoseconds to end transfer the logical 0 for ws2811 in fast mode

    const auto BIT_1_HIGH_VOLTAGE_TIME = (600);    //nanoseconds to start transfer the logical 1 for ws2811 in fast mode
    const auto BIT_1_LOW_VOLTAGE_TIME = (650);     //nanoseconds to end transfer the logical 1 for ws2811 in fast mode

    const int CYCLES_0_HIGH = BIT_0_HIGH_VOLTAGE_TIME/delay;
    const int CYCLES_0_LOW = BIT_0_LOW_VOLTAGE_TIME/delay;

    const int CYCLES_1_HIGH = BIT_1_HIGH_VOLTAGE_TIME/delay;
    const int CYCLES_1_LOW = BIT_1_LOW_VOLTAGE_TIME/delay;

    const int BITS_FOR_SINGLE_LED = 24;         //how many bits contains a signal for a single LED
    const int PIN = 0;                          //Output pin
    const int LEDS = 10;


    pinMode (PIN, OUTPUT) ;
    auto programFinish = std::chrono::high_resolution_clock::now();
    auto programStart = std::chrono::high_resolution_clock::now();
    for (int i = 0; i < LEDS; i++) {
        if (i >= firstLed && i <= lastLed) {
            for (int bit = 0; bit < BITS_FOR_SINGLE_LED; bit++) {
                digitalWrite(PIN, HIGH);
                simpleDelay(CYCLES_1_HIGH);
                digitalWrite(PIN, LOW);
                simpleDelay(CYCLES_1_LOW);
            }
        }
        else {
            for (int bit = 0; bit < BITS_FOR_SINGLE_LED; bit++) {
                digitalWrite(PIN, HIGH);
                simpleDelay(CYCLES_0_HIGH);
                digitalWrite(PIN, LOW);
                simpleDelay(CYCLES_0_LOW);
            }
        }
    }
    programFinish = std::chrono::high_resolution_clock::now();
    long operationTime = (std::chrono::duration_cast<std::chrono::nanoseconds>(programFinish - programStart).count())/(BITS_FOR_SINGLE_LED*LEDS) ;

    printf("Completed in ");
    std::cout << std::chrono::duration_cast<std::chrono::nanoseconds>(programFinish - programStart).count() << " ns but must be no longer as 300 000 nanoseconds on the Raspberry Pi 3b" << endl;
    std::cout <<"Operation must be 1250 nanoseconds nut it is: "<<operationTime << " nanoseconds" << endl;
}



void simpleDelay(int cycles){
    for (int i = 0; i < cycles; i++){
        if (lastStatement == true){
            digitalWrite(DELAY_PIN, LOW);
            lastStatement = false;
        }
        else{
            digitalWrite(DELAY_PIN, HIGH);
            lastStatement = true;
        }
    }
}

int calculateOperationTime(){
    auto programEnd = std::chrono::high_resolution_clock::now();
    const int steps = 10*24;
    auto programStart = std::chrono::high_resolution_clock::now();
    for (int i = 0; i < steps; i++ ){
        digitalWrite(DELAY_PIN, HIGH);
        digitalWrite(DELAY_PIN, LOW);
    }
    programEnd = std::chrono::high_resolution_clock::now();
    long deltaTime = std::chrono::duration_cast<std::chrono::nanoseconds>(programEnd - programStart).count();
    deltaTime/=(steps*2);
    return deltaTime;
}

I need to send this code to my customer for tests. He has a Raspberry Pi 3B with the same operating system. I can launch the compiled file from the release directory of the project using simple command in the terminal: sudo ./FileName .But when I try to launch this compiled file on a clear fresh installed Raspberry Pi OS 32 bit it can not be launched. The terminal says: sudo ./FileName: command not found. I need to install wiringPi and Code::blocks, compile the file from the IDE and after that I can launch the compiled file. How can I export the compiled file as executable for Raspberry Pi OS 32 bit (ARM-architecture)? How can I make executable in C++ for Linux ARM?

0

There are 0 answers