Monday, June 8, 2015

Raspberry Pi and Wi-Fi dropout problem

Wi-Fi connection gets dropped quite often. I have Wi-Pi adapter that has Ralink rt2800us chipset (you can find tests of different adapters here). You can confirm this from dmesg:
$ dmesg | grep rt2x00
[ 5.800208] ieee80211 phy0: rt2x00_set_rt: Info - RT chipset 5390, rev 0502 detected
[ 6.134049] ieee80211 phy0: rt2x00_set_rf: Info - RF chipset 5370 detected
[ 18.272745] ieee80211 phy0: rt2x00lib_request_firmware: Info - Loading firmware file 'rt2870.bin'
[ 18.275301] ieee80211 phy0: rt2x00lib_request_firmware: Info - Firmware detected - version: 0.29
Now, how can we improve Wi-Fi stability? First, you can disable the power management of the Wi-Fi adapter. However, you can also write a script that will ping something, say, every, minute. Check power management:
$ iwconfigwlan0 IEEE 802.11bgn ESSID:"***********"
Mode:Managed Frequency:2.447 GHz Access Point: F4:EC:38:CA:D9:88
Bit Rate=108 Mb/s Tx-Power=20 dBm
Retry long limit:7 RTS thr:off Fragment thr:offPower Management:onLink Quality=55/70 Signal level=-55 dBm
Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0Tx excessive retries:0 Invalid misc:1 Missed beacon:0
Disable power management as follows if enabled:
$ echo “wireless-power off” >> /etc/network/interfaces
You can also try to keep the connection alive. Add crontab job /usr/local/bin/reconnect-wifi.sh that will check Wi-Fi state every 5 minutes:
#!/bin/bashifconfig wlan0 | grep -q "inet addr"if [ "$?" != 0 ]; then ifup --force wlan0fi
Add new job to crontab. Open your crontab:
$ crontab -e
and add this line at the end:
*/5 * * * * root /usr/local/bin/reconnect-wifi.sh >> /var/log/syslog 2>&1

Saturday, May 9, 2015

Improving working lighting

Recently I decided to improve my working lighting. For this purposes I bought 10W LED projector. But it turned out it has pretty low quality and has a few issues: overheating and flickering. It was decided to improve both.

To improve flickering I replaced original 120uF, 100V output capacitor with 1000uF, 100V capacitor (I would put 2000uF there but I was have to rewire everything inside even for 1000uF to fit it). Be very careful with high voltage capacitor, this circuit doesn't have discharge resistor.


To reduce hit a bit from LED matrix I put 1 Ohm, 5W resistor. It also would be nice to replace heat sink with a bigger one.


To fit everything inside was quite a challenge. Now testing. The following images show original and improved lighting respectively (and yes, video would be better):




Saturday, April 25, 2015

Cross-Compiling for the Raspberry Pi: distributed compilation

So far I've been trying different cross-compiling techniques: QEmu, Scratchbox and Raspberry Pi tools. But I should say, they didn't work for me. Just try to build something as big as GStreamer and you will get what I'm saying.

The new approach that I'm heavily using right now is distributed compilation. It allows you by just launching the make command, having your remote PC working instead of your Pi, and a few seconds later having your program/library compiled just as if everything happened on the Pi itself.

1. Configure slaves: install distcc and configure it. Figure out how many processors you have available on the machine(s) and how many of those you would like to share. Start slave as follows (or configure it as a daemon):
$ distccd --user nobody --jobs 8 --allow 192.168.1.133 --verbose --log-stderr
2. Configure Raspbian master: install distcc and configure it. Edit /etc/distcc/hosts and comment out the line with +zeroconf. Add space-delimited list of slaves on your network.

3. Compile it! Edit PATH so it uses distcc instead of the local compiler:
$ export PATH=/usr/lib/distcc:$PATH
$ which gcc
Start compilation process.

UPDATE: very important thing that I forgot to mention. Before running distcc on your slave machine you will need to install Raspberry Pi tools and update PATH as follows:
$ export PATH=$RPI_TOOLS/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin:$PATH

Friday, December 19, 2014

Cross-Compiling for the Raspberry Pi

It's not cost-efficient to develop and compile on the Pi itself. Instead, you would probably to develop and compile on your multi-core development system, then transfer the binary over to the Pi and test it there. To do this, you need a set of tools, a toolchain,

The following steps describe how to create a no-compromises Raspberry Pi toolchain on Ubuntu 12.04 using Crosstool-NG.

1. Install dependencies

Run the following command to install the required packages:
$ sudo apt-get install gawk bison flex gperf cvs texinfo automake libtool ncurses-dev g++ subversion python-dev libexpat1-dev cmake
2. Download, build, and install Crosstool-NG

Crosstool-NG isn't available in the standard Ubuntu repositories. Run the following commands to download, build, and install it:
$ pushd ~/raspberry_pi/build
$ curl -O http://crosstool-ng.org/download/crosstool-ng/crosstool-ng-1.18.0.tar.bz2
$ tar xf crosstool-ng-1.18.0.tar.bz2
$ cd crosstool-ng-1.18.0
$ ./configure --enable-local && make && make install
$ export PATH=`pwd`:$PATH
$ popd
3. Configure, build, and install the toolchain

Crosstool-NG comes with a tool called menuconfig that makes it easy to configure how the toolchain should be built. Run the following commands to launch menuconfig, then follow the sub-sections below to configure the toolchain build parameters:
$ pushd ~/raspberry_pi/build/toolchain
$ ct-ng menuconfig
Setup Path Options
  • Navigate to Paths and misc options.
  • Enable Try features marked as EXPERIMENTAL.
  • Set Prefix directory to ${HOME}/raspberry_pi/toolchains/${CT_TARGET}.
  • Enable Use a mirror.
  • Set Number of parallel jobs to twice the number of HW threads.
Setup Target Options
  • Navigate to Target options.
  • Set Target Architecture to arm.
  • Leave Endianness as Little and Bitness as 32-bit.
  • Set append ‘hf' to the tuple (EXPERIMENTAL).
Setup Operating System Options
  • Navigate to Operating System.
  • Set Target OS to Linux.
Setup Binary Utility Options
  • Navigate to Binary utilities.
  • Set Binutils to 2.22.
Setup Compiler Options
  • Navigate to C compiler.
  • Enable Show Linaro versions.
  • Enable C++ support.
C-library
  • Set eglibc version to 2_13.
Setup Debug Options
  • Navigate to Debug facilities.
  • Enable gdb, then press [Enter] to configure additional GDB settings.
    • Enable Build a static cross gdb.
    • Set Cross-gdb extra config to --with-expat.
  • Enable ltrace.
  • Enable strace.
Exit and confirm to save the configuration file returning to your shell.

4. Build the toolchain

We are now ready to build and install the toolchain. Start the build by running the following commands:
$ ct-ng build
$ popd 
If the build was successful, the toolchain will be located at ~/raspberry_pi/toolchains/arm-unknown-linux-gnueabihf/. All the tools (gcc, ld, gdb, etc) are located in the bin/ directory of the toolchain with the name of the toolchain prefixed.

Run the following command to add the toolchain binaries to the PATH environment variable:
$ pushd ~/raspberry_pi/toolchains/arm-unknown-linux-gnueabihf/bin
$ export PATH=`pwd`:$PATH
$ popd

Monday, November 24, 2014

How to print a cog without 3D printer

For one of the projects I have 3D printed stepper-driven tank platform. However there is one cog missing because the original one doesn't fit to my motor shaft.

Unfortunately on this moment I do not have an access to 3D printer and was have to find a way around to make this cog. I decided to try oven bake modelling clay with procelain finish.

I made a print of original cog and motor shaft on the peace of clay and cut it with x-acto knife. Then I baked it for a 15 minutes with ~115*C. It's really strong, you cannot break it with hands. However you have to be very careful and do not overheat it:

It looks and works pretty well. No complains so far.

Tuesday, May 13, 2014

Stream video/audio from Raspberry Pi

  1. Stream audio with vlc:

    Raspberry Pi
    $ cvlc -vvv alsa://hw:1 --sout '#rtp{sdp=rtsp://:8554/}'
    Desktop
    $ vlc rtsp://raspberry-pi:8554/

  2. Stream video with vlc

    Raspberry Pi
    $ raspivid -fps 25 -g 240 -o - -t 0 -b 1500000 --vflip -w 1200 -h 600 | \
    cvlc -vvv stream:///dev/stdin \
    --sout '#standard{access=http,mux=ts,dst=:8090}' :demux=h264
    Desktop
    $ vlc http://raspberry-pi:8090/

Saturday, March 15, 2014

PropGCC and Raspberry Pi

1. Install makeinfo.
$ cd ~/tmp/
$ wget http://ftp.gnu.org/gnu/texinfo/texinfo-4.13a.tar.gz
$ tar zxvf texinfo-4.13a.tar.gz
$ cd texinfo-4.13
$ ./configure
$ make
$ export PATH=$PATH:~/tmp/texinfo-4.13/makeinfo/
2. Install Raspberry Pi cross compiler.
$ mkdir ~/rpi
$ cd ~/rpi
$ git clone git://github.com/raspberrypi/tools.git
$ export PATH=$PATH:~/rpi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/
3. Build and install PropGCC.
$ cd ~/tmp/
$ hg clone https://code.google.com/p/propgcc/
$ cd propgcc
$ make CROSS=rpi
The output is in /opt/parallax-rpi.

References:

Saturday, February 8, 2014

Pinout for HYDRA SD Max Storage Card


The pinout for the HYDRA SD Max Storage Card:


SD card interface:

PinNameDescription
1I/O_0DO
2I/O_1CLK
3I/O_2DI
4I/O_3CS
143.3V3.3V
20GNDGND

Also see Table 2.0 from "HYDRA SD Max Storage Card User Manual Sample" for more details.

Wednesday, January 15, 2014

Virtual Raspbian on QEMU in Ubuntu


How to run virtual Raspbian on QEMU in Ubuntu:

1. Compile QEMU for ARM (1176).

$ sudo apt-get install git zlib1g-dev libsdl1.2-dev libpixman-1-dev
$ cd tmp
$ git clone git://git.qemu-project.org/qemu.git && cd qemu
$ ./configure --target-list="arm-softmmu arm-linux-user" --enable-sdl --prefix=/usr/local
$ make
$ sudo make install
2. Prepare QEMU environment and raspbian image.
$ mkdir ~/qemu-vms/ && cd ~/qemu-vms/
Download Raspbian Wheezy from http://www.raspberrypi.org/downloads and Linux kernel for QEMU from http://xecdesign.com/downloads/linux-qemu/kernel-qemu.
$ file ~/qemu-vms/2014-01-07-wheezy-raspbian.img
~/qemu-vms/2014-01-07-wheezy-raspbian.img: x86 boot sector; partition 1: ID=0xc, starthead 130, startsector 8192, 114688 sectors; partition 2: ID=0x83, starthead 165, startsector 122880, 5662720 sectors, code offset 0xb8
Take the partition 2 'startsector' value an multiply by 512, and use this figure as the offset value in the mount command below:
$ sudo mount ~/qemu-vms/2014-01-07-wheezy-raspbian.img -o offset=$((122880*512)) /mnt
Comment out the line in the /mnt/etc/ld.so.preload file and unmount:
$ sudo emacs -nw /mnt/etc/ld.so.preload
$ sudo umount /mnt
3. Run simulation.
$ qemu-system-arm -kernel kernel-qemu -cpu arm1176 -m 256 -M versatilepb -no-reboot -serial stdio -append "root=/dev/sda2 panic=1" -hda ~/qemu-vms/2014-01-07-wheezy-raspbian.img -redir tcp:5022::22
QEMU gives you a root shell, run:
$ fsck /dev/sda2
$ shutdown -r now
UPDATE: how to open ssh connection (see -redir option):
$ ssh -p 5022 pi@localhost
UPDATE: how expand free space:

1. Create /etc/udev/rules.d/90-qemu.rules with the following content and shutdown the system:
KERNEL=="sda", SYMLINK+="mmcblk0"
KERNEL=="sda?", SYMLINK+="mmcblk0p%n"
KERNEL=="sda2", SYMLINK+="root"
2. Resize the image:
$ qemu-img resize /qemu-vms/2014-01-07-wheezy-raspbian.img +4G
3. Boot up your emulator again and do:

$ sudo ln -snf mmcblk0p2 /dev/root
$ sudo raspi-config

Choose the first option to resize your disk, and it will tell you to reboot.

UPDATE: update keyboard mappings if necessary:

$ sudo dpkg-reconfigure keyboard-configuration