Engineers Garage

  • Projects and Tutorials
    • Electronic Projects
      • 8051
      • Arduino
      • ARM
      • AVR
      • PIC
      • Raspberry pi
      • STM32
    • Tutorials
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Products News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • EE Resources
    • DesignFast
    • LEAP Awards
    • Oscilloscope Product Finder
    • White Papers
    • Webinars
  • EE Learning Center
  • Women in Engineering

Single User Multi Tasking on Raspberry Pi-(Part 11/38)

By Ajish Alfred

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.

Example of Single-User-Multi-Tasking

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

 

 

 

Command to list all processes running in OS

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:

 

List of newly created process in Linux OS

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

*******************************************************************************
Note:
In this project the Raspberrypi board version 2 is used, but a previous version of the “bcm2835” library is installed. Accessing the GPIO pin 13 is not possible with this library and hence the 3rd IO pin is selected as pin24 of the P1 port of the Raspberrypi. The circuit and the code are modified accordingly. Those who have the version 2 of the Raspberrypi and the latest version of the “bcm2835” library can use the GPIO pin 13 using “RPI_V2_GPIO_P1_13” instead of “RPI_GPIO_P1_13” in the pin definition.
For example to define a ‘PIN’ as 13th pin of P1 port of Raspberrypi board version2, use the following statement in the code;
#define PIN RPI_V2_GPIO_P1_13

 

*******************************************************************************

 

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 library

return 0;
}

//------------------------------------------ led blinking code --------------------------------------------------//
 

###

 


Circuit Diagrams

Circuit-Diagram-Single-User-Multitasking-using-Raspberry-Pi

Project Components

  • LED
  • Resistor

Project Video


Filed Under: Raspberry pi
Tagged With: multi-tasking, Raspberry Pi
 

Questions related to this article?
👉Ask and discuss on EDAboard.com and Electro-Tech-Online.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


Featured Tutorials

  • Designing Gate Driver Circuit and Switching Mechanism for Modified Sine Wave Inverter – (Part 9/17)
  • Completing Modified Sine Wave Inverter Design with Full Bridge Circuit and Step Up Transformer – (Part 10/17)
  • Designing an Offline UPS – Part (12 /17)
  • How to reduce Switching Time of a Relay – (Part 15/17)
  • Testing MOSFET – (Part 16/17)
  • Driving High Side MOSFET using Bootstrap Circuitry – (Part 17/17)

Stay Up To Date

Newsletter Signup

Sign up and receive our weekly newsletter for latest Tech articles, Electronics Projects, Tutorial series and other insightful tech content.

EE Training Center Classrooms

EE Classrooms

Recent Articles

  • MicroPython – I2C protocol in ESP8266 and ESP3
  • New automotive radar sensor enables reliable in-cabin monitoring system
  • TI breaks ground on 300-mm semiconductor wafer-fabrication plants in Texas
  • New wireless AR Smart Viewer reference design
  • Infineon launches scalable and wireless charging platform with configurable controllers

Most Popular

5G 555 timer circuit 8051 ai Arduino atmega16 automotive avr dc motor display Electronic Part Electronic Parts Fujitsu ic infineontechnologies integratedcircuit Intel IoT ir lcd ldr led maximintegratedproducts microchip microchiptechnology Microchip Technology microcontroller microcontrollers mosfet motor powermanagement Raspberry Pi remote renesaselectronics renesaselectronicscorporation Research samsung semiconductor sensor software STMicroelectronics switch Technology vishayintertechnology wireless

RSS EDABOARD.com Discussions

  • Manifest in Git bitbucket
  • What's the deal with all these "MPPT" IC's with no current sense?
  • Photovoltaic MOSFET Drivers - Voltage Rating
  • Impedance requirement for SDRAM signals
  • A circuit that can adjust a resistance and probing a voltage node

RSS Electro-Tech-Online.com Discussions

  • How to quickly estimate lead acid battery capacity ?
  • IRS2453 the H circuit
  • Ampro 16mm Stylist projector woes.
  • Finally switched to Linux.
  • Multistage BJT amplifier
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • About Us
  • Contact Us
  • Advertise

Copyright © 2022 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Projects and Tutorials
    • Electronic Projects
      • 8051
      • Arduino
      • ARM
      • AVR
      • PIC
      • Raspberry pi
      • STM32
    • Tutorials
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Products News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • EE Resources
    • DesignFast
    • LEAP Awards
    • Oscilloscope Product Finder
    • White Papers
    • Webinars
  • EE Learning Center
  • Women in Engineering