Homepage Wiki Forum Buy

Tutorial API

From GNUBLIN

Link to the documentation: API

Contents

Primary aims of the API:

  • Easy for hardware beginners
  • No complicated C/C++ spellings
  • partially Based on Arduino functions


Internal GPIO as output

#define BOARD GNUBLIN
//#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);
   }
}

Internal GPIO as input

#define BOARD GNUBLIN
//#define BOARD RASPBERRY_PI
 
#include "gnublin.h"
 
 
int main()
{
   gnublin_gpio gpio;
 
   gpio.pinMode(3,INPUT);
 
   while(1){
     if(gpio.digitalRead(3))
     {
        printf("GPIO is set \n");
     }
     sleep(2);
   }
}

Internal analog input

#define BOARD GNUBLIN
//#define BOARD RASPBERRY_PI
 
#include "gnublin.h"
 
 
int main()
{
   gnublin_adc ad;
 
 
   while(1){
        printf("AD value %i \n",ad.getValue(1));
   }
}

I2C

#define BOARD GNUBLIN
//#define BOARD RASPBERRY_PI
 
#include "gnublin.h"
 
 
int main()
{
   gnublin_i2c i2c;
 
   i2c.setAddress(0x42);
 
   char buffer[8];
   char RxBuf[8];
 
   buffer[0]=0x22;
 
   i2c.send(buffer,5);
   i2c.send(0x12, buffer, 2);   //sende 2 byte aus buffer an Register-Adresse 0x12
 
   i2c.receive(RxBuf, 3);       // lese 3 bytes und speichere sie in RxBuf
   i2c.receive(0x23, RxBuf, 3);  // lese von Register-Adresse 0x23 3 bytes und speichere sie in RxBuf 
 
}

SPI

#define BOARD GNUBLIN
//#define BOARD RASPBERRY_PI
 
#include "gnublin.h"
 
 
int main()
{
   gnublin_spi spi;
 
   spi.setSpeed(10000);
   spi.setCS(14);
   unsigned char send_buffer[9] = "getValue";
   char buffer[9];   
   while(1){
     spi.send(sendbuffer,8);
     sleep(2);
     spi.receive(buffer,8);
   }
}

Module-Relay

#define BOARD GNUBLIN
//#define BOARD RASPBERRY_PI
 
#include "gnublin.h"
 
 
int main()
{
   gnublin_module_relay relay;
 
   relay.setAddress(0x72);
 
   relay.switchPin(1,ON);
 
}

Module-Display (2x16)

#define BOARD GNUBLIN
//#define BOARD RASPBERRY_PI
 
#include "gnublin.h"
 
 
int main()
{
   gnublin_module_dogm dogm;
 
   dogm.setRsPin(14);
   dogm.setCS(11);
 
   dogm.print("Hallo Welt");
 
   sleep(2);
 
   dogm.clear();
   dogm.print("Zeile 1", 1);
   dogm.print("Zeile 2", 2);
   dogm.shift(5);
 
   sleep(2);
 
   dogm.returnHome();
   dogm.clear();
   dogm.print("Zeile 1, Offset 2", 1, 2);
 
   sleep(2);
 
   dogm.controlDisplay(0,1,0);
}

Module-Temperature

#define BOARD GNUBLIN
//#define BOARD RASPBERRY_PI
 
#include "gnublin.h"
 
 
int main()
{
   gnublin_module_lm75 lm75;
 
 
   lm75.setAddress(0x4f);
 
   printf("Temperature %i \n", lm75.getTemp());
   printf("Raw Value %i \n",lm75.getValue());
   printf("Temperature Float Value %f \n",lm75.getTempFloat());
 
}

Module-Step

#define BOARD_GNUBLIN
//#define BOARD RASPBERRY_PI
 
#include "gnublin.h"
 
 
int main()
{
	gnublin_module_step motor;
 
 
        motor.setAddress(0x76);
	motor.getFullStatus1();
	motor.runInit();
	motor.resetPosition();
	motor.setPosition(1000);
	return 0;
 
}

Ordner Struktur

  • examples Example Programs
  • modules Classes for modules
  • gnublin-tools GNUBLIN terminal tools
  • drivers I2C, UART, SPI, ... Functions are used as the basis for Modules & Co.
In other languages