Tuesday, December 5, 2017

Using IR remote on Raspberry Pi 3

Refs:
http://www.instructables.com/id/Raspberry-Pi-Universal-Remote/
https://raspberrypi.stackexchange.com/questions/70945/setting-up-a-remote-control-using-lirc
https://www.raspberrypi.org/forums/viewtopic.php?f=35&t=145751


1. Install lirc
sudo apt-get install lirc

2. Change /etc/modules
sudo vim /etc/modules

Add the following to the bottom of the file:

lirc_dev
lirc_rpi gpio_in_pin=23 gpio_out_pin=22


3. Replace /etc/lirc/hardware.conf with the following content:

########################################################
# /etc/lirc/hardware.conf
#
# Arguments which will be used when launching lircd
LIRCD_ARGS="--uinput"

# Don't start lircmd even if there seems to be a good config file
# START_LIRCMD=false

# Don't start irexec, even if a good config file seems to exist.
# START_IREXEC=false

# Try to load appropriate kernel modules
LOAD_MODULES=true

# Run "lircd --driver=help" for a list of supported drivers.
DRIVER="default"

# usually /dev/lirc0 is the correct setting for systems using udev
DEVICE="/dev/lirc0"
MODULES="lirc_rpi"

# Default configuration files for your hardware if any
LIRCD_CONF=""
LIRCMD_CONF=""
########################################################

4. Update /boot/config.txt by modifying the following line:

# Uncomment this to enable the lirc-rpi module
dtoverlay=lirc-rpi,gpio_in_pin=23,gpio_out_pin=22
# dtparam=gpio_in_pull=up

5. sudo reboot

6. Record the IR commands and save it to /etc/lirc/lircd.conf

7. sudo lircd -d /dev/lirc0

8. irsend -# 600 SEND_ONCE FAIRYLIGHTS KEY_POWER



Wednesday, October 31, 2012

Rebuild a new kernel for ZTE-V9


I have bought this bargain device for a while but have not done something until this month.

So start from building a kernel on Mac OS X and flash it.

Build the kernel:

1. Get the kernel source code from ZTE website - google it.
2. Unzip the source
3. Install Android SDK and NDK.
4. Run the following command from platform-tools folder of Android SDK after connecting the device to the Mac:
./adb pull /proc/config.gz ~
This will copy the config file from the device to the Mac.
5. gunzip ~/config.gz
This command unzips the config file to config.
6. Copy config to .config in the unzip kernel source code folder (root folder).
7. Make a file called elf.h and put the content on the bottom of this post to it. Then put elf.h in the kernel source code folder (root folder).
8. Make a bash file called build.sh in kernel source code folder (root folder) with the following string:
make ARCH=arm SUBARCH=arm CROSS_COMPILE=~/android-ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86/bin/arm-linux-androideabi- HOSTCFLAGS="-I/opt/local/include/ -I."
Here, it assumes the NDK is installed in the home folder.
If there is an error msg saying: the symlink include/asm points to asm-x86 but asm-arm was expected, delete include/asm folder.
9. Run ./build.sh. If there is an error saying: ERROR: the symlink include/asm points to asm-x86 but asm-arm was expected, just delete linux/asm which points to asm-x86 folder.
10. Wait for the new kernel image

If everything goes well, there will be arch/arm/boot/zImage which is the compressed kernel.

Repackage the new kenrel:

Now build two tools for making an kernel image - mkbootimg and unpackbootimg. There maybe some pre-built versions available on web but it is quite easy to build them from the source code which is available from the master repository of Google Android source code - or google for an alternative.

Then get the current running kernel:

1. Run this command on V9: cat /dev/mtd/mtd2 > /mnt/sdcard/boot.img
2. Run this on Mac: ./adb pull /mnt/sdcard/boot.img .
3. Then: ./unpackbootimg -i boot.img

There will be couple files:
-rwxr-xr-x  1 Ray  staff  5242880 17 Oct 21:47 boot.img
-rw-r--r--  1 Ray  staff        9 23 Oct 14:32 boot.img-base
-rw-r--r--  1 Ray  staff        9 23 Oct 14:34 boot.img-base.txt
-rw-r--r--  1 Ray  staff        1 23 Oct 14:32 boot.img-cmdline
-rw-r--r--  1 Ray  staff        1 23 Oct 14:36 boot.img-cmdline.txt
-rw-r--r--  1 Ray  staff        5 23 Oct 14:32 boot.img-pagesize
-rw-r--r--  1 Ray  staff        5 23 Oct 14:35 boot.img-pagesize.txt
-rw-r--r--  1 Ray  staff   232299 23 Oct 14:32 boot.img-ramdisk.gz
-rw-r--r--  1 Ray  staff  3171056 23 Oct 14:32 boot.img-zImage

Copy arch/arm/boot/zImage to current folder.

Finally run:
mkbootimg –kernel zImage –ramdisk boot.img-ramdisk.gz –cmdline “(boot.img-cmdline.txt)” –base (boot.img-base.txt) –pagesize (boot.img-pagesize.txt) -o ./newboot.img

