├── Connecting_a_Push_Switch.html ├── Connecting_an_LED.html ├── Controlling_Servo_Motors.html ├── Finding_your_way_around_the_GPIO_connector.html ├── Programming_an_Arduino_from_Raspberry_pi.html ├── Raspberry_Pi_Radio_Transmitter.html ├── Using_Resistive_Sensors.html ├── Using_a_4-Digit_LED_Display.html ├── Using_a_RaspiRobot_Board_to_Drive_a_Bi-Polar_Stepper_Motor.html ├── Using_lots_of_LEDs.html ├── atlas.json ├── images ├── get_started.png ├── rpck_0411.png ├── rpck_0801.png ├── rpck_0901.png ├── rpck_0912.png ├── rpck_0913.png ├── rpck_1001.png ├── rpck_1002.png ├── rpck_1003.png ├── rpck_1014.png ├── rpck_1101.png ├── rpck_1102.png ├── rpck_1201.png ├── rpck_1202.png ├── rpck_1203.png ├── rpck_1301.png ├── rpck_1302.png ├── rpck_1402.png ├── toc_01.png ├── toc_02.png ├── toc_03.png ├── toc_04.png ├── toc_05.png ├── toc_06.png ├── toc_07.png ├── toc_08.png ├── toc_09.png └── toc_10.png ├── index.html └── theme └── html ├── analytics.js ├── atlas_assets.css ├── bird.png ├── html.css ├── html.xsl ├── layout.html ├── logo-white-titleonly.svg ├── logo-white.svg ├── syntax.css └── titlepage.svg /Connecting_a_Push_Switch.html: -------------------------------------------------------------------------------- 1 |
2 |

Connecting a Push Switch

3 | 4 | 5 | 6 |
7 |

Problem

8 | 9 |

You want to connect a switch to your Raspberry Pi so that when you press it, some Python code is run.

10 |
11 | 12 |
13 |

Solution

14 | 15 |

Connect a switch to a GPIO pin and use the RPi.GPIO library in your Python program to detect the button press.

16 | 17 |

To make this recipe, you will need:

18 | 19 | 27 | 28 |

shows how to connect a tactile push switch, using a breadboard and jumper wires.

29 | 30 |
31 |
Connecting a push switch to a Raspberry Pi
32 |
33 | 34 |

Open an editor (nano or IDLE) and paste in the following code. As with all the program examples in this book, you can also download the program from the Code section of the Raspberry Pi Cookbook website, where it is called switch.py.

35 | 36 |

This example code displays a message when the button is pressed:

37 | 38 |
39 | import RPi.GPIO as GPIO
40 | import time
41 | 
42 | GPIO.setmode(GPIO.BCM)
43 | 
44 | GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP)
45 | 
46 | while True:
47 |     input_state = GPIO.input(18)
48 |     if input_state == False:
49 |         print('Button Pressed')
50 |         time.sleep(0.2)
51 | 52 |

You will need to run the program as superuser:

53 | 54 |
55 | pi@raspberrypi ~ $ sudo python switch.py
56 | Button Pressed
57 | Button Pressed
58 | Button Pressed
59 | Button Pressed
60 |
61 | 62 |
63 |

Discussion

64 | 65 |

You will notice that the switch is wired so that when it is pressed, it will connect pin 18 configured as an input to GND. The input pin is normally pulled up to 3.3V by the optional argument pull_up_down=GPIO.PUD_UP in GPIO.setup. This means that when you read the input value using GPIO.input, False will be returned if the button is pressed. This is a little counterintuitive.

66 | 67 |

Each GPIO pin has software configurable pull-up and pull-down resistors. When using a GPIO pin as an input, you can configure these resistors so that one or either or neither of the resistors is enabled, using the optional pull_up_down parameter to GPIO.setup. If this parameter is omitted, then neither resistor will be enabled. This leaves the input floating, which means that its value cannot be relied upon and it will drift between high and low depending on what it picks up in the way of electrical noise.

68 | 69 |

If it is set to GPIO.PUD_UP, the pull-up resistor is enabled; if it is set to GPIO.PUD_DOWN, the pull-down resistor is enabled.

70 | 71 |

You might expect the push switch to have just two connections, which are either open or closed. While some of these tactile push switches do have just two connections, most have four. shows how these connections are arranged.

72 | 73 |
74 |
A tactile push switch
75 |
76 | 77 |

Actually, there are only really two electrical connections, because inside the switch package pins B and C are connected together, as are A and D.

78 |
79 | 80 |
81 |

See Also

82 | 83 |

For more information on using a breadboard and jumper wires with the Raspberry Pi, see “Using a Breadboard with Jumper Leads”.

84 | 85 |

To use a switch to trigger an interrupt, see “Programming with Interrupts”.

86 | 87 |

To debounce a switch, see “Debouncing a Button Press”.

88 | 89 |

To use external pull-up or pull-down resistors, see “Using an External Pull-up Resistor”.

90 |
91 |
92 | -------------------------------------------------------------------------------- /Connecting_an_LED.html: -------------------------------------------------------------------------------- 1 |

Connecting an LED

2 | 3 | 4 | 5 |

Problem

You want to know how to connect an LED to the Raspberry Pi.

Solution

Connect an LED (see “Opto-Electronics”) to one of the GPIO pins using a 470Ω or 1kΩ series resistor (see “Resistors and Capacitors”) to limit the current. To make this recipe, you will need:

shows how you can wire this using solderless breadboard and male-to-female jumper leads.

Connecting an LED to a Raspberry Pi

Having connected the LED, we need to be able to turn it on and off using commands from Python. To do this, follow “Installing RPi.GPIO” to install the RPi.GPIO Python library.

Start a Python console (“Using the Python Console”) from the Terminal with superuser access and enter these commands:

$ sudo python
12 | >>> import RPi.GPIO as GPIO
13 | >>> GPIO.setmode(GPIO.BCM)
14 | >>> GPIO.setup(18, GPIO.OUT)
15 | >>> GPIO.output(18, True)
16 | >>> GPIO.output(18, False)

This will turn your LED on and off.

Discussion

LEDs are a very useful, cheap, and efficient way of producing light, but you do have to be careful how you use them. If they are connected directly to a voltage source (such as a GPIO output) that is greater than about 1.7 volts, they will draw a very large current. This can often be enough to either destroy the LED or whatever is providing the current—which is not good if your Raspberry Pi is providing the current.

You should always use a series resistor with an LED because the series resistor is placed between the LED and the voltage source, which limits the amount of current flowing through the LED to a level that is safe for both the LED and the GPIO pin driving it.

Raspberry Pi GPIO pins can only provide about 3 mA of current. LEDs will generally illuminate with any current greater than 1 mA, but will be brighter with more current. Use as a guide to selecting a series resistor based on the type of LED; the table also indicates the approximate current that will be drawn from the GPIO pin.

Selecting series resistors for LEDs and a 3.3V GPIO pin

Red

470Ω

3.5

Red

1kΩ

1.5

Orange, yellow, green

470Ω

2

Orange, yellow, green

1kΩ

1

Blue, white

100Ω

3

Blue, white

270Ω

1

As you can see, in all cases, it is safe to use a 470Ω resistor. If you are using a blue or white LED, you can reduce the value of the series resistor considerably. If you want to play it safe, use 1kΩ.

