raspberry pi notes

Cards (26)

  • Raspberry Pi
    • Wasn't designed for physical computing, but for education
    • Uses Broadcom BCM2835 system-on-chip, powerful GPU for high-definition video and fast graphics rendering
    • 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
    1. Operating System
    2. Programming Language
  • Raspbian
    • Released by the Raspberry Pi Foundation, based on Debian, default "official" distribution for general work with a Pi
  • Occidentalis
    • Adafruit's customised Raspbian, assumes headless use, enables sshd by default for remote connection, registers itself using zero-configuration networking with the name raspberrypi.local
  • Command for logging in to the Pi remotely
    $ ssh root@raspberrypi.local
  • Python programming example
    • import RPi.GPIO as GPIO
    • from time import sleep
    • GPIO.setmode(GPIO.BOARD)
    • GPIO.setup(8, GPIO.OUT)
    • led = False
    • GPIO.output(8, led)
    • while 1: GPIO.output(8, led) led = not led sleep(10)
  • Contrast Python with C++
    Python compiles to relatively large and slow code compared to C++, but is likely fast enough for most tasks and handles memory management automatically
  • Python handles memory management automatically, resulting in fewer bugs, but may cause pauses in operation depending on the garbage collection strategy
  • Issues with Linux for "real-time" use
    • 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
  • Python's compiler catches a number of syntax errors and attempts to use undeclared variables
  • Python is a relatively permissive language compared to C++ which performs a greater number of calculations at runtime
  • Additional classes of programming errors in Python 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
  • Debugging
    1. 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
    2. As long as the device itself hasn't crashed, you may be able to ssh into the Raspberry Pi and do some debugging while your program has failed
  • 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
  • Highly open components
    • 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