Author: admin

  • RGPIO – LCD Screens

    Common Character LCD Screens can be controlled with between 6 and 11 GPIO pins. RGPIO L-Mode contains simple support for a 6-pin or 7-pin solution. The 6 or 7 pins are D4,D5,D6,D7,EN,RS with an optional RW (for most uses RW can be hard-wired to GND).

    Initialize RGPIO with the ports:

    L<RS>,<RW>,<EN>,<D4>,<D5>,<D6>,<D7>D

    For the PiBoard, the initialization is (RW is hardwired to GND, and we use 0 for that pin:

    L17,0,11,22,23,24,25C

    The initialization will reset the the screen and clear it.
    Some screens need additional initialization which need to be sent to the screen separately.
    To write characters to the LCD:

    LDHello world

    To send special codes, use \Cxx or \Xxx where xx is a hexadecimal pair. \C for a command (RS=1) and \X for a character (RS=0). For example, to write to the screen’s top-left, prefix with \C80. (the beginning of row 2 is often \CA0 on a 2-line screen).
    Special positioning commands include \C01 (clear screen); \C02 (go to top left)
    When sending \ using a command shell or programming language that uses \ as an escape character, you will need to double it:

    ./p LD\\C80

    These screens usually have a built-in font with most of the characters you need, and with the ability to add your own characters at code positions 00-07 or 00-0F.
    To add an elipsis at character position 00 (6 blank rows, one row of alternate bits,1 blank row):

    LD\C40\x00\x00\x00\x00\x00\x00\x15\x00\xC80

    To print a short line of elipsis characters

    LD\x00\x00\x00\x00\xC80
  • RGPIO Port handling

    RGPIO commands for simple ports (P-mode) are:

    Command Comment Example
    P<port>+ Set port Hi (turn it on) P4+
    P<port>- Set port Lo (turn it off) P11-
    P<port>R Set port input and read value P0x12R
    P[n,]<port>L Report when port goes Lo
    Cache n events – default=0, report once only.
    P8L
    P[n,]<port>H Report when port goes Hi
    Cache n events – default=0, report once only.
    P2,8H
    P[n,]<port>L Report when port changes
    Cache n events – default=1; if n=0, once only.
    P0,8C
    P<port>l Set port Hi and time how long before it goes Lo P8l
    P<port>h Set port Lo and time how long before it goes Hi P8l
    P<port>U Turn on the internal pullup on the port P8U
    P<port>u Turn off the internal pullup on the port P8u
    Command Response
    P4R P4:on
    This reports the current state of the port.
    P8L E8:off 2013/03/15 14:21:35 (812355433)
    After an L command is sent, RGPIO watches for the port to change (using a hardware interrupt). The output will be available after the event has occured. The output can be pollled for, or a signal can be set. The output indicates the port, and state, the time and an incrementing timestamp for the event.
    P7h E7:on t=56000
    After an h command is sent, RGPIO sets the port Lo and then times how long (in nanoseconds) it takes for the port to go Hi. The output can be pollled for, or a signal can be set. The output indicates the port, and state, the elapsed time.
  • Raspberry Pi – RGPIO

    RGPIO is a Raspberry Pi installable module that provides a device driver interface GPIO (General Purpose Input/Output).

    Installing RGPIO

    Put rgpio.ko in /lib/modules/3.6.11+/kernel/drivers/rgpio
    Add rgpio to the list of modules to load at startup in /etc/modules
    Run depmod to update modprobe’s list of module dependencies.

    What RGPIO looks like

    RGPIO creates a device: /dev/rgpio

    This device is a character mode device that you can write text strings to and read text strings from. These strings tell RGPIO what to do, and tell you what RGPIO has found.

    For testing, it is useful to set up a small script – I call it p containing:

    [ -c /dev/rgpio ] && echo $@ > /dev/rgpio && cat - < /dev/rgpio

    ([ -c /dev/rgpio ] stops anything being written to a non-existent device.)

    Then you can use rgpio by entering commands as follows, and the output will be shown immediately:

    user@rpi:/home/me# ./p P14R
    RGPIO 14:on

    Help is built in:

    user@rpi:/home/me# ./p H
    {P|O|I|W|L}     set mode: PIN,One-wire,I2C,PWM,LCD
    ?               show Help
    pidS            Sending SIGIO to process when new output is added (pid=0 to cancel)
    {P|O|I|W|L}?    show Help for each mode
                    #,% can be decimal, 0x Hex or 0b Binary

    RGPIO Modes

    P mode: control the individual GPIO pins. This includes reading from and writing (Lo or Hi) to the pin, watching for changes in the read-state, and setting the internal pull-ups for each pin.

    W mode: PWM control – hardware (on Raspberry Pi, this is only on pin 18) or software modes.

    L mode: control a parallel character LCD device

    I mode: seek, query and control I2C devices

    O mode: seek, query and control 1-Wire devices

    Here are some Python examples using RGPIO on the PiBoard

  • Raspberry Pi – creating and installing a new kernel

    Abstract: Build your own Linux Kernel for Raspberry Pi.

    Follow the directions in Raspberry Pi – Setting up driver/module development environment.

    In directory Projects/source/tools/mkimage
    ./imagetool-uncompressed.py ../../linux/arch/arm/boot/zImage
    Create directory Projects/source/modules and in Projects/source/linux:
    make ARCH=arm CROSS_COMPILE=/tools/x-tools/arm-unknown-linux-gnueabi/bin/arm-unknown-linux-gnueabi- modules_install INSTALL_MOD_PATH=../modules
    You now have tools/mkimage/kernel.org and modules/lib which need to be copied to the Raspberry Pi
    scp tools/mkimage/kernel.org rpi:/boot
    rsync -r --safe-links modules/lib/* rpi:/lib/

  • Linux – Override monitor settings

    Abstract: Sometimes Linux doesn’t find the correct monitor settings. This is how to override them.

    Find out what Linux thinks your monitor is called:
    eg under KDE, run Size & Orientation – the monitors available will be shown with their names. VGA1, HDMI1 etc..

    Get the monitor settings you want using the cvt tool:
    cvt 1280 1024
    The output will be something like:
    Modeline "1280x1024_60.00" 109.00 1280 1368 1496 1712 1024 1027 1034 1063 -hsync +vsync

    Create or modify the file /etc/X11/xorg.conf.d/50-monitor.conf using the line just output:
    Section “Monitor”
    Identifier “VGA1” # use whatever name you discovered above
    Modeline … # as from the cvt output
    Option “PreferredMode” “1280x1024_60.00” # as on the Modeline
    EndSection

  • Raspberry Pi – setting up Web server

    Abstract: This is how to setup a Web server on Raspberry Pi

    Update your Raspberry Pi first.

    Run this commands to install this
    apt-get install apache2 The Apache web server
    apt-get install php5 libapache2-mod-php5 php5 and php5 support for Apache
    apt-get install mysql-server mysql-client MySQL server and client.
    You will be prompted to enter a SQL root password.
    apt-get install php5-mysql MySQL support for php

    Configure Apache. By defualt, a single-page website is active – /var/www/index.html.

    You can test php is working by creating a file: /var/www/phpinfo.php:

    Then in your webbrowser, visit http://rpi/phpinfo.php and you will see the php configuration screen.

  • Raspberry Pi – updating

    Abstract: This is how to update the OS and firmware on Raspberry Pi

    Note: If you don’t have git installed, you will need to install it with:
    apt-get install git-core
    Command Description
    apt-get update get latest updates to apt-get
    apt-get upgrade update to latest OS
    wget https://raw.github.com/Hexxeh/rpi-update/master/rpi-update -O /usr/bin/rpi-update
    chmod +x /usr/bin/rpi-update
    rpi-update
    Update the firmware
    You will need to reboot for these changes to work.
    You may need to delete /boot/config.txt and allow Linux to reconfigure itself.
    Note: any additional modules you have loaded will be lost (and will probably be for the wrong kernel version).
  • Raspberry Pi – Setting up driver/module development environment

    Abstract: This post gives the steps required to set up a cross-compiling development environment for Raspberry Pi.
    The base platform is a Linux computer (examples are given for a SuSE 12.2 installation running as a virtual computer on SuSE 12.2 using KVM as the hypervisor).
    1. Installing some prerequisites:
      1. git (use to access the source code repositories)
        On SuSE, use YaST to install if it’s not already there
        On Debian, use apt-get git to install
      2. Create your base directory: we will use ~/Projects
    2. Installing a cross-compiler:
      1. Download and compile the latest crosstool-ng from crosstool-ng.org (you will need to be root for the final make install)
        wget crosstool-ng.org/download/crosstool-ng/crosstool-ng-1.17.0.tar.bz2
        tar -xvz crosstool-ng-1.17.0.tar.bz2
        cd crosstool-ng-1.17.0
        ./configure
        make
        make install
      2. Configure a cross compiler
        mkdir ~/Projects/souce/ccc;cd ~/Projects/souce/ccc
        ct-ng menuconfig

        The cross compiler configuration requires the following settings:

        Section Setting
        Paths and misc [x] Try features marked as EXPERIMENTAL)
        (/tools/x-tools/${CT_TARGET}) Prefix directory
        Target options Target Architecture (arm)
        Endianness: (Little endian)
        Bitness: (32-bit)
        Operating System Target OS (linux)
        Linux kernel version (3.?.?) – use the correct value!
        Binary utilities binutils version: choose the latest not marked EXPERIMENTAL
        C Compiler [x] Show Linaro vesions (EXPERIMENTAL)
        gcc version – choose one of the Lenaro versions: 4.6-2-12.04 does work
        Exit from ct-ng menu configuration.
      3. Build a cross-compiler.
        As root (or with sudo prefix):
        ct-ng buid
        Note: if build fails with a message about Static linking impossible, edit the .config file and change CT_WANTS_STATIC_LINKING=n and try again.
        The compiler will be in /tools/x-tools/arm-unknown-linux-gnueabi
        The build takes quite a while… (42 minutes on a single core of i5-2500 at 3.3GHz)
    3. Installing the Linux Kernel Sources (which are required for compiling modules and drivers):
      1. Create a source directory ~/Projects/source an running the following commands from that directory:
      2. git clone git://github.com/raspberrypi/linux.git
      3. git clone git://github.com/raspberrypi/firmware.git
      4. git clone git://github.com/raspberrypi/tools.git
      You will now have three directories under ~/Projects/source: linux, firmware and tools.
    4. Set the right version of the Linux Kernel – which needs to be the same version you are using on the RaspberryPi.
      You can find the version RaspberryPi is running using the command:

      raspberrypi:~> uname -sr
      Linux 3.2.27+
      You can see the available versions of the Linux kernel by:
      rpidev:~> cd ~/Projects/source/linux
      rpidev:linux> git branch -r
        origin/HEAD -> origin/rpi-3.6.y
        origin/master
        origin/rpi-3.2.27
        origin/rpi-3.6.y
        origin/rpi-patches
      You can set the version to rpi-3.2.27 using:
      git checkout rpi-3.2.27
      • ARM System Type=Broadcom BCM2708 family
      • When changing the kernel version, you need to initialize it. This process will remove the .config file, so it’s a good idea to keep a copy in (eg) ../linux.config
        make mrproper
        To set the configuration, use one or more of the following
        • Copy from your backup: cp ../linux.config .config
        • Get it from the Raspberry Pi ssh root@rpi zcat /proc/config > .config
        • Check the configuration: make ARCH=arm CROSS_COMPILE=/tools/x-tools/arm-unknown-linux-gnueabi/bin/arm-unknown-linux-gnueabi- oldconfig
          This will prompt you to confirm any new options – use the default except for:
      • Edit the configuration: make ARCH=arm CROSS_COMPILE=/tools/x-tools/arm-unknown-linux-gnueabi/bin/arm-unknown-linux-gnueabi- menuconfig
        Some areas you might want to configure (especially if you’re planning to use this kernel on the device):

        • Floating Point emulation: you need one emulation set
        • Networking support (enable for more, disable for smaller)
        • Device drivers (enable for more, disable for smaller)
      • You can check the version your source code tree is at using:
        make kernelversion
      • Build the kernel using: (-j2 means use 2 core in parallel)
        make ARCH=arm CROSS_COMPILE=/tools/x-tools/arm-unknown-linux-gnueabi/bin/arm-unknown-linux-gnueabi- -j2
      • To compile my_module, use the following makefile:
        obj-m:=mymodule.o
        And compile with:
        make ARCH=arm CROSS_COMPILE=/tools/x-tools/arm-unknown-linux-gnueabi/bin/arm-unknown-linux-gnueabi- -C ~/Projects/source/linux SUBDIRS=`pwd` modules
    5. SSH with keys (no passwords)

      Abstract: Instructions on setting up a Linux computer (server) so you can log in (from your client) with ssh without having to enter a password (using keys).

      Without a password, authentication is done with a key. To achieve password-less access, you need a key, and the computer you are logging in to needs to know about that key.
      A Key has two parts – private and public. You keep the private part, you give the public part to anyone who needs to know you are who you say you are.

      Generate a key on the client computer using:
      ssh-keygen -t rsa
      This will create two files:

      File Description
      ~/.ssh/id_rsa Your private key
      ~/.ssh/id_rsa.pub Your public key

      You need to add the contents of ~/.ssh/id_rsa.pub to the file ~/.ssh/authorized_keys on the server, logged in as the user you will be using:
      cat ~/.ssh/id_rsa.pub | ssh user@server "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"
      This is the last time you will need to enter the password.
      From now on, you can just connect using:
      ssh user@server
      Or, if you are logged on to the client as the same username, just
      ssh-keygen -R ip-address