embeded/raspberry pi2015. 9. 10. 13:40

wiring pi gpio 유틸 도움말을 보던 중에

어? 이런 기능이?

혹시.. 2B에도 적용되려나?


usbp   high | low

Change  the USB current limiter to high (1.2 amps) or low (the default, 600mA)

This is only applicable to the model B+


[링크 : https://projects.drogon.net/testing-setting-the-usb-current-limiter-on-the-raspberry-pi-b/]



+ 2015.09.11

어? 2b랑 b+이랑 보드 같은거 아니었어!??!?

pi@raspberrypi ~ $ gpio usbp high

USB power contol is applicable to B+ boards only.

pi@raspberrypi ~ $ gpio usbp low

USB power contol is applicable to B+ boards only. 


차이를 모르겠다 -_-a

아무튼.. 설정은 되는데 테스트는 나중에 USB 하드라도 물려봐야지 머..

pi@raspberrypi ~ $ gpio -g write 38 0

pi@raspberrypi ~ $ gpio -g mode 38 out

pi@raspberrypi ~ $ gpio -g write 38 1


I know the following:


Setting max_usb_current=1 sets the available current over USB to 1.2A (default is 600mA)

This can help if you have a decent power supply (2A, at least) and need to power something like a small external HDD or something that needs 300+ mA.

This feature is only available on the B+ and Pi model 2 (at the time of this writing)

[링크 : http://raspberrypi.stackexchange.com/.../is-setting-max-usb-current-1-to-give-more-power...]



max_usb_current


Together with the raspberry PI B+ a new config.txt setting was introduced.


  max_usb_current=1

when adding this line the USB power manager will change its output current limit (for all 4 USB ports combined) from 600mA to double that, 1200mA.

[링크 : http://elinux.org/RPiconfig#USB_Power]



---

집에와서 해보니..

두개중에 하나만 해줘도 되는거 같고..

$ cat /boot/config.txt 

safe_mode_gpio=4

max_usb_current=1


이렇게 38번 핀을 high 로 해도 USB 하드가 바로 전력소비가 커버되는지 삑삑삑삑

스핀들 모터가 못돌다가 조용해진다.(인식/마운트 성공)

$ gpio -g mode 38 out

$ gpio -g write 38 1 



결론 B+이나 2B나 같으니 2B에서도 된다!

Posted by 구차니
embeded/raspberry pi2015. 9. 7. 16:43

흐음.. 한번 써봐야지


int waitForInterrupt (int pin, int timeOut) ;

gpio edge 0 falling


int wiringPiISR (int pin, int edgeType,  void (*function)(void)) ;

INT_EDGE_FALLING

INT_EDGE_RISING

INT_EDGE_BOTH

INT_EDGE_SETUP


gpio edge <pin> rising/falling/both/none

This enables the given pin for edge interrupt triggering on the rising, falling or both edges. (Or none which disables it)



       edge   This exports a GPIO pin  in  the  /sys/class/gpio  directory,  set  the

              direction  to  input and set the edge interrupt method to none, rising,

              falling or both.  Use like the  export  command  above  and  note  that

              BCM_GPIO pin number is used not not wiringPi pin numbering.


              Like the export commands above, ownership is set to that of the calling

              user, allowing subsequent access from user programs  without  requiring

              root/sudo. 


[링크 : http://wiringpi.com/reference/priority-interrupts-and-threads/]

[링크 : https://projects.drogon.net/raspberry-pi/wiringpi/functions/]

Posted by 구차니
embeded/raspberry pi2015. 9. 4. 18:44

pigpio 라는 다른 라이브러리가 존재한다.

[링크 : http://abyz.co.uk/rpi/pigpio/examples.html]


라즈베리 B 인거 같은데..

출력은 22Mhz 까지(단순하게 on/off만) 가능

[링크 : http://codeandlife.com/2012/07/03/benchmarking-raspberry-pi-gpio-speed/]


아무튼..

TSL235R 라는 녀석이 결과물이 주파수로 나와서

그걸 이용하는 예제

#!/usr/bin/python

import RPi.GPIO as GPIO


GPIO.setmode(GPIO.BCM)

GPIO.setup(25, GPIO.IN)


impuls_count = 0

# Do next lines for i.e. 1000ms:

GPIO.wait_for_edge(25, GPIO.FALLING)

impuls_count = impuls_count + 1


[링크 : http://stackoverflow.com/..../how-to-get-the-frequency-of-a-square-wave-in-a-python-script] 





Posted by 구차니
embeded/raspberry pi2015. 9. 3. 09:45

dht 관련 dtoverlay가 존재하는게 생각이 나서 삽질..

Name:   dht11

Info:   Overlay for the DHT11/DHT21/DHT22 humidity/temperature sensors

        Also sometimes found with the part number(s) AM230x.

Load:   dtoverlay=dht11,<param>=<val>

Params: gpiopin                  GPIO connected to the sensor's DATA output.

                                 (default 4)


[링크 : https://github.com/raspberrypi/firmware/blob/master/boot/overlays/README] 


오홍 존재는 하네?(라즈비안)

$ sudo find / -name dht11.ko

/lib/modules/4.1.6+/kernel/drivers/iio/humidity/dht11.ko

/lib/modules/4.1.6-v7+/kernel/drivers/iio/humidity/dht11.ko


$ sudo modprobe dht11

$ lsmod | grep dht11

dht11                   3531  0

industrialio           35498  1 dht11


$ modinfo dht11

filename:       /lib/modules/4.1.6-v7+/kernel/drivers/iio/humidity/dht11.ko

license:        GPL v2

description:    DHT11 humidity/temperature sensor driver

author:         Harald Geyer <harald@ccbib.org>

srcversion:     136C0D2A25E76F8042B460C

alias:          of:N*T*Cdht11*

depends:        industrialio

intree:         Y

vermagic:       4.1.6-v7+ SMP preempt mod_unload modversions ARMv7 


/boot/overlays 에 파일이 존재하지 않아도 커널에 모듈로 내장되어 있는지 리부팅후 lsmod로 확인이 가능하다.

$ sudo vi /boot/config.txt

dtoverlay=dht11


/sys/devices/platform $ ls -al

합계 0

drwxr-xr-x 17 root root    0  9월  3 09:40 .

drwxr-xr-x  9 root root    0  9월  3 09:40 ..

drwxr-xr-x  2 root root    0  9월  3 09:44 alarmtimer

drwxr-xr-x  2 root root    0  9월  3 09:44 bcm2835_AUD0.0

drwxr-xr-x  2 root root    0  9월  3 09:44 bcm2835_AUD1.1

drwxr-xr-x  2 root root    0  9월  3 09:44 bcm2835_AUD2.2

drwxr-xr-x  2 root root    0  9월  3 09:44 bcm2835_AUD3.3

drwxr-xr-x  2 root root    0  9월  3 09:44 bcm2835_AUD4.4

drwxr-xr-x  2 root root    0  9월  3 09:44 bcm2835_AUD5.5

drwxr-xr-x  2 root root    0  9월  3 09:44 bcm2835_AUD6.6

drwxr-xr-x  2 root root    0  9월  3 09:44 bcm2835_AUD7.7

drwxr-xr-x  8 root root    0  9월  3 09:44 clocks

drwxr-xr-x  3 root root    0  9월  3 09:42 dht11@0

drwxr-xr-x  2 root root    0  9월  3 09:40 regulatory.0

drwxr-xr-x  2 root root    0  9월  3 09:44 serial8250

drwxr-xr-x 17 root root    0  9월  3 09:40 soc

drwxr-xr-x  2 root root    0  9월  3 09:44 timer

-rw-r--r--  1 root root 4096  9월  3 09:40 uevent


어짜피 이녀석은.. 위의 녀석의 심볼릭 링크

/sys/bus/iio/devices/iio:device0 $ ls -al

합계 0

drwxr-xr-x 2 root root    0  9월  3 09:42 .

drwxr-xr-x 3 root root    0  9월  3 09:42 ..

-r--r--r-- 1 root root 4096  9월  3 09:42 dev

-rw-r--r-- 1 root root 4096  9월  3 09:42 in_humidityrelative_input

-rw-r--r-- 1 root root 4096  9월  3 09:42 in_temp_input

-r--r--r-- 1 root root 4096  9월  3 09:42 name

lrwxrwxrwx 1 root root    0  9월  3 09:42 of_node -> ../../../../firmware/devicetree/base/dht11@0

lrwxrwxrwx 1 root root    0  9월  3 09:42 subsystem -> ../../../../bus/iio

-rw-r--r-- 1 root root 4096  9월  3 09:42 uevent



집에가서 센서 달고 해봐야지..


lm-sensor에서 dht11을 iio를 통해 값을 불러 올 수 있도록 수정 된 듯?

[링크 : http://lists.lm-sensors.org/pipermail/lm-sensors/2013-July/039283.html]



GPIO4 라고 되어있는데.. 그냥 핀번호 상으로 4번에 하니 먼가 되긴한다..

$ gpio readall

 +-----+-----+---------+------+---+---Pi 2---+---+------+---------+-----+-----+

 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |

 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+

 |     |     |    3.3v |      |   |  1 || 2  |   |      | 5v      |     |     |

 |   2 |   8 |   SDA.1 | ALT0 | 1 |  3 || 4  |   |      | 5V      |     |     |

 |   3 |   9 |   SCL.1 | ALT0 | 1 |  5 || 6  |   |      | 0v      |     |     |

 |   4 |   7 | GPIO. 7 |   IN | 1 |  7 || 8  | 1 | ALT0 | TxD     | 15  | 14  |

 |     |     |      0v |      |   |  9 || 10 | 1 | ALT0 | RxD     | 16  | 15  |

 |  17 |   0 | GPIO. 0 |   IN | 0 | 11 || 12 | 0 | IN   | GPIO. 1 | 1   | 18  |

 |  27 |   2 | GPIO. 2 |   IN | 0 | 13 || 14 |   |      | 0v      |     |     |

 |  22 |   3 | GPIO. 3 |  OUT | 1 | 15 || 16 | 0 | IN   | GPIO. 4 | 4   | 23  |

 |     |     |    3.3v |      |   | 17 || 18 | 1 | OUT  | GPIO. 5 | 5   | 24  |

 |  10 |  12 |    MOSI | ALT0 | 0 | 19 || 20 |   |      | 0v      |     |     |

 |   9 |  13 |    MISO | ALT0 | 0 | 21 || 22 | 1 | OUT  | GPIO. 6 | 6   | 25  |

 |  11 |  14 |    SCLK | ALT0 | 0 | 23 || 24 | 1 | OUT  | CE0     | 10  | 8   |

 |     |     |      0v |      |   | 25 || 26 | 1 | OUT  | CE1     | 11  | 7   |

 |   0 |  30 |   SDA.0 |   IN | 1 | 27 || 28 | 1 | IN   | SCL.0   | 31  | 1   |

 |   5 |  21 | GPIO.21 |   IN | 1 | 29 || 30 |   |      | 0v      |     |     |

 |   6 |  22 | GPIO.22 |   IN | 1 | 31 || 32 | 0 | IN   | GPIO.26 | 26  | 12  |

 |  13 |  23 | GPIO.23 |   IN | 0 | 33 || 34 |   |      | 0v      |     |     |

 |  19 |  24 | GPIO.24 |   IN | 0 | 35 || 36 | 0 | IN   | GPIO.27 | 27  | 16  |

 |  26 |  25 | GPIO.25 |   IN | 0 | 37 || 38 | 0 | IN   | GPIO.28 | 28  | 20  |

 |     |     |      0v |      |   | 39 || 40 | 0 | IN   | GPIO.29 | 29  | 21  |

 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+

 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |

 +-----+-----+---------+------+---+---Pi 2---+---+------+---------+-----+-----+ 


/sys/bus/iio/devices/iio:device0 $ sudo cat in_*

65000

24000


/sys/bus/iio/devices/iio:device0 $ sudo cat in*
95000
19000

/sys/bus/iio/devices/iio:device0 $ sudo cat in_*
cat: in_humidityrelative_input: 입력/출력 오류
cat: in_temp_input: 연결 시간 초과

$ dmesg
[   93.266278] iio iio:device0: Only 0 signal edges detected
[   94.390030] dht11: WARNING: decoding ambiguous
[   95.416292] iio iio:device0: Only 0 signal edges detected
[  105.476356] iio iio:device0: Only 0 signal edges detected
[  113.646349] iio iio:device0: Only 0 signal edges detected
[  165.000461] dht11: WARNING: decoding ambiguous
[  199.120659] dht11: WARNING: decoding ambiguous
[  201.230684] dht11: WARNING: decoding ambiguous
[  204.160759] dht11: WARNING: decoding ambiguous
[  205.186935] iio iio:device0: Only 0 signal edges detected

저 값이 무슨 의미인지도 모르겠고.. (그냥 65% 24도로 보면되려나?)

잘 안읽히거나 연결 시간 초과로 읽는데 오래 걸리기도 하니까..

여러번 계속 읽어 봐야 한다. ㄷㄷㄷ



+

2015.09.09

그래도 어떤 사람은 75% 성공률로 읽는다는데.. 난 더 낮은 느낌?

[링크 : https://www.raspberrypi.org/forums/viewtopic.php?p=779355]


쓰레드로 된건 읽기 왜케 힘드냐 -_-

[링크 : http://www.spinics.net/lists/linux-iio/msg19328.html]

Posted by 구차니
embeded/raspberry pi2015. 9. 3. 09:13

생각해보니.. 음속은 기온에 비례하는데

공식으로는 대충


음속 = (331.3 + 0.606 * 섭씨) m/s

0도에서 약 331m인데

실온이면 약 18도 로 잡고(10.908m/s) 342.208m/s

근사치로 340 정도 잡으면 될거 같긴한데


[링크 : https://en.wikipedia.org/wiki/Speed_of_sound]


어짜피 DHT-11 온도/습도 센서가 있으니까..

이걸로 온도 잰걸로 음속을 환산해주면 좀더 정확해지려나? +_+


[링크 : http://eleparts.co.kr/EPXF6C83]

[링크 : http://eleparts.co.kr/EPXF43N9]


Posted by 구차니
embeded/raspberry pi2015. 9. 2. 16:23


CPU의 시리얼 번호를 기반으로 MAC을 생성 하는 듯?

그나저나.. BogoMIPS가 멋대로 바뀌네? ㄷㄷㄷ


타이머로 변경되면서 클럭 변경되면 다르게 나오려나?

$ cat /proc/cpuinfo

processor       : 0

model name      : ARMv7 Processor rev 5 (v7l)

BogoMIPS        : 38.40

Features        : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm

CPU implementer : 0x41

CPU architecture: 7

CPU variant     : 0x0

CPU part        : 0xc07

CPU revision    : 5 


$ cat /proc/cpuinfo

processor       : 3

model name      : ARMv7 Processor rev 5 (v7l)

BogoMIPS        : 57.60

Features        : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm

CPU implementer : 0x41

CPU architecture: 7

CPU variant     : 0x0

CPU part        : 0xc07

CPU revision    : 5


Hardware        : BCM2709

Revision        : a21041

Serial          : 00000000a37ce24e


$ sudo cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq; cat /proc/cpuinfo

900000

processor       : 0

model name      : ARMv7 Processor rev 5 (v7l)

BogoMIPS        : 57.60

Features        : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm

CPU implementer : 0x41

CPU architecture: 7

CPU variant     : 0x0

CPU part        : 0xc07

CPU revision    : 5


$ sudo cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq; cat /proc/cpuinfo

600000

processor       : 0

model name      : ARMv7 Processor rev 5 (v7l)

BogoMIPS        : 38.40

Features        : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm

CPU implementer : 0x41

CPU architecture: 7

CPU variant     : 0x0

CPU part        : 0xc07

CPU revision    : 5


---

라즈 B


# cat /proc/cpuinfo

processor       : 0

model name      : ARMv6-compatible processor rev 7 (v6l)

Features        : half thumb fastmult vfp edsp java tls

CPU implementer : 0x41

CPU architecture: 7

CPU variant     : 0x0

CPU part        : 0xb76

CPU revision    : 7


Hardware        : BCM2708

Revision        : 000e

Serial          : 0000000055593a15


# ifconfig

eth0      Link encap:Ethernet  HWaddr B8:27:EB:59:3A:15

---



$ ifconfig
eth0      Link encap:Ethernet  HWaddr b8:27:eb:7c:e2:4e
          inet addr:192.168.10.23  Bcast:192.168.10.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1685 errors:0 dropped:2 overruns:0 frame:0
          TX packets:358 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:107201 (104.6 KiB)  TX bytes:52547 (51.3 KiB)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:8 errors:0 dropped:0 overruns:0 frame:0
          TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:1104 (1.0 KiB)  TX bytes:1104 (1.0 KiB)


$ cat /sys/class/net/eth0/address

b8:27:eb:7c:e2:4e


[링크 : http://www.robert-drummond.com/2013/05/23/how-to-find-the-mac-address-of-your-raspberry-pi/]

Posted by 구차니
embeded/raspberry pi2015. 8. 27. 08:24

자유낙하 실험... 은 아니고

가방에 넣어 두었는데

가방이 떨어지면서 먼가 불쾌한 철퍽 하는 소리..

꺼내보니 액정까진 아니고 액정 보호유리가 깨지고..

켜보니... ㅠㅠ


터치 축 틀어짐 -_-!!!!

캘리브레이션 한다고 될진 모르겠지만 끄아아아아 ㅠㅠ



사요나라

바이바이

잘가

ㅠㅠ





그러니 다시 사야하나? ㅠㅠ

[링크 : http://eleparts.co.kr/EPXDR9TM]

Posted by 구차니
embeded/raspberry pi2015. 8. 24. 15:47

아두이노랑은 이렇게 하라는데

일단.. I2C로 할거니까.. 저렇게 위에 4개 선을 연결하면 어찌어찌 라즈베리에서도 사용가능 할 듯



장치 ID는 0xE5 고정

ADXL345

REGISTER DEFINITIONS

Register 0x00—DEVID (Read Only)

The DEVID register holds a fixed device ID code of 0xE5 (345 octal). 



데이터는 X/Y/Z축 LSB / MSB 순으로 들어 있다.


Register 0x32 to Register 0x37—DATAX0, DATAX1, DATAY0, DATAY1, DATAZ0, DATAZ1 (Read Only)

 These six bytes (Register 0x32 to Register 0x37) are eight bits each and hold the output data for each axis. Register 0x32 and Register 0x33 hold the output data for the x-axis, Register 0x34 and Register 0x35 hold the output data for the y-axis, and Register 0x36 and Register 0x37 hold the output data for the z-axis. The output data is twos complement, with DATAx0 as the least significant byte and DATAx1 as the most significant byte, where x represent X, Y, or Z. The DATA_FORMAT register (Address 0x31) controls the format of the data. It is recommended that a multiple-byte read of all registers be performed to prevent a change in data between reads of sequential registers



I 2 C

 With CS tied high to VDD I/O, the ADXL345 is in I2 C mode, requiring a simple 2-wire connection, as shown in Figure 40. The ADXL345 conforms to the UM10204 I 2 C-Bus Specification and User Manual, Rev. 03—19 June 2007, available from NXP Semiconductors. It supports standard (100 kHz) and fast (400 kHz) data transfer modes if the bus parameters given in Table 11 and Table 12 are met. Single- or multiple-byte reads/writes are supported, as shown in Figure 41. With the ALT ADDRESS pin high, the 7-bit I 2 C address for the device is 0x1D, followed by the R/W bit. This translates to 0x3A for a write and 0x3B for a read. An alternate I2 C address of 0x53 (followed by the R/W bit) can be chosen by grounding the ALT ADDRESS pin (Pin 12). This translates to 0xA6 for a write and 0xA7 for a read. There are no internal pull-up or pull-down resistors for any unused pins; therefore, there is no known state or default state for the CS or ALT ADDRESS pin if left floating or unconnected. It is required that the CS pin be connected to VDD I/O and that the ALT ADDRESS pin be connected to either VDD I/O or GND when using I2 C


[링크 : http://eleparts.co.kr/data/design/product_file/SENSOR/G_SENSOR/data/ADXL345.pdf]


---





---

pi@raspberrypi /boot/overlays $ dmesg | grep i2c

[    3.862054] bcm2708_i2c_init_pinmode(1,2)

[    3.863939] bcm2708_i2c_init_pinmode(1,3)

[    3.866020] bcm2708_i2c 3f804000.i2c: BSC1 Controller at 0x3f804000 (irq 79) (baudrate 100000)


pi@raspberrypi /boot/overlays $ lsmod | grep i2c

i2c_bcm2708             4990  0


pi@raspberrypi /boot/overlays $ insmod i2c-dev

Error: could not load module i2c-dev: No such file or directory


pi@raspberrypi /boot/overlays $ sudo vi /etc/modules

i2c-dev

i2c-bcm2708


pi@raspberrypi ~ $ lsmod | grep i2c

i2c_dev                 6027  0

i2c_bcm2708             4990  0


pi@raspberrypi ~ $ i2cdetect -y 1

     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f

00:          -- -- -- -- -- -- -- -- -- -- -- -- --

10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

50: -- -- -- 53 -- -- -- -- -- -- -- -- -- -- -- --

60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

70: -- -- -- -- -- -- -- --

pi@raspberrypi ~ $ i2cdetect -y 0

Error: Could not open file `/dev/i2c-0' or `/dev/i2c/0': No such file or directory


pi@raspberrypi ~ $ i2cdetect -l

i2c-1   i2c             3f804000.i2c                            I2C adapter


pi@raspberrypi ~ $ i2cdetect -F 1

Functionalities implemented by /dev/i2c-1:

I2C                              yes

SMBus Quick Command              yes

SMBus Send Byte                  yes

SMBus Receive Byte               yes

SMBus Write Byte                 yes

SMBus Read Byte                  yes

SMBus Write Word                 yes

SMBus Read Word                  yes

SMBus Process Call               yes

SMBus Block Write                yes

SMBus Block Read                 no

SMBus Block Process Call         no

SMBus PEC                        yes

I2C Block Write                  yes

I2C Block Read                   yes


pi@raspberrypi ~ $ lsmod | grep -i i2c

i2c_dev                 6027  0

i2c_bcm2708             4990  0



insmod가 아니라 modprobe ...


pi@raspberrypi ~ $ sudo modprobe i2c_dev

pi@raspberrypi ~ $ lsmod | grep i2c

i2c_dev                 6027  0

i2c_bcm2708             4990  0


[링크 : http://raspberrypi.stackexchange.com/.../how-to-make-raspbian-load-the-i2c-dev-module-on-boot-up]



---





#include <stdio.h>
#include <stdlib.h>
#include <linux/i2c-dev.h>
#include <fcntl.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <iostream>

int main(int argc, char **argv)
{
   printf("**** ADXL435 example program ****\n");
   
   int fd;                                          // File descrition
   char *fileName = "/dev/i2c-1";                        // Name of the port we will be using
   int  address = 0x53;                              // Address of the SRF02 shifted right one bit
   char buf[6];                              // Buffer for data being read/ written on the i2c bus
   short x,y,z;

   if ((fd = open(fileName, O_RDWR)) < 0) {               // Open port for reading and writing
      printf("Failed to open i2c port\n");
      exit(1);
   }
   
   if (ioctl(fd, I2C_SLAVE, address) < 0) {               // Set the port options and set the address of the device we wish to speak to
      printf("Unable to get bus access to talk to slave\n");
      exit(1);
   }

   buf[0] = 0x2d;                                       // Commands for performing a ranging
   buf[1] = 0x18;
   
   if ((write(fd, buf, 2)) != 2) {                        // Write commands to the i2c port
      printf("Error writing to i2c slave\n");
      exit(1);
   }

   buf[0] = 0x31;                                       // Commands for performing a ranging
   buf[1] = 0x09;
   
   if ((write(fd, buf, 2)) != 2) {                        // Write commands to the i2c port
      printf("Error writing to i2c slave\n");
      exit(1);
   }

                                       // This sleep waits for the ping to come back
while(true){   

   buf[0] = 0x32;                                       // This is the register we wish to read from
   if ((write(fd, buf, 1)) != 1) {                        // Send the register to read from
      printf("Error writing to i2c slave\n");
      exit(1);
   }
   

usleep(1000);
  memset(&buf,0,sizeof(buf));

   if (read(fd, buf, 6) != 6) {                        // Read back data into buf[]
      printf("Unable to read from slave\n");
      exit(1);
   }
   else { x=y=z=0;
//               memset(&buf,0,sizeof(buf));

      x = ((short)buf[1]<<8) | (short) buf[0]; 
       y = ((short)buf[3]<<8) | (short) buf[2];
       z = ((short)buf[5]<<8) | (short) buf[4];
       std::cout<<"x:"<<x<<"\ty:"<<y<<"\tz:"<<z<<std::endl;
   }
}
   return 0;

} 



Posted by 구차니
embeded/raspberry pi2015. 8. 24. 15:30


raspi-config 면 기본 설정을 될테고..

나머지는 간단한(?) 테스트용 유틸리티 설치?


$ sudo apt-get install i2c-tools libi2c-dev python-smbus

$ sudo i2cdetect -y 1

[링크 : http://www.rasplay.org/?p=6409]

[링크 : https://learn.adafruit.com/adafruits-raspberry-pi-lesson-4-gpio-setup/configuring-i2c]


예제코드 / 스켈레톤 코드

char *fileName = "/dev/i2c-0";

fd = open(fileName, O_RDWR);

ioctl(fd, I2C_SLAVE, address);

write(fd, buf, 1);

read(fd, buf, 2); 

[링크 : http://www.robot-electronics.co.uk/files/rpi_sd21.c]

    [링크 : http://www.robot-electronics.co.uk/htm/raspberry_pi_examples.htm]


pi@raspberrypi ~ $ i2cdetect

Error: No i2c-bus specified!

Usage: i2cdetect [-y] [-a] [-q|-r] I2CBUS [FIRST LAST]

       i2cdetect -F I2CBUS

       i2cdetect -l

  I2CBUS is an integer or an I2C bus name

  If provided, FIRST and LAST limit the probing range. 


활성화 시키지 않으면 이런 에러가 발생한다.

pi@raspberrypi ~ $ i2cdetect -y 1

Error: Could not open file `/dev/i2c-1' or `/dev/i2c/1': No such file or directory 


근데..

전에 처럼 또.. 연결 안하고 안켜면 활성화도 안되는 기분?

pi@raspberrypi ~ $ sudo i2cdetect -y 1

Error: Could not open file `/dev/i2c-1' or `/dev/i2c/1': No such file or directory


pi@raspberrypi ~ $ dmesg | grep i2c

[    3.872815] bcm2708_i2c_init_pinmode(1,2)

[    3.874707] bcm2708_i2c_init_pinmode(1,3)

[    3.877782] bcm2708_i2c 3f804000.i2c: BSC1 Controller at 0x3f804000 (irq 79) (baudrate 100000) 



Posted by 구차니
embeded/raspberry pi2015. 8. 23. 22:16

머.. fbtft 였나..

fb를 쓰는거니 당연히 되는 걸로 생각이 되긴 해야 하지만..

사이즈나 속도 면에서 무슨 제약이 걸려서 안되는게 아닐까 싶기도?

아무튼 되는거 보면 왜 놀라운걸까 ㅋㅋ




Posted by 구차니