0% found this document useful (0 votes)
19 views48 pages

CHP 5

Uploaded by

kshah007036
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views48 pages

CHP 5

Uploaded by

kshah007036
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 48

Prototyping Embedded

Devices
Introduction
• Once we have an idea as to what product/device we would like to
make, we then figure out as to what components/modules we
would need to turn our idea into something tangible.
• The more you dabble in electronics and microcontrollers, the
bigger your collection of spare parts and leftovers from previous
projects will grow.
• You use what’s easily to hand, partly because it’s generally
something you’re familiar with already but also because it helps
keep the costs down.
• Using a mobile phone, laptop, or desktop computer to develop the
initial software may be slightly expensive.
• We go over some popular choice of platforms available in the
market and attempt to understand a good fit based on our
requirements and criteria.
Electronics
• Most of the prototyping may be done on solderless boards (enable
you to build components together into a circuit with just a push-fit
connection) increasing flexibility.
• We can categorize the electronics to be used into 2 categories:
• Sensors: Sensors are the ways of getting information into your device,
finding out things about your surroundings.
• Actuators: Actuators are the outputs for the device—the motors, lights,
and so on, which let your device do something to the outside world.
• The simplest interactions could be through digital I/O, which has
only two states: a button can either be pressed or not; or an LED
can be on or off (via the use of GPIO pins).
• If you want a more nuanced connection than just on/off, you need
an analogue signal (use of rotary knob).
• Because computers are purely digital devices, you need a way to
translate between the analogue voltages in the real world and the
digital of the computer. (ADCs0 to a predefined max limit).
• DACs let you generate varying voltages from a digital value but are
less common as a standard feature of microcontrollers owing to
pulse-width modulation.
• Serial Peripheral Interface (SPI) bus and Inter-Integrated Circuit
(I2C) offer more complicated sensors and modules.
• Sensors
• Pushbuttons, switches, potentiometers (rotary as well as linear) are the simplest form of
sensors.
• Sensing the environment: light-dependent resistors, thermistors, temperature sensors.
• Microphones, piezo elements
• Distance-sensing modules
• Actuators
• LEDs
• LCDs
• Piezo elements
• Speakers
• Solenoids
• Motors (stepper motor) and stepo
• Scaling up the electronics
• From the perspective of the electronics, the starting point for prototyping
is usually a “breadboard” push-fitting components and wires to make up
circuits without requiring any soldering and therefore makes
experimentation easy.
• Once we’re happy with the design, we can go with making something
more robust.
• Moving beyond the protoboard option tends to involve learning how to lay
out a PCB.
• For small production runs, you’ll likely use through-hole components, so
called because the legs of the component go through holes in the PCB and
tend to be soldered by hand.
• You will often create your designs as companion boards to an
existing microcontroller platform—referred as shields in the
Arduino community—for bootstrapping production without
worrying about designing the entire system from scratch.
• When you want to scale things even further, moving to a combined
board allows you to remove any unnecessary components from the
microcontroller board, and switching to surface mount
components.
Embedded computing basics
• Our desktop is a collection of discrete modules to provide different
aspects of functionality.
• Each of these also take up a corresponding chunk of physical space
consequently.
• Microcontrollers:
• IOT devices take advantages of more tightly integrated and miniaturized
solutions.
• Microcontrollers are very limited in their capabilities; however, they can
still achieve a lot despite their limitations.
• Both 8-bit as well as 32-bit microcontrollers are popular in terms of use.
• The 8-bit microcontrollers resemble the working of the early home
computers (1980s) although they do exhibit certain improvements.
• The microcontroller market comprises many manufacturers.
• They are easy to wire up to all types of sensors, lights, and motors.
• As the devices using them are focused on performing one task, their code
footprint is considerably simpler and slimmer.
• In such systems, functions that that require greater resource levels are
usually provided via additional single purpose chips.
• System-on-Chips
• SoC sits between the low-end microcontroller and a full-blown PC.
• SoCs combine a processor and a number of peripherals onto a single chip
but usually have more capabilities in comparison to a microcontroller.
• Use of processors, RAM, and SD(for storage).
• They also use an OS.
• A wide selection of embedded operating systems is available.
• As the price falls for increased computing power, the popularity and
familiarity of options such as Linux are driving its wider adoption.
• Choosing your platform
• The platform you choose depends on the particular blend of price,
performance, and capabilities that suit what you’re trying to achieve
(subjective).
• Following are some factors we need to consider while choosing a platform:
• Processor Speed
• The processor speed, or clock speed, of your processor tells you how fast it can
process the individual instructions in the machine code for the program it’s running.
Naturally, a faster processor speed means that it can execute instructions more
quickly.
• You may alsp consider the MIPS rate for this aspect.
• Floating-point calculations, in case they are a part of your calculations (a by-the-
numbers slower processor with hardware floating-point support could be faster than
a slightly higher performance processor without it)
• Generally, you will use the processor speed as one of a number of factors when
weighing up similar systems.
• Microcontroller vs. SoC
• RAM
• If you have more RAM, you may be able to do more things or have more flexibility
over your choice of coding algorithm.
• Majorly depends on how much data you’d be handling.
• Memory limitations can be handled either via code or by using an online service.
• The size of the RAM required will differ from project to project (different for
microcontrollers and SoCs).
• Networking
• How your device connects to the rest of the world is a key consideration for IOT
products.
• Wired vs Wireless.
• WiFi (short-range alternatives as well)
• Use of Bluetooth 4.0
• Use of mobile phone networks/ SMS(lower bandwidth, higher latency), smartphones
using 3G connectivity (for higher data rates) services for remote or outdoor
deployments.
• USB
• Your system can make use of USB for power and networking purposes.
• If your device can rely on a more powerful computer being nearby, tethering to it via
USB can be an easy way to provide both power and networking.
• We can opt for a version of microcontroller that supports the use of USB.
• Instead of the microcontroller presenting itself as a device, some can also act as the
USB “host” this would allow the microcontroller to connect with items that we
generally connect with a computer.
• At times, some devices may need additional software to connect to the
microcontroller.
• Power Consumption
• Faster processors are often more power hungry than slower ones.
• For devices which might be portable or rely on an unconventional power supply
(batteries, solar power) depending on where they are installed, power consumption
may be an issue lower consumption is usually desirable.
• However, processors may have a minimal power-consumption sleep mode. This mode
may allow you to use a faster processor to quickly perform operations and then return
to low-power sleep (this would facilitate the use of a more powerful processor in a low-
power embedded device).
• Interfacing with Sensors and Other Circuitry
• In addition to talking to the Internet, your device needs to interact with either
sensors to gather data about its environment; or motors, LEDs, screens, and so on, to
provide output.
• Based on the version of microcontroller, you could choose a suitable/compatible
circuitry, like peripheral buses (SPI/I2C),ADC/DAC, generic GPIO pins.
• Physical size and form factor
• The amount of space required for all the transistors and other components that make
up the circuitry on the silicon is not the limiting factor in the size of the chip anymore
owing to the continuing improvement in the techniques used for making silicon
chips.
• Nowadays, the size is governed by the number of connections it needs to make to
the surrounding components on the PCB.
• Depending on your design requirements, you can either choose through-hole
components or surface mount components for your circuitry.
• Thus, it is possible to use the complex designs without resorting to PCBs the size of a
table.
• The limit to the size that each connection can be reduced to is then governed by the
capabilities and tolerances of your manufacturing process.
• Due to these trade-offs in size versus manufacturing complexity, many chip designs
are available in a number of different form factors, known as packages. This lets the
circuit designer choose the form that best suits his particular application.
ARDUINO
• Poster child for IOT and physical computing in general (created in 2006).
• A group from the Interaction Design Institute Ivrea (IDII), Northern Italy,
wanted a board for its design students to use to build interactive projects. An
assortment of boards was around at that time, but they tended to be
expensive, hard to use, or both.
• So, the team put together a board which was cheap to buy and included an
onboard serial connection to allow it to be easily programmed. Combined
with an extension of the Wiring software environment, it made a huge impact
on the world of physical computing.
• Wiring is an open-source electronics prototyping platform composed of a
programming language, an integrated development environment (IDE), and a
single-board microcontroller.
• The entire project (code and schematics) was open sourcethus, ,
an entire ecosystem of boards, add-ons, and related kits has
flourished.
• The Arduino team’s focus on simplicity rather than raw
performance for the code has made the Arduino the board of
choice in almost every beginner’s physical computing project, and
the open source ethos has encouraged the community to share
circuit diagrams, parts lists, and source code.
• A good number of resources are available online so as to start and
complete an Arduino project.
• The “standard” Arduino board has gone through a number of iterations:
Arduino NG, Diecimila, Duemilanove, and Uno (there are recent versions
as well). as of 2016, there have been 17 versions.
• The Uno (which happens to be the most used board) features an ATmega328
microcontroller and a USB socket for connection to a computer. It has 32KB of
storage and 2KB of RAM.
• The Uno also provides 14 GPIO pins (of which 6 can also provide PWM output)
and 6 10-bit resolution ADC pins. The ATmega’s serial port is made available
through both the IO pins, and, via an additional chip, the USB connector.
• If you need more space or a greater number of inputs or outputs, the Arduino
Mega 2560 does it for youprovides a more powerful ATmega microcontroller to
the same software environment, providing 256KB of Flash storage, 8KB of RAM,
three more serial ports, a massive 54 GPIO pins (14 of those also capable of
PWM) and 16 ADCs.
• Alternatively, the more recent Arduino Due has a 32-bit ARM core microcontroller
and is the first of the Arduino boards to use this architecture. Its specs are similar to
the Mega’s, although it ups the RAM to 96KB.
• Developing on the Arduino
• More than just specs, the experience of working with a board may be the
most important factor, at least at the prototyping stage.
• The Arduino is optimised for simplicity, and this is evident from the way it
is packaged for use.
• Using a single USB cable, you can not only power the board but also push
your code onto it, and (if needed) communicate with it—for example, for
debugging or to use the computer to store data retrieved by the sensors
connected to the Arduino.
• Operating system
• Arduino does not have any default OS (runs on bare metal).
• A lightweight real-time OS(RTOS) can be uploaded on Arduino (offers built-
in support for multi-tasking).
• The avr-gcc toolset can be used to compile the code. This toolset is a
collection of programs that lets you compile the code to be run on the AVR
chip (used by the Arduino board).
• Language
• The language used here is a slightly modified dialect of C++ derived from the
Wiring platform.
• Includes libraries for reading and writing data from the I/O pins provided on
the board and some basic handling for interrupts.
• Within the code, the order can be overlooked. As a best practice though,
following appropriate order is preferable.
• Following are the two routines used in the Arduino code:
• setup(): run once the board first boots. Could be used to set the modes of the I/O
pins used.
• loop(): run repeatedly on a tight loop.
• A sample code snippet (blinking led):

//Pin 13 has an LED connected on most Arduino boards


int led=13;
//the setup routine runs once you press the reset button
//we then initialize the same pin as an output
void setup()
{
pinMode(led, OUTPUT);
}
//the loop routine runs over and over again
void loop()
{
digitalWrite(led, HIGH);
delay(1000);
digitalWrite(led, LOW);
delay(1000);
}
• setup() only sets up the pin that we will be using here.
• loop() is then repeatedly called for executing the entire cycle (ON-wait-
OFF) on loop.
• Debugging
• A fair number of errors are caught during compilation.
• Extensive debugging experience may not be required for some errors.
• As Arduino is not generally connected to a screen, identifying errors could
be challenging.
• There could also be runtime errors or some error that may give you
incorrect result.
• E.g., in the case of Bubblino, if it stops working, there could be a possibility
that we would be unable to determine what the root cause is here.
• Therefore, we may need proper error-catching mechanisms.
• Runtime programming errors may be tricky to catch as avr-gcc compiler
does not support exception handling. (Therefore, the usual try…catch logic
cannot be used here).
• Checking your data/interactions prior to using them is extremely
important.
• E.g., the first commercial available version of WhereDial has a bank of
several LEDs specifically for consumer-level debugging.
• It can be thus be said that code is not always perfect/errorfree.
• Therefore, we need ways to identify where the errors are occurring /could
potentially occur.
• In the absence of a screen, Arduino allows you to write/pass on
information over the USB cable through Serial.write()(uses a serial monitor
• Some notes on hardware
• The Arduino exposes a number of GPIO pins and is usually supplied with
headers.
• Each pin is labelled clearly.
• In general, the board has power outputs, one or more electric ground
connections, numbered digital pins, and numbered analog pins(prefixed
with an “A”).
• While Arduino uses a single USB connection to power up, it also has a
socket for supplying external power supply.
• Apart from the standard boards, a number of other boards are focused on
a specific niche:
• Arduino Ethernet
• LilyPad
• These add-on specialized boards are called shields.
• Different shields may provide different capabilities.
• A standard Arduino with an Ethernet shield is equivalent to an Arduino
Ethernet (the latter is thinner, however, it loses the convenience of a USB
connection).
• Openness
• As previously discussed, this is a completely open project.
• The only part that is protected is the Arduino trademark.
• This culture of sharing resources/openness has immensely helped in
developing the subsequent versions.
• E.g., Arduino Fio board (originally the Funnel IO) was initially developed as
a third-party board but was then adopted as an official Arduino approved
board.
Raspberry Pi
• It wasn’t designed for physical computing, but rather for education
purposes.
• The idea/vision was to build a computer that was small and
inexpensive and was designed to be programmed and experimented
with.
• Broadcom BCM2835 SoC:
• Exceptionally powerful GPU (capable of high-definition video and fast
graphics rendering)
• Low-power, cheap but serviceable 700 MHz ARM CPU
• Thus, this entire project has always taken inspiration from a previous
attempt to improve computer literacy in the U.K.
• BBC Micro was invented as BBC producers wanting to create a TV program
about programming realized that there weren’t any cheap yet powerful
computer platforms known in U.K. schools that were comprehensible enough
for a discussion on their show.
• Model A and Model B (names) were derived from the versions of these
platforms initially created.
• The Foundation was able to deal with large suppliers and push down the costs
of components.
• The final price of Model B was £25 (which also had a built-in Ethernet
connection).
• This is approximately the same price as an Arduino, yet has boards of
completely different specifications.
A comparison of Arduino Due and
Raspberry Pi Model B
Arduino Due Raspberry Pi Model B
CPU Speed 84 MHz 700MHz
GPU None Broadcom Dual-core Videocore IV
Media Co-processor
RAM 96 KB 512 MB
Storage 512 KB SD card (4 GB+)
OS Bootloader Various Linux distributions, other
Oss available as well
Connections 54 GPIO Pins 8 GPIO Pins
12 PWM outputs 1 PWM output
4 UARTs 1 UART
SPI bus SPI bus with two chip sets
I2C bus I2C bus
• Raspberry Pi is effectively a computer that can run a real, modern
OS, communicate with a keyboard and mouse, talk to the Internet,
and drive a TV/monitor with high-resolution graphics.
• Furthermore, the Pi Model B has a built-in Ethernet and can use
cheap and convenient USB wifi dongles.
• Although the specifications of the Pi are in general more capable
than the best of the Arduino platforms, we cannot deem that to be
“better” without considering what these devices are for.
• However, a whole host of devices is available in the same target
market as that of Raspberry Pi.
• While they may seem to have slightly better specifications, there
may not be any justifiable reasons for us to choose any other
platform over Raspberry Pi.
• If we do end up choosing anything else, some plausible reasons
may be:
• Existing hardware;
• Better tool support for a specific chipset;
• Ease of use considerations
• Cases and extension boards
• Because the Pi can be useful as a general purpose computer without requiring
constant prototyping with electronic components, one of the first demands
was for convenient and attractive cases (many makers/designers have
blogged/documented/shared their experiences/designs).
• Although there was no official case as such, there have been reports of an
early, well-designed case created by Paul Beech.
• Extension boards and other accessories are already available for Raspberry Pi.
• For example, Gertboard.
• As this platform is considerably more high level and capable, the attention
with respect to its developmental aspects may be spread more thinly.
• Physical computing just happens to be one of those aspects that attention
might be paid to.
• Developing on the Raspberry Pi
• The number of variables on the Raspberry Pi are considerably greater and
there is much more of an emphasis on being able to do things in
alternative ways.
• Best practices have definitely evolve over the years.
• Operating System
• Linux distribution is the recommended OS for Raspberry Pi.
• Raspbian: a distro (distribution package) based on Debian. This is the default general
distribution.
• Occidentalis: This is Adafruit’s customized Raspbian (here the assumption is that the
kit will be used in a headless mode).
• In the headless mode, we need not set up a keyboard and monitor
separately.
• Some tweaks that the system uses here are:
• sshd protocol for connecting to the console
• The device registers itself with zero-configuration networking
• With respect to Arduino, the simplicity with respect to its development
environment is its greatest advantage.
• However, with Raspberry Pi, we’ve had to make decisions regarding which
distro to use.
• The Pi may boot up if sufficient power is supplied via the USB port; a
powered USB could be the best option.
• After the bootup, we can communicate with the Pi either via the keyboard
or monitor attached to the system or through ssh.
• Once we’ve connected to a device, we can work on other task (e.g.,
developing a software application/any other problem).
• Programming languages:
• Python is suggested as a preference for educational programming  ”Pi”
originated from Python.
• Consider the program for blinking LED.
• While the code is almost similar to what was covered in Arduino (C++), the
difference here lies in the modularization (use of modules).
• Following situations become much more simpler with the use of Python:
• Handling strings of character data.
• Completely avoiding having to handle memory management (and related bugs).
• Making calls to Internet services and the parsing the data received.
• Connecting to databases and more complex processing.
• Abstracting common patterns or complex behaviors.
• Reuse of readily available code/libraries.
• There could be tradeoffs related to either the Linux platform itself or to the
use of high-level programming language:
• A comparison between Python and C++ in this regard:
• Python compiles relatively large (in terms of memory usage) and slow code.
• Python handles memory management automatically.
• Linux itself arguably has some issues for “real-time” use.
• Arduino runs only the one set of instructions, in a tight loop, until it is turned off or it
crashes.
• The most important issue is probably the ease of use of the environment
• Debugging:
• Possibly, the additional classes of programming errors won’t cause failure
at the compilation stage, they could eventually crash the program when it
is running.
• Whereas the Arduino had fairly limited debugging capabilities, Python code
on Linux gives you the advantages of both the language and the OS.
• You could step through the code using Python’s integrated debugger,
attach to the process using the Linux strace command, view logs, see how
much memory is being used, and so on.
• Because the Pi is a general-purpose computer, without the strict memory
limitations of the Arduino, you can simply use try... catch... logic so that you
can trap errors in your Python code and determine what to do with them.
• Python and other high-level languages also have mature testing tools
which allow you to assert expected behaviours of your routines and test
that they perform correctly automated testing.

• SOME NOTES ON THE HARDWARE


• The Raspberry Pi has 8 GPIO pins, which are exposed along with power
and other interfaces in a 2-by-13 block of male header pins no individual
labelling as in Arduino.
• The intention is rather that you will plug a cable onto the whole block,
which leads to a “breakout board” where you do actual work with the
GPIO.
• Female jumper wires can be used.
• The block of pins provides both 5V and 3.3V outputs. However, the GPIO
pins themselves are only 3.3V tolerant.
• Raspberry Pi does not have any analogue inputs (ADC), which means that
options to connect it to electronic sensors are limited, out of the box, to
digital inputs (that is, on/off inputs such as buttons). To get readings from
light-sensitive photocells, temperature sensors, potentiometers, and so
on, you need to connect it to an external ADC via the SPI bus.
• The voltage transmitted over USB from a laptop computer, a powered USB
hub, or a USB charger varies greatly.
• OPENNES
• Because one of the goals of the Raspberry Pi is to create something “hackable”,
it is no surprise that many of the components are indeed highly open.
• While the core Broadcom chip itself is a proprietary piece of hardware, and they
have released only a partial datasheet for the BCM2835 chipset, many of the
Raspberry Pi core team are Broadcom employees and have been active in
creating drivers and the like for it, which are themselves open source.
• These team members have been able to publish certain materials, such as PDFs
of the Raspberry Pi board schematics, and so on. however, hardware still
cannot be considered open.
• The Broadcom chip is currently harder to source than either the widely available
Atmel chips in the Arduino or the Texas Instruments chip in the BeagleBone. This
could make it harder to spin up a prototype into a product.

You might also like