C.H.I.P. (8) BMP280 i2c

OLED繋いだから、早速同じi2cのBMP280を試す。

chen@chip:~$ git clone https://github.com/prisme60/BMP280.git

コメントに書いてる方法でコンパイル

chen@chip:~/BMP280$ gcc -Wall -o BMP280 ./BMP280.c
./BMP280.c: In function ‘main’:
./BMP280.c:339:2: error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode
for(int i = 0; i < argc; i++) {
^
./BMP280.c:339:2: note: use option -std=c99, -std=gnu99, -std=c11 or -std=gnu11 to compile your code
./BMP280.c:371:4: error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode
for(int i=0;i<20;i++) {
^

エラーがたくさんある。オプションがつければいいらしい。

chen@chip:~/BMP280$ vi BMP280.c

でもソースを斜めてみると、二箇所だけfor文に定義するから、簡単に直せる。ただ定義文を関数先頭に書くだけ。

chen@chip:~/BMP280$ gcc -Wall -o BMP280 ./BMP280.c
chen@chip:~/BMP280$ ./BMP280

i2c_Open : Failed to open the i2c bus, error : 13
Check to see if you have a bus: /dev/i2c-1
This is not a slave device problem, I can not find the bus/port with which to talk to the device

sudoじゃないとダメだね。

chen@chip:~/BMP280$ sudo ./BMP280

Device accessed via File descriptor:3 at Address:0x76 has returned:0
[0]=3 [1]=6E [2]=B5 [3]=66 [4]=32 [5]=0
T1=28163 T2=26293 T3=50
P1=38053 P2=-10790 P3=3024 P4=7462 P5=-175 P6=-7 P7=15500 P8=-14600 P9=6000
adc_Temperature=536630 adc_Pressure=311387
{“temperature”:26.96,”Pressure64″:1017.5,”Pressure32″:1017.5,”PressureDouble”:1017.5}
adc_Temperature=536636 adc_Pressure=311390
{“temperature”:26.97,”Pressure64″:1017.5,”Pressure32″:1017.5,”PressureDouble”:1017.5}
adc_Temperature=536636 adc_Pressure=311390
{“temperature”:26.97,”Pressure64″:1017.5,”Pressure32″:1017.5,”PressureDouble”:1017.5}

延々と続く…

Leave a Reply

Your email address will not be published. Required fields are marked *