If you wanted to extend the experiments that you made in the Python console into a program that makes the LED blink on and off repeatedly, you could paste the following code into the IDLE (“Editing Python Programs with IDLE”) or nano (“Editing a File”) editors. Save the file as led_blink.py. You can also download the program from the Raspberry Pi Cookbook website. Follow the link to this book and then the Downloads section.

import RPi.GPIO as GPIO
17 | import time
18 | 
19 | GPIO.setmode(GPIO.BCM)
20 | GPIO.setup(18, GPIO.OUT)
21 | 
22 | while (True):
23 |     GPIO.output(18, True)
24 |     time.sleep(0.5)
25 |         GPIO.output(18, False)
26 |         time.sleep(0.5)

Remember that to run the program, you must have superuser privileges for the RPi.GPIO library, so you need to use this command:

$ sudo python led_blink.py

See Also

Check out this handy series resistor calculator.

For more information on using breadboard and jumper wires with the Raspberry Pi, see “Using a Breadboard with Jumper Leads”.

27 | -------------------------------------------------------------------------------- /Controlling_Servo_Motors.html: -------------------------------------------------------------------------------- 1 |

Controlling Servo Motors

2 | 3 | 4 | 5 |

Problem

You want to use a Raspberry Pi to control the position of a servo motor.

Solution

Use PWM to control the width of pulses to a servo motor to change its angle. Although this will work, the PWM generated is not completely stable, so there will be a little bit of jitter with the servo.

You should also power the servo from a separate 5V power supply because peaks in the load current are likely to crash or overload the Raspberry Pi.

To make this recipe, you will need:

The breadboard layout for this is shown in .

Controlling a servo motor

The 1kΩ resistor is not essential, but it does protect the GPIO pin from unexpectedly high currents in the control signal, which could occur if a fault developed on the servo.

The leads of the servo may not be the same as the colors indicated in . It is common for the 5V wire to be red, the ground brown, and the control lead orange.

You can, if you prefer, power the servo from a battery pack rather than a power supply. Using a four-cell AA battery holder with rechargeable batteries will provide around 4.8V and work well with a servo. Using four alkali AA cells to provide 6V will be fine for many servos, but check the datasheet of your servo to make sure it is OK with 6V.

The user interface for setting the angle of the servo is based on the gui_slider.py program intended for controlling the brightness of an LED (“Controlling the Brightness of an LED”). However, you can modify it so that the slider sets the angle, between 0 and 180 degrees ().

User interface for controlling a servo motor

Open an editor (nano or IDLE) and paste in the following code. As with all the program examples in this book, you can also download the program from the Code section of the Raspberry Pi Cookbook website, where it is called servo.py.

Note that this program uses a graphical user interface, so you cannot run it from SSH.

You must run it from the windowing environment on the Pi itself or via remote control using VNC (“Controlling the Pi Remotely with VNC”). You also need to run it as superuser, so run it with the command sudo python servo.py:

from Tkinter import *
14 | import RPi.GPIO as GPIO
15 | import time
16 | 
17 | GPIO.setmode(GPIO.BCM)
18 | GPIO.setup(18, GPIO.OUT)
19 | pwm = GPIO.PWM(18, 100)
20 | pwm.start(5)
21 | 
22 | class App:
23 | 
24 |     def __init__(self, master):
25 |         frame = Frame(master)
26 |         frame.pack()
27 |         scale = Scale(frame, from_=0, to=180,
28 |               orient=HORIZONTAL, command=self.update)
29 |         scale.grid(row=0)
30 | 
31 | 
32 |     def update(self, angle):
33 |         duty = float(angle) / 10.0 + 2.5
34 |         pwm.ChangeDutyCycle(duty)
35 | 
36 | root = Tk()
37 | root.wm_title('Servo Control')
38 | app = App(root)
39 | root.geometry("200x50+0+0")
40 | root.mainloop()

Discussion

Servo motors are used in remote control vehicles and robotics. Most servo motors are not continuous; that is, they cannot rotate all the way around but rather just over an angle of about 180 degrees.

The position of the servo motor is set by the length of a pulse. The servo expects to receive a pulse at least every 20 milliseconds. If that pulse is high for 1 millisecond, the servo angle will be zero; if it is 1.5 milliseconds, it will be at its center position; and if it is 2 milliseconds, it will be at 180 degrees ().

Servo motors

The example program sets the PWM frequency to 100 Hz, which will send a pulse to the servo every 10 milliseconds. The angle is converted into a duty cycle between 0 and 100. This actually produces pulses shorter than the 1 millisecond expected minimum value and longer than 2 milliseconds maximum.

See Also

If you have a lot of servos to control, or require greater stability and precision, then you can use a dedicated servo controller module, as described in “Controlling a Large Number of Servo Motors”.

Adafruit has developed another method of servo control.

For more information on using a breadboard and jumper wires with the Raspberry Pi, see “Using a Breadboard with Jumper Leads”.

41 | -------------------------------------------------------------------------------- /Finding_your_way_around_the_GPIO_connector.html: -------------------------------------------------------------------------------- 1 |

Finding Your Way Around the GPIO Connector

2 | 3 | 4 | 5 |

Problem

You need to connect electronics to the GPIO connector, but you need to know more about what all the pins do.

Solution

shows the GPIO pinout for both revisions 1 and 2 of the Raspberry Pi Model B. The quick way to tell the boards apart is that if you have an older revision 1 board, it has a black audio socket. The revision 2 boards have a blue audio socket.

The GPIO pinout

There were three changes to the GPIO connector between revision 1 and revision 2. These are highlighted in bold in . First, the I2C port was swapped. The two pins SDA and SCL are still SDA and SCL but use a different internal I2C interface. This means that if you’re using the pins as GPIO rather than I2C, then you will refer to them as 2 and 3 on a revision 2 board. Also, GPIO 21 was replaced by GPIO 27 on revision 2.

At the top of the connector, there are 3.3V and 5V power supplies. The GPIO uses 3.3V for all inputs and outputs. Any pin with a number next to it can act as a GPIO pin. Those that have another name after them also have some other special purpose, so 14 TXD and 15 RXD are the transmit and receive pins of the serial interface. SDA and SCL form the I2C interface, and MOSI, MISO, and SCKL from the SPI interface.

Discussion

A GPIO pin can be used as either a digital input or a digital output, and both operate at 3.3V. Unlike the Arduino, the Raspberry Pi does not have any analog inputs. For that you must use an external analog-to-digital converter (ADC) or connect the Pi to an interface board (like the Gertboard) or to an Arduino or an aLaMode board, as discussed in Chapter 14.

See Also

See “Measuring a Voltage” for connecting an ADC to a Raspberry Pi.

6 | -------------------------------------------------------------------------------- /Programming_an_Arduino_from_Raspberry_pi.html: -------------------------------------------------------------------------------- 1 |

Programming an Arduino from Raspberry Pi

2 | 3 | 4 | 5 |

Problem

You want to run the Arduino IDE on a Raspberry Pi so that you can write and upload programs onto an Arduino.

Solution

The Arduino IDE is available for the Raspberry Pi. It is a little bit slow, but usable. Use these commands to install it:

$ sudo apt-get update
 6 | $ sudo apt-get install arduino

At the time of writing, this installs version 1.0.1, which is not the latest version but will suit the Arduino Uno; it will not, however, work for newer boards like the Leonardo and Due. They can still be used with the Raspberry Pi, but you will need some other computer to program them before connecting them to the Raspberry Pi.

