I first ordered the following items from amazon.com:
Raspberry Pi Model B Revision 2.0 (512MB)
The video output connections are for HDMI or very primitive composite video, not VGA. An adapter cable is needed for most monitors.
HTC Micro USB AC Travel Charger Adapter, Charging Data Cable and Malcom Distributors Dual USB Port 2.1A Car Charger Power Adapter for HTC Micro USB Data Charging Cable for HTC Thunderbolt, Thunderbolt 4G, HTC Freestyle, HTC 7 PRO, HTC DROID Incredible 2
It is important to have an AC adapter that supplies 5 V at 1 A as this one does. This also includes a car adapter that can power a two USB ports, one with 1 A and the other with 2.1 A.
I would call this book "essential." This 2nd edition covers the more convenient NOOBS method of getting the operating system set up.
This is quite a nice introduction to using Python on the Pi.
FAVI Entertainment Wireless Keyboard (Built-in TouchPad/Laser Pointer) - Black
This unit has a model name of Rii mini and includes its matching wireless USB adapter. There is no need to order a USB adapter. In fact, one that I did order did not seem to work with the Rii mini. The model name for this unit is Rii mini and operates with a 2.4 GHz DSSS connection. A bluetooth unit is available, but appears to be a bit troublesome to get working.
SanDisk Ultra 32 GB MicroSDHC C10/UHS1 Memory Card with Adapter (SDSDQU-32G-AFFP-A)
The adapter is necessary since the Rasberry Pi card slot is for a normal-sized card.
A month later, I ordered the Gertboard from Newark/Element14 for $50. It is an excellent companion to the Raspberry Pi. See below for more.
Several months later, I ordered another Pi and the following additional goodies from Amazon and other sources:
This unit does a nice job of converting the HDMI output to VGA so that I could use the Raspberry Pi with VGA monitors and projectors. This is an excellent unit, but took over a month to arrive from China since I don't pay extra for fast shipping.
This helps protect the Pi, but the top must be removed to attach the Gertboard.
A second Raspberry Pi since my first one is now a dedicated critter cam.
This is for my second Pi and seems a better choice than the power supply I bought for the first Pi.
The normal camera (like all cameras) has a filter to block out infrared light. This camera does not have that filter and therefore can be used with an infrared flood light to see at night. It is also useful for examining the infrared reflactions from vegetation that indicates plant health.
This should light up our garden with infrared light for night viewing by the PiNoIR camera.
These ultrasonic distance sensors are designed for 5V use, but can be used with the 3.3V Pi when a resistor divider is used to reduce the echo pulse from 5V to 3.3V. The Pi has a 5V pin to provide power to this sensor.
I bought two of these to play with using the motor controller on the Gertboard.
I also bout two of these stepping motors, but needed the Allegro chips (see next item) to control them
These take control voltages and a power source (battery) to drive stepping motors. I needed 4 chips for 2 stepping motors, but bought 2 extra.
A system image needed to be loaded from the Raspberry Pi Organization page at .http://www.raspberrypi.org/downloads. The file I obtained was 2013-02-09-wheezy-raspbian.zip. This file needs to be unzipped and placed on the memory card. On my Linux system I did this with the instruction dd if=2013-02-09-wheezy-raspbian.zip of=/dev/sdb bs=2M. Instructions for doing it from Microsoft and Apple systems are given in the documentation available from Embedded Linux Wiki site.
For information about the Gertboard, the Gertboard_UM_with_python.pdf is available on the web.
The only hitch in getting to the first boot was that I had an error in my dd instruction for putting the system on the memory card. I had used if=/dev/sdb1 rather than if=/dev/sdb. I had not yet received my 16 GB class 10 SanDisk card, but using an old 4GB class 4 card worked fine.
Once it is working with a network connection, you should update the raspbian system as follows:
sudo apt-get update sudo apt-get upgrade sudo apt-get install rpi-update sudo rpi-update sudo reboot
UPDATE: I now have the 16 GB card and am enjoying the enormous "disk" space and rapid access.
When checking out the raspbian graphical user interface (GUI), I found that the system had problems working the cursor with the Rii mini tablet. Tentatively, I think the work-around is to be wiggling your finger on the tablet as the system figures out the appropriate driver when starting the GUI.
I installed the following software:
Prepare software for communicating with the gertboard. gertboard_sw is found at element14.com
The gertboard has a microprocessor which is normally the ATmega328P. A compiler for it can be found at Source Forge
Note: When I tried to use the avra compiler that I could get by simply doing sudo apt-get install avra I would get a version that could not handle the m328Pdef.inc file that matches the ATmega328P processor in the Gertboard.
It is compiled as follows:
tar xjf avra-1.3.0.tar.bz2 cd avra-1.3.0 cd src touch NEWS touch ChangeLog ln -s ../AUTHORS . ln -s ../README . sudo apt-get install automake aclocal autoconf automake -a ./configure make sudo make install sudo mv /usr/local/bin/avra /usr/bin/avra
The definition file m328Pdef.inc can be obtained from http://www.hubholic.com/upload/avr/m328pdef.inc. When using it, the assembler will express unhappiness with pragmas, but that can be ignored.
It is useful to be able to locate files using the command locate someFile. This is a very quick command because it depends on having a database of files on the machine. The database, however, must be updated occasionally using the command sudo updatedb. I do this only when I look for something that is recently installed or created.
This makes sure that the program syntax is highlighted in useful colors. It is also necessary to uncomment syntax on in /etc/vim/vimrc.
A 2 mA LED was placed in a small Experimentor 350 board in series with an 820 ohm resistor. The value of 820 Ohms was chosen to be near the 750 ohm value calculated to produce 2 mA through the diode when the pin is at 3.3V [750 ohms = (3.3 V - 1.8 V)/(0.002 A)]. The long pin of the LED was connected to the RaspberryPi GPIO connector at pin #3 that is at ground potential. The long pin of the LED was connected to the resistor and the other end of the resistor was connected to the RasberryPi board GPIO connector at pin #12 (Processor pin GPIO-18). Care was taken to correctly identify the pins and not accidentally mess with the adjacent Do Not Connect pin. Clear instructions were provided by the book Raspberry Pi User Guide by Upton and Halfacree
The GPIO pin pull-up/down resistors must be set for pull-up to be able to supply 2 mA of current for the LED.
The following program made the light blink 3 times:
#! /usr/bin/python import RPi.GPIO import time RPi.GPIO.setmode(RPi.GPIO.BOARD) startTime=time.time() for i in range(11): RPi.GPIO.setup(12,RPi.GPIO.OUT,RPi.GPIO.PUD_UP,0) time.sleep(0.25) RPi.GPIO.setup(12,RPi.GPIO.OUT,RPi.GPIO.PUD_UP,1) time.sleep(0.25) print 'Took {0:5.2f} seconds.'.format(time.time()-startTime) RPi.GPIO.cleanup()
This program prints out 5.51 seconds for the time it required to complete, but if done 100 times, it takes 50.58 seconds and if done 1000 times, it takes 501.51 seconds. If 10 blinks are done without using a loop instruction, 5.01 seconds are required.
The following program uses bit-banging to send a text file out the USART port with a format of 8 data bits, 1 stop bit, and no parity bit.
Bit-banging is a technique of explicitly manipulating individual output pins from a user program. It is a crude way to do things, but convenient in a pinch.
The imported Python package RPi.GPIO, written in the C programming language, tells low-level system drivers how to set the GPIO pins on an ARM (bcm2708) similar to that running the Raspberry Pi (bcm2835). This Python example uses RPi.GPIO.
#! /usr/bin/python import RPi.GPIO import time RPi.GPIO.setmode(RPi.GPIO.BOARD) Message='' with open('ASCIIData','r') as f: line=f.readline() while line: Message+=line line=f.readline() print Message, bitDuration=0.001 def startBit(): RPi.GPIO.setup(12,RPi.GPIO.OUT,RPi.GPIO.PUD_UP,0) time.sleep(bitDuration) def oneBit(): RPi.GPIO.setup(12,RPi.GPIO.OUT,RPi.GPIO.PUD_UP,1) time.sleep(bitDuration) def zeroBit(): RPi.GPIO.setup(12,RPi.GPIO.OUT,RPi.GPIO.PUD_UP,0) time.sleep(bitDuration) def stopBit(): RPi.GPIO.setup(12,RPi.GPIO.OUT,RPi.GPIO.PUD_UP,1) time.sleep(2*bitDuration) startTime=time.time() for c in Message: print '{0:1s}'.format(c), bString=bin(ord(c)) oString='' for i in range(10-len(bString)): oString+='0' oString+=bString[2:] startBit() for b in oString[::-1]: if b=='1': oneBit() elif b=='0': zeroBit() else: print 'illegal character in oString:',oString import sys sys.exit() stopBit() print 'Took {0:5.2f} seconds.'.format(time.time()-startTime) RPi.GPIO.cleanup()
This program took 13 ms per character when sending a file with 62 characters.
The SPI bus is a widely used way to talk to computer peripherals. With the Gertboard attached to the Raspberry Pi, the SPI bus is the best way to talk to the Gertboard's ATmega328P processor, its two analog-to-digital (A/D) converters, or its two digital-to-analog (D/A) converters. It can be operated using bit-banging, but it is best to use a dedicated device drivers which create the devices /dev/spidev0.0 and /dev/spidev0.1.
vi /etc/modprobe.d/raspi-blacklist.conf
Run your favorite editor (could be nano rather than vi) and comment out the line that says "blacklist spi-bcm2708" by putting a pound sign (#) at its start.
sudo reboot
Restart the raspberry pi. It might need to be unplugged as well, but I don't think so.
uname -a
check the system identification which might read something like Linux raspberrypi2 3.10.19+ #600 PREEMPT Sat Nov 16 20:34:43 GMT 2013 armv6l GNU/Linux
ls /dev/spidev*
This should show two driver files, /dev/spidev0.0 /dev/spidev0.1 which application programs will use to connect to the SPI bus.
lsmod | grep spi
This will now show the driver module spi_bcm2708.
Obtain the program spidev_test.c from kernel.org.
Edit spidev_test.c to change a line that contains /dev/spidev1.1 to /dev/spidev0.0 to match the new drivers in our Raspberry Pi.
spidev_test.c -o spidev_test
Compile the spidev_test.c program.
Connect a jumper between board pins 19 and 21 (GPIO-10 [MOSI] and GPIO-9[MISO]) on the Raspberry Pi GPIO connector.
Be sure you connect to the correct pins. There are certain pins that must not be touched. See, for example, the diagram on this page or in the Raspberry Pi User Guide.
sudo ./spidev_test
Run the program and see if it gives the following output:
spi mode: 0 bits per word: 8 max speed: 500000 Hz (500 KHz) FF FF FF FF FF FF 40 00 00 00 00 95 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF DE AD BE EF BA AD F0 0D
If this shows all 00 bytes, it has failed the test. You may have not connected the correct pins together.
It is necessary to install a Python module that uses these /dev/spidev0.0 and /dev/spidev0.1 drivers. This is done as follows:
mkdir spi cd spi mkdir python-spi cd python-spi wget https://raw.github.com/doceme/py-spidev/master/setup.py wget https://raw.github.com/doceme/py-spidev/master/spidev_module.c sudo python setup.py install
This is a simple Python program to test if the Python module installed correctly:
#!/usr/bin/python import spidev import time spi = spidev.SpiDev() spi.open(0,0) while True: resp = spi.xfer2([0x00]) print resp[0] time.sleep(1)
If you name the program spitest.py, you will need to give it execute permission by doing:
sudo +x spitest.py
and then run it by doing:
./spitest.py
It will simply return '0's until you stop it by pressing ctrl-C.
sudo python spitest.py
These are used for the event logging project described below.
The Raspbian Linux system has generic code that can handle a wide range of ARM processors and lacks support for some features of the bmc2835 processor.
To install a C library for access to the GPIO pins and using the SPI bus, we follow instructions from Mike McCauley at http://www.airspayce.com:
Start in your home directory.
Create a subdirectory named C_GPIO_Library (or whatever name you like).
This uncompresses and places files in a subdirectory called bcm2835-1.35 where the 1.35 is the current version number.
Change into that directory.
Prepare for the compilation of the library files.
More preparation.
See if it passed a check. It should say 1 test passed
This places the files in the appropriate Linux system directories for reference by the C compiler. It uses /usr/local/include and /usr/local/lib for its files instead of /usr/include and /usr/lib which are standard for the Raspbian system so they should be moved or better, symbolic links can be used.
Go back up to the C_GPIO_Library directory.
This now compiles the blink.c source code into the object code blink which when run will blink the LED every second. The LED must be wired as described earlier except this time the program is set to use pin 11 rather than pin 12. Again, be careful with when working with these pins to use the correct ones, have a suitable resistor in series with the LED, and the LED polarity correct.
This command runs the blink program and starts the LED blinking every second. You must use control-C to stop it.
The other programs can be run the same way. Note that the spin.c program needs to have the MISO and MOSI pins connected together. Correct operation of the spin.c program will produce the following output line:
Read from SPI: 01 02 11 33
The program spidev_test.c that we used above works directly with the spidev and bcm2708 modules whereas these work via the bcm2835 library directly accesses the processor chip input/output registers via the linux /dev/mem device. It does not depend on any driver modules and is a better match to the bcm2835 processor in the Raspberry Pi.
The details including program listings for the following are at here as applied to monitoring the clicks of a Geiger counter.
The Gertboard connects directly to the GPIO pins of the Raspberry Pi and provides a nice variety of input/output capabilities. It also contains an ATmega328P processor with additional capabilities. Whereas the Raspberry Pi must multitask among many programs and therefore is not directly suitable for rapit real-time data acquisition, the ATmega328P can be setup as a dedicated data acquisition processor.
The following three programs had to be written to get the ATmega328P to log events and report the results back to the Raspberry Pi.
This interrupt-driven assembly language program runs a timer, records the timer values when events are detected, and sends the resulting time values to the Raspberry Pi when requested. It can store up to 64 values before needing to upload them to the Raspberry Pi.
This Python program assembles the object code from the assembler into commands that place the code into the ATmega328P memory. I wanted to fully understand how this procedure works and refused to use other programs. I especially dislike using canned a "Integrated Development Environment" because that hides how things really work and locks the user into a particular system. So, I use an ordinary command-line editor vim, wrote this uploading program.
This is a prototype Python program that brings the data from the ATmega328P into the Raspberry Pi. A user would modify this program to store the data in whatever manner is desired.
Last updated: May 4, 2014
Contact Craig Van Degrift if you have problems or questions with this web site.