Raspberry GPIO interfaces C++ library. This library is a collection of useful tools to interface with GPIO for Raspberry Pi and orangepi, SPI / I2C / IO pin. This library if used in combo with openFrameworks for creative coding adds more functionality for a graphical debugging.
Class I2C for i2c interface
I2c(const char * deviceName);
~I2c();
void setup(const char * deviceName);
void addressSet(uint8_t address);
void write(uint8_t command);
void writeByte(uint8_t command, uint8_t data);
void writeBlockData(uint8_t command, uint8_t size, __u8 * data);
uint16_t readByte(uint8_t command);
uint16_t tryReadByte(uint8_t command);
uint16_t readBlock(uint8_t command, uint8_t size, uint8_t * data);
uint16_t tryReadByte(uint8_t address, uint8_t command);
Class GPIO for I/O read write
enum GPIO_MAP_PIN {
GPIO2 = 2, GPIO14 = 14,
GPIO3 = 3, GPIO15 = 15,
GPIO4 = 4, GPIO18 = 18,
GPIO17 = 17, GPIO23 = 23,
GPIO27 = 27, GPIO24 = 24,
GPIO22 = 22, GPIO25 = 25,
GPIO10 = 10, GPIO8 = 8,
GPIO9 = 9, GPIO7 = 7,
GPIO11 = 11, GPIO12 = 12,
GPIO5 = 5, GPIO16 = 16,
GPIO6 = 6, GPIO20 = 20,
GPIO13 = 13, GPIO21 = 21,
GPIO19 = 19,
GPIO26 = 26,
};
enum INTERNAL_STATE {
LOW = 0,
HIGH = 1,
OUT = 0,
IN = 1
};
GPIO();
GPIO(string pin);
GPIO(int pin);
GPIO(string pin, string dir, string val);
GPIO(int pin, int dir, int val);
void setup(string pin);
void setup(int pin);
void setup(string pin, string dir, string val);
void setup(int pin, int dir, int val);
int export_gpio();
int unexport_gpio();
int setdir_gpio(string dir);
int setdir_gpio(int dir);
int setval_gpio(string val);
int setval_gpio(int val);
int getval_gpio(string& val);
int getval_gpio(int& val);
string get_gpionum();
int get_igpionum();
Class SPI2 for SPI interface
int getFD (int channel);
int readWrite(int channel, unsigned char *data, int len);
int setup (int channel, int speed);
GPSSerial for interface GPS module (openframeworks implementation)
double convertDegMinToDecDeg (float degMin);
float getLatitude();
float getLongitude();
float getTime();
float getAltitude();
string getRawData();
void start(string device, int baund, int _sleep=1000);
void stop();
Class ReadRawData for parsing GPS serial output (without openframeworks c++ pure)
int setup(string file, int _baundrate, int _sleep);
double convertDegMinToDecDeg (float degMin);
float getLatitude();
float getLongitude();
float getTime();
float getAltitude();
string getRawData();
void update();
void start();
void close();
vector splitstring(const string & source, const string & delimiter, bool ignoreEmpty=false);
Class SerialIO for read write serial (without openframeworks c++ pure)
int iosetup(string serialport, int baud);
int iowrite(int fd, const char* str);
int iowritebyte(int fd, uint8_t b);
int ioread_until(int fd, char buf[10][20], char until);
char ioread(int fd);
int ioavailable(int fd);
void stop();
Class MCP for help interface MCP30XX
MCP(string devspi, unsigned char spiMode, unsigned int spiSpeed, unsigned char spibitsPerWord);
MCP();
~MCP();
void setup(string devspi, unsigned char spiMode, unsigned int spiSpeed, unsigned char spibitsPerWord);
int readWrite(unsigned char *data);
int xclose();
Class GETGoogleImage help for GPS MAPS
string urlStaticMap(float latitude, float longitude, int zoom=10,
int w=350, int h=350, string type="roadmap", string color = "green");
string request(float latitude, float longitude, int zoom=10,
int w=350, int h=350, string type="roadmap", string color = "green");
Class LED for LED APA102 interface
void setupAPA102(int port=0, int speed=8000000);
void setAPA102(int numLed, vector colors, int BRIGHTNESS);
void clearAPA102(int numLed);
Class Kalman for filtering
double getAngle(double newAngle, double newRate, double dt);
void setAngle(double newAngle);
double getRate();
void setQangle(double newQ_angle);
void setQbias(double newQ_bias);
void setRmeasure(double newR_measure);
double getQangle();
double getQbias();
double getRmeasure();
Class OLED for display oled i2c
enum OLEDBG { BLACK,WHITE };
void setup(OLEDBG bg);
void setDisplayOff();
void setDisplayOn();
void setBrightness(int Brightness);
void setPageMode();
void rotateDisplay180();
void setWhiteBackground();
void setBlackBackground();
void setCursor(int x, int y);
void drawBitmap(int *Bitmaparray, int x, int y, int w, int h);
void clearDisplay();
void printChar(char Char);
void printString(char *Data);
void printNumber(long Data);
Class TCPServer for remote control GPIO
void setup(int port);
string receive();
string getMessage();
void Send(string msg);
void detach();
void clean();
Class TCPClient for remote control GPIO
TCPClient();
bool setup(string address, int port);
bool Send(string data);
string receive(int size = 4096);
string read();
Class GPIOS graphic interface for control I/O GPIO (only openframeworks)
enum TYPEGPIOS{ PIA = 0, PIB = 1, PIBP = 2, PIAP = 3, PI2 = 4, PI3 = 5, PIZERO = 6, H3 = 7 };
void setup( TYPEGPIOS _t, int __x, int __y);
void draw();
Class UI Gtk+ graphic interface (without openframework)
namespace UIGpio
struct _DescEvent
{
string name;
string type;
string value;
}
DescEvent;
_DescEvent getEvent() { return buffer; }
void setWindowSize(int w, int h)
void setup(string title="title", int colum=10, int rows=10)
void addColorPalett(string title)
void addList(string title, vector listed, int column, int row)
void addInput(string title, int column, int row)
void addImage(string img, int column, int row)
void addSlider(string title, int column, int row, int min, int max, int step=1)
void addToggle(string title, int column, int row)
void addCheck(string title, int column, int row)
void addButton(string title, int column, int row)
void show()
Class LogHighLight for debug log color
Log("foreground: red and background: white",FG_RED,BG_WHITE)<<"\n";
Log("ofxGPIO debug",FG_MAGENTA,BG_BLACK)<<"\n";
/* foreground color */
FG_RED
FG_GREEN
FG_BLUE
FG_DEFAULT
FG_BLACK
FG_YELLOW
FG_MAGENTA
FG_CYAN
FG_LIGHT_GRAY
FG_DARK_GRAY
FG_LIGHT_RED
FG_LIGHT_GREEN
FG_LIGHT_YELLOW
FG_LIGHT_BLUE
FG_LIGHT_MAGENTA
FG_LIGHT_CYAN
FG_WHITE
/* background color */
BG_RED
BG_GREEN
BG_BLUE
BG_DEFAULT
BG_BLACK
BG_YELLOW
BG_MAGENTA
BG_CYAN
BG_WHITE
Sample Code i2c MPU6050
#include iostream
#include "ofxGPIO.h"
#define MPU 0x68
using namespace std;
int main(){
I2c * bus;
float ap = 0.955;
bus = new I2c("/dev/i2c-1");
bus->addressSet(MPU);
int8_t power = bus->readByte(MPU_POWER1);
bus->writeByte(MPU_POWER1, ~(1 << 6) & power);
while(1)
{
int16_t temp = bus->readByte(MPU_TEMP1) << 8
| bus->readByte(MPU_TEMP2);
int16_t xacc = bus->readByte(MPU_ACCEL_XOUT1) << 8
| bus->readByte(MPU_ACCEL_XOUT2);
int16_t yacc = bus->readByte(MPU_ACCEL_YOUT1) << 8
| bus->readByte(MPU_ACCEL_YOUT2);
int16_t zacc = bus->readByte(MPU_ACCEL_ZOUT1) << 8
| bus->readByte(MPU_ACCEL_ZOUT2);
int16_t xgyr = bus->readByte(MPU_GYRO_XOUT1) << 8
| bus->readByte(MPU_GYRO_XOUT2);
int16_t ygyr = bus->readByte(MPU_GYRO_YOUT1) << 8
| bus->readByte(MPU_GYRO_YOUT2);
int16_t zgyr = bus->readByte(MPU_GYRO_ZOUT1) << 8
| bus->readByte(MPU_GYRO_ZOUT2);
}
return 0;
}