After installation, you will find an Electronics group in your Programs menu ().

The Arduino IDE running on Raspberry Pi

The Arduino IDE connects to the Raspberry Pi through its USB cable to program it. This connection also requires that the serial console be disabled. You can follow “Freeing the Serial Port” to do this, but a second option is to run a script created by Kevin Osborn that both disables the serial console and configures the serial ports and Arduino profiles necessary to get things running. This has the advantage that it also sets up the aLaMode board to be ready for use (“Getting Started with an aLaMode Board and a Raspberry Pi”).

To download and run this script, follow these steps:

$ wget https://github.com/wyolum/alamode/blob/master/bundles
 7 |   /alamode-setup.tar.gz?raw=true -O alamode-setup.tar.gz
 8 | $ tar -xvzf alamode-setup.tar.gz
 9 | $ cd alamode-setup
10 | $ sudo ./setup

If you have not previously disabled your serial console and are relying on the preceding script to do it, then you will need to reboot for this change to take effect.

$ sudo reboot

You can now connect your Arduino to your Raspberry Pi. From the Tools menu, select Board and set the board type to Arduino Uno. Then, from the Serial Port option, select /dev/ttyACM0. To upload a test program that will make the LED on the Arduino blink, select the File menu and then click "Examples, Basic," and finally click Blink. Click on the right-arrow on the toolbar to begin the compile and upload process. If all is well, you should see a "Done Uploading" message in the status area at the bottom of the IDE window.

If you find that the device ttyACM0 is not listed even though your Arduino is plugged in, try restarting the Arduino IDE. If that doesn’t work, then you may have to reboot your Raspberry Pi. Leave the Arduino connected while you reboot and restart the Arduino IDE.

Discussion

To get the most out of using Arduino with Raspberry Pi, you need to learn a little Arduino programming. You may find the book Programming Arduino: Getting Started with Sketches (McGraw-Hill/Tab Books), by yours truly, helpful.

You can, however, make use of an Arduino without needing to write any code on the Arduino side, using a project called PyFirmata. “Setting up PyFirmata to Control an Arduino from a Raspberry Pi” explains how to use PyFirmata.

See Also

The Arduino IDE setup script came from the blog Bald Wisdom.

11 | -------------------------------------------------------------------------------- /Raspberry_Pi_Radio_Transmitter.html: -------------------------------------------------------------------------------- 1 |

Raspberry Pi Radio Transmitter

2 | 3 | 4 | 5 |

Problem

You want to convert your Raspberry Pi into a high-powered FM transmitter that will send a radio signal to a normal FM radio receiver ().

Solution

The clever folks at Imperial College London have created some C code and a Python wrapper that allow you to do just this. The download even includes the theme from Star Wars to play as a sample.

All you need is a short length of wire attached to GPIO pin 4. A female-to-male header lead will work just fine for this. In fact, it should work with the radio right next to your Pi without any kind of antenna—such is the strength of the transmission.

Raspberry Pi as an FM transmitter

The first step is to install the pifm library using the following commands:

$ mkdir pifm
 6 | $ cd pifm
 7 | $ wget http://www.icrobotics.co.uk/wiki/images/c/c3/Pifm.tar.gz
 8 | $ tar -xzf Pifm.tar.gz

Next, find yourself an FM radio receiver and tune it to 103.0 MHz. If this frequency is already occupied by some other transmission, pick another frequency and make note of it.

Now run the following command (changing the final parameter from 103.0 to a different frequency if you had to change frequency):

sudo ./pifm sound.wav 103.0

If all is well, you should hear the stirring tones of the Star Wars theme.

Discussion

You need to know that this project may not be legal in your country. The power output is higher than that of FM transmitters used with MP3 players.

You can play other .wav files, but they must be 16-bit 44.1kHz mono.

The code also includes a Python library that you can use within your own Python programs. So, you could write yourself a user interface to allow the selection and playing of tunes.

The following fragment of code illustrates the use of the Python interface:

pi@raspberrypi ~/pifm $ sudo python
 9 | Python 2.7.3 (default, Jan 13 2013, 11:20:46)
10 | [GCC 4.6.3] on linux2
11 | Type "help", "copyright", "credits" or "license" for more information.
12 | >>> import PiFm
13 | >>> PiFm.play_sound("sound.wav")

Were you to put a Raspberry Pi in your vehicle, this would be a great way of outputting sound through the vehicle’s audio system.

See Also

This description is based on the original post from Imperial College London.

14 | -------------------------------------------------------------------------------- /Using_Resistive_Sensors.html: -------------------------------------------------------------------------------- 1 |

Using Resistive Sensors

2 | 3 | 4 | 5 |

Problem

You want to connect a variable resistor to a Raspberry Pi and measure the position of its rotation.

Solution

You can measure resistance on a Raspberry Pi using nothing more than a capacitor, a couple of resistors, and two GPIO pins. In this case, you will be able to read the position of the knob on a small variable resistor (trimpot).

To make this recipe, you will need:

shows the arrangement of components on the breadboard.

Measuring resistance on a Raspberry Pi

Open an editor (nano or IDLE) and paste in the following code. As with all the program examples in this book, you can also download the program from the Code section of the Raspberry Pi Cookbook website, where it is called pot_step.py.

import RPi.GPIO as GPIO
14 | import time
15 | 
16 | GPIO.setmode(GPIO.BCM)
17 | 
18 | a_pin = 18
19 | b_pin = 23
20 | 
21 | def discharge():
22 |     GPIO.setup(a_pin, GPIO.IN)
23 |     GPIO.setup(b_pin, GPIO.OUT)
24 |     GPIO.output(b_pin, False)
25 |     time.sleep(0.005)
26 | 
27 | def charge_time():
28 |     GPIO.setup(b_pin, GPIO.IN)
29 |     GPIO.setup(a_pin, GPIO.OUT)
30 |     count = 0
31 |     GPIO.output(a_pin, True)
32 |     while not GPIO.input(b_pin):
33 |         count = count + 1
34 |     return count
35 | 
36 | def analog_read():
37 |     discharge()
38 |     return charge_time()
39 | 
40 | while True:
41 |     print(analog_read())
42 |     time.sleep(1)

When you run the program, you should see some output like this:

$ sudo python pot_step.py
43 | 10
44 | 12
45 | 10
46 | 10
47 | 16
48 | 23
49 | 43
50 | 53
51 | 67
52 | 72
53 | 86
54 | 105
55 | 123
56 | 143
57 | 170

The reading will vary between about 10 and about 170 as you rotate the knob of the trimpot.

Discussion

To explain how this program works, I first need to explain how the step response technique can be used to measure the resistance of the variable resistor.

shows the schematic diagram for the recipe.

Measuring resistance using step response

This way of doing things is called step response because it works by seeing how the circuit responds from the step change when an output is switched from low to high.

You can think of a capacitor as a tank of electricity, and as it fills with charge, the voltage across it increases. You can’t measure that voltage directly, because the Raspberry Pi doesn’t have an ADC converter. However, you can time how long it takes for the capacitor to fill with charge to the extent that it gets above the 1.65V or so that constitutes a high digital input. The speed at which the capacitor fills with charge depends on the value of the variable resistor (Rt). The lower the resistance, the faster the capacitor fills with charge and the voltage rises.

