Wednesday, January 29, 2014

Google's Python Class

Google's Python Class -- this is a free class for people with a little bit of programming experience who want to learn Python. The class includes written materials, lecture videos, and lots of code exercises to practice Python coding. These materials are used within Google to introduce Python to people who have just a little programming experience.

Visit: https://developers.google.com/edu/python/

Google's Python Class
Google's Python Class


A beginners guide to the Unix and Linux

UNIX Tutorial for Beginners is a on-line beginners guide to the Unix and Linux operating system. Eight simple tutorials which cover the basics of UNIX / Linux commands.

UNIX Tutorial for Beginners
UNIX Tutorial for Beginners
This tutorial is available for download so you can work offline, download.

Tuesday, January 28, 2014

Node-RED: A visual tool for wiring the Internet of Things

Node-RED
Node-RED
Node-RED is a browser base, on top of Node.js, to provide visual tool for wiring the Internet of Things. It support hardwares include Arduno, Raspberry Pi and BeagleBone Black.

Visit: http://nodered.org/

Sunday, January 26, 2014

Enable I2C of Raspberry Pi

By default, i2c is disabled in Raspberry Pi. To enable it, follow the step:
  • $ sudo nano /etc/modules
    add the lines:
    i2c-bcm2708
    i2c-dev


  • $ sudo nano /etc/modprobe.d/raspi-blacklist.conf
    comment the line of
    #blacklist i2c-bcm2708

  • install i2c-tools for testing
    $ sudo apt-get install i2c-tools
  • reboot
  • After reboot, run i2c-tools to test
    run the command with -1 option for rev 2 board, or -0 for rev 1 board.
    $ sudo i2cdetect -y 1
    sudo i2cdetect -y 0
  • In my test on rev2, with no i2c device inserted:


    with Tontec 2.4-inch TFT LCD Touch Screen attached:

Friday, January 24, 2014

evtest, tool for input event testing

evtest is a open source tool that can be used for testing the USB HID class drivers and any other drivers based on event framework . Its an event device test program. It helps in seeing the event layer events that a USB HID device like a USB keyboard or a USB mouse or a keypad or a touchscreen might be generating. Thus it can be used to test USB HID(USB Mouse and USB keyboard),keypad and touchscreen modules.

Supports-

  • Detection of USB mouse movements, left button click, right button click, middle button click, wheeling.
  • Detection of keys pressed on USB keyboard .Value of key pressed appears on the serial console.
  • Detection of keys pressed on keypad.Value of key pressed appears on the serial console.
  • Detection of pressure values on touching the touchscreen.

reference:



To install evtest, enter:
$ sudo apt-get install evtest


What is a Raspberry Pi?

Thursday, January 23, 2014

Half success, half fail experiment, cross compile kernel module for Raspberry Pi on Ubuntu

This post show cross compile kernel module for Raspberry Pi on Ubuntu. It success to build kernel module, hello.ko, run on Raspberry Pi. It fail after the Pi update firmware with rpi-update!.

To make sure the source used to compile our code is same as that running on Raspberry Pi, Cross compile Raspberry Pi kernel from source on Ubuntu and move the kernel.img and files to SD Card.

In Ubuntu, create hello.c
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>

static int __init hello_init(void)
{ 
 printk(KERN_INFO "Hello Raspberry Pi!\n");
 return 0;
}

static void __exit hello_exit(void)
{
 printk(KERN_INFO "Bye Raspberry Pi!\n");
}

module_init(hello_init);
module_exit(hello_exit);

Makefile
obj-m += hello.o

all:
 make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- -C /<git clone linux directory> M=$(PWD) modules

clean:
 make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- -C /<git clone linux directory> M=$(PWD) clean

Where <git clone linux directory> is the git clone linux directory in Cross compile Raspberry Pi kernel from source on Ubuntu and move the kernel.img and files to SD Card.

Then build the kernel module with the command:
$ make

Copy the generated hello.ko to Raspberry Pi.

Insert the module with the command:
$ sudo insmod hello.ko

or, remove it with the command:
$ sudo rmmod hello.ko

You can type dmesg command to check that the word "Hello Raspberry Pi!" and "Bye Raspberry Pi!" logged. They are printed to kernel by hello.ko with the function printk().


The fail half is:
Once you update Raspberry Pi's firmmware with the command:
$ sudo rpi-update

Then reboot. hello.ko cannot be inserted again in new firmware, caused with "Invalid module format"!


Remark:
- It's 3.10.27+ #3 before rpi-update, with hello.ko insert successful.


- Updated to 3.10.27+ #630 PREEMPT after rpi-update, with insmod fail.



