Microcontroller Fundamental and Programming
Microcontroller Fundamental and Programming
Processor
At the heart of the SoC is its Processor. It usually has multiple processor cores.
Multiple cores allow for different processes to run at the same time, which
increases the speed of the system as it enables your computer to perform
multiple operations at the same time. Basically, the operating system sees the
multiple cores as multiple CPUs, which increases performance. As multiple cores
are fitted onto the same chip, there is less latency, which is because of faster
communication between the cores.
There are RAM types designed for non-volatile function as well. These are FRAM
(Ferroelectric RAM), MRAM (Magnetoresistive random-access memory), which
stores data in magnetic states, PRAM (Parameter Random Access Memory),
which is used in Macintosh computers to store system settings including the
display and time-zone settings. Other than these, there is RRAM (Resistive
Random Access Memory), which has a component called memristor. A
memristor is a resistor whose voltage varies as per the applied voltage.
Other components
Other components necessary for a fully functioning SOC are timing sources like
clocks, timers, oscillators, phase lock loop systems, voltage regulators, and power
management units.
Microcontroller
A microcomputer made on a single semiconductor chip is called single-chip
microcomputer. Since, single chip microcomputers are generally used in control
applications, they are also called microcontrollers.
Microcontroller contains all essential components of a microcomputer such as
CPU, RAM, ROM/EPROM, I/O lines etc. Some single chip microcontrollers contain
devices to perform specific functions such as DMA channels, A/D converter, serial
port, pulse width modulation, etc.
The Boards
Boards The board selection has two effects: it sets the parameters (e.g. CPU
speed and baud rate) used when compiling and uploading sketches; and sets and
the file and fuse settings used by the burn bootloader command. Some of the
board definitions differ only in the latter, so even if you've been uploading
successfully with a particular selection you'll want to check it before burning the
bootloader. You can find a comparison table between the various boards here.
Arduino Software (IDE) includes the built in support for the boards in the
following list, all based on the AVR Core. The Boards Manager included in the
standard installation allows to add support for the growing number of new boards
based on different cores like Arduino Due, Arduino Zero, Edison, Galileo and so
on.
Arduino Library
The Library is considered as the advanced feature, which extends the capabilities
of the Arduino IDE. It means that the libraries provide extra functionality to the
programming platform of Arduino. The libraries in Arduino are written in C or C+
+ (.cpp). These libraries allow us to manipulate data and work with the hardware.
To implement any Library in the Arduino IDE, go to the Sketch -> Import Library.
There are several libraries available for download. We can also create our own
library.
The standard libraries are listed below:
EEPROM Library
It stands for Electronic Erasable Programmable Read Only Memory. The EEPROM
is associated with the microcontroller present on the AVR or Arduino Boards. The
EEPROM library allows us to read the bytes stored in the memory when the
power of the board is off.
The size of EEPROM varies in different boards, such as 1KB or 1024 bytes on the
ATmega328P. It can also be of 4KB or 4096 bytes on the Microcontroller
ATmega2560, etc.
The library is declared as:
1. #include <EEPROM.h>
For example, EEPROM Read, EEPROM Clear, EEPROM Write, EEPROM Get,
EEPROM Update, EEPROM Put, EEPROM Iteration, etc.
Ethernet Library
The Ethernet library works with the Arduino Ethernet shield and other related
devices. The Ethernet library allows us to connect the Arduino board to the
Internet.
The SPI bus acts as an intermediate between the board and the shield.
The associated library is:
1. #include <Ethernet.h>
2. #include <SPI.h>
For example, TelnetClient, WebServer, WebClientRepeating, WebClient,
ChatServer, DnsWebClient, UdpNtpClient, UdpSendReceiveString, etc.
Firmata Library
For the programming environment, we can create custom firmware without
producing our own objects and protocols.
It is used to implement the firmware protocol, which communicates with the
software on the host computer.
The associated library is:
1. #include <Firmata.h>
GSM Library
The GSM library exists on the IDE version 1.0.4 and up.
The GSM library allows us to perform the operations on the Arduino board similar
to the GSM phone, such as internet connection, send and receive messages, and
to place voice calls.
The library is declared as:
1. #include <GSM.h>
Liquid Crystal Library
It is a library that permits Arduino to communicate with LCDs, which are based on
a compatible chipset called Hitachi HD44780. Such chipsets are found on most
types of text-based LCDs. It works with either an 8-bit mode or 4-bit mode. Here,
the bit mode signifies the data lines in addition to the enable, rs, and rw control
lines (optional).
The library is declared as:
1. #include <LiquidCrystal.h>
The examples are Hello World, Cursor, Blink, etc.
SD Library
It allows writing to or reading from SD cards. For example, Arduino Ethernet
Shield. The file names include the paths separated by the forward slashes, which
are passed to the SD Library. But, SPI is used for the communication between the
SD card and the Arduino.
The library is declared as:
1. #include <SPI.h>
2. #include <SD.h>
The examples are Dump files, List Files, Read Write, etc.
Servo Library
The Servo library permits Arduino to work with servo motors. It allows controlling
the integrated shaft and gears. We can also position shaft at different angles
between 0 and 180 degrees. The servo library on Arduino boards can support
upto 12 motors, while on Arduino Mega board, it can support upto 48 motors.
The library is declared as:
1. #include <Servo.h>
SPI Library
The SPI (Serial Peripheral Interface) is a serial data protocol.
The microcontrollers use the serial protocol to communicate over short distances
with one or more peripheral devices quickly.
The required connection of SPI is a full-duplex that allows devices to
simultaneously sent and receive data.
The library is declared as:
1. #include <SPI.h>
The examples are Dump files, List Files, Read Write, etc.
Stepper Library
The Stepper library in Arduino permits to control of bipolar or unipolar stepper
motors.
The library is declared as:
1. #include <Stepper.h>
The Stepper includes stepper speed control, stepper one revolution, etc.
Software Serial Library
The Software Serial Library permits serial communication over digital
Input/output pins. The 0 and 1 pins are inbuilt on Arduino for the serial interface.
We can include multiple serial ports in our code that can operate with speed upto
115200 bps (bits per second).
The library is declared as:
1. #include <SoftwareSerial.h>
TFT LCD Library
The TFT LCD library is included in the IDE version 1.0.5 and later. It allows the
Arduino to communicate with the TFT LCD screen. It further helps to draw images,
shapes, lines, and text to the screen.
The SD card slot present on the onboard screen can be used by implementing the
SD library.
The TFT library for communication depends on the SPI library with the SD card
and screen.
The library is declared as:
1. #include <SPI.h>
2. #include <TFT.h>
WiFi Library
The WiFi library permits Arduino to establish a connection with the internet. It
can either be a server to receive the incoming connections or a client to perform
outgoing connections.
The personal encryptions supported by the WiFi library are WPA2 and WEP
except for WPA2 Enterprise. Arduino uses the SPI bus to communicate with the
WiFi shield.
The library is declared as:
1. #include <WiFi.h>
The examples include WiFiWebClient, WiFiWebServer, etc.
Audio Library
The Audio library is compatible with the Arduino Due board only. It enables the
board to playback .wav files from the specific storage devices, such as the SD card.
It plays sounds by using the DAC0 and DAC1 pins.
The library is declared as:
1. #include <Audio.h>
The example is a Simple Audio Player.
Audio Zero Library
It enables the board (Arduino Zero, MKR1000, and MKRZero) to playback .wav
files from the storage devices, such as the SD card.
Arduino Zero and MKR1000 board play sound by using the DAC0 pin.
The library is declared as:
1. #include <AudioZero.h>
The example is the Simple Audio Player Zero.
Arduino Sound Library
The Arduino Sound Library permits the board to analyze and play audio data,
which is provided by Arduino on SAMD21 based board using the I2S bus. The
SAMD21 based boards are Arduino Zero, MKR1000, MKRZero, or Genuino Zero.
The library is declared as:
1. #include <AudioSound.h>
The examples include WavePlayBack, ClapDetector, WhistleDetector, etc.
Now, let's discuss the process to install the library in Arduino.
RASPBERRY PI :
Raspberry Pi is a credit card sized micro processor available in different models
with different processing speed starting from 700 MHz. Whether you have a
model B or model B+, or the very old version, the installation process remains the
same. People who have checked out the official Raspberry Pi website, But using
the Pi is very easy and from being a beginner, one will turn pro in no time. So, it's
better to go with the more powerful and more efficient OS, the Raspbian. The
main reason why Raspbian is extremely popular is that it has thousands of pre
built libraries to perform many tasks and optimize the OS. This forms a huge
advantage while building applications.
GPIO
GPIO is an acronym for General Purpose Input/Output. A Raspberry Pi has 26
GPIO pins. These allow you to send and receive on/off signals to and from
electronic components such as LEDs, motors, and buttons.
Interfacing Raspberry Pi
You can link devices and components to your Raspberry Pi using a lot of different
types of connections. The Interfaces tab is where you turn these different
connections on or off, so that your Raspberry Pi recognises that you’ve linked
something to it via a particular type of connection.
o Camera — enable the Raspberry Pi Camera Module
o SSH — allow remote access to your Raspberry Pi from another computer
using SSH
o VNC — allow remote access to the Raspberry Pi Desktop from another
computer using VNC
o SPI — enable the SPI GPIO pins
o I2C — enable the I2C GPIO pins
o Serial — enable the Serial (Rx, Tx) GPIO pins
o 1-Wire — enable the 1-Wire GPIO pin
o Remote GPIO — allow access to your Raspberry Pi’s GPIO pins from another
computer
Programming in Raspberry Pi
Programming in Raspberry Pi is done with the help of python programming concepts.
Feature of Python :
Easy to code: With the clear syntax developers get an idea on code
identification instead of {};
Simple Syntax: Python has a simple syntax similar to the English Language
Interpreted Language: Python runs on interpreter system. The code can be
executed as soon as it is written. Prototyping can be very quick.
Embeddable: Python allows integration with other languages. It is possible
to put our code in other programming languages like C++ etc.
Extensible: Python is extensible language. It allows developers to write
programs with fewer lines than some other programming languages.
Portable: Python code is portable there is no need to change the code for
different machines. You can run one code in many machines.
Free and open-source: Python is open-source language. Its source code is
freely available to the public you can download it, change and distribute it.
Community supports: Python has already got its huge response in the
market with the above-mentioned features thus provides many users
grouped into community to support the advancements further.
Easy to learn: Learning and implementation of python is relatively simple
and easy when compared to other native languages like C++ and java.
Easy to debug: Python scripting language is one of the better language to
debug than C++ and C. In this source code is executed line by line.
Library support: Python supports large standard libraries. Installation of the
libraries is easy, and it saves time.