To be able to get a good reading, you must also be able to empty the capacitor each time before you take a reading. In , connection A is used to charge the capacitor through Rc and Rt, and connection B is used to discharge (empty) the capacitor through Rd. The resistors Rc and Rd are used to make sure that there is no way too much current can flow as the capacitor is charged and discharged.

The steps involved in taking a reading are first to discharge the capacitor through Rd and then to let it charge through Rc and Rt.

To discharge it, connection A (GPIO 18) is set to be an input, effectively disconnecting Rc and Rt from the circuit. Connection B (GPIO 23) is then set to be an output and low. This is held there for 5 milliseconds to empty the capacitor.

Now that the capacitor is empty, you can start to allow charge to flow into it by setting connection B to be an input (effectively disconnecting it) and then enabling connection A to be a high output at 3.3V. Capacitor C will now begin to charge through Rc and Rt. The while loop will then simply count as fast as possible until the voltage at connection B switches from being low to high at about 1.65V.

At that point, the counting stops and the count value is returned.

shows how a resistor and capacitor in this kind of arrangement charge and discharge as the voltage is toggled between high and low.

Charging and discharging a capacitor

You can see that the voltage at the capacitor increases rapidly at first but then tails off as the capacitor becomes full. Fortunately, you are interested in the area of the curve up until the capacitor reaches about 1.65V, which is a fairly straight line, meaning that the time taken for the voltage across the capacitor to rise to this point is roughly proportional to the resistance of Rt and hence the position of the knob.

This approach is not hugely accurate, but it is very low cost and easy to use.

See Also

Using a step response works well with all kinds of resistive sensors for light (“Measuring Light”) and even gas detection (“Detecting Methane”).

For more accurate measurements of the trimpot position, see “Measuring a Voltage”, where the pot is used with an ADC converter.

58 | -------------------------------------------------------------------------------- /Using_a_4-Digit_LED_Display.html: -------------------------------------------------------------------------------- 1 |

Using a Four-Digit LED Display

2 | 3 | 4 | 5 |

Problem

You want to display a four-digit number in an old-fashioned, seven-segment LED display.

Solution

Use an I2C LED module, such as the model shown in attached via a breadboard to a Raspberry Pi.

Seven-segment LED display with Raspberry Pi

To make this recipe, you need:

shows the arrangement of components on the breadboard.

The breadboard layout for an LED display with Raspberry Pi

For this recipe to work, you will also need to set up your Raspberry Pi for I2C, so follow “Setting up I2C” first.

The display has an accompanying Python library written by Adafruit. It isn’t installed as a proper library, so to use it, you first need to download the folder structure. If you do not have Git installed, install it now with the following command (see “Fetching Source Code with git”).

$ sudo apt-get install git

Now, you can download the folder structure from GitHub:

$ git clone https://github.com/adafruit/Adafruit-Raspberry-Pi-Python-Code.git

Change directory into the Adafruit code using:

$ cd Adafruit-Raspberry-Pi-Python-Code
10 | $ cd Adafruit_LEDBackpack

In this folder, you will find a test program that will display the time. Run it using the command:

$ sudo python ex_7segment_clock.py

Discussion

If you open the example file ex_7segment_clock.py in nano, you’ll see that the key commands are:

from Adafruit_7Segment import SevenSegment

which import the library code into your program. You then need to create a instance of SevenSegment using the next line of code. The address supplied as an argument is the I2C address (see “Setting up I2C”).

Every I2C slave device has an address number. The LED board has three pairs of solder pads on the back that can be bridged with solder if you want to change the address. This is essential if you need to operate more than one of the displays from a single Raspberry Pi.

segment = SevenSegment(address=0x70)

To actually set the contents of a particular digit, use a line like this one:

segment.writeDigit(0, int(hour / 10))

The first argument (0) is the digit position. Note that these positions are 0, 1, 3, and 4. Position 2 is reserved for the two dots in the center of the display.

The second argument is the number to display.

See Also

You can find out more about the Adafruit library at http://bit.ly/HQBE6W.

11 | -------------------------------------------------------------------------------- /Using_a_RaspiRobot_Board_to_Drive_a_Bi-Polar_Stepper_Motor.html: -------------------------------------------------------------------------------- 1 |

Using a RaspiRobot Board to Drive a Bipolar Stepper Motor

2 | 3 | 4 | 5 |

Problem

You want to control a bipolar stepper motor using a RaspiRobot board.

Solution

The RaspiRobot board uses the same L293D dual H-Bridge chip that you used in “Using a Bipolar Stepper Motor”.

The RaspiRobot board uses the power supply directly from its DC socket as the supply to the motor and regulates that same supply down to 5V to drive the Raspberry Pi. So in this case, the 12V power will be supplying both the 12V stepper motor and the Raspberry Pi.

The Raspberry Pi should not be powered through its USB connection when the RaspiRobot board is also powered, or slight differences in the 5V from the Raspberry Pi USB and the 5V regulated supply from the RaspiRobot board could cause large currents to flow and damage either the board or the Raspberry Pi. Power one board or the other, but not both.

Connect the stepper motor and power supply to the RaspiRobot board as shown in . The wire colors for the Adafruit 12V stepper motor are in order, from nearest the DC socket: yellow, red, grey, and green.

Using a RaspiRobot board to control a bipolar stepper motor

With a little modification to the pin allocations and step sequence, we can use the program from “Using a Bipolar Stepper Motor” with a RaspiRobot board.

Open an editor (nano or IDLE) and paste in the following code. As with all the program examples in this book, you can also download the program from the Code section of the Raspberry Pi Cookbook website, where it is called stepper_rrb.py. This program uses the command line, so you can run it from SSH.

If you’re using Python 3, change the command raw_input to just input:

import RPi.GPIO as GPIO
 6 | import time
 7 | 
 8 | GPIO.setmode(GPIO.BCM)
 9 | 
10 | coil_A_1_pin = 17
11 | coil_A_2_pin = 4
12 | coil_B_1_pin = 10
13 | coil_B_2_pin = 25
14 | 
15 | GPIO.setup(coil_A_1_pin, GPIO.OUT)
16 | GPIO.setup(coil_A_2_pin, GPIO.OUT)
17 | GPIO.setup(coil_B_1_pin, GPIO.OUT)
18 | GPIO.setup(coil_B_2_pin, GPIO.OUT)
19 | 
20 | forward_seq = ['1011', '1111', '1110', '1010']
21 | reverse_seq = list(forward_seq) # to copy the list
22 | reverse_seq.reverse()
23 | 
24 | def forward(delay, steps):
25 |   for i in range(steps):
26 |     for step in forward_seq:
27 |       set_step(step)
28 |       time.sleep(delay)
29 | 
30 | def backwards(delay, steps):
31 |   for i in range(steps):
32 |     for step in reverse_seq:
33 |       set_step(step)
34 |       time.sleep(delay)
35 | 
36 | 
37 | def set_step(step):
38 |   GPIO.output(coil_A_1_pin, step[0] == '1')
39 |   GPIO.output(coil_A_2_pin, step[1] == '1')
40 |   GPIO.output(coil_B_1_pin, step[2] == '1')
41 |   GPIO.output(coil_B_2_pin, step[3] == '1')
42 | 
43 | while True:
44 |   set_step('0000')
45 |   delay = raw_input("Delay between steps (milliseconds)?")
46 |   steps = raw_input("How many steps forward? ")
47 |   forward(int(delay) / 1000.0, int(steps))
48 |   set_step('0000')
49 |   steps = raw_input("How many steps backwards? ")
50 |   backwards(int(delay) / 1000.0, int(steps))

