0% found this document useful (0 votes)
243 views

Tutorial API - Gnublin

The document provides an overview of the GNUBLIN API tutorial, which teaches how to use the API to control various aspects of the GNUBLIN board like GPIO pins, analog inputs, I2C, SPI, and modules for relays, displays, temperature sensors, and stepper motors. Code examples are given for each topic to demonstrate how to define the board, include the API header, and call API functions to set pin modes, read/write values, send/receive data, and interface with external modules.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
243 views

Tutorial API - Gnublin

The document provides an overview of the GNUBLIN API tutorial, which teaches how to use the API to control various aspects of the GNUBLIN board like GPIO pins, analog inputs, I2C, SPI, and modules for relays, displays, temperature sensors, and stepper motors. Code examples are given for each topic to demonstrate how to define the board, include the API header, and call API functions to set pin modes, read/write values, send/receive data, and interface with external modules.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

13/05/2016

TutorialAPIGNUBLIN

Homepage

Wiki

Forum

Buy

TutorialAPI
FromGNUBLIN
Linktothedocumentation:API

Contents
1PrimaryaimsoftheAPI:
2InternalGPIOasoutput
3InternalGPIOasinput
4Internalanaloginput
5I2C
6SPI
7ModuleRelay
8ModuleDisplay(2x16)
9ModuleTemperature
10ModuleStep
11OrdnerStruktur

PrimaryaimsoftheAPI:
Easyforhardwarebeginners
NocomplicatedC/C++spellings
partiallyBasedonArduinofunctions

InternalGPIOasoutput
#defineBOARDGNUBLIN
//#defineBOARDRASPBERRY_PI

#include"gnublin.h"

intmain()
{
gnublin_gpiogpio;

gpio.pinMode(3,OUTPUT);

while(1){
gpio.digitalWrite(3,HIGH);
sleep(2);
gpio.digitalWrite(3,LOW);
sleep(2);
}
}

http://en.gnublin.org/index.php/Tutorial_API

1/4

13/05/2016

TutorialAPIGNUBLIN

InternalGPIOasinput
#defineBOARDGNUBLIN
//#defineBOARDRASPBERRY_PI

#include"gnublin.h"

intmain()
{
gnublin_gpiogpio;

gpio.pinMode(3,INPUT);

while(1){
if(gpio.digitalRead(3))
{
printf("GPIOisset\n");
}
sleep(2);
}
}

Internalanaloginput
#defineBOARDGNUBLIN
//#defineBOARDRASPBERRY_PI

#include"gnublin.h"

intmain()
{
gnublin_adcad;

while(1){
printf("ADvalue%i\n",ad.getValue(1));
}
}

I2C
#defineBOARDGNUBLIN
//#defineBOARDRASPBERRY_PI

#include"gnublin.h"

intmain()
{
gnublin_i2ci2c;

i2c.setAddress(0x42);

charbuffer[8];
charRxBuf[8];

buffer[0]=0x22;

i2c.send(buffer,5);
i2c.send(0x12,buffer,2);//sende2byteausbufferanRegisterAdresse0x12

i2c.receive(RxBuf,3);//lese3bytesundspeicheresieinRxBuf
i2c.receive(0x23,RxBuf,3);//lesevonRegisterAdresse0x233bytesundspeicheresieinRxBuf

http://en.gnublin.org/index.php/Tutorial_API

2/4

13/05/2016

TutorialAPIGNUBLIN

SPI
#defineBOARDGNUBLIN
//#defineBOARDRASPBERRY_PI

#include"gnublin.h"

intmain()
{
gnublin_spispi;

spi.setSpeed(10000);
spi.setCS(14);
unsignedcharsend_buffer[9]="getValue";
charbuffer[9];
while(1){
spi.send(sendbuffer,8);
sleep(2);
spi.receive(buffer,8);
}
}

ModuleRelay
#defineBOARDGNUBLIN
//#defineBOARDRASPBERRY_PI

#include"gnublin.h"

intmain()
{
gnublin_module_relayrelay;

relay.setAddress(0x72);

relay.switchPin(1,ON);

ModuleDisplay(2x16)
#defineBOARDGNUBLIN
//#defineBOARDRASPBERRY_PI

#include"gnublin.h"

intmain()
{
gnublin_module_dogmdogm;

dogm.setRsPin(14);
dogm.setCS(11);

dogm.print("HalloWelt");

sleep(2);

dogm.clear();
dogm.print("Zeile1",1);
dogm.print("Zeile2",2);
dogm.shift(5);

sleep(2);

dogm.returnHome();
dogm.clear();
dogm.print("Zeile1,Offset2",1,2);

http://en.gnublin.org/index.php/Tutorial_API

3/4

13/05/2016

TutorialAPIGNUBLIN

dogm.print("Zeile1,Offset2",1,2);

sleep(2);

dogm.controlDisplay(0,1,0);
}

ModuleTemperature
#defineBOARDGNUBLIN
//#defineBOARDRASPBERRY_PI

#include"gnublin.h"

intmain()
{
gnublin_module_lm75lm75;

lm75.setAddress(0x4f);

printf("Temperature%i\n",lm75.getTemp());
printf("RawValue%i\n",lm75.getValue());
printf("TemperatureFloatValue%f\n",lm75.getTempFloat());

ModuleStep
#defineBOARD_GNUBLIN
//#defineBOARDRASPBERRY_PI

#include"gnublin.h"

intmain()
{

gnublin_module_stepmotor;

motor.setAddress(0x76);

motor.getFullStatus1();

motor.runInit();

motor.resetPosition();

motor.setPosition(1000);

return0;

OrdnerStruktur
examplesExamplePrograms
modulesClassesformodules
gnublintoolsGNUBLINterminaltools
driversI2C,UART,SPI,...FunctionsareusedasthebasisforModules&Co.
Retrievedfrom"http://en.gnublin.org/index.php?title=Tutorial_API&oldid=581"
Category:
API
Thispagewaslastmodifiedon13May2013,at10:26.Thispagehasbeenaccessed4,882
times.DisclaimersAboutGNUBLIN
http://en.gnublin.org/index.php/Tutorial_API

4/4

You might also like