Homepage Wiki Forum Buy

For Beginners

From GNUBLIN

In the tutorial for beginners you will learn how to switch a LED on and off on the Gnublin-Board and how to use a digital Input. Further you will learn some commands to explore the Linux system on your board.

Contents


Login as root

You have two options to connect to your Gnublin Board. The first option is to use the intern USB_to_RS232 converter as a shell for Linux, or you can buildup a virtual network connection over the USB interface with which you can connect over SSH. The first option is more comfortable and easier.

After the root login you can do most of the experiments on this site.

... INIT: Entering runlevel: 5 Starting Dropbear SSH server: dropbear. Starting syslogd/klogd: -C64 -m 20 done EDLK (Built by Poky 5.0) 5.0 armv5te ttyS0 armv5te login: root login[558]: root login on `ttyS0'


Control Digital In/Outputs

With Linux you can access the external peripherie straight in your Filesystem. How to control the red LED on the Board is described below. GPIO assignment (Gnublin Standard Edition):

GPIO3...........LED1
GPIO11..........X4-2  J5-12
GPIO13..........
GPIO14..........X4-3  J5-11
GPIO15..........X4-4

GPIO3 is the red LED on the Board.You can control it over the sysfs. Change to the directory

cd /sys/class/gpio

Activating the GPIO3 pin

root@armv5te:/sys/class/gpio# echo 3 > export

Change directory to the newly created directory gpio3

root@armv5te:/sys/class/gpio# cd gpio3/

Show the direction of the pin:

root@armv5te:/sys/devices/virtual/gpio/gpio3# cat direction

Use the pin as an Output:

root@armv5te:/sys/devices/virtual/gpio/gpio3# echo out > direction

Turn on the LED

root@armv5te:/sys/devices/virtual/gpio/gpio3# echo 1 > value

Turn off the LED

root@armv5te:/sys/devices/virtual/gpio/gpio3# echo 0 > value

Do you have the heart to write a blink program? ;)


If you want to request the GPIO pin as an Input you can do the following.

Taster-gpio11.jpg

The easiest way is to connect a switch between the GND-pin and the used GPIO-pin (in the example below its GPIO11)


Here is how the circuit looks like:

Switch at GPIO11

      VCC 3.3V
         |
        10K
 __T__   |
 o   o---+------> GPIO11 (white/blue)
 |
===
GND (blue)
 


root@armv5te:/sys/class/gpio# echo 11 > export

To use the pin as an Input you must set the direction:

root@armv5te:/sys/class/gpio# cd gpio11/
root@armv5te:/sys/devices/virtual/gpio/gpio11# echo in > direction

Output if the pin is high or low (1 = about 3.3V, 0 = about 0 V or rather GND) is easy. Therefor you must only cat the file value

cat /sys/class/gpio/gpio11/value

This is the way how GPIO works on a Linux platform.


Measure analog voltage

Adc-poti.png

The easiest way to measure analog voltage is to use shell commands. At first you have to select the desired analog-input GPA1:

root@armv5te:~# echo "1" > /dev/lpc313x_adc

Thats it, now you can measure analog voltage with the following command:

root@armv5te:~# cat /dev/lpc313x_adc

The output of the command is just a simple Hexnumber like:

0x3b2

The adc has a resolution of 10bit by default. The values you get are between 0 and 0x3ff for the default resolution. The adc can work with resolution of 8bit or 4bit, too. Details about how to configure the resolution can be found in the Treiber .


Explore the GNUBLIN Linux

Show processes which are running:

root@armv5te:~# ps -efl

The Output looks like the following.

F S UID PID PPID C PRI NI ADDR SZ WCHAN STIME TTY TIME CMD 4 S root 1 0 0 80 0 - 398 poll_s 03:11 ? 00:00:00 init [5] 1 S root 2 0 0 80 0 - 0 kthrea 03:11 ? 00:00:00 [kthreadd] 1 S root 3 2 0 80 0 - 0 run_ks 03:11 ? 00:00:00 [ksoftirqd/0] 5 S root 4 2 0 -40 - - 0 watchd 03:11 ? 00:00:00 [watchdog/0] 1 S root 5 2 0 80 0 - 0 worker 03:11 ? 00:00:00 [events/0] 1 S root 6 2 0 80 0 - 0 worker 03:11 ? 00:00:00 [khelper] 1 S root 9 2 0 80 0 - 0 async_ 03:11 ? 00:00:00 [async/mgr] 1 S root 99 2 0 80 0 - 0 bdi_sy 03:11 ? 00:00:00 [sync_supers] 1 S root 101 2 0 80 0 - 0 bdi_fo 03:11 ? 00:00:00 [bdi-default] 1 S root 103 2 0 80 0 - 0 worker 03:11 ? 00:00:00 [kblockd/0] 1 S root 108 2 0 80 0 - 0 worker 03:11 ? 00:00:00 [ksuspend_usbd] 1 S root 112 2 0 80 0 - 0 hub_th 03:11 ? 00:00:00 [khubd] 1 S root 120 2 0 80 0 - 0 worker 03:11 ? 00:00:00 [kmmcd] 1 S root 145 2 0 80 0 - 0 watchd 03:11 ? 00:00:00 [khungtaskd] 1 S root 146 2 0 80 0 - 0 kswapd 03:11 ? 00:00:00 [kswapd0] 1 S root 147 2 0 80 0 - 0 worker 03:11 ? 00:00:00 [aio/0] 1 S root 277 2 0 80 0 - 0 mtd_bl 03:11 ? 00:00:00 [mtdblockd] 1 S root 280 2 0 80 0 - 0 worker 03:11 ? 00:00:00 [spi_lpc313x.0] 1 S root 305 2 0 80 0 - 0 mmc_qu 03:11 ? 00:00:00 [mmcqd] 1 S root 323 2 0 80 0 - 0 bdi_wr 03:11 ? 00:00:00 [flush-179:0] 5 S daemon 517 1 0 80 0 - 410 poll_s 03:12 ? 00:00:00 /sbin/portmap 1 S root 546 1 0 80 0 - 548 poll_s 03:12 ? 00:00:00 /usr/sbin/dropbear -r /etc/dropbear/dropbear_rsa_host_key -p 22 4 S root 555 1 0 80 0 - 526 syslog 03:12 ? 00:00:00 /sbin/klogd -n 4 S root 556 1 0 80 0 - 607 wait 03:12 ttyS0 00:00:00 -sh 0 S root 557 1 0 80 0 - 462 n_tty_ 03:12 tty1 00:00:00 /sbin/getty 38400 tty1 4 R root 1427 556 0 80 0 - 615 - 03:20 ttyS0 00:00:00 ps -efl

If you type the command

top

you can see your processes in "Real-Time". You can quit the application by typing a small q.


Show memmory usage:

df -h

this is how the output looks like:

/dev/root 934.8M 683.2M 204.1M 77% /
tmpfs 2.7M 20.0K 2.7M 1% /var/volatile
tmpfs 2.7M 0 2.7M 0% /media/ram


You can see the free memmory of the SD-card in the first row (/dev/root). The tmpfs partitions are used as dynamic memmory for some applications running.

With the command uptime you can display the time a Linux system is running.

root@armv5te:~# uptime
23:34pm up 0:10, 1 user, load average: 0.00, 0.00, 0.00

And with the command cat /proc/cpuinfo you can get some information about the CPU.

root@armv5te:~# cat /proc/cpuinfo Processor : ARM926EJ-S rev 5 (v5l) BogoMIPS : 89.70 Features : swp half thumb fastmult edsp java CPU implementer : 0x41 CPU architecture: 5TEJ CPU variant : 0x0 CPU part : 0x926 CPU revision : 5 Hardware : NXP EA313X Revision : 0000 Serial : 0000000000000000


The command free is also useful. With this command you can show the usage of the RAM and more.

root@armv5te:~# free total used free shared buffers cached Mem: 5572 5048 524 0 240 2668 -/+ buffers/cache: 2140 3432 Swap: 65528 36 65492


An editor for Gnublin to write programs on

To write a program for GNUBLIN directly on the GNUBLIN you need something like a texteditor. GNUBLIN has two texteditors in the eldk-root-file-system the classical vi and nano .

Create a new file with vi:

vi test.txt

To write something inside the newly created file, you have to press the button i to get into insert-mode If you have finished writing you have to press ESC first to get out of the insert-mode and get back into the command-mode Now you can save your file and quit the editor by typing :wq or for the lazy people :x

Commands:

  •  :w (save Document)
  •  :q (quit Document)
  •  :x (write and quit Document)


nano - The user-friendly editor

You can edit a textfile with the following command:

nano test.txt

You can see a menu with useful commands at the bottom of the shell. You can save a file with the command CTRL+o and afterwards pressing the Enter button.If you want to close nano you must press CTRL-X. The other commands are self-explanatory.


Hello World, the first project of a developer

The purpose of an Embedded System is, in nearly every case, to automate some processes in the "real world" or to regulate a system. There are a lot of programs, ways to communicate and literature about hardware. You have a huge variety of program languages you can use. Below you can see a small "Hello-World-Program" in different languages, and how you can execute it. We use vi or nano to make and edit the Hello World Program.

Bash Scripts

hello.sh

#!/bin/bash          
STR="Hello World!"
echo $STR

How to Execute:

sh hello.sh

C Programs

There is a ready-to-go C-Compiler on the Gnublin. Of course it's not the fastest Compiler, but for small programs it's sufficient.

hello.c

 #include <stdio.h> 
 int main(void)
 {
   printf("Hello World!\r\n");
   return 0;
 }

You can compile the program with following command:

gcc -o hello hello.c

How to Execute:

./hello

Python Scripts

hello.py

#!/usr/bin/python
# Hello world python program

print "Hello World!";


How to Execute:

python hello.py

Squirrel Scripts

hello.sq:

print("Hello World!\n")

How to Execute:

sq hello.sq

Lua Scripts

hello.lua:

print ("Hello World!\n")

How to Execute:

lua hello.lua

Perl Scripts

hello.pl

#!/usr/bin/perl
# Hello world perl program

print "Hello World!\n";

How to Execute:

perl hello.pl


Some small test-programs on GNUBLIN

After the login you can find some test-programs in the home-folder.

for example

sh blink.sh

With the command CTRL-C you can quit the application.

Or

lua blink.lua
In other languages