There are no items in your cart
Add More
Add More
Item Details | Price |
---|
A few years back, microcontroller programming could be done only by technology experts like electrical/electronics engineers and hobbyists. Building a development board from scratch or even using a breadboard was an area dominated by experts mentioned earlier. But today the landscape of microcontroller programming has changed a lot. It has become more user friendly and even school children have these topics curated as part of their curriculum. All these changes are attributed to the development of the Arduino boards and the Arduino Programming Language. For a beginner who is interested only in the beeps and blinks can certainly dive into Arduino programming immediately. But here we show you the domain where Arduino boards belong to in detail. We show you a glimpse of how deep the topic of microcontroller programming is, in this blog.
We discuss,
The world today is becoming more and more digital, connected and automated with each passing day. What makes this transformation possible? Embedded systems. The computer systems in automobiles, the ATMs we use, the washing machine at our home, the toy car children play with, all these devices can be classified as embedded systems. Embedded systems play a part in nearly every aspect of modern life. In today’s evolving world, technology is not only becoming more and more advanced, but also more and more common in our everyday lives. This is the era of IoT i.e internet of things or connected devices. So how is this possible? Embedded systems use microprocessors or microcontrollers to do the computations. That's how its done. Today virtually all commercially produced electronic devices use microprocessors or microcontrollers. This is a multi-billion dollar industry world wide.
What is the common element in all of these? Its the presence of a computing unit possibly a microprocessor or a microcontroller. A microcontroller is a programmable IC, capable of multiple functions depending on how it’s programmed. Many different kinds of microcontroller exist that offer a wide range of functionality. The versatility of the microcontroller is what makes it one of the most powerful tools in modern design. The features and functionality of microcontrollers are unique to each brand or model. So how do you define an embedded system?
It can be defined as,
"A microprocessor based system built to execute certain functionalities and not designed to be programmed by the end user in the same way that a PC is."
The second part is what differentiates an embedded system from a PC. i.e the user can decide on the functionalities required. But cannot change it by adding or removing software or hardware. But with a PC this is what we exactly do. Now this definition isn’t a hard and fast rule. The advancements in technology has blurred the boundaries between a PC and an embedded system. However for the sake of the discussion, we shall stick with it.
A different a view on embedded systems is shown in the figure given here. Embedded systems can be considered as a computation box. This computation box will have a computing element (microprocessor or microcontroller) within it that does all the processing. The computations are done on data. This data reaches the computation box through input devices which could be keyboard, sensors, storage devices, communication networks or even input pins. The processed data goes out of the computation box through display, communication networks, storage devices, transducers or even output pins. This approach gives a practical view on how embedded systems perform.
Some of the essential attributes of an embedded system are given below:
All embedded systems have 2 parts, a hardware part and a software part. As you can see in the figure shown above the software part runs on top of the hardware. The software part defines the purpose and the functionalities of the system. The hardware is selected and designed to execute these software definitions.
Let's take a closer look at the hardware layer. The major hardware components of an embedded system can be classified as shown in the figure below.
The hardware part is of no use without a working software.
As shown here in the above figure the software part has 2 layers. A system software layer and an application software layer. The system software layer is an optional part. Not every embedded system needs it. Mostly this is applicable only for those embedded systems that employ an operating system(OS). The application software is then built on top of the operating system. If the OS is absent, application software directly runs on top of the hardware layer. So what does an OS do and what does an application software do? OS creates a software ecosystem on top of the hardware. Only the OS has direct accesses to the hardware. Whereas an application software is the one that actually defines the task to be performed. The instructions are sent from the application software to the OS, which is then transferred to the hardware for execution. In case of non OS based systems, application software directly accesses the hardware to execute the tasks. If the requirements are very minimal, OS is optional. Application software is enough to perform the task. But if there are multiple tasks with varying priorities then it is best to employ an OS for scheduling the work. Application software can be written on top of this OS to implement the embedded system functionalities.
An embedded system project goes through several phases of development. These stages are shown in the table given here.
PHASE |
ACTIVITY |
Gathering requirements | In this stage the concept is introduced. A preliminary requirement analysis is done. The concept or product idea is revisited several times to confirm and verify various requirements. Then the system is defined. i.e its features, and requirements. We define exactly what the system is going to do in this phase. |
Design the architecture | The design of the embedded system happens here. We define the architecture for implementing it. The architecture of an embedded system is an abstraction of the embedded device. It shows the general idea of the system without any specific details. |
Implement the design | Embedded system development happens in this stage. The architecture is implemented here. The architecture has the definitions of both the hardware and software in it. Those definitions are developed in this stage. i.e coding and circuit design are done in this stage. |
Test the system | The implementation is tested and reviewed. Both the software and hardware are tested. If there are errors or bugs it is corrected. Testing is done again. This process undergoes several iterations until the design requirements are met with no bugs or errors. The implementation becomes market ready after this phase. |
Maintain the system |
The product is deployed into the field, in this stage. Technical support, trainings and maintenance has to be done for the user throughout the device’s life time. |
There are various tools involved in the development of an embedded system. It ranges from tools that that help in writing code to tools that help in loading software into the hardware. A typical development setup is shown here.
It is made up of a
The target and host are connected by some transmission medium. It could be by serial port or ethernet or by some other communication method. The host has several software tools installed in it such as ,
The translation tool flow is shown here.
The pre-processor organizes and restructures the source code. It is then compiled by the compiler to create object files. The linker links the object file with relevant libraries to create the executable. All these activities are happening in host PC. The executable is downloaded into a target board using a loader utility software over a communication port.
Developers use a variety of programming languages in embedded systems. The most used languages include assembly, C, C++, Python, and Java. Programming languages that developers frequently use in embedded systems have some key advantages. Selection of programming language is based on certain factors like size of memory, speed of execution and portability. The amount of memory required by a program plays an important role as embedded processors or microcontrollers have a limited amount of RAM and ROM. The execution speed of the program refers to the number of instructions required to achieve a job. This varies from language to language. Portability is the ability to run in different processors using one program. A comparison chart of the commonly used programming languages is shown in the table below.
‘C’ is used in a wide range of embedded systems from handheld devices to supercomputers. Embedded ‘C’ is an extension of the ‘C’ language, which is used for developing an embedded system. ‘C’ is processor independent, small, easy to learn, understand and debug. It is fairly efficient, reliable, flexible and portable between different platforms. It also supports low level bit wise data manipulations.
‘C++’ is an object-oriented language. It is not efficient in terms of memory and speed of the system. So its rarely used in embedded systems.
Python is an interpreted language. It needs very powerful processors to run. Its very easy to learn and it is feature rich. But it cannot be used for real time applications.
JAVA is mainly used in high-end applications (like mobile phones) and offers portability across systems to process the applications. But it is not preferred for smaller embedded devices.
In the early days of computing, processors had very little RAM and ROM. In such systems assembly language was mainly used to limit the program size and control the execution speed. In powerful systems, assembly is commonly used for coding those sections that must run very fast i.e where each clock cycle counts. Assembly language is very fast, but it is typically more difficult to program and the presence of different instruction set architecture for each processor makes it non-portable.
An embedded project will have a list of requirements. The microcontroller selected for the project should meet all theses requirements. Common features people look for in a microcontroller include I/O pins, clock frequency and storage memory. However a countless number of other specifications exist. These features enable the microcontroller to interact with the real world. Microcontrollers are a practical, affordable and flexible solution to many challenges of circuit design and modern control systems. So, the steps for microcontroller programming include write program code on your computer, compile the code with a compiler for the microcontroller you are using and then upload the compiled version of the program to the microcontroller. While details such as the tools or languages used to program the microcontroller can vary the thought process used to program them is universal. A microcontroller does not know what to do by itself. It’s your job to tell it what you want it to do. Although it looks simple, the vast array of microcontrollers available, its features and the various tool sets available can be overwhelming for a beginner. It might be difficult for a beginner to assemble a board from scratch even for switching on or blinking a LED. This is where Arduino programming is useful. Arduino programming is a bit easier if you want to start really simple. It is an easy tool for fast prototyping, aimed at students without a background in electronics and programming.
Arduino is an open-source electronics platform. It can read inputs from a sensor or read the state of a button or switch on a motor or a LED. It is based on an easy-to-use hardware and software. The Arduino board can be instructed what to do by sending a set of instructions to the microcontroller on the board. For that the Arduino programming language and the Arduino Software (IDE) is used. The Arduino development system has everything setup in an easy to use manner for everyone interested in tinkering with electronics. All the complicated libraries and drivers are taken care of by the software. The Arduino ecosystem includes software as well as hardware electronic boards that are compatible to the software. So even beginners and students without a background in electronics and programming can start tinkering with it from the word go.
Ever since the Arduino boards came out they were used in thousands of projects from everyday objects to complex scientific instruments. A world wide community of makers have contributed immensely and that has created an incredible amount of accessible knowledge that can be of great help to novices and experts alike. Arduino boards are highly flexible. They can be connected very easily to different modules such as obstacle sensors, presence detectors, fire sensors, GSM modules, GPS modules, etc. The main function of the Arduino board is to control electronics through reading inputs & changing the outputs. Some of the popular Arduino boards include Arduino Uno (R3, Arduino Nano, Arduino Micro, Arduino Due, Arduino Mega (R3) Board and Arduino Leonardo Board. Visit the official website of Arduino to know more about various Arduino boards.
A burglar alarm is basically an intruder alert system used to prevent theft or robbery and protect one’s premises. Its an example of embedded system. A simplified block diagram of the hardware is shown in figure below. A proximity infra red (PIR) sensor is used here for monitoring the presence of any person or movement. PIR sensor is basically a motion detector. An Arduino Uno board is used as the computing unit. A buzzer and a switch are also connected to the Arduino Uno board. As can be seen from the figure, if motion is detected, PIR sensor sends signal to Arduino Uno. On receiving this Arduino Uno will activate the buzzer to produce a sound alarm. This activated sound alarm will continue until the “reset” push button switch is pressed by someone.
The firmware will be written to make these functionalities work. A sample flow chart of the firmware is shown in figure below.
You can actually make an understanding on how the various embedded devices around work using this approach. Find out its features and functionalities first. Then think about how the design would be. For e.g: a camera or a washing machine or an automatic door opener in malls. Build your understanding this way.
So now let’s try a simple project. We do this in Tinkercad. Tinkercad is a free web app for 3D design, electronics & coding. It's used by teachers, kids, hobbyists, and designers all over the world to imagine, design and make anything. It has various tools and step by step tutorials within it to assist the user. To use Tinkercad you need an account. Create one for yourself. Its a straight forward process.
You can reach the Tinkercad website at www.tinkercad.com. Once you have logged in, select circuits and start tinkering. This will lead to a workspace where you could drag the components from the component set at the right side of the web page. Provisions for wiring the hardware, writing code and simulating them are also available. These are provided at the top menu bar.
This is a very easy to use platform. With Tinkercad you could perform various projects virtually that is online without using a real hardware. We shall try a simple project to demonstrate how coding is done in Arduino platform. We display certain text messages on an LCD screen in response to a button press. So the requirements are as follows:
The schematic of the project is shown here.
Select the components in Tinkercad. You can change the drop down list to select a category. Drag the component Arduino with LCD and breadboard to the workspace. Next search for push button and then resistor. Drag and drop them to the work space. You have all the components now. Connect them as shown in the schematic.
The LCD is a 16x2 module. i.e 2 rows of 16 characters each. So the text to be displayed should be chosen such that it has only 16 characters in one row. Its a HD44780 based module. What it means is that, there is an IC inside the LCD module. This IC is HD44780. The Arduino Uno will be communicating with this IC. Also there are around 16 pins for the LCD module. The pin outs of the LCD module is given in the table below.
Pin |
Functionality |
VSS | Ground |
VCC | 5V |
VEE | Contrast pin. It is used to adjust the contrast of display. A potentiometer is connected to this pin. The pot is rotated to adjust the contrast. |
RS | Register select pin. Command register is selected when the pin is LOW. Whereas data register is selected when this pin is HIGH. |
R/W | Read/Write pin. When this pin is LOW, write to register is enabled. When the pin is HIGH, read from the register is enabled. Here we do only write operations so its connected to ground. |
E | Enable pin. Data is send to data pins when a HIGH to LOW pulse is given. |
D0 - D7 | These are 8 data pins. Only D4 to D7 is used in 4 bit mode. |
LD+ / LD- | They are the anode and cathode of the LED backlight. |
The data and control pins of the LCD are connected to Arduino Uno’s digital pins as needed. We use digital pins 12, 11, 5, 4, 3, 2 to connect RS, E, D4, D5, D6, D7 respectively. The push button is connected to digital pin 7.
Now let’s see the firmware.
To use LCD, we need to call "Liquid Crystal" library. This is an inbuilt library. To use it we have to include the LiquidCrystal.h header file.
#include <LiquidCrystal.h>
Next we have to initialize the library with the pin numbers used. The function LiquidCrystal lcd() is used for that. The function has six input parameters which are the digital pin numbers used to connect "RS, E, D4, D5, D6 and D7" with Arduino Uno. Those values are passed to the LCD initialization function.
LiquidCrystal lcd_1(12, 11, 5, 4, 3, 2);
The code for detecting key or button press is shown here.
int buttonState = 0;
int prevbuttonCount = -1;
int buttonCount = 0;
void ReadButton(void)
{
//read the state of
//pushbutton value
buttonState = digitalRead(7);
//check if pushbutton
//is pressed.
//If it is, then
//buttonState is HIGH
if(buttonState == HIGH)
{
buttonCount++;
if(buttonCount>=5)
{
buttonCount=0;
}
buttonState=LOW;
}
}
The state of the button press, the count of button presses and its previous value has to be stored in variables for processing. This is shown here. If you look at the code, the button state is first read using Arduino digital read operation. If the press is detected, the state becomes HIGH. If its HIGH the count variable has to be incremented. If the count becomes 5 or above, its value is reset to zero. After updating the count value, the state is also updated to LOW.
Arduino has 2 routines the setup() and loop() routines. In the setup routine initialization are done.
void setup()
{
//Set up the number
//of columns and rows
//on the LCD.
lcd_1.begin(16, 2);
//Set up the pin to
//which push button is
//connected as input.
pinMode(7, INPUT);
}
Here the LCD has to be initialized first. This is done in the setup routine. Also the pin to which the button is connected should also be initialized as INPUT.
void loop()
{
//Display Section //Set cursor position
lcd_1.setCursor(0, 0);
//Check the value of
//button count
if(buttonCount!=prevbuttonCount)
{
if(buttonCount==0)
{
lcd_1.print("CODECIRCUITRY");
}
if(buttonCount==1)
{
lcd_1.print("Learn Arduino & C");
}
if(buttonCount==2)
{
lcd_1.print("Join the Course");
}
if(buttonCount==3)
{
lcd_1.print("Theory+Project");
}
if(buttonCount==4)
{
lcd_1.print("Get Certificate");
}
prevbuttonCount = buttonCount;
}
//wait for 100ms
delay(100);
}
In the loop routine, tasks that has to be repeated continuously is written. First we set the cursor position to the first row. After that we check if the value of the buttonCount variable and prevbuttonCount variable are same. If they are not same, it means button press has happened. Then based on the count a specific string will be displayed on the screen. After displaying the string the value of prevbuttonCount is updated to the current buttonCount variable. The buttonCount is updated by the ReadButton() routine that we discussed earlier. It is also invoked in the loop routine. Since the loop routine runs continuously, ReadButton() also checks for button presses continuously. If it detects a press, then the count changes, and a string is displayed as discussed previously.
A delay of 100 microseconds is also provided to prevent false switch presses. Press the Start Simulation button to run the simulation. After that press the push button with the mouse pointer. You can see the animation of the button press in Tinkercad when its clicked. The messages gets displayed on the screen sequentially. After the last message it loops back to the first message.
One thing to be noted is that the simulation in Tinkercad can be slow due to internet bandwidth issues. This can be seen in the clock running on the top menu bar. So time your simulations using that clock as reference.
We at CODECIRCUITRY offers the course "Arduino & ‘C’ Programming: Learn Through Projects" for you to get started in embedded systems. The fundamentals of Arduino and ‘C’ programming are taught in this course through numerous hands-on sessions and multiple projects. Once you are comfortable with the software interface Arduino provides, we slowly start digging deeper into the hardware and software that lies underneath. Understanding the inner details certainly gives you an edge in the job market.
The expected outcomes of this course include
For anyone passionate about embedded systems this is a very exciting period. There’s a lot of innovation and development happening at a rapid pace in various sectors like Internet of Things, smart cities, automotive, machine vision, machine learning/deep learning, robotics, healthcare, consumer electronic products and so on. As an embedded systems engineer, one would be dealing with some of the most advanced and complicated technologies. The number of startups India has produced in these recent years is enormous. Even in domains such as space technology where only government entities had scope earlier, now privately funded R&D teams are innovating. Also the central government has come up with lots of initiatives and plans to make India an electronics hub in both product making as well as chip manufacturing. So choosing this field would be a smart career option to people who are interested in electronics and electrical engineering.
Our course aims to equip you with technical knowledge on Arduino & 'C' programming, help you build various projects and thus launch yourself to a platform from where you could explore the advanced concepts on your own. We welcome you to join our course on "Arduino & ‘C’ Programming:Learning Through Projects"
Thank you
codecircuitry
Our vision is to create a platform where anyone could upskill as well as build their knowledge on hardware & firmware development through industry relevant courses in electronics, programming & mathematics at affordable prices. Driven by our passion for technology, we aim to bring in innovative hardware products and software applications at affordable prices. We also offer firmware development and guidance services in Beaglebone, Nvidia Jetson, Raspberry Pi and Arduino.