Raspberry Pi using as access point

Hostapd + dnsmasq for Raspberry Pi 

Last time I used Android phone as a keyboard and mouse to remotely control the RPi X-server, but it required WiFi connection to login the RPi if I need to control the terminal. 

This time I tried to make RPi work as an access point to directly communicate with Android phone.
  1. hostapd settingsInstall hostapd package.
    sudo apt-get install bridge-utils hostapd
    Get hostpad that is for the RTL8188CUS chipset which is used for Edimax EW-7811Uh.
    wget http://dl.dropbox.com/u/1663660/hostapd/hostapd.zipunzip hostapd.zip
    Replace the hostapd that is installed with the package.
    sudo mv /usr/sbin/hostapd /usr/sbin/hostapd.original
    sudo mv hostapd /usr/sbin/hostapd.edimax
    sudo ln -sf /usr/sbin/hostapd.edimax /usr/sbin/hostapd
    sudo chown root.root /usr/sbin/hostapd
    sudo chmod 755 /usr/sbin/hostapd
    If eth0 and wlan0 need to be bridged, edit the interfaces file.
     sudo nano /etc/network/interfaces
    Modify the file as below. (after the part related to wlan0)
    auto br0
    iface br0 inet dhcp
    bridge_ports eth0 wlan0
     Create hostapd.conf file
    sudo nano /etc/hostapd/hostapd.conf
    Add the following lines.
    interface=wlan0
    driver=rtl871xdrv
    bridge=br0
    ssid=[NETWORK NAME]
    channel=6
    wmm_enabled=0
    wpa=1
    wpa_passphrase=[PASSWORD]
    wpa_key_mgmt=WPA-PSK
    wpa_pairwise=TKIP
    rsn_pairwise=CCMP
    auth_algs=1
    macaddr_acl=0
    Run hostapd and see if network is detected by Android phone.
    sudo hostapd -dd /etc/hostapd/hostapd.conf
    Modify hostpad file if you want to run hostapd at the startup.
    sudo nano /etc/default/hostapd
    Uncomment "DAEMON_CONF" in the file and add the path to the file.
    DAEMON_CONF="/etc/hostapd/hostapd.conf"
    Reboot the system and see if hostapd is automatically run.
    sudo shutdown -r now


  2. dnsmasq settings
    hostapd is to make it RPi as access point.
    Now, we install dnsmasq to automatically assign the IP address to the clients.
    Install dnsmasq.
    sudo apt-get install dnsmasq
    This will automatically start the dnsmasq, so stop it.
    sudo service dnsmasq stop
    Create the new configuration file.
    sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.original
    sudo touch /etc/dnsmasq.conf
    Edit the file as below.
    interface=wlan0
    expand-hosts
    domain=local
    dhcp-range=10.0.0.10,10.0.0.20,24h
    dhcp-option=3,10.0.0.1
     Edit the interfaces file again.
    sudo nano /etc/network/interfaces
    Comment out or delete the part modified previously, then modify it as below. (section1) 
    #auto br0
    #iface br0 inet dhcp
    #bridge_ports eth0 wlan0
    iface wlan0 inet static
    address 10.0.0.1
    network 10.0.0.0
    netmask 255.255.255.0
    broadcast 10.0.0.255
     Reboot the RPi
    sudo shutdown -r now
    

  3. Connecting the Android phone to RPi
    After rebooting RPi, you will see the network name on your phone.
    Connect to the network and make sure the IP is obtained.
    Then, launch the SSH apps and try login RPi.
    I used "ConnectBot" app.
    You can also use "Simple Computer Remote" app to control the RPi once X-server is started.

Hardware:
    Raspberry Pi
    EW-7781Uh WiFi dongle

    PS Vita Portable Charger 
   
Summary:
RPi is now connected to an Android phone directly without WiFi network.
This will allow me to access to RPi at anywhere.


Reference:     
http://willhaley.com/blog/raspberry-pi-hotspot-ew7811un-rtl8188cus/
http://ariandy1.wordpress.com/2013/04/07/setting-up-wifi-access-point-with-edimax-ew-7811un-on-raspberry-pi/

Easy Connection between PC and Raspberry Pi with USB to Serial Dongle

I was frustrated with Wi-Fi connection between PC and Raspberry Pi (RPi) when I use RPi outdoors. First, I needed network setup. It was frequently troublesome.