Discussion

The RaspiRobot board uses the L293D in a different arrangement from how you used it in “Controlling the Direction of a DC Motor”, as it uses a pin to enable each channel (pins 17 and 10), and a second pair of pins that controls the direction of each motor (pins 4 and 25). This means that as well as changing the pin allocations, you also need to modify the step sequence to:

forward_seq = ['1011', '1111', '1110', '1010']

The first and third bit of each part of the sequence are always 1, enabling both motors. It is now only the second and fourth bits that control the polarity of each of the two stepper windings.

See Also

You can find out more about the RaspiRobot board and other projects that use it at the RaspiRobot website.

To drive a stepper motor using a L293D on a breadboard, see “Using a Bipolar Stepper Motor”.

51 | -------------------------------------------------------------------------------- /Using_lots_of_LEDs.html: -------------------------------------------------------------------------------- 1 |

Using Lots of LEDs (Charlieplexing)

2 | 3 | 4 | 5 |

Problem

You want to control lots of LEDs using as few GPIO pins as possible.

Solution

The way to do this is to use a technique called Charlieplexing. The name comes from the inventor, Charlie Allen of the company Maxim, and the technique takes advantage of the feature of GPIO pins that allows them to be changed from outputs to inputs while a program is running. When a pin is changed to be an input, not enough current will flow through it to light an LED or influence other pins connected to the LED that are set as outputs.

shows the arrangement for controlling six LEDs with three pins.

Charlieplexing

shows the breadboard layout for the LEDs and resistors.

Charlieplexing breadboard layout

To make this recipe, you will need:

Open an editor (nano or IDLE) and paste in the following code. As with all the program examples in this book, you can also download the program from the Code section of the Raspberry Pi Cookbook website, where it is called charlieplexing.py.

This example code prompts you to enter a number between 0 and 5 and then lights one of the six LEDs:

import RPi.GPIO as GPIO
12 | 
13 | pins = [18, 23, 24]
14 | 
15 | pin_led_states = [
16 |   [1, 0, -1], # A
17 |   [0, 1, -1], # B
18 |   [-1, 1, 0], # C
19 |   [-1, 0, 1], # D
20 |   [1, -1, 0], # E
21 |   [0, -1, 1]  # F
22 | ]
23 | 
24 | GPIO.setmode(GPIO.BCM)
25 | 
26 | def set_pin(pin_index, pin_state):
27 |     if pin_state == -1:
28 |         GPIO.setup(pins[pin_index], GPIO.IN)
29 |     else:
30 |         GPIO.setup(pins[pin_index], GPIO.OUT)
31 |         GPIO.output(pins[pin_index], pin_state)
32 | 
33 | def light_led(led_number):
34 |     for pin_index, pin_state in enumerate(pin_led_states[led_number]):
35 |         set_pin(pin_index, pin_state)
36 | 
37 | set_pin(0, -1)
38 | set_pin(1, -1)
39 | set_pin(2, -1)
40 | 
41 | while True:
42 |     x = int(raw_input("Pin (0 to 5):"))
43 |     light_led(x)

Discussion

To understand how Charlieplexing works, imagine that you want to light LED A in . An LED will only light when its positive lead is high, and its negative lead is low. If the voltage is the other way around, it will not light. To light LED A, you need its lead connected to GPIO 18 (via a resistor) to be high and the other lead to LED A, connected to GPIO 23 by a resistor, to be low. However, you must also make sure that GPIO 24 is set to be an input; otherwise, LED C or D will also light depending on whether GPIO 24 is high or low.

The array pin_led_states holds the settings for each GPIO for each of the six LEDs. If the value is 0, the pin is low; 1 means high and -1 means set to be an input.

The number of LEDs that can be controlled per GPIO pin is given by the formula:

LEDs = n2 - n

Using 4 pins, we can have 16, 4, or 12 LEDs, whereas 10 pins would give you a massive 90 LEDs.

In this example, you’re lighting only one LED at a time. To light more than one at a time, you need to run a refresh loop that keeps the desired state of the LEDs in an array and refreshes the display, turning on the LEDs that need to be on before moving on to the next. It must do this sufficiently fast so that it appears that more than one of the LEDs is on at the same time.

The more LEDs you use when it comes to making it appear that more than one LED is on at a time, the less time the LED will actually be lit, and the dimmer the LEDs will become.

See Also

For more information about Charlieplexing, see Wikipedia. If you are interested in using only a single LED, see “Connecting an LED”.

