2019年7月20日土曜日

Raspberry Pi 3A+ にI2Cポートを追加

I2Cポート不足又は、SDA1, SCL1 を他の用途に使ってる時の対応です。

/boot/config.txtに以下を追加

GPIO 0をSDA、GPIO 1をSCL、クロックディレイを2μsec、busを3とする場合の設定、

dtoverlay=i2c-gpio,i2c_gpio_sda=0,i2c_gpio_scl=1,i2c_gpio_delay_us=2,bus=3

reboot後、デバイス確認
# i2cdetect -y 3
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- 4c -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

認識してますね。

温度センサーLM73での動作確認

確認 python script (かなり手抜き)

[LM73lib.py]
LM73_ADDRESS             = 0x4c
I2C_BUSNUM               = 3   #<== normal 1?!
LM73_TEMP_REGISTER       = 0

class LM73(object):
        def __init__(self, address=LM73_ADDRESS, busnum=I2C_BUSNUM):
                self._address = address
                self._bus = smbus.SMBus(busnum)

        def regdata2float (self, regdata):
                return (regdata / 16.0)

        def getTemp(self):
#               set 13bit resolution
#               p2,p1,p0-->pointer B'100'
#               TO_DIS,RES1,RES0,'0' ==>B'0100'
                self._bus.write_i2c_block_data(self._address, 0x04, [0x40])
                """Reads the temp from the LM73 sensor"""
                raw = self._bus.read_word_data(self._address, LM73_TEMP_REGISTER)
                print "raw: ",
                print raw
#               low byte, high byte ==> high byte, low byte
                raw = ((raw << 8) & 0xFF00) + (raw >> 8)
                raw = raw >> 3
                return self.regdata2float(raw)
             
[LM73_test.py]             
#!/usr/bin/env python
# -*- coding:utf-8 -*-

import LM73lib
sensor = LM73lib.LM73(busnum=3)
print sensor.getTemp()

#  ./LM73_test.py
raw:  10254
28.3125
とりあえず、それなりの結果かな..

2019年7月11日木曜日

Raspberry Pi 4 Model B arrived!

「出来がいまいちとの評判もある」Raspberry Pi 4 Model B が入手できたのでちょっと触ってみました。


余ってたPC用12Vファンをusb 2.0 5vで緩く廻す。
ヒートシンク無し
unix ベンチでも60度C超えないよ 
吸気より排気の方が冷える

























余ってたPC用12VファンをRPi 5Vを12Vに昇圧して速く(定格で)廻す。
unix ベンチでも55度C超えないよ 























[基本情報]
# vcgencmd version
Jun 20 2019 16:05:00
Copyright (c) 2012 Broadcom

version 407b1da8fa3d1a7108cb1d250f5064a3420d2b7d (clean) (release) (start_cd)

# cat /proc/cpuinfo
processor       : 0
model name      : ARMv7 Processor rev 3 (v7l)
BogoMIPS        : 108.00
Features        : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32
CPU implementer : 0x41
CPU architecture: 7
CPU variant     : 0x0
CPU part        : 0xd08

CPU revision    : 3
.
. あと3 core
.

Hardware        : BCM2835
Revision        : c03111

Serial          : 10000000b7d72729

# cat /proc/meminfo

MemTotal:        4051032 kB
MemFree:         3854844 kB

MemAvailable:    3827636 kB

※4GBモデル..
.



# cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq

1500000

涼しい!!!
# vcgencmd measure_temp
temp=48.0'C


[usb 3.0]

# lspci
00:00.0 PCI bridge: Broadcom Limited Device 2711 (rev 10)
01:00.0 USB controller: VIA Technologies, Inc. VL805 USB 3.0 Host Controller (rev 01)

余ってたusb メモリで試す。

# hdparm -t /dev/sda

/dev/sda:
SG_IO: bad/missing sense data, sb[]:  70 00 05 00 00 00 00 0a 00 00 00 00 20 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
 Timing buffered disk reads: 304 MB in  3.00 seconds = 101.17 MB/sec
root@raspi4:~#

101.17 MB/secと高速 !!!!

定番の
[UNIX Benchmark]
   
   BYTE UNIX Benchmarks (Version 5.1.3)

   System: raspi4: GNU/Linux
   OS: GNU/Linux -- 4.19.50-v7l+ -- #895 SMP Thu Jun 20 16:03:42 BST 2019
   Machine: armv7l (unknown)
   Language: en_US.utf8 (charmap="ANSI_X3.4-1968", collate="ANSI_X3.4-1968")
   CPU 0: ARMv7 Processor rev 3 (v7l) (0.0 bogomips)

   CPU 1: ARMv7 Processor rev 3 (v7l) (0.0 bogomips)
   BYTE UNIX Benchmarks (Version 5.1.3)

   System: raspi4: GNU/Linux
   OS: GNU/Linux -- 4.19.50-v7l+ -- #895 SMP Thu Jun 20 16:03:42 BST 2019
   Machine: armv7l (unknown)
   Language: en_US.utf8 (charmap="ANSI_X3.4-1968", collate="ANSI_X3.4-1968")
   CPU 0: ARMv7 Processor rev 3 (v7l) (0.0 bogomips)

   CPU 1: ARMv7 Processor rev 3 (v7l) (0.0 bogomips)

   CPU 2: ARMv7 Processor rev 3 (v7l) (0.0 bogomips)

   CPU 3: ARMv7 Processor rev 3 (v7l) (0.0 bogomips)

   13:22:30 up 50 min,  2 users,  load average: 0.15, 0.03, 0.01; runlevel 5

------------------------------------------------------------------------
Benchmark Run: 水  7月 10 2019 13:22:30 - 13:50:32
4 CPUs in system; running 4 parallel copies of tests

Dhrystone 2 using register variables       40558612.6 lps   (10.0 s, 7 samples)
Double-Precision Whetstone                     9568.0 MWIPS (9.6 s, 7 samples)
Execl Throughput                               2762.7 lps   (29.9 s, 2 samples)
File Copy 1024 bufsize 2000 maxblocks        212991.3 KBps  (30.0 s, 2 samples)
File Copy 256 bufsize 500 maxblocks           59038.7 KBps  (30.0 s, 2 samples)
File Copy 4096 bufsize 8000 maxblocks        564952.0 KBps  (30.1 s, 2 samples)
Pipe Throughput                              606927.9 lps   (10.0 s, 7 samples)
Pipe-based Context Switching                 190875.9 lps   (10.0 s, 7 samples)
Process Creation                               4626.3 lps   (30.0 s, 2 samples)
Shell Scripts (1 concurrent)                   5876.2 lpm   (60.0 s, 2 samples)
Shell Scripts (8 concurrent)                    804.0 lpm   (60.1 s, 2 samples)
System Call Overhead                        1868584.3 lps   (10.0 s, 7 samples)

System Benchmarks Index Values               BASELINE       RESULT    INDEX
Dhrystone 2 using register variables         116700.0   40558612.6   3475.5
Double-Precision Whetstone                       55.0       9568.0   1739.6
Execl Throughput                                 43.0       2762.7    642.5
File Copy 1024 bufsize 2000 maxblocks          3960.0     212991.3    537.9
File Copy 256 bufsize 500 maxblocks            1655.0      59038.7    356.7
File Copy 4096 bufsize 8000 maxblocks          5800.0     564952.0    974.1
Pipe Throughput                               12440.0     606927.9    487.9
Pipe-based Context Switching                   4000.0     190875.9    477.2
Process Creation                                126.0       4626.3    367.2
Shell Scripts (1 concurrent)                     42.4       5876.2   1385.9
Shell Scripts (8 concurrent)                      6.0        804.0   1340.0
System Call Overhead                          15000.0    1868584.3   1245.7
                                                                   ========
System Benchmarks Index Score                                         850.7

とりあえず......