I looked for an easier way. Using USB2Serial dongle would be one of the ways.

Connection using USB to Serial dongle


I bought USB to Serial dongle from Amazon. It cost about $11, not so expensive.


NooElec PL2303 USB to Serial (TTL) Module/Adapter

Download and Install driver

To connect from PC to RPi, you need to download and install driver software here. I'm using Mac. The above product has drivers for Windows/Android/Mac.

Cable Connection

Cable connection is easy. You just connect three pins - GND, TX, and RX. RPi pin assignment is here.


USB to SerialRaspberry Pi
GNDGND(P1.6)
RXDUART_TXD(P1.8)
TXDUART_RXD(P1.10)

Connect with a Terminal Program

After the above setup, you can connect with your terminal program.
  • Baud Rate: 115200
  • Bits: 8
  • Parity: None
  • Stop Bits: 1
  • Flow Control: None

Raspberry Pi remote control

Remote keyboard + mouse for Raspberry Pi I wanted to remotely control the RPi using Android phone, and here is the notes what I have done.
  1. Android phone settingInstall "Simple Computer Remote" Apps on your Android phone.
    also, install "ConnectBot" if you need to use SSH to log into the RPi.
  2. RPi settingLog into the RPi and install the package.
    This creates a file named "SimpleComputerRemote" into /opt/rekap.
    wget http://philproctor.github.io/SimpleComputerRemote/downloads/simplecomputerremote_1.2_armhf.deb
    dpkg -i simplecomputerremote_1.2_armhf.deb
    Check the installed package
    dpkg --list simplecomputerremote
    Add /opt/rekap/SimpleComputerRemote as a startup application to automatically start the server when x-server is started.
    This requires to add/modify a file located at /home/pi/.config/autostart.

    mkdir /home/pi/.config/autostart (if the directory does not exist.)
    cd /home/pi/.config/autostart
    sudo nano SimpleComputerRemote.desktop
    Add following lines in the SimpleComputerRemote.desktop file and save it.
    [Desktop Entry]
    name=SimpleComputerRemote
    GenericName=Remote Control
    Comment=Allow remote control using Simple Computer Remote
    Exec=/opt/rekap/SimpleComputerRemote
    Terminal=False
    Type=Application
    Start the x-server.
  3. Connecting the Android phone to RPi
    After x-server is up, launch "Simple Computer Remote" app on Android phone.
    Go to "Settings > Select Server" and you will see RPi on the list.
    Click RPi and go back to the home screen of the application.
    Now you see the cursor moving when you touch the screen on the phone :)
    (Sometimes the application does not show the RPi as an active server. Try "Reconnect" and see if RPi shows up in the server list.)

    If you do not want to use PC next time, you can use "ConnectBot" apps to log into the RPi and startx over ssh.

Hardware:
    Raspberry Pi
    EW-7781Uh WiFi dongle
    PS Vita Portable Charger 
   
Summary:
"Simple Computer Remote" app is working with RPi and also "ConnectBot" can SSH to the RPi.
It is more than I expected and quite nice!
Using the libreoffice or something, I can use RPi for presentation machine during the meetings :)


Reference:     
http://philproctor.github.io/SimpleComputerRemote/
http://www.raspberrypi.org/phpBB3/viewtopic.php?f=27&t=40797

Mini Monitor for Raspberry Pi


I was looking for an inexpensive small monitor for Raspberry Pi. I found one monitor in the web page here. It is 4.3 inch TFT color monitor, which we can buy from Amazon.


4.3'' Color TFT Car Monitor Support 480 x 272 Resolution + Car/Automobile Rear-view System Mirror Display Monitor

I tried it with 12V DC Power Adapter. It worked but it is a little bit difficult to read messages on the terminal.

Macro shot of the actual monitor screen


However I could use this monitor for visual things, for example video streaming.

I feel some heat on the back side when I use the monitor with 12V DC. Now I use this monitor with 6V DC using a voltage adjustable power adapter below.


Velleman Compact Universal DC Adapter Power Supply




