Saturday, January 31, 2015

Install pip on Raspberry Pi

pip is a recommended tool for installing Python packages.

To install pip for Python2 on Raspberry Pi:
$ sudo apt-get install python-pip

To install pip for Python3 (or Python3.2) on Raspberry Pi:
$ sudo apt-get install python3-pip

To install any package:
$ pip install package
for Python2.
$ pip-3.2 install package
for Python3.

To uninstall any package:
$ pip uninstall package
for Python2.
$ pip-3.2 uninstall package
for Python3.

Thursday, January 29, 2015

Raspberry Pi System Software Reference

Raspberry Pi System Software Reference

Raspberry Pi is Linux, but it's a unique flavor of Linux, specifically for the ARM-based Pi. Raspberry Pi Software Reference guides you through the boot process, including options for tweaking HDMI, memory, and other boot options. You'll learn the details of run levels and creating new services, and how to use the custom command vcgencmd for doing things like reporting temperature, clock speeds, and voltage. And while there are cross-compilers available for some flavors of Linux, one of the most important things you'll get from Raspberry Pi Software Reference is how to build your own Raspberry Pi cross-compiler on your Mac OSX, Linux, or Windows computer.

What you’ll learn
  • In-depth coverage of boot options on the RPi
  • Working with runlevels
  • Options for vcgencmd
  • Building a cross-compiler for the Raspberry Pi on Mac OSX, Linux, or Windows
Who this book is for
All Raspberry Pi users, especially developers who need to create their own cross-compiler for the Raspberry Pi.

Table of Contents
Ch. 1 - Preparation
Ch. 2 – Booting ARM Linux
Ch. 3 – Initialization: Working with Runlevels
Ch. 4 – vcgencmd: Reporting Voltages and Temperatures
Ch. 5 - Linux Console
Ch. 6 – Building a Cross-Compiler
Ch. 7 – Cross-Compiling the Kernel
Appendix A: Glossary
Appendix B: Power Standards
Appendix C: Raspbian apt Commands
Appendix D: ARM Compile Options
Appendix E: Mac OS X Tips

Wednesday, January 7, 2015

Raspberry Pi + Arduino i2c communication, Wire.write() multi-byte from Arduino requestEvent

Last exercise show Raspberry Pi master + Arduino slave i2c communication, write block of data from Pi to Arduino Uno, and read a single byte from Arduino Uno. In this post show how to echo multi-byte from Arduino in requestEvent, by calling Wire.write().

In Raspberry Pi, i2c master, it send block of data to Arduino Uno, i2c slave, by calling bus.write_i2c_block_data(), to trigger receiveEvent in Arduino.
then call number of bus.read_byte() to trigger requestEvent in Arduino. The first byte echo from Arduino is the number of byte to sent, then echo the data in reversed sequency. run on Raspberry Pi
#have to run 'sudo apt-get install python-smbus'
#in Terminal to install smbus
import smbus
import time
import os

# display system info
print os.uname()

bus = smbus.SMBus(1)

# I2C address of Arduino Slave
i2c_address = 0x07
i2c_cmd_write = 0x01
i2c_cmd_read = 0x02

def ConvertStringToBytes(src):
    converted = []
    for b in src:
    return converted

# send welcome message at start-up
bytesToSend = ConvertStringToBytes("Hello Uno")
bus.write_i2c_block_data(i2c_address, i2c_cmd_write, bytesToSend)

# loop to send message
exit = False
while not exit:
    r = raw_input('Enter something, "q" to quit"')
    bytesToSend = ConvertStringToBytes(r)
    bus.write_i2c_block_data(i2c_address, i2c_cmd_write, bytesToSend)
    # delay 0.1 second
    # with delay will cause error of:
    # IOError: [Error 5] Input/output error
    data = ""
    numOfByte = bus.read_byte(i2c_address)
    print numOfByte
    for i in range(0, numOfByte):
        data += chr(bus.read_byte(i2c_address));
    print data
    if r=='q':

i2c_slave_12x6LCD.ino, run on Arduino Uno
 LCD part reference to:

#include <LiquidCrystal.h>
#include <Wire.h>

#define LED_PIN 13
boolean ledon = HIGH;
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

byte slave_address = 7;
int echonum = 0;

void setup() {
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print startup message to the LCD.
  lcd.print("Arduino Uno");
  pinMode(LED_PIN, OUTPUT);
  digitalWrite(LED_PIN, HIGH);


void loop() {


char echo[32];
int index = 0;

void requestEvent(){

void receiveEvent(int howMany) {
  int numOfBytes = Wire.available();
  //display number of bytes and cmd received, as bytes
  lcd.setCursor(0, 0);
  lcd.print(" ");
  byte b =;  //cmd
  lcd.print(" ");
  index = 0;

  //display message received, as char
  lcd.setCursor(0, 1);
  for(int i=0; i<numOfBytes-1; i++){
    char data =;
    echo[i] = data;
  echonum = numOfBytes-1;

void toggleLED(){
  ledon = !ledon;
    digitalWrite(LED_PIN, HIGH);
    digitalWrite(LED_PIN, LOW);