44 | -------------------------------------------------------------------------------- /atlas.json: -------------------------------------------------------------------------------- 1 | { 2 | "files": [ 3 | "Raspberry_Pi_Radio_Transmitter.html", 4 | "Finding_your_way_around_the_GPIO_connector.html", 5 | "Connecting_an_LED.html", 6 | "Using_lots_of_LEDs.html", 7 | "Controlling_Servo_Motors.html", 8 | "Using_a_RaspiRobot_Board_to_Drive_a_Bi-Polar_Stepper_Motor.html", 9 | "Connecting_a_Push_Switch.html", 10 | "Using_Resistive_Sensors.html", 11 | "Using_a_4-Digit_LED_Display.html", 12 | "Programming_an_Arduino_from_Raspberry_pi.html" 13 | ], 14 | "formats": { 15 | "pdf": { 16 | "version": "web", 17 | "index": false, 18 | "toc": false 19 | }, 20 | "epub": { 21 | "index": false, 22 | "toc": false, 23 | "epubcheck": false 24 | }, 25 | "mobi": { 26 | "index": false, 27 | "toc": false 28 | }, 29 | "html": { 30 | "index": false, 31 | "toc": true, 32 | "consolidated": false, 33 | "javascripts": [ 34 | "theme/html/analytics.js" 35 | ] 36 | } 37 | }, 38 | "theme": "", 39 | "title": "razzpisampler" 40 | } -------------------------------------------------------------------------------- /images/get_started.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oreilly-media-content/razzpisampler/cda93e517bc40bec48a92f7b82b09cb3907f4b52/images/get_started.png -------------------------------------------------------------------------------- /images/rpck_0411.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oreilly-media-content/razzpisampler/cda93e517bc40bec48a92f7b82b09cb3907f4b52/images/rpck_0411.png -------------------------------------------------------------------------------- /images/rpck_0801.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oreilly-media-content/razzpisampler/cda93e517bc40bec48a92f7b82b09cb3907f4b52/images/rpck_0801.png -------------------------------------------------------------------------------- /images/rpck_0901.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oreilly-media-content/razzpisampler/cda93e517bc40bec48a92f7b82b09cb3907f4b52/images/rpck_0901.png -------------------------------------------------------------------------------- /images/rpck_0912.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oreilly-media-content/razzpisampler/cda93e517bc40bec48a92f7b82b09cb3907f4b52/images/rpck_0912.png -------------------------------------------------------------------------------- /images/rpck_0913.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oreilly-media-content/razzpisampler/cda93e517bc40bec48a92f7b82b09cb3907f4b52/images/rpck_0913.png -------------------------------------------------------------------------------- /images/rpck_1001.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oreilly-media-content/razzpisampler/cda93e517bc40bec48a92f7b82b09cb3907f4b52/images/rpck_1001.png -------------------------------------------------------------------------------- /images/rpck_1002.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oreilly-media-content/razzpisampler/cda93e517bc40bec48a92f7b82b09cb3907f4b52/images/rpck_1002.png -------------------------------------------------------------------------------- /images/rpck_1003.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oreilly-media-content/razzpisampler/cda93e517bc40bec48a92f7b82b09cb3907f4b52/images/rpck_1003.png -------------------------------------------------------------------------------- /images/rpck_1014.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oreilly-media-content/razzpisampler/cda93e517bc40bec48a92f7b82b09cb3907f4b52/images/rpck_1014.png -------------------------------------------------------------------------------- /images/rpck_1101.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oreilly-media-content/razzpisampler/cda93e517bc40bec48a92f7b82b09cb3907f4b52/images/rpck_1101.png -------------------------------------------------------------------------------- /images/rpck_1102.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oreilly-media-content/razzpisampler/cda93e517bc40bec48a92f7b82b09cb3907f4b52/images/rpck_1102.png -------------------------------------------------------------------------------- /images/rpck_1201.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oreilly-media-content/razzpisampler/cda93e517bc40bec48a92f7b82b09cb3907f4b52/images/rpck_1201.png -------------------------------------------------------------------------------- /images/rpck_1202.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oreilly-media-content/razzpisampler/cda93e517bc40bec48a92f7b82b09cb3907f4b52/images/rpck_1202.png -------------------------------------------------------------------------------- /images/rpck_1203.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oreilly-media-content/razzpisampler/cda93e517bc40bec48a92f7b82b09cb3907f4b52/images/rpck_1203.png -------------------------------------------------------------------------------- /images/rpck_1301.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oreilly-media-content/razzpisampler/cda93e517bc40bec48a92f7b82b09cb3907f4b52/images/rpck_1301.png -------------------------------------------------------------------------------- /images/rpck_1302.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oreilly-media-content/razzpisampler/cda93e517bc40bec48a92f7b82b09cb3907f4b52/images/rpck_1302.png -------------------------------------------------------------------------------- /images/rpck_1402.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oreilly-media-content/razzpisampler/cda93e517bc40bec48a92f7b82b09cb3907f4b52/images/rpck_1402.png -------------------------------------------------------------------------------- /images/toc_01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oreilly-media-content/razzpisampler/cda93e517bc40bec48a92f7b82b09cb3907f4b52/images/toc_01.png -------------------------------------------------------------------------------- /images/toc_02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oreilly-media-content/razzpisampler/cda93e517bc40bec48a92f7b82b09cb3907f4b52/images/toc_02.png -------------------------------------------------------------------------------- /images/toc_03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oreilly-media-content/razzpisampler/cda93e517bc40bec48a92f7b82b09cb3907f4b52/images/toc_03.png -------------------------------------------------------------------------------- /images/toc_04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oreilly-media-content/razzpisampler/cda93e517bc40bec48a92f7b82b09cb3907f4b52/images/toc_04.png -------------------------------------------------------------------------------- /images/toc_05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oreilly-media-content/razzpisampler/cda93e517bc40bec48a92f7b82b09cb3907f4b52/images/toc_05.png -------------------------------------------------------------------------------- /images/toc_06.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oreilly-media-content/razzpisampler/cda93e517bc40bec48a92f7b82b09cb3907f4b52/images/toc_06.png -------------------------------------------------------------------------------- /images/toc_07.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oreilly-media-content/razzpisampler/cda93e517bc40bec48a92f7b82b09cb3907f4b52/images/toc_07.png -------------------------------------------------------------------------------- /images/toc_08.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oreilly-media-content/razzpisampler/cda93e517bc40bec48a92f7b82b09cb3907f4b52/images/toc_08.png -------------------------------------------------------------------------------- /images/toc_09.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oreilly-media-content/razzpisampler/cda93e517bc40bec48a92f7b82b09cb3907f4b52/images/toc_09.png -------------------------------------------------------------------------------- /images/toc_10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oreilly-media-content/razzpisampler/cda93e517bc40bec48a92f7b82b09cb3907f4b52/images/toc_10.png -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Raspberry Pi Cookbook 6 | 7 | 8 | 9 | 10 | 20 | 21 | 22 | 23 | 28 | 29 |
30 | 31 |
32 |
33 | Raspberry Pi Cookbook 34 |
35 |
36 | 37 |
38 |
39 |

A sampler of companion videos and excerpts from Raspberry Pi Cookbook by Simon Monk.

40 |
41 |
42 | 43 |
44 |
45 |
46 |

Get Started

47 |
48 | 49 |
50 |
51 |

About Simon Monk

52 |
53 | 54 |
55 |
56 |

About the Book

57 |
58 | 59 |
60 |
61 |

About the Videos

62 |
63 |
64 | 65 |
66 |
67 |

Sampler Contents

68 |
69 |
70 | 71 |
72 |
73 | 74 |

1. Raspberry Pi Radio Transmitter

75 |

(from Chapter 4, "Software")

76 |
77 | 78 |
79 | 80 |

2. Finding Your Way Around the GPIO Connector

81 |

(from Chapter 8, "GPIO Basics")

82 |
83 | 84 |
85 | 86 |

3. Connecting an LED

87 |

(from Chapter 9, "Controlling Hardware")

88 |
89 | 90 |
91 | 92 |

4. Using Lots of LEDs (Charlieplexing)

93 |

(from Chapter 9, "Controlling Hardware")

94 |
95 |
96 | 97 |
98 |
99 | 100 |

5. Controlling Servo Motors

101 |

(from Chapter 10, "Motors")

102 |
103 | 104 |
105 | 106 |

6. Using a RaspiRobot Board to Drive a Bipolar Stepper Motor

107 |

(from Chapter 10, "Motors")

108 |
109 | 110 |
111 | 112 |

7. Connecting a Push Switch

113 |

(from Chapter 11, "Digital Inputs")

114 |
115 | 116 |
117 | 118 |

8. Using Resistive Sensors

119 |

(from Chapter 12, "Sensors")

120 |
121 |
122 | 123 |
124 |
125 | 126 |

9. Using a Four-Digit LED Display

127 |

(from Chapter 13, "Displays")

128 |
129 | 130 |
131 | 132 |

10. Programming an Arduino from Raspberry Pi

133 |

(from Chapter 14, "Arduino and Raspberry Pi")