Raspberry Pi + Camera Board on RC Car using Wii Remote

  1. Video demo
    Here is a first test run video
    of the RC car using Wii Remote.


  2. Wii Remote setups
    I used wiiuse library to get the data from Wii Remote.
    http://sourceforge.net/projects/wiiuse/

    [TBD]

  3. I-Racer setups
    I referred to the Sparkfun site for the documents, especially command sets.
    https://www.sparkfun.com/products/11162

    [TBD]
  4. System configuration


  5. Start playing!
    Video settings

    Launch the command prompt and run the command below.
    RX (PC)
    [Path to nc.exe]\nc.exe -L -p 5001 | [Path to mplayer.exe]\mplayer.exe -fps 31 -cache 1024 -
    Log into the RPi and type the following command.
    TX (RPi)
    raspivid -t 999999 -o - | nc [insert the IP address of the client] 5001
    This will run the video streaming.

    Controller settings

    Connect the bluetooth devices, I-Racer and Wii Remote.

    Launch the controller program.
    [TBD]
Hardware:
    Raspberry Pi
    Raspberry Pi Camera Board
    EW-7781Uh WiFi dongle
    PS Vita Portable Charger 
    Wii Remote Controller
   
Summary:
    This is the test run of our PC version RC car project using Wii Remote and Raspberry Pi camera board.
    It still requires the improvement and there is a bit of controller lag, but it was still fun playing with it :)
    Maybe it would be also nice to use Wii Wheel. I should try that when I have a chance.


Reference:    
http://sourceforge.net/projects/wiiuse/
https://www.sparkfun.com/products/11162

Raspberry Pi Camara Board with Portable Battery Pack

  1. External Battery Pack with RPi + Camera
    Last time, I was not able to run the RPi camera board at 1080@30 with the battery pack I have.
    I tried to measure the voltage and current
    using multimeter.
    However, my test condition was not great, and long cable caused too much voltage drop to make RPi work properly...
    Hope I have good test tools... it would be nice to make USB current monitor using tiny MCU...
  2. Using PS Vita Portable ChargerI had Vita charger which is capable to output up to 1500mA and tested again.

    TX (RPi)
    raspivid -t 999999 -o - | nc [insert the IP address of the client] 5001

    RX (Windows 7)
    [Path to nc.exe]\nc.exe -L -p 5001 | [Path to mplayer.exe]\mplayer.exe -fps 31 -cache 1024 -

    This time it worked!
    It was the power issue.
    I assume average current is ok but I am guessing the peak current was actually causing issue.
    ..
Hardware:
    Raspberry Pi
    Raspberry Pi Camera Board
    EW-7781Uh WiFi dongle
    PS Vita Portable Charger

   
Summary:
    WiFi video streaming was tested using Raspberry Pi camera board and Vita portable charger.
    Video image was displayed properly and response was less than fast enough.


Reference:    

Raspberry Pi Camera board Test

  1. Raspberry PI Camera module over WiFiI had been interested in the Raspberry Pi Camera board and finally decided to spend money on the RPi Camera.
    It is actually quite nice and useful, and I am very happy with this, especially I can now try using this instead of USB camera :)
    Here is a note for the quick test.
  2. Setups
    There is nicely documented site in the raspberrypi.org, and this page helped me a lot to bring up the board quickly.  (Thank you!)

    http://www.raspberrypi.org/camera#

    As this site describes, I just used NETCAT and MPLAYER.


  3. Start Streaming!

    TX (RPi)
    raspivid -t 999999 -o - | nc [insert the IP address of the client] 5001

    RX (Windows 7)

    [Path to nc.exe]\nc.exe -L -p 5001 | [Path to mplayer.exe]\mplayer.exe -fps 31 -cache 1024 -

    I was actually able to stream the 1080p@30 video quite nicely.

    This is really interesting...


  4. Using battery pack...
    After the streaming check, I was curious it would work with the battery pack that I was using for RC Car project.
    Then, let's try..
    The battery pack is capable to output DC 5V < 1200mA.
    It seems like Raspberry Pi consumes about 700mA @5V.
    Not sure the how much the camera draws the current, but I read some people saying around 250mA.
    Maybe it would be worth trying the external battery!
    ...

    The result was interesting, and using above same resolution, the video was so unstable. It sometimes stop working.
    (I did not debug much but at least WiFi process was killed.)
    Also, I saw strange lines in the video image.
    I needed to lower the resolution to around 640 x 480 to make it work stable at 30Hz.


    TX (RPi)
    raspivid -t 999999 -w 640 -h 480 -o - | nc [insert the IP address of the client] 5001

    Hmm... this battery was working fine with RPi using USB camera though...

    Notes:
    
    1.  How to take picture/video using camera board
         Picture (JPEG)


           $ raspistill -o filename.jpg
         
          Video (for 5 seconds, h264)


           $ raspivid -t 5000 -o filename.h264

    2. How to transfer the file using NETCAT
         TX(RPi)
       $ nc [insert the IP address of the host(PC)] 5001 > filename


         RX(PC)
       $ nc -l 5001 < filename