Cross compile Raspberry Pi kernel from source on Ubuntu

This post show how to build Raspberry Pi kernel on Ubuntu, then copy the kernel.img and other files to Raspbian installed SD Card.

Create our working directory, raspberrypi:
  • $ mkdir raspberrypi
  • cd raspberrypi
Before start our works, install the necessary tools and source code of Raspberry Pi linux:
  • $ git clone https://github.com/raspberrypi/tools.git
  • $ git clone https://github.com/raspberrypi/linux.git
Prepare the .config file from pre-packaged config, bcmrpi_cutdown_defconfig:
  • $ cd linux
  • $ make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- bcmrpi_cutdown_defconfig
Build kernel:
  • $ make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi-
  • $ mkdir ../modules
  • $ make modules_install ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- INSTALL_MOD_PATH=../modules/
  • $ cd ../tools/mkimage/
  • $ ./imagetool-uncompressed.py ../../linux/arch/arm/boot/Image
Now insert a Raspbian installed SD Card, and run the command:
  • $ sudo rm /media/<boot-partition>/kernel.img
  • $ sudo mv kernel.img /media/<boot-partition>/
  • $ sudo rm -rf /media/<rootfs-partition>/lib/modules/
  • $ sudo rm -rf /media/<rootfs-partition>/lib/firmware/
  • $ cd ../../modules/
  • $ sudo cp -a lib/modules/ /media/<rootfs-partition>/lib/
  • $ sudo cp -a lib/firmware/ /media/<rootfs-partition>/lib/
  • $ sync
Now you can remove the SD Card and use it to boot Raspberry Pi with the new kernel.

- The original kernel run 3.10.25+

- The new generated kernel run 3.10.27+

Tuesday, January 21, 2014

DIY WiFi Raspberry Pi Touchscreen Camera - Make your own Cloud-connected point-and-shoot camera

This project, DIY WiFi Raspberry Pi Touchscreen Camera, explores the Adafruit PiTFT touchscreen and the Raspberry Pi camera board to create a simple point-and-shoot digital camera. One can optionally use WiFi and Dropbox (a cloud file storage and synchronization service) to automatically transfer photos to another computer for editing.

Sunday, January 19, 2014

failed experiment: build "Hello World" kernel module for Raspberry Pi

It is a failed experiment to build "Hello World" kernel module for Raspberry Pi, follow the step:
  • Run with a new installed Raspbian, wheezy, 2014-01-07.
  • Download and transfer the source code of Raspberry Pi
  • Create hello.c and Makefile follow "The Linux Kernel Module Programming Guide", 2.3. Hello World (part 2).

    hello.c
    #include <linux/module.h>
    #include <linux/kernel.h>
    #include <linux/init.h>
    
    static int __init hello_init(void)
    { 
     printk(KERN_INFO "Hello Raspberry Pi!\n");
     return 0;
    }
    
    static void __exit hello_exit(void)
    {
     printk(KERN_INFO "Bye Raspberry Pi!\n");
    }
    
    module_init(hello_init);
    module_exit(hello_exit);
    

    Makefile
    obj-m += hello.o
    
    all:
     make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
    
    clean:
     make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
    

  • Then make it, without error.
  • When I try to insert the module hello.ko, error of invalid module format reported.
    $ sudo insmod ./hello.ko
    Error: could not insert module ./hello.ko: Invalid module format



  • "disagrees about version of symbol module_layout" logged in /var/log/messages'. I assume it is something mis-match between the kernel version in my source and the running system.
  • Then I update Raspberry Pi to most update with:
    $ sudo rpi-update
    $ sudo apt-get update
    $ sudo apt-get upgrade
    and reboot
  • I try to insmod again, but fail with "Unable to handle NULL pointer dereference at virtual address 00000004", and the system hang-up.
    "Unable to handle NULL pointer dereference at virtual address 00000004"
I'm a newbies in Linux programming, and ask for help. Please leave me comment for any advice.

Free online ebook: The Linux Kernel Module Programming Guide

"The Linux Kernel Module Programming Guide" - FREE ebook online.

The Linux Kernel Module Programming Guide
The Linux Kernel Module Programming Guide



