we developed a C++ API to easily interact with typical embedded Linux interfaces. In the first place we wrote the code for our Open Source embedded Linux board called Gnublin. But it turned out, that the API also works on the Raspberry Pi.
Check out our git repository:
https://github.com/embeddedprojects/gnublin-api
We encourage you to test it on your RPi and give us some feedback!
For detailed information check out our documentation
Here is some example code, to give you a brief look, how the API works:
Simple gpio access:
Code: Select all
#define BOARD RASPBERRY_PI
#include "gnublin.h"
int main()
{
gnublin_gpio gpio;
gpio.pinMode(3,OUTPUT);
while(1){
gpio.digitalWrite(3,HIGH);
sleep(2);
gpio.digitalWrite(3,LOW);
sleep(2);
}
}
Code: Select all
#define BOARD RASPBERRY_PI
#include "gnublin.h"
int main()
{
gnublin_i2c i2c;
i2c.setAddress(0x42); // set the address of the slave you want to read/write
char buffer[8];
char RxBuf[8];
buffer[0]=0x22;
i2c.send(buffer,5);
i2c.send(0x12, buffer, 2); //send 2 bytes from buffer to register-address 0x12
i2c.receive(RxBuf, 3); // read 3 bytes and store them in RxBuf
i2c.receive(0x23, RxBuf, 3); // read from tegister-address 0x23 3 bytes and store them in RxBuf
}