Homepage Wiki Forum Buy

Tutorial API RaspberryPi

From GNUBLIN

Revision as of 06:04, 8 September 2013 by Sauterbe (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Contents


The huge advantage of the GNUBLIN are the many modules. There is a small tool on the command line for each module with which you can control the module already. It happens that what you would expect: motor rotates, temperature value is displayed, the display shows text, etc.

Suitable for every module there are calls available in the API to write own programs in C and C++. In addition to the support for Gnublin we implemented a support for RaspberryPi too.

On these pages, all the information is collected.

Rasp all.jpg


Quickinstall

The RaspberryPi must be started and have a connection to the Internet. With git you can now clone the repository. If Git should not be installed on your RaspberryPi, do that as follows:

pi@raspberrypi ~ $ sudo apt-get install git

Now you can clone the repository:

pi@raspberrypi ~ $ git clone https://github.com/embeddedprojects/gnublin-api.git

Change in the directory

pi@raspberrypi ~ $ cd gnublin-api

Before you can compile the API, you must specify that you want to run the API on a RaspbberryPi. These changes are in the file 'API config.mk':

These lines have to commented out: 2, 12, 17. But in these lines you have to remove the # at the beginning: 6, 14, 18. The API config.mk file looks as follows:

  1. #Crosscompiler for Gnublin
  2. #CXX := arm-linux-gnueabi-g++
  3. #Crosscompiler for Raspberry Pi:
  4. #CXX := arm-linux-gnueabihf-g++
  5. #Compiler for onboard compilation:
  6. CXX := g++
  7.  
  8. #Compilerflags:
  9. CXXFLAGS = -Wall
  10.  
  11. #Architecture for gnublin:
  12. #Architecture = armel
  13. #Architecture for raspberryPi:
  14. Architecture = armhf
  15.  
  16. #Define which Board you want:
  17. #BOARD := GNUBLIN
  18. BOARD := RASPBERRY_PI
  19.  
  20. #DO NOT EDIT BEYOND THIS LINE!
  21. BOARDDEF := -DBOARD=$(BOARD)

Now we can compile the API and install the programs and examples:

pi@raspberrypi ~ $ make && sudo make install

The API needs the following drivers:

pi@raspberrypi ~ $ sudo modprobe spi-bcm2708
pi@raspberrypi ~ $ sudo modprobe i2c-bcm2708
pi@raspberrypi ~ $ sudo modprobe i2c-dev


These are included in the actual RaspberryPi Debian version.

Optionally you can add the drivers in the file /etc/modules to load them on every boot:

spi-bcm2708
i2c-bcm2708
i2c-dev

One module per line.

If you have already connected an expansion board, you can test the small tools immediately. Just write gnublin on the terminal and press the "Tab" key two times, to see the available tools.

The API

Everything works like on GNUBLIN:


The only difference is, you have to write:

#define BOARD RASPBERRY_PI

in front of the

#include "gnublin.h"

The adapter board

The adapter board is connected directly to the RaspberryPi. On the board there are 5 more connection options for modules. Modules are simply connected via a ribbon cable.

RASPBERRY-BRIDGE schraeg bestueckt.JPG

The display only can be connected on the connector with the label "/dev/spidev".

SPI

The SPI bus is routed to two connectors, each with a different chip select line. These are marked with /dev/spidev0.0 and /dev/spidev0.1.

In the API and GNUBLIN tools the CS 0 is used by default, so the socket /dev/spidev0.0. However, you can any time use another, when indicating the corresponding CS pin.

Here, the tool "gnublin-dogm" can used with the other connecter:

pi@raspberry:~# sudo gnublin-dogm -g 4 -c 1 -i

The RS pin is on GPIO 4 at spidev0.1. At spidev0.0 it is GPIO 25.

old version

At the first version of GnuPi (green board), you also have to know: The display only works at the following connector. In addition, you have to braze the two red marked bridges. (GPIO8 -> GPIO23; GPIO4 -> GPIO14)

Tip: The GPIO have to be previously set by hand to LOW.

pi@raspberrypi ~ $ sudo su
root@raspberrypi:/home/pi# echo "14" > /sys/class/gpio/export
root@raspberrypi:/home/pi# echo "out" > /sys/class/gpio/gpio14/direction
root@raspberrypi:/home/pi# exit

Rasp lcd.JPG

Pin Assignment

GNUBLIN Connector.JPG

1:1 signals go to all the sockets

  • I2C (SDA, SCL)
  • SPI (MISO, MOSI, SCK)
  • GP (3 piece)
  • GND
  • 3.3V



Differences in the connectors

I2C module is used, this can be connected where you like. In SPI modules must be defined a CS line and an IRQ line.

I2C


SPI

  • Download schematic

Toolchain

TDB (We just fit in)

wget https://raw.github.com/embeddedprojects/gnublin-api/master/gnublin.cpp
wget https://raw.github.com/embeddedprojects/gnublin-api/master/gnublin.h

It is used gnueabihf-arm-linux-g++ as g++ on RaspberryPi! Currently I have created a soft link, so we do not need to adjust the Makefile:

sudo ln -s /usr/bin/g++ /usr/local/bin/arm-linux-gnueabi-g++

Porting documentation Gnublin tools

In this section you will find information about porting the tools and API interfaces.

GNUBLIN Module-LCD 2x16

  • Interface: SPI
  • Tool: OK
  • API: OK

Information about the tool:

pi@raspberrypi ~ $ sudo modprobe spi-bcm2708
pi@raspberrypi ~ $ sudo gnublin-dogm -i
pi@raspberrypi ~ $ sudo gnublin-dogm -n -w "Hello"
  • CS Pin (hangs on Module Pin 11 : RaspberryPi Pin 8 CE0)
  • RS Pin (hangs on Module Pin 14 : RaspberryPi Pin 4)

Hint: GPIO14 must be set to LOW by hand prior to use:

pi@raspberrypi ~ $ sudo su
root@raspberrypi:/home/pi# echo "14" > /sys/class/gpio/export
root@raspberrypi:/home/pi# echo "out" > /sys/class/gpio/gpio14/direction
root@raspberrypi:/home/pi# exit

GNUBLIN Module-Temperature

  • Interface: I2C
  • Tool: OK
  • API: OK

Information about the tool:

pi@raspberrypi ~ $ sudo modprobe i2c-bcm2708
pi@raspberrypi ~ $ sudo modprobe i2c-dev
pi@raspberrypi ~ $ sudo gnublin-lm75

GNUBLIN Module-Step

  • Interface: I2C
  • Tool: OK
  • API: OK

Information about the tool:

pi@raspberrypi ~ $ sudo modprobe i2c-bcm2708
pi@raspberrypi ~ $ sudo modprobe i2c-dev

GNUBLIN Module-Relay

  • Interface: I2C
  • Tool: OK
  • API: OK

Information about the tool:

pi@raspberrypi ~ $ sudo modprobe i2c-bcm2708
pi@raspberrypi ~ $ sudo modprobe i2c-dev
In other languages