134 |
135 |
136 | 137 |
138 | 139 | 157 | 158 | 159 | 160 | -------------------------------------------------------------------------------- /theme/html/analytics.js: -------------------------------------------------------------------------------- 1 | window.analytics||(window.analytics=[]),window.analytics.methods=["identify","track","trackLink","trackForm","trackClick","trackSubmit","page","pageview","ab","alias","ready","group","on","once","off"],window.analytics.factory=function(t){return function(){var a=Array.prototype.slice.call(arguments);return a.unshift(t),window.analytics.push(a),window.analytics}};for(var i=0;i li:nth-child(even) > a, 44 | .navbar .nav > li > a:focus, 45 | .navbar .nav > li > a:hover { 46 | background-color: #00adef; } 47 | 48 | .navbar .nav > li { 49 | border-left: 1px solid #63D1F4; 50 | } 51 | 52 | .navbar .nav > li:last-child { 53 | border-right: 1px solid #63D1F4; 54 | } 55 | 56 | nav[data-type="toc"] ol li ol { 57 | display: none; 58 | } 59 | 60 | div.navigation { 61 | margin-top: 30px; 62 | overflow: auto; 63 | width: 100%; 64 | } 65 | 66 | div.navigation ul { 67 | padding-left: 0; 68 | } 69 | 70 | div.navigation ul li { 71 | display: inline-block; 72 | padding: 7px; 73 | } 74 | 75 | div.navigation ul li.prev:before { 76 | content: "< "; 77 | } 78 | 79 | div.navigation ul li.next:after { 80 | content: " >"; 81 | } 82 | 83 | div.navigation ul li.prev { 84 | float: left; 85 | } 86 | 87 | div.navigation ul li.next { 88 | float: right; 89 | } 90 | 91 | .booktitle { 92 | background-image: url("bird.png"); 93 | background-repeat: no-repeat; 94 | background-position: right top; 95 | border-bottom: 2px solid #00adef; 96 | } 97 | 98 | .booktitle img { 99 | width: 600px; 100 | height: auto; 101 | display: block; 102 | margin-top: 30px; 103 | margin-bottom: 30px; 104 | } 105 | 106 | .lede { 107 | font-size: 1.1em; 108 | text-align: center; 109 | margin-top: 20px; 110 | margin-bottom: 40px; 111 | } 112 | 113 | .lede p { 114 | margin-bottom: 0; 115 | } 116 | 117 | .bluetop { 118 | border-top: 2px solid #00adef; 119 | } 120 | 121 | img.toc { 122 | width: 100px; 123 | border: 1px solid #d8d8d8; 124 | border-radius: 10px; 125 | -webkit-border-radius: 10px; 126 | -moz-border-radius: 10px; 127 | } 128 | 129 | .featured img { 130 | height: 130px; 131 | width: auto; 132 | -webkit-box-shadow:0 0 2px 0 #808080; 133 | box-shadow:0 0 2px 0 #808080; 134 | } 135 | 136 | p.supplemental { 137 | font-size: 0.8em; 138 | margin-top: 0; 139 | } 140 | 141 | .logo.logo-white { 142 | background-image: url("logo-white.svg"); 143 | height: 16px; 144 | width: 85px; 145 | } 146 | 147 | .logo.logo-white-titleonly { 148 | background-image: url("logo-white-titleonly.svg"); 149 | height: 16px; 150 | width: 220px; 151 | } 152 | 153 | div.booklink { 154 | text-align: center; 155 | } 156 | 157 | div.booklink img { 158 | max-height: 120px; 159 | } 160 | 161 | figure { 162 | text-align: center; 163 | } 164 | 165 | figcaption { 166 | font-style: italic; 167 | margin: 10px 0 10px 0; 168 | } 169 | 170 | pre { 171 | margin-left: 30px; 172 | } 173 | 174 | div[data-type="note"], div.navigation li { 175 | background-color: #F0F8FF; 176 | border-radius: 5px; 177 | -webkit-border-radius: 5px; 178 | -moz-border-radius: 5px; 179 | border: 1px solid #63D1F4; 180 | padding: 1px 10px; 181 | margin: 30px 0; 182 | } 183 | 184 | @media (min-width: 768px) and (max-width: 979px) { 185 | 186 | } 187 | 188 | @media (max-width: 767px) { 189 | 190 | .titlepage { 191 | background-size: 100% auto; 192 | width: 100%; 193 | height: 100px; 194 | } 195 | } -------------------------------------------------------------------------------- /theme/html/html.xsl: -------------------------------------------------------------------------------- 1 | 9 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /theme/html/layout.html: -------------------------------------------------------------------------------- 1 | {{ doctype }} 2 | 3 | 4 | 5 | {{ title }} 6 | 7 | {{ header }} 8 | 9 | 10 | 19 | 20 | 21 | 22 | Discuss on GitHub 23 | 24 | 34 | 35 |
36 |
37 |
38 | 39 | {{ content }} 40 | 41 | 47 | 48 |
49 | 50 |
51 |

Sampler Contents:

52 | {{ toc }} 53 | 54 | 58 | 59 |
60 |
61 |
62 | 63 | 81 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /theme/html/logo-white-titleonly.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 16 | 25 | 34 | 43 | 50 | 58 | 65 | 72 | 80 | 87 | 92 | 99 | 103 | 107 | 117 | 124 | 128 | 132 | 142 | 143 | 144 | -------------------------------------------------------------------------------- /theme/html/logo-white.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | 10 | 12 | 13 | 14 | 15 | 20 | 23 | 25 | 27 | 28 | 31 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /theme/html/syntax.css: -------------------------------------------------------------------------------- 1 | /* ----------------- syntax highlighting and coloring text in general ----------------- */ 2 | 3 | /* legacy stuff */ 4 | code.boolean, .navy { 5 | color: rgb(0,0,128); /* navy */ 6 | } 7 | code.character, .olive { 8 | color: rgb(128,128,0); /* olive */ 9 | } 10 | code.comment, .blue { 11 | color: rgb(0,0,255); /* blue */ 12 | } 13 | code.conditional, .limegreen { 14 | color: rgb(50,205,50); /* limegreen */ 15 | } 16 | code.constant, .darkorange { 17 | color: rgb(255,140,0); /* darkorange */ 18 | } 19 | code.debug, .darkred { 20 | color: rgb(139,0,0); /* darkred */ 21 | } 22 | code.define, .darkgoldenrod, .gold { 23 | color: rgb(184,134,11); /* darkgoldenrod */ 24 | } 25 | code.delimiter, .dimgray { 26 | color: rgb(105,105,105); /* dimgray */ 27 | } 28 | code.error, .red { 29 | color: rgb(255,0,0); /* red */ 30 | } 31 | code.exception, .salmon { 32 | color: rgb(250,128,11); /* salmon */ 33 | } 34 | code.float, .steelblue { 35 | color: rgb(70,130,180); /* steelblue */ 36 | } 37 | pre code.function, .green { 38 | color: rgb(0,128,0); /* green */ 39 | } 40 | code.identifier, .royalblue { 41 | color: rgb(65,105,225); /* royalblue */ 42 | } 43 | code.ignore, .gray { 44 | color: rgb(128,128,128); /* gray */ 45 | } 46 | code.include, .purple { 47 | color: rgb(128,0,128); /* purple */ 48 | } 49 | code.keyword, .sienna { 50 | color: rgb(160,82,45); /* sienna */ 51 | } 52 | code.label, .deeppink { 53 | color: rgb(255,20,147); /* deeppink */ 54 | } 55 | code.macro, .orangered { 56 | color: rgb(255,69,0); /* orangered */ 57 | } 58 | code.number, .brown { 59 | color: rgb(165,42,42); /* brown */ 60 | } 61 | code.operator, .black { 62 | color: #000; /* black */ 63 | } 64 | code.preCondit, .teal { 65 | color: rgb(0,128,128); /* teal */ 66 | } 67 | code.preProc, .fuschia { 68 | color: rgb(255,0,255); /* fuschia */ 69 | } 70 | code.repeat, .indigo { 71 | color: rgb(75,0,130); /* indigo */ 72 | } 73 | code.special, .saddlebrown { 74 | color: rgb(139,69,19); /* saddlebrown */ 75 | } 76 | code.specialchar, .magenta { 77 | color: rgb(255,0,255); /* magenta */ 78 | } 79 | code.specialcomment, .seagreen { 80 | color: rgb(46,139,87); /* seagreen */ 81 | } 82 | code.statement, .forestgreen { 83 | color: rgb(34,139,34); /* forestgreen */ 84 | } 85 | code.storageclass, .plum { 86 | color: rgb(221,160,221); /* plum */ 87 | } 88 | code.string, .darkred { 89 | color: rgb(139,0,0); /* darkred */ 90 | } 91 | code.structure, .chocolate { 92 | color: rgb(210,106,30); /* chocolate */ 93 | } 94 | code.tag, .darkcyan { 95 | color: rgb(0,139,139); /* darkcyan */ 96 | } 97 | code.todo, .black { 98 | color: #000; /* black */ 99 | } 100 | code.type, .mediumslateblue { 101 | color: rgb(123,104,238); /* mediumslateblue */ 102 | } 103 | code.typedef, .darkgreen { 104 | color: rgb(0,100,0); /* darkgreen */ 105 | } 106 | code.underlined { 107 | text-decoration: underline; /* guess what */ 108 | } 109 | 110 | /* Pygments with manni theme */ 111 | pre code.hll { background-color: #ffffcc } 112 | pre code.c { color: #0099FF; font-style: italic } /* Comment */ 113 | pre code.err { color: #AA0000 } /* Error */ 114 | pre code.k { color: #006699; font-weight: bold } /* Keyword */ 115 | pre code.o { color: #555555 } /* Operator */ 116 | pre code.cm { color: #35586C; font-style: italic } /* Comment.Multiline */ 117 | pre code.cp { color: #009999 } /* Comment.Preproc */ 118 | pre code.c1 { color: #35586C; font-style: italic } /* Comment.Single */ 119 | pre code.cs { color: #35586C; font-weight: bold; font-style: italic } /* Comment.Special */ 120 | pre code.gd { background-color: #FFCCCC } /* Generic.Deleted */ 121 | pre code.ge { font-style: italic } /* Generic.Emph */ 122 | pre code.gr { color: #FF0000 } /* Generic.Error */ 123 | pre code.gh { color: #003300; font-weight: bold } /* Generic.Heading */ 124 | pre code.gi { background-color: #CCFFCC } /* Generic.Inserted */ 125 | 126 | /* Overriding default manni style of #AAAAAA gray for Generic Output with #000000 black, which is better suited to ORM terminal output */ 127 | pre code.go { color: #000000 } /* Generic.Output */ 128 | 129 | pre code.gp { color: #000099; font-weight: bold } /* Generic.Prompt */ 130 | pre code.gs { font-weight: bold } /* Generic.Strong */ 131 | pre code.gu { color: #003300; font-weight: bold } /* Generic.Subheading */ 132 | pre code.gt { color: #99CC66 } /* Generic.Traceback */ 133 | pre code.kc { color: #006699; font-weight: bold } /* Keyword.Constant */ 134 | pre code.kd { color: #006699; font-weight: bold } /* Keyword.Declaration */ 135 | pre code.kn { color: #006699; font-weight: bold } /* Keyword.Namespace */ 136 | pre code.kp { color: #006699 } /* Keyword.Pseudo */ 137 | pre code.kr { color: #006699; font-weight: bold } /* Keyword.Reserved */ 138 | pre code.kt { color: #007788; font-weight: bold } /* Keyword.Type */ 139 | pre code.m { color: #FF6600 } /* Literal.Number */ 140 | pre code.s { color: #CC3300 } /* Literal.String */ 141 | pre code.na { color: #330099 } /* Name.Attribute */ 142 | pre code.nb { color: #336666 } /* Name.Builtin */ 143 | pre code.nc { color: #00AA88; font-weight: bold } /* Name.Class */ 144 | pre code.no { color: #336600 } /* Name.Constant */ 145 | pre code.nd { color: #9999FF } /* Name.Decorator */ 146 | pre code.ni { color: #999999; font-weight: bold } /* Name.Entity */ 147 | pre code.ne { color: #CC0000; font-weight: bold } /* Name.Exception */ 148 | pre code.nf { color: #CC00FF } /* Name.Function */ 149 | pre code.nl { color: #9999FF } /* Name.Label */ 150 | pre code.nn { color: #00CCFF; font-weight: bold } /* Name.Namespace */ 151 | pre code.nt { color: #330099; font-weight: bold } /* Name.Tag */ 152 | pre code.nv { color: #003333 } /* Name.Variable */ 153 | pre code.ow { color: #000000; font-weight: bold } /* Operator.Word */ 154 | pre code.w { color: #bbbbbb } /* Text.Whitespace */ 155 | pre code.mf { color: #FF6600 } /* Literal.Number.Float */ 156 | pre code.mh { color: #FF6600 } /* Literal.Number.Hex */ 157 | pre code.mi { color: #FF6600 } /* Literal.Number.Integer */ 158 | pre code.mo { color: #FF6600 } /* Literal.Number.Oct */ 159 | pre code.sb { color: #CC3300 } /* Literal.String.Backtick */ 160 | pre code.sc { color: #CC3300 } /* Literal.String.Char */ 161 | pre code.sd { color: #CC3300; font-style: italic } /* Literal.String.Doc */ 162 | pre code.s2 { color: #CC3300 } /* Literal.String.Double */ 163 | pre code.se { color: #CC3300; font-weight: bold } /* Literal.String.Escape */ 164 | pre code.sh { color: #CC3300 } /* Literal.String.Heredoc */ 165 | pre code.si { color: #AA0000 } /* Literal.String.Interpol */ 166 | pre code.sx { color: #CC3300 } /* Literal.String.Other */ 167 | pre code.sr { color: #33AAAA } /* Literal.String.Regex */ 168 | pre code.s1 { color: #CC3300 } /* Literal.String.Single */ 169 | 170 | /* Overriding manni default yellow #FFCC33 with brown #AA6600, which is easier to read */ 171 | pre code.ss { color: #AA6600 } /* Literal.String.Symbol */ 172 | 173 | pre code.bp { color: #336666 } /* Name.Builtin.Pseudo */ 174 | pre code.vc { color: #003333 } /* Name.Variable.Class */ 175 | pre code.vg { color: #003333 } /* Name.Variable.Global */ 176 | pre code.vi { color: #003333 } /* Name.Variable.Instance */ 177 | pre code.il { color: #FF6600 } /* Literal.Number.Integer.Long */ 178 | 179 | /* Sanders's additions to manni */ 180 | pre code.g { color: #005500 } /* Generic */ 181 | pre code.l { color: #CC6600 } /* Literal */ 182 | pre code.l { color: #FF9900 } /* Literal.Date */ 183 | pre code.n { color: #000088 } /* Name */ 184 | pre code.nx { color: #000088 } /* Name.Other */ 185 | pre code.py { color: #9966FF } /* Name.Property */ 186 | pre code.p { color: #000000 } /* Punctuation */ 187 | pre code.x { color: #FF0066 } /* Other */ -------------------------------------------------------------------------------- /theme/html/titlepage.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 16 | 24 | 32 | 39 | 45 | 52 | 57 | 62 | 69 | 75 | 79 | 85 | 89 | 93 | 101 | 107 | 111 | 115 | 123 | 124 | 125 | --------------------------------------------------------------------------------