Hardware:
    Raspberry Pi
    Raspberry Pi Camera Board
    EW-7781Uh WiFi dongle
    Concept Green Battery Portable Charger

   
Summary:
    WiFi video streaming was tested using Raspberry Pi camera board.

    RPi CPU usage was less than 40% for nc and about 6% for raspivid (top command)
    When I tried the battery pack, the video was so unstable...

    It could be the power line issue, and I should probably measure the current and voltage next time.

Reference:    
    http://www.raspberrypi.org/camera#
    http://en.wikipedia.org/wiki/Raspberry_Pi

Joystick for smartphone

Just found a joystick for smartphone games.
This might be good tool for our RC car project : )

Brick Joystick 001/002 for Smartphone Game


Android RC Car with Live Video Camera Streaming


We developed a system streaming video from a camera which was on an RC car. You can build this system on your own with your Android phone by less than $100.

This article based on the previous articles, "Web Cam Streaming from Raspberry Pi to Android using gstreamer" and "iRacer Controller Android Application".

Hardware

Items

Raspberry Pi
with a case
PS3 Eye Battery iRacer (RC Car)


Best Raspberry PI Kit (Recommended!)

RC Car appearance

Side-View
Front-View

                                                


System Diagram

Android Application

You can download the Android application source code from here.
Make sure that you choose the branch name "withStreaming".


Raspberry Pi: Streaming video and microphone from Microsoft LifeCam

  1. Wireless Video and Audio streaming using JPEG format WebcamInitially, I was using YUV format of PS3 Eye and encode the data to JPEG format to stream the video data over TCP/UDP, but it was taking large cpu usage of Rpi.
    I was thinking this could be due to the JPEG encoding...
    Microsoft LifeCam supports MJPEG format, and I am hoping this will reduce the cpu usage because PI does not need to deal with encoding.
    Well, let's see...

    Best Raspberry PI Kit (Recommended!)

           

  2. Microsoft LifeCam support format
    I used Microsoft LifeCam Cinema 720p HD Webcam, and here is the support formats.

    v4l2-ctl --list-formats

    ioctl: VIDIOC_ENUM_FMT
            Index       : 0
            Type        : Video Capture
            Pixel Format: 'YUYV'
            Name        : YUV 4:2:2 (YUYV)

            Index       : 1
            Type        : Video Capture
            Pixel Format: 'MJPG' (compressed)
            Name        : MJPEG

    If you want to check details of each format, use "v4l2-ctl --list-formats-ext" command.


  3.                                     


  4. Start Streaming!

    TX (RPi)
    gst-launch -v v4l2src ! "image/jpeg,width=320,height=240,framerate=30/1" ! multipartmux ! tcpserversink host=x.x.x.x port=5000 sync=false alsasrc device=hw:1 ! audioconvert ! audioresample ! 'audio/x-raw-int,rate=8000,width=16,channels=1' ! udpsink host=x.x.x.x port=5001
    RX (Android phone)
    Please refer to the previous work using Android smartphone streaming.(Link)
Hardware:
    Raspberry Pi
    Microsoft LifeCam Cinema 720p HD Webcam
    EW-7781Uh WiFi dongle
    Android phone (Droid X)

Summary:
    Video and microphone streaming was tested using MJPEG format of Microsoft LifeCam.

    Video and audio latency was reasonable (< 1 sec). 
    RPi CPU usage was less than 30% (top command)

Reference:

iRacer Controller Android Application



I wrote a simple Android application for iRacer controller. This video is a demo of the application.

Application source code is disclosed here.



Stellaris LaunchPad working I2C code example

