2011年4月27日 星期三

BeagleBoard i2c SRF08

SRF08 is an ultra sonic range finder, I'm trying to connect it to BeagleBoard. The hardware interface is i2c and we need to do some modify to kernel & u-boot to get it work.

http://www.robot-electronics.co.uk/htm/srf08tech.shtml

Reference
http://yetanotherhackersblog.wordpress.com/2011/04/07/interfacing-the-beagleboard-with-an-srf08-ultrasonic-ranger-over-i2c/?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+BeagleBoard+%28BeagleBoard.org%29&utm_content=FaceBook

1.Hardware interface
BeagleBoard i2c interface runs at 1.8v and SRF08 i2c interface runs at 5v. In order to get it work, we need i2c level shift. There are some chips can do it, what I got is PCA9517.
http://elinux.org/BeagleBoard_Hardware_Interfacing

http://ics.nxp.com/support/documents/interface/pdf/an97055.pdf

2.The circuit


We are planing to use BeagleBoard I2C2 interface, which pins are at expansion connector pin 23 and 24.

Be attention ! all the 10k resisters are rquired.
http://groups.google.com/group/beagleboard/browse_thread/thread/a6c42ef56c6a2da2/1608e6c0f0207a8d?lnk=raot

3.u-boot
First, make sure the pin mux is correct.

boards/ti/beagle/beagle.h

-MUX_VAL((CP(I2C2_SCL), (IEN | PTU | EN | M4) \
-MUX_VAL((CP(I2C2_SDA), (IEN | PTU | EN | M4) \
+MUX_VAL((CP(I2C2_SCL), (IEN | PTU | EN | M0) \
+MUX_VAL((CP(I2C2_SDA), (IEN | PTU | EN | M0) \


Then enable pull-up internal resister on i2c2
http://groups.google.com/group/beagleboard/browse_thread/thread/f5d308f24b27bb38/21febf1a98e0be0c?lnk=raot


4.kernel
Enable I2C2 interface

static int __init omap3_beagle_i2c_init(void)
{
        omap_register_i2c_bus(1, 2600, beagle_i2c_boardinfo,
                        ARRAY_SIZE(beagle_i2c_boardinfo));

+#if defined CONFIG_INPUT_ST_MOTION_SENSOR
        omap_cfg_reg(AE4_34XX_GPIO136);
        omap_register_i2c_bus(2, 400, beagle_i2c2_boardinfo,
                        ARRAY_SIZE(beagle_i2c2_boardinfo));
+#else
+       omap_register_i2c_bus(2, 100, NULL, 0);
+#endif
        /* Bus 3 is attached to the DVI port where devices like the pico DLP
         * projector don't work reliably with 400kHz */
        omap_register_i2c_bus(3, 100, NULL, 0);
        return 0;
}

Then you can find /dev/i2c-2 device node

5.Testing

# ls /dev/i2c-2 -al
crw-rw----    1 root     root      89,   2 Jan  1 00:00 /dev/i2c-2

# i2cdetect -r 2
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will probe file /dev/i2c-2 using read byte commands.
I will probe address range 0x03-0x77.
Continue? [Y/n] y
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: 70 -- -- -- -- -- -- --                        


Get range in centimeters

# i2cset 2 112 0 81
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will write to device file /dev/i2c-2, chip address 0x70, data address
0x00, data 0x51, mode byte.
Continue? [Y/n] y
# i2cget 2 112 2
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will read from device file /dev/i2c-2, chip address 0x70, data address
0x02, using read byte data.
Continue? [Y/n] y
0x00
# i2cget 2 112 3
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will read from device file /dev/i2c-2, chip address 0x70, data address
0x03, using read byte data.
Continue? [Y/n] y
0x25

We got 0x25 = 37 cm




2011年4月8日 星期五

Beagleboard xM - Camera board

延續之前 DVSDK ,接著來看DSP Multimedia的應用

1.Beagleboard XM camera board
Leopard imaging inc 有一系列camera board支援BeagleBoard XM.
https://www.leopardimaging.com/Beagle_Board_xM_Camera.html\



有1.3M / 3M / 5M (百萬畫素) 鏡頭.其中 1.3M / 3M camera board 在 DVSDK 上已有driver.
我手邊有 LI-LBCM3M1 三百萬畫素 CMOS sensor mt9t111 (相容 mt9t112), DVSDK PSP linux已經包含mt9t112 driver.
載入camera driver需要修改bootloader 環境變數.
首先將SD card 連接至PC, 新增檔案BOOT/boot_dvi_lbcm3m1.cmd 如下

setenv bootargs 'console=ttyS2,115200n8 root=/dev/mmcblk0p2 rw ip=off mem=55M@0x80000000 mpurate=1000  omap_vout.vid1_static_vrfb_alloc=y omapfb.vram=0:8M mem=384M@0x88000000 omapfb.mode=dvi:hd720 omapdss.def_disp=dvi rootwait vram=8M camera=lbcm3m1'
fatload mmc 0 80200000 uImage
bootm 80200000

接著產生 boot_dvi_lbcm3m1.scr

gigijoe@gigijoe-laptop:/media/BOOT$ mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n 'Execute Boot Script' -d boot_dvi_lbcm3m1.cmd boot_dvi_lbcm3m1.scr
Image Name:   Execute Boot Script
Created:      Tue Mar 29 20:19:04 2011
Image Type:   ARM Linux Script (uncompressed)
Data Size:    304 Bytes = 0.30 kB = 0.00 MB
Load Address: 0x00000000
Entry Point:  0x00000000
Contents:
   Image 0:      296 Bytes =    0 kB = 0 MB

增加camera=lbcm3m1,使相對應的driver會被自動載入.

root@beagleboard-dvsdk:~# lsmod
Module                  Size  Used by
sdmak                   3759  0
lpm_omap3530            6537  0
dsplinkk              124358  1 lpm_omap3530
cmemk                  21358  0
bufferclass_ti          4838  0
omaplfb                 8770  0
pvrsrvkm              129682  2 bufferclass_ti,omaplfb
ipv6                  249320  14
rtc_twl                 4263  0
rtc_core               12531  1 rtc_twl
mt9t112                 9329  0

2.Test camera board
首先先測試camera影像是否正常,最方便的方式是使用DVSDK built-in gstreamer
Camera device node 是 /dev/video0

gst-launch v4l2src always_copy=FALSE ! video/x-raw-yuv,width=640,height=480 ! queue max-size-buffers=8000 max-size-time=0 max-size-bytes=0 ! TIDmaiVideoSink videoStd=720P_60 videoOutput=AUTO numBufs=5

應該會在DVI output上看到影像



3.Play with camera board

現在來看實際上的應用,場景是將Camera board得到的影像透過DSP 壓縮成H.264格式,接著以RTP H.264封裝透過網路傳送到PC端,接著PC端將影像解壓縮並顯示在銀幕上

BeagleBoard XM : 192.168.168.89

gst-launch v4l2src always_copy=FALSE ! video/x-raw-yuv,width=640,height=480 ! queue max-size-buffers=8000 max-size-time=0 max-size-bytes=0 ! TIVidenc1 codecName=h264enc engineName=codecServer ! rtp264pay pt=96 ! multiudpsink client="192.168.168.56:1234"

PC : 192.168.168.56

gst-launch udpsrc port=1234 caps="application/x-rtp,media=(string)video,clock-rate=(int)90000,encoding-name=(string)H264" ! gstrtpjitterbuffer latency=100 ! rtph264depay ! ffdec_h264 ! xvimagesink