Table of Contents
Foreword
1. Authorship
2. Versioning and Notes
3. Acknowledgements
1. Introduction
1.1. What Is A Kernel Module?
1.2. How Do Modules Get Into The Kernel?
2. Hello World
2.1. Hello, World (part 1): The Simplest Module
2.2. Compiling Kernel Modules
2.3. Hello World (part 2)
2.4. Hello World (part 3): The __init and __exit Macros
2.5. Hello World (part 4): Licensing and Module Documentation
2.6. Passing Command Line Arguments to a Module
2.7. Modules Spanning Multiple Files
2.8. Building modules for a precompiled kernel
3. Preliminaries
3.1. Modules vs Programs
4. Character Device Files
4.1. Character Device Drivers
5. The /proc File System
5.1. The /proc File System
5.2. Read and Write a /proc File
5.3. Manage /proc file with standard filesystem
5.4. Manage /proc file with seq_file
6. Using /proc For Input
6.1. TODO: Write a chapter about sysfs
7. Talking To Device Files
7.1. Talking to Device Files (writes and IOCTLs)
8. System Calls
8.1. System Calls
9. Blocking Processes
9.1. Blocking Processes
10. Replacing Printks
10.1. Replacing printk
10.2. Flashing keyboard LEDs
11. Scheduling Tasks
11.1. Scheduling Tasks
12. Interrupt Handlers
12.1. Interrupt Handlers
13. Symmetric Multi Processing
13.1. Symmetrical Multi-Processing
14. Common Pitfalls
14.1. Common Pitfalls
A. Changes: 2.0 To 2.2
A.1. Changes between 2.4 and 2.6
B. Where To Go From Here
B.1. Where From Here?
Index


Saturday, January 18, 2014

Raspberry Pi with mini LCD display without HDMI

It's a portable Raspberry Pi running with mini LCD, and wireless keyboard, powered by portable battery pack.


With "Setup Tontec 2.4-inch TFT LCD 240x320 RGB Pixels Touch Screen Display Monitor For Raspberry Pi", "Run mztx06a program on startup automatically" and "Auto login Pi". You can disconnect HDMI, power Pi with portable battery pack, and using Wireless Keyboard, to make it a portable.

Thursday, January 16, 2014

PortaPow USB Power Monitor / Multimeter / DC Ammeter

PortaPow USB Power Monitor / Multimeter / DC Ammeter for Solar Panels, Mains Chargers, etc -

This multi-meter plugs directly into any USB socket and allows you to connect any USB cable into it for charging or data transfer. It displays on screen the voltage and current which is being output, acting as both a volt and amp meter.

Flexible cable means you can turn the LCD screen to face you - unlike 'all in one' designs it won't be fixed facing the floor/wall regardless of how the USB socket is oriented.

The meter is useful for solar panels with USB outputs, since it will then allow you to position the panel to maximize the energy it outputs, see what factors affect the panel's performance, and also to see when the output is too low to be worth using the solar panel.

It is also allows you to compare the power of different USB sockets and study the quirks of USB charging. It has an upper limit of 3A.

Note that USB sockets will only output as much power as is demanded by the device you are charging, this is the figure the monitor will show. The monitor will not show the maximum possible power output from the USB socket.

Updated 7th Jan 2014 - Now with improved build quality and even lower resistance for more accurate results

  • Plugs into any USB socket, shows the power (current and voltage) going from the socket to the device you're charging from it in real time.
  • Extremely useful for solar panels which have a USB output, allows you to angle the panel to get the most energy
  • Accurate to 0.01A, 0.01V, upto 3000mA (3A). Uses only 4mA (20mW) of power.
  • Short 10cm cable means you can turn the screen to face you but still has low resistance.
  • Updated 7th Jan 2014 - Now with improved build quality and even lower resistance for more accurate results

Tuesday, January 14, 2014

Download and transfer the source code of Raspberry Pi

In the steps, the source code of Raspberry Pi in GitHub (linux and firmware) are downloaded to a host PC running Ubuntu, then copy to Raspberry Pi.



  • - In Host PC side -
    Because the source code of Raspberry Pi is too large, and too long time to download, it will be done in another host pc.

    - Create git directory to hold the files.
    $ mkdir git
    $ cd git

    - git clone the source code.
    $ git clone https://github.com/raspberrypi/linux
    $ git clone https://github.com/raspberrypi/firmware

    It take long time to finish.
  • - In Host PC side -, after downloaded:
    - Compress and copy to Pi, under /home/pi.
    tar -cvf linux.tar.gz --exclude .git linux
    scp linux.tar.gz pi@raspberrypi:/home/pi
  • - In Pi side -, switch to /home/pi directory
    tar -xvf linux.tar.gz
    cd linux
    zcat /proc/config.gz > .config
    make oldconfig
    make modules_prepare
  • - In host PC side -, host PC: copy Module.symvers to pi's linux directory.
    scp firmware/extra/Module.symvers pi@raspberrypi:/home/pi/linux
  • - In Pi side -, move linux directory to /usr/src/kernels/$(uname -r)
    $ sudo mkdir /usr/src/kernels
    cd ~
    sudo mv linux /usr/src/kernels/$(uname -r)
    cd /lib/modules/$(uname -r)

    make links for build and source
    sudo ln -s /usr/src/kernels/$(uname -r) build
    sudo ln -s /usr/src/kernels/$(uname -r) source