I tried using Stellaris LaunchPad evaluation board (EK-LM4F120XL) with I2C communication and I had a trouble. I'd like to show you a working I2C code example here to avoid wasting time.

The reason of the difficulty was that the Launch Pad I2C pins for booster pack were shared with other GPIO pins in the default configuration. Therefore you need to configure the pins in right way.

See the function SetupI2C() below.


#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_gpio.h"
#include "inc/hw_uart.h"
#include "inc/hw_sysctl.h"
#include "inc/hw_i2c.h"
#include "driverlib/debug.h"
#include "driverlib/fpu.h"
#include "driverlib/gpio.h"
#include "driverlib/pin_map.h"
#include "driverlib/interrupt.h"
#include "driverlib/sysctl.h"
#include "driverlib/systick.h"
#include "driverlib/uart.h"
#include "driverlib/rom.h"
#include "driverlib/i2c.h"
#include "utils/ustdlib.h"
#include "utils/uartstdio.h"

#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>

#define I2C_SLAVE_ADDRESS       0x60

/*****************************************************************************/
/* This function returns:
 * I2C_MASTER_ERR_NONE, I2C_MASTER_ERR_ADDR_ACK, I2C_MASTER_ERR_DATA_ACK, or
 * I2C_MASTER_ERR_ARB_LOST.
 */
static unsigned long WaitI2CDone( unsigned int long ulBase){
    // Wait until done transmitting
    while( I2CMasterBusy(I2C3_MASTER_BASE));
    // Return I2C error code
    return I2CMasterErr( I2C3_MASTER_BASE);
}

static void SetupI2C(){
    /***
     * Shared Pin Setting
     */
    // You need to set the shared pins as input.
    GPIOPinTypeGPIOInput(GPIO_PORTB_BASE, GPIO_PIN_6 | GPIO_PIN_7);
    // Change the pad configuration to WPU
    GPIOPadConfigSet( GPIO_PORTB_BASE, GPIO_PIN_6 | GPIO_PIN_7, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_OD_WPU);

    /***
     * I2C Setting
     */
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);

    GPIOPinTypeI2CSCL(GPIO_PORTD_BASE, GPIO_PIN_0); //  special I2CSCL treatment for M4F devices
    GPIOPinTypeI2C(GPIO_PORTD_BASE, GPIO_PIN_1);

    GPIOPinConfigure(GPIO_PD0_I2C3SCL);
    GPIOPinConfigure(GPIO_PD1_I2C3SDA);

    SysCtlPeripheralEnable( SYSCTL_PERIPH_I2C3);

    I2CMasterInitExpClk( I2C3_MASTER_BASE, SysCtlClockGet(), false);
    SysCtlDelay(10000);
}


int main(void) {
    uint8_t data = 0;
    int16_t i2c_err = I2C_MASTER_ERR_NONE;

    //
    // Setup the system clock to run at 50 Mhz from PLL with crystal reference
    //
    SysCtlClockSet(SYSCTL_SYSDIV_4|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|
                    SYSCTL_OSC_MAIN);
    SysCtlDelay(10000);

    SetupI2C();

    /** Send register address.
     */
    I2CMasterSlaveAddrSet( I2C3_MASTER_BASE, I2C_SLAVE_ADDRESS, false);   // false = write, true = read
    // Set register address of AK8963
    I2CMasterDataPut( I2C3_MASTER_BASE, 0x00);
    // Start sending data
    I2CMasterControl( I2C3_MASTER_BASE, I2C_MASTER_CMD_SINGLE_SEND);
    WaitI2CDone( I2C3_MASTER_BASE);

    /** Set read mode.
     */
    I2CMasterSlaveAddrSet( I2C3_MASTER_BASE, I2C_SLAVE_ADDRESS, true);   // false = write, true = read

    /** Single Read
     */
    I2CMasterControl( I2C3_MASTER_BASE, I2C_MASTER_CMD_SINGLE_RECEIVE);
    if( (i2c_err = WaitI2CDone( I2C3_MASTER_BASE)))
        data = 0xff;
    else
        data = I2CMasterDataGet(I2C3_MASTER_BASE);

    return 0;
}


[AKM Chip Booster] Audio ADC AK5704 PCB Design

Designing a PCB prototype with AK5704 is not so difficult and I show an example with my design. People who are not familiar with AK5704,...