The Raspberry pi is a mini computer which is designed in a single board with all the essential components required for running an operating system. The Raspberry pi board runs on ARM11 processor but is available at extremely cheap price. The board is provided with a RCA connector which can be used to connect it directly to a TV screen which is based on PAL and NTSC standard. The board also has a HDMI connector output which can be used to connect the board to a HD TV.
There is an Ethernet port which can be used to connect the board to a computer network.. Those who don’t want to use a HDTV and separate keyboard and mouse for the Rspberrypi board can plug the board using a LAN cable to the Ethernet port of the PC and do remote access in TUI or GUI mode. The operating systems like Archlinux ARM, OpenELEC, Pidora, Raspbmc, RISC OS and the Raspbian and also Ubuntu versions are available for the Raspberrypi board.
Linux operating systems especially Ubuntu is preferred for all kind of programming and development. For accessing the Broadcom chip peripherals like timers, interrupt controller, GPIO, I2C, SPI, PWM, UART etc. using C code there is a library file called “bcm2835”. The immediate advantage of having an Operating System like Ubuntu running on an embedded system device is multitasking. All Linux OS provides Multi-user Multitasking feature. This article discusses how to perform single user multitasking in a Raspberrypi board.
In this project the Raspberrypi board is loaded with Ubuntu and is remotely accessed using VNC. The Raspberrypi board is also connected to the internet. There are 26 connectors which can be taken out from the connector port of the Raspberrypi board. All the connector pins are taken out using 13*2 pin female connectors and at the other end of their wire 26 pin Burg stick male connectors are attached. The Burg stick male connectors allow each pin out from the Raspberrypi board to be plugged into the holes of a breadboard. To access the pins that coming out of the Broadcom controller of the Raspberrypi board using C language, a C library is available called “bcm2835” which has been downloaded and installed.
There are eight general purpose IO pins on the 13*2 pin connectors of the Raspberrypi board and to each one of them a LED is connected through 1K resistor. Separate code has been written to blink the LEDs individually and made them executable. The code for blinking LED connected to one of the general purpose IO is given below:
This code can blink the LED connected to the GPIO_0 (PIN_11) of the Raspberrypi board. The user can use vim editor to write the code and save into a file, say “blink1.c”. From command line it uses the following command to compile the code with the new library file to generate the executable file “blink1”.
cc blink1.c -lbcm2835 -o blink1
Similarly the code for blinking the LEDs connected to each of the IO pins are written and compiled to make executable files named blink2, blink3, blink4, blink5, blink6, blink7 and blink8. It is suggested to keep all the .c files and the executable files in a single folder for this particular project.
The user can run any of the LED blinking programs from the command line. For example to execute the file ‘blink1’, the user can use the following command:
./blink1
Normally to run another executable file from the same command line, the user normally has to wait till the current program stops executing. The user can terminate the execution using the ‘kill’ command also as given below:
killall blink1
In this case the user is able to run a single task at a time and has to wait till the task to complete. This is an example of Single-User-Single-Tasking.
When using the GUI mode the user can simply open a new terminal and execute another program, but is not possible in case there is only TUI. The user can do Multi-tasking from the TUI by executing each and every code as a background process.
The user can execute the ‘blink1’ as a background process using the following command and then he/she will be provided with a terminal prompt again from where a new code can be executed.
./blink1 &
Now the user can execute the ‘blink2’ as a background process using the following command and again he/she will be provided with a terminal prompt from where a new code can be executed.
./blink2 &
This way the user can run as many code as he/she wish simultaneously and this is an example of Single-User-Multi-Tasking. Thus the user can perform multi-tasking with the eight LED codes by entering the following eight commands one after the other.
./blink1 &
./blink2 &
./blink3 &
./blink4 &
./blink5 &
./blink6 &
./blink7 &
./blink8 &
The following is a screenshot of the Single-User-Multitasking example which blinks eight LEDs connected to the GPIOs of the Raspberrypi board by executing eight individual codes simultaneously.
Fig. 2: Example of Single-User-Multi-Tasking
This will create eight background processes which the Ubuntu OS will execute simultaneously due to its multitasking feature. All the processes that are currently running in the OS can be listed using the following command:
ps –e
Fig. 3: Command to list all processes running in OS
The newly created process will appear at the end of the list as shown in the following image:
Fig. 4: List of newly created process in Linux OS
The numbers listed in the left most row is the ‘process-id’. Every process running in the Linux OS has a similar number associated to it called the process-id.
The user can terminate the required process say ‘blink1’ using its name as:
killall blink1
or using its process-id as:
kill 2641
***Note that in this project the latest version of library “bcm2835” is used with an old version of Raspberrypi board. It is not possible to access the pin number 13 of the old board with the latest library version and hence in the code “blink3.c” the pin number 24 is used to blink the 3rd LED. The circuit diagram is also drawn accordingly. Those who have the latest version of the board can use the pin 13 without any trouble.
To find the ‘Revision’ and other important details about the Raspberrypi board, use the following command:
cat /proc/cpuinfo
Project Source Code
###
//------------------------------------------ led blinking code --------------------------------------------------// #include <bcm2835.h> #define PIN RPI_GPIO_P1_11
int main()
{
if (!bcm2835_init()) // initialize the library
return 1;bcm2835_gpio_fsel (PIN, BCM2835_GPIO_FSEL_OUTP); // Set the pin to be an output
while (1)
{
bcm2835_gpio_write(PIN, HIGH); // Turn it on
bcm2835_delay(500); // wait a bit
bcm2835_gpio_write(PIN, LOW); // turn it off
bcm2835_delay(500); // wait a bit
}
bcm2835_close(); // close the libraryreturn 0;
}//------------------------------------------ led blinking code --------------------------------------------------//
###
Circuit Diagrams
Project Components
Project Video
Filed Under: Raspberry pi
Filed Under: Raspberry pi
Questions related to this article?
👉Ask and discuss on Electro-Tech-Online.com and EDAboard.com forums.
Tell Us What You Think!!
You must be logged in to post a comment.