Raspberry Pi source on GitHub

Link to Raspberry Pi source on GitHub: https://github.com/raspberrypi

You can find githib of noobs (New Out Of Box Software), firmware, linuxuserland (Source code for ARM side libraries for interfacing to Raspberry Pi GPU)target_fstools, and quake3.

As example, if you want to get a copy of the linux repository, enter the command:
$ git clone https://github.com/raspberrypi/linux

or enter the following command to clone fireware repository:
$ git clone https://github.com/raspberrypi/firmware

Git receives a copy of nearly all data that the server has. Every version of every file for the history of the project is pulled down when you run git clone. ~ reference: http://git-scm.com/book/en/Git-Basics-Getting-a-Git-Repository#Cloning-an-Existing-Repository


Monday, January 13, 2014

Linux lsmod command: list loaded kernel modules

The Linux command lsmod print the contents of the /proc/modules file, list the currently loaded kernel modules.
lsmod
lsmod: list loaded kernel modules

NOOBS, Raspbian and Arch updated

NOOBS(2014-01-09), Raspbian wheezy(2014-01-07) and Arch(2014-01-06) updated, available Raspberrypi.org downloads page.

Sunday, January 12, 2014

Test internet bandwidth using speedtest-cli

speedtest-cli is command line interface for testing internet bandwidth using speedtest.net. speedtest-cli works with Python 2.4-3.4.

Test internet bandwidth using speedtest-cli
Test internet bandwidth using speedtest-cli
Download speedtest-cli:
$ wget -O speedtest-cli https://raw.github.com/sivel/speedtest-cli/master/speedtest_cli.py
$ chmod +x speedtest-cli

Run:
$ ./speedtest-cli

SpeedTest on Raspberry Pi vs PC:



For PC user, direct visit http://www.speedtest.net/ with your browser.
http://www.speedtest.net/
http://www.speedtest.net/


Thursday, January 9, 2014

NEOMART Low-profile Raspberry Pi MicroSD / TF to SD Card Adapter for Raspberry Pi

NEOMART Low-profile Raspberry Pi MicroSD / TF to SD Card Adapter for Raspberry Pi
Raspberry Pi low-profile microSD Card Adaptor can be used to convert a microSD card for direct use with your Raspberry Pi, without the use of full size SD card, which often get damaged because it sticks out of the PCB.

Low-profile adapters are tiny and sit completely flush with the edge of the Raspberry Pi, so there's no risk of knocking your SD card out (or having it stolen!) And the whole adapter is under the board "hidden".

  • Perfectly Fits Raspberry Pi SD Card Slot
  • TF Deck with Gold Plated
  • Designed For Raspberry Pi Board
  • No edge exposed outside card slot to avoid damage of card or main board
  • MicroSD Card and Raspberry Pi NOT Included

Wednesday, January 8, 2014

Disable Suspend mode on Raspberry Pi

The file /etc/lightdm/lightdm.conf is the configuration of LighDM, display manager. To disable Suspend mode, edit the file with the command:

$ sudo nano /etc/lightdm/lightdm.conf

Scroll down to [SeatDefaults] section, uncomment and edit the command "xserver-command=X" to enter X server command to run:
xserver-command=X -s 0 -dpms

/etc/lightdm/lightdm.conf
/etc/lightdm/lightdm.conf
where:
-s 0 sets screen-saver timeout time in minutes.
-dpms disables DPMS (display power management services).

reference: http://www.xfree86.org/current/Xserver.1.html

Restart your Raspberry Pi.

Clean Rubbish bin in command line

In Raspbian, the files of Rubbish should be in ~/.local/share/Trash/files, to clean it in command line manually, enter:

rm -rf ~/.local/share/Trash/files

Tuesday, January 7, 2014

Set auto login Pi

To set auto login pi, without asking of user and password:

$ sudo nano /etc/inittab

comment the line(may be have little bit differency on various version):
#1:2345:respawn:/sbin/getty --noclear 38400 tty1

add the line:
1:2345:respawn:/bin/login -f pi tty1 </dev/tty1 >/dev/tty1 2>&1

/etc/inittab
/etc/inittab

Run program on startup automatically

A simple way to run a program on startup automatically, is editing /etc/rc.local to run it.

Refer to last post of "Setup Tontec 2.4-inch TFT LCD 240x320 RGB Pixels Touch Screen Display Monitor For Raspberry Pi", I want to run the program mztx06a on startup automatically.

sudo nano /etc/rc.local

Insert the code to run mztx06a.

/etc/rc.local
/etc/rc.local
remark: where the last '&' force the program run in background.




Setup Tontec 2.4-inch TFT LCD 240x320 RGB Pixels Touch Screen Display Monitor For Raspberry Pi

This post show the steps to setup the "Display Part" of "Tontec 2.4-inch TFT LCD 240x320 RGB Pixels Touch Screen Display Monitor For Raspberry Pi".

[But I can't make the "Touch Part" work! If you know how, please let me know by leaving me comment. See the "Cross compile Raspberry Pi kernel to inslude tsc2007.ko" on bottom.]

Tontec 2.4-inch TFT LCD 240x320 RGB Pixels Touch Screen Display
Tontec 2.4-inch TFT LCD 240x320 RGB Pixels Touch Screen Display on Raspberry Pi
- Plug the "Tontec 2.4-inch TFT LCD 240x320 RGB Pixels Touch Screen Display" to the connector on Raspberry Pi, no extra power supply is needed.

- Power up Raspberry Pi and login.

- Download "https://s3.amazonaws.com/tontec/24usingmanual.zip" (it can be found in the product page), using the command in Terminal.
$ wget https://s3.amazonaws.com/tontec/24usingmanual.zip

- Unzip the file.

- Enter unzipped directory <download directory>/mztx-ext-2.4/src

- Enter the command:
$ make

- Edit file /boot/config.txt with the command:
sudo pico /boot/config.txt

Uncomment and change the two 2 lines

framebuffer_width=320
framebuffer_height=240

Save and exit.

- Reboot.

- After login, enter mztx-ext-2.4/src Directory. Run the program mztx06a with command:
sudo ./mztx06a

You should see the LCD turned on now.



Next: If you prefer the mztx06a program automatically run on startup, refer to next post "Run program on startup automatically".

Related: Raspberry Pi with mini LCD display without HDMI.



remark: more discussing in Raspberry Pi forum http://www.raspberrypi.org/forum/viewtopic.php?f=91&t=64414



More:
- Cross compile Raspberry Pi kernel to inslude tsc2007.ko

Updated:
osandov's Raspberry Pi TSC2007 Kernel Modules updated

Monday, January 6, 2014

Android App - RPi Hardware Guide

This App, RPi Hardware Guide, sets out, in one convenient location, detailed information on all the hardware components of your Raspberry Pi.

It will assist new users as well as experienced Pi enthusiasts with a comprehensive understanding of the device and its capabilities.

It includes (but is not limited to):
- An interactive guide of Raspberry Pi Model A
- An interactive guide of Raspberry Pi Model B
- A powerful search function
- An image gallery (Paid version only)
- Quick reference section
- Extensive Information on /boot/config.txt
- Extensive Information on the Official Raspberry Pi Camera Board

RPi Hardware Guide
RPi Hardware Guide
Google Play:


Thursday, January 2, 2014

Wednesday, January 1, 2014

Change keyboard layout of Raspberry Pi to US

The default keyboard layout of Raspberry Pi is UK. To change to US, you can edit the file /etc/default/keyboard. Enter the command:
$ sudo nano /etc/default/keyboard

Chnage to XKBLAYOUT="us".

Save the file and exit.

Then reboot.

Set desktop size of vncserver

Once TightVNC server installed, we can start a vncserver with -geometry option to specify the size of the desktop to be created. Default is 1024x768.

example: 
vncserver -geometry 640x480
vncserver -geometry 800x600

Run vncserver with -geometry option
Desktop of vncserver with various size

Check Python version

To check install Python version in command line, run python with "-V" option:
python -V
python3 -V
pypy -V

To check running python version in python code:
import sys
print(sys.version)

Check Python version
Check Python version

NOOBS v1.3.3 released

Updated NOOBS v1.3.3 available now.

Highlights for updated Raspbian include:

  • New firmware and 3.10 kernel, with numerous functionality improvements.
  • New hardware-accelerated X driver included and enabled by default.
  • Mathematica and the Wolfram Language installed by default.
  • Updated Scratch image.
  • PyPy 2.2, with incremental garbage collection.
  • New V4L2 camera driver, and an updated v4l-utils package.

details: http://www.raspberrypi.org/archives/5580

Download New Out Of Box Software (NOOBS) here.