This example shows how to install biicode, code a C++ led blink with WiringPi, make the cross compilation and send the executable to your Raspberry Pi.
You don’t need to have WiringPi installed in your computer or the rpi. Biicode will download and configure it automatically for you, it is already in biicode!
Debian linux distribution required
You need to use a native debian linux or in a virtual machine to use the cross compilation tools.
First, download and install biicode.
Then, open the console and type:
~$ bii setup:rpi
First, create a project:
~$ bii init myproject
Then we can use the convenience new
command to create some folders and a “Hello World” C++ main file. Of course, you can do it manually too.
~$ cd myproject
~/myproject$ bii new myuser/myblock --hello=cpp
myuser
, there’s no need to register an account to use biicode, only
to upload and share contents. You can use other name too.
If you have already registered you might want to replace myuser
with your real biicode username.This should be the resulting layout:
+-- myproject
| +-- bii
| +-- blocks
| | +-- myuser
| | | +-- myblock
| | | | +-- main.cpp
| +-- deps
Configure your project to the cross compiling running bii rpi:settings
:
~$ cd myproject
~/myproject$ bii rpi:settings
Define RPI settings for external C/C++ cross-building
If you are working on board the RPI, you don't need these settings:
RPI username (pi): [ENTER]
RPI IP Address: 192.168.1.44
RPI directory to upload (bin): [ENTER] #This folder must exist into your Raspberry Pi.
Creating toolchain for Raspberry PI
Run "$bii cpp:configure --toolchain=rpi" to activate it
Run "$bii cpp:configure --toolchain=None" to disable it
Activate the toolchain for Raspberry PI with bii cpp:configure --toolchain=rpi
:
bii configure --toolchain=rpi
Lets check that everything is fine by building and trying to run the hello world aplication. It could fail the execution because it is compiled to Raspberry PI.
~/myproject$ bii build
...
~/myproject$ ./bin/user_myblock_main
./bin/user_myblock_main: cannot execute binary file
To send the binary to your Raspberry Pi, you just need to execute the bii rpi:send
command and the file will be sent using rsync to the address provided in your settings.
$ bii rpi:send
Sending with rsync -Pravdtze ssh [PROJECT_DIRECTORY]/bin/* [RPI_USER]@[RPI_IP]:[DIRECTORY]/[PROJECT_NAME]
[RPI_USER]@[RPI_IP]'s password:
The Raspberry Pi user’s password will be asked. If you have not changed your password, for Raspbian the default one is raspberry.
Finally, to execute your program on your Raspberry Pi, you need to establish a connection. You can use the rpi:ssh
command if you want remote access. You’ll find your program deployed in the path configured in your settings:
$ bii rpi:ssh
...
Connecting with ssh <rpi_user>@<rpi_ip>
<rpi_user>@<rpi_ip>'s password:
pi@raspberrypi ~ $ cd hello_rpi
pi@raspberrypi ~/hello_rpi $ ls
myuser_myblock_main
pi@raspberrypi ~/hello_rpi $ ./user_myblock_main
Hello world!
Copy the following code containing a simple sum function and a test into the main.cpp file
#include "drogon/wiringpi/wiringPi/wiringPi.h"
#define LED 0
int main (void){
wiringPiSetup () ;
pinMode (LED, OUTPUT) ;
digitalWrite (LED, HIGH) ; // On
}
Execute the following command to find unresolved dependencies and retrieve necessary files from servers:
~/myproject$ bii find
Now you are ready to compile and deploy your new application. First, cross-compile your program and make sure the binary is generated running bii build
from your project location:
$ bii build
...
Configuring cross compiler for ARM architecture:
...
[100%] Built target myuser_myblock_main
The binaries are created in bin
folder.
Didn’t work? No problem, read or contact us in the biicode forum.
Any suggestion or feedback? Write us! It is very welcomed :)