0% found this document useful (0 votes)
7 views

Raspberry Pi Notes (E-Next - In)

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Raspberry Pi Notes (E-Next - In)

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

RASPBERRY PI

• The Raspberry Pi, unlike the Arduino, wasn’t designed for physical computing at all, but rather, for
education.
• Uses Broadcom BCM2835 system-on-chip, powerful graphics processing unit (GPU), capable
of high-definition video and fast graphics rendering.
• the Raspberry Pi is effectively a computer that can run a real, modern operating system,
communicate with a keyboard and mouse, talk to the Internet, and drive a TV/monitor with
high-resolution graphics.

DEVELOPING ON THE RASPBERRY PI

• Operating System
• Although many operating systems can run on the Pi, we recommend using a popular Linux
distribution, such as
• Raspbian:
• Released by the Raspbian Pi Foundation, It is based on Debian.
• This is the default “official” distribution and is certainly a good choice for general work with a Pi.

https://E-next.in
• Occidentalis:
• This is Adafruit’s customised Raspbian.
• Unlike Raspbian, the distribution assumes that you will use it “headless”—not connected to
keyboard and monitor—so you can connect to it remotely by default.
• The main advantages are that
◾ The sshd (SSH protocol daemon) is enabled by default, so you can connect to the console
remotely.
◾ The device registers itself using zero-onfiguration networking (zeroconf) with the name
raspberrypi.local, so you don’t need to know or guess which IP address it picks up from the
network in order to make a connection.
• The following command, from a Linux or Mac command line, lets you log in to the Pi just as
you would log in to a remote server:
• $ ssh [email protected]
• From Windows, you can use an SSH client such as PuTTY

Programming Language
• One choice to be made is which programming language and environment you want to use.
• Python is a good language for educational programming (and indeed the name “Pi” comes
initially from Python).

• “blinking lights” example:


• import RPi.GPIO as GPIO
• from time import sleep
• GPIO.setmode(GPIO.BOARD)
• # set the numbering scheme to be the
• # same as on the board
• GPIO.setup(8, GPIO.OUT)
• # set the GPIO pin 8 to output mode
• led = False
• GPIO.output(8, led)
• # initiate the LED to off
• while 1:
GPIO.output(8, led)
led = not led
# toggle the LED status on/off for the next iteration
sleep(10)
# sleep for one second

CONTRAST PYTHON WITH C++


 Python, as with most high-level languages, compiles to relatively large (in terms of
memory usage) and slow code, compared to C++.
 There is no issue because the Pi has more than enough memory.
 The speed of execution may or may not be a problem: Python is likely to be “fast enough” for
most tasks, and certainly for anything that involves talking to the Internet.
 Python handles memory management automatically.
 Automatic memory management generally results in fewer bugs.
 However, this automatic work has to be scheduled in and takes some time to complete.
 Depending on the strategy for garbage collection, this may result in pauses in
operation which might affect timing of subsequent events.

https://E-next.in
Raspberry Pi Notes

 Linux itself arguably has some issues for “real-time” use.


 With many processes that may run simultaneously, precise timings may vary due to
 how much CPU priority is given to the Python runtime at any given moment.
 An Arduino runs only the one set of instructions, in a tight loop, until it is turned
off or crashes.
 The Pi constantly runs a number of processes.
 If one of these processes misbehaves, or two of them clash over resources (memory,
 CPU, access to a file or to a network port), they may cause problems that are entirely
unrelated to your code.

Debugging
 While Python’s compiler also catches a number of syntax errors and attempts to use
undeclared variables, it is also a relatively permissive language (compared to C++) which
performs a greater number of calculations at runtime.
 This means that additional classes of programming errors won’t cause failure at compilation
but will crash the program when it’s running, 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.
 As long as the device itself hasn’t crashed, you may be able to ssh into the Raspberry Pi and
do some of this debugging while your program has failed.
 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.

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.
 The pins in the Raspberry Pi aren’t individually labelled.
 The block of pins provides both 5V and 3.3V outputs.
 The GPIO pins themselves are only 3.3V tolerant.
 The Pi doesn’t have any over-voltage protection, so you are at risk of breaking the board
if you supply a 5V input!
 The Raspberry Pi doesn’t have any analogue inputs (ADC), which means that options to
connect it to electronic sensors are limited.
 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.

OPENNESS
 Many of the components are indeed highly open: the customised Linux distributions such
as “Raspbian” (based on Debian), the ARM VideoCore drivers, and so on.
 The core Broadcom chip itself is a proprietary piece of hardware.

Khan S. Alam https://E-next.in

https://E-next.in

You might also like