So newboot.img is the new kernel image.

Flash the new kernel:
1. ./adb push ./newboot.img /mnt/sdcard/newboot.img
2. ./adb shell
3. cat /dev/zero > /dev/mtd/mtd2
4. flash_image boot /mnt/sdcard/newboot.img
5. reboot

That's all.

If everything is fine, V9 should be back in normal.

Btw, to confirm the new image is installed, change CONFIG_LOCALVERSION in .config to something different before running ./build.sh so the kernel version is different from Settings page on V9.

=====================

#ifndef _LINUX_ELF_H
#define _LINUX_ELF_H

#include

#define R_386_NONE        0
#define R_386_32          1
#define R_386_PC32        2
#define R_ARM_NONE        0
#define R_ARM_PC24        1
#define R_ARM_ABS32       2
#define R_MIPS_NONE       0
#define R_MIPS_16         1
#define R_MIPS_32         2
#define R_MIPS_REL32      3
#define R_MIPS_26         4
#define R_MIPS_HI16       5
#define R_MIPS_LO16       6

#endif /* _LINUX_ELF_H */

Wednesday, May 26, 2010

Database access denied when mythtv-backend connects to MySQL

Verified with mysql-admin. The password is not mythtv. Not sure who sets it during MythTV setup. Changing it to mythtv can successfully finish MythTV backend setup.

And because of this wrong password, MythWeb cannot connect to the database - need to change it in /etc/apache2/sites-enabled/mythweb.conf

Add: The MythTV's password is changed again. I have to change it to mythtv in/etc/mythtv/mysql.txt. Who did this change

Tuesday, May 25, 2010

Installing AF9035 DVB-T USB Tuner on Ubuntu 10.04 (lucid) 64bit

There is already a discussion on http://ubuntuforums.org/showthread.php?t=1364396 but it does not solve the problem.

I tried these steps:

1. Get the 64bit source code from http://www.linux-cam.com/downloads/9035.linux.PC.dvb-tV9.07.10.1.zip

2. Get the kernel source code. My running kernel is 2.6.32.22. So I get the source code of 2.6.32.13

3. Make a folder called AF903x_SRC\v4l\kernel-2.6.32

4. Add the following lines to Makefile:

ifneq (,$(findstring 2.6.32, $(CURRENT)))
@cp -f v4l/kernel-2.6.32/* ./
endif

5. Copy dvb-usb.h and dvb-pll.h from the kernel source code to AF903x_SRC folder

6. Run the following commands from console:

sudo make clean
sudo make
sudo make install


7. Plug-in USB tuner, then run this command: cat /var/log/messages. It shows the following messages:

May 25 21:34:30 HTPC kernel: [215971.529790] usb 2-1: new high speed USB device using ehci_hcd and address 18
May 25 21:34:30 HTPC kernel: [215971.686942] usb 2-1: configuration #1 chosen from 1 choice
May 25 21:34:30 HTPC kernel: [215971.692255] input: Afa Technologies Inc. AF9035A USB Device as /devices/pci0000:00/0000:00:06.1/usb2/2-1/2-1:1.1/input/input25
May 25 21:34:30 HTPC kernel: [215971.692644] generic-usb 0003:15A4:1001.0016: input,hidraw0: USB HID v1.01 Keyboard [Afa Technologies Inc. AF9035A USB Device] on usb-0000:00:06.1-1/input1
May 25 21:34:31 HTPC kernel: [215971.963099] AF903X: af903x_module_init
May 25 21:34:31 HTPC kernel: [215971.963181] DRIVER_RELEASE_VERSION : v9.07.10.1
May 25 21:34:31 HTPC kernel: [215971.963189] FW_RELEASE_VERSION : v8_8_63_0
May 25 21:34:31 HTPC kernel: [215971.963196] API_RELEASE_VERSION : 200.20090402.0
May 25 21:34:31 HTPC kernel: [215972.472189] dvb-usb: found a 'ITEtech USB2.0 DVB-T Recevier' in warm state.
May 25 21:34:31 HTPC kernel: [215972.545942] dvb-usb: will pass the complete MPEG2 transport stream to the software demuxer.
May 25 21:34:31 HTPC kernel: [215972.546762] DVB: registering new adapter (ITEtech USB2.0 DVB-T Recevier)
May 25 21:34:31 HTPC kernel: [215972.547603] DVB: registering adapter 0 frontend 0 (AF903X USB DVB-T)...
May 25 21:34:31 HTPC kernel: [215972.559440] dvb-usb: ITEtech USB2.0 DVB-T Recevier successfully initialized and connected.
May 25 21:34:31 HTPC kernel: [215972.559570] usbcore: registered new interface driver dvb_usb_af903x

Verify the tuner with http://parker1.co.uk/mythtv_dvb.php and get the perfect ABC HDTV. But I am surprised that it's 1280 x 720 - not full HD.

Note: Not sure if disabling usbhid is required. I did that as mentioned in the discussion but did not notice any change before I successfully installed the driver.

Sunday, May 23, 2010

Start Blogging...

Nothing to say today. It's late