2019年12月23日月曜日

0.56 inch 4-Digit 7-Segment Display w/I2C(HT16K33) Backpack - Red on a Raspberry Pi

Raspberry Piに、HT16K33 I2C制御の 7 segをつけてみた。
(cheep¥339でした)
つなぎ方はネットに色々あるので省略(I2C)
VCCは3.3V接続です。


# i2cdetect -y 1

     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- 3c -- -- --
40: -- -- -- -- -- -- -- -- 48 -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: 70 -- -- -- -- -- -- --

I2Cアドレスは、デフォルト0x70ですね
ジャンパで、0x71-0x77に変更可能なようです。





































































ライブラリは、Adafruit_Python_LED_Backpackを使わせて頂きました。


2019年12月21日土曜日

TM1637 7 segment display on a Raspberry Pi

Raspberry Piに、TM1637制御の 7 segをつけてみた。
(cheep¥200以下でした)
つなぎ方はネットに色々あるので省略(疑似I2Cってところ)
VCCは3.3V接続です。






























































ライブラリは、
https://raspberrytips.nl/tm1637-4-digit-led-display-raspberry-pi/
の方の
https://raspberrytips.nl/files/tm1637.py
のを拝借して、アルファベット表示も可能なように変更

[tm1637_ab.py]
# https://raspberrytips.nl/tm1637-4-digit-led-display-raspberry-pi/
# by shinshinshin

import sys
import os
import time
import RPi.GPIO as IO

IO.setwarnings(False)
IO.setmode(IO.BCM)

HexDigits = {
             "0":0x3f,
             "1":0x06,
             "2":0x5b,
             "3":0x4f,
             "4":0x66,
             "5":0x6d,
             "6":0x7d,
             "7":0x07,
             "8":0x7f,
             "9":0x6f,
             "A":0x77,
             "B":0x7c,
             "C":0x39,
             "D":0x5e,
             "E":0x79,
             "F":0x71,
             "G":0x3D,
             "H":0x74,
             "I":0x04,
             "J":0x0E,
             "K":0x70,
             "L":0x38,
             "M":0x54,
             "N":0x37,
             "O":0x5C,
             "P":0x73,
             "Q":0x67,
             "R":0x50,
             "S":0x65,
             "T":0x78,
             "U":0x3E,
             "V":0x1C,
             "W":0x52,
             "X":0x76,
             "Y":0x6E,
             "Z":0x49,
             " ":0x00,
             "-":0x40,
             "|":0x36,
             }


ADDR_AUTO = 0x40
ADDR_FIXED = 0x44
STARTADDR = 0xC0
BRIGHT_DARKEST = 0
BRIGHT_TYPICAL = 2
BRIGHT_HIGHEST = 7
OUTPUT = IO.OUT
INPUT = IO.IN
LOW = IO.LOW
HIGH = IO.HIGH

class TM1637:
        __doublePoint = False
        __Clkpin = 0
        __Datapin = 0
        __brightnes = BRIGHT_TYPICAL;
        __currentData = [0,0,0,0];

        def __init__( self, pinClock, pinData, brightnes ):
                self.__Clkpin = pinClock
                self.__Datapin = pinData
                self.__brightnes = brightnes;
                IO.setup(self.__Clkpin,OUTPUT)
                IO.setup(self.__Datapin,OUTPUT)
        # end  __init__

        def Clear(self):
                b = self.__brightnes;
                point = self.__doublePoint;
                self.__brightnes = 0;
                self.__doublePoint = False;
                data = [0x7F,0x7F,0x7F,0x7F];
                self.Show(data);
                self.__brightnes = b;                           # restore saved brightnes
                self.__doublePoint = point;
        # end  Clear

        def ShowInt(self, i):
                s = str(i)
                self.Clear()
                for i in range(0,len(s)):
                        self.Show1(i, int(s[i]))

        def Show( self, data ):
                for i in range(0,4):
                        self.__currentData[i] = data[i];

                self.start();
                self.writeByte(ADDR_AUTO);
                self.stop();
                self.start();
                self.writeByte(STARTADDR);
                for i in range(0,4):
                        self.writeByte(self.coding(data[i]));
                self.stop();
                self.start();
                self.writeByte(0x88 + self.__brightnes);
                self.stop();
        # end  Show

        def SetBrightnes(self, brightnes):              # brightnes 0...7
                if( brightnes > 7 ):
                        brightnes = 7;
                elif( brightnes < 0 ):
                        brightnes = 0;

                if( self.__brightnes != brightnes):
                        self.__brightnes = brightnes;
                        self.Show(self.__currentData);
                # end if
        # end  SetBrightnes

        def ShowDoublepoint(self, on):                  # shows or hides the doublepoint
                if( self.__doublePoint != on):
                        self.__doublePoint = on;
                        self.Show(self.__currentData);
                # end if
        # end  ShowDoublepoint

        def writeByte( self, data ):
                for i in range(0,8):
                        IO.output( self.__Clkpin, LOW)
                        if(data & 0x01):
                                IO.output( self.__Datapin, HIGH)
                        else:
                                IO.output( self.__Datapin, LOW)
                        data = data >> 1
                        IO.output( self.__Clkpin, HIGH)
                #endfor

                # wait for ACK
                IO.output( self.__Clkpin, LOW)
                IO.output( self.__Datapin, HIGH)
                IO.output( self.__Clkpin, HIGH)
                IO.setup(self.__Datapin, INPUT)

                while(IO.input(self.__Datapin)):
                        time.sleep(0.001)
                        if( IO.input(self.__Datapin)):
                                IO.setup(self.__Datapin, OUTPUT)
                                IO.output( self.__Datapin, LOW)
                                IO.setup(self.__Datapin, INPUT)
                        #endif
                # endwhile
                IO.setup(self.__Datapin, OUTPUT)
        # end writeByte

        def start(self):
                IO.output( self.__Clkpin, HIGH) # send start signal to TM1637
                IO.output( self.__Datapin, HIGH)
                IO.output( self.__Datapin, LOW)
                IO.output( self.__Clkpin, LOW)
        # end start

        def stop(self):
                IO.output( self.__Clkpin, LOW)
                IO.output( self.__Datapin, LOW)
                IO.output( self.__Clkpin, HIGH)
                IO.output( self.__Datapin, HIGH)
        # end stop

        def coding(self, data):
                if( self.__doublePoint ):
                        pointData = 0x80
                else:
                        pointData = 0;

                if(data == 0x7F):
                        data = 0
                else:
#
# by shinshinshin start
#                       data = HexDigits[data] + pointData;
                        if data in HexDigits:
                           data = HexDigits[data] + pointData;
                        else:
                           data = HexDigits[" "] + pointData;
# by shinshinshin end
                return data
        # end coding

# end class TM1637_ab

[tm1637_ab_time_temp.py]

#!/usr/bin/env python
# -*- coding: utf-8 -*-

# https://raspberrytips.nl

import sys
import time
import re
import datetime
import RPi.GPIO as GPIO
import tm1637_ab

def get_temp():
#  DEVID="28-000003613615"
  DEVID="28-000000ffe755"
  for line in open('/sys/bus/w1/devices/' + DEVID + '/w1_slave', 'r'):
     m = re.findall(r't=(?P<temp>\d+)\s+', line)
     if m:
       return [int(m[0])/1000, (int(m[0])%1000/10)]
     else:
        m = ''

#CLK -> GPIO23 (Pin 16)
#Di0 -> GPIO24 (Pin 18)

##Display = tm1637.TM1637(23,24,tm1637.BRIGHT_TYPICAL)
Display = tm1637_ab.TM1637(16,12,tm1637_ab.BRIGHT_TYPICAL)

Display.Clear()
Display.SetBrightnes(1)

while(True):

#### current time

   now = datetime.datetime.now()
   hour = now.hour
   minute = now.minute
   second = now.second
   currenttime = [ str(hour / 10), str(hour % 10), str(minute / 10), str(minute % 10) ]

   Display.SetBrightnes(7)

   Display.Show(currenttime)
   Display.ShowDoublepoint(1)

   time.sleep(2)

#### temp

   temp=get_temp()
   currenttemp = [ str(int(temp[0] / 10)), str(temp[0] % 10), "C", "-"]

   Display.SetBrightnes(3)
   Display.Show(currenttemp)
   Display.ShowDoublepoint(0)

   time.sleep(1)






2019年12月1日日曜日

Raspberry Pi 3 Model A+ case w/Fan

Raspberry Pi 3 Model A+ 用のFan装着可能なケースってなかなか
ないんですよね。3A+が人気なさそうなので。

AliExpressのを調達してみました。Fanも付いてました。
china post経由でワンコイン









































2019年10月12日土曜日

Raspberry Pi でOLEDにmpd 曲名を追加

Adafruit_Python_SSD1306
のサンプルスクリプトstats.pyにmpd の曲名を追加してみました。

stats.py

[追加]
import os
import os.path
import re

.
.
.
# fontは別途install要
font2 = ImageFont.truetype('/home/pi/font/misakifont/misaki_gothic.ttf', 8, encoding='unic')
.
.
.
    cmd = "mpc current"
    FullSongName = subprocess.check_output(cmd, shell = True )
   
    fo=os.path.basename(FullSongName)
    f=fo.decode('utf-8')
    regexp = re.compile("^[0-9]+ +|^[0-9]+-")
    if f=='':
       SongName=''
    else:
       fn, ext = os.path.splitext(f)
       pre = regexp.search(fn)
       if pre is None:
          SongName=fn
       else:
          SongName=fn.replace(pre.group(), "")
       
         
.
.
.
    draw.text((x, top+43),    unicode(SongName),  font=font2, fill=255)

2019年10月4日金曜日

Raspberry Pi Zero W に BU7150

Raspberry Pi Zero W に
秋月のBU7150使用 超小型・低電圧駆動アンプモジュール(85mW/1.5V)を付けてみました。
驚き!! ノイズ僅少












RPi audio filter











































2019年10月3日木曜日

Raspberry Pi Zero W に PAM8012

Raspberry Pi Zero W に
秋月のPAM8012使用2ワットD級アンプモジュールを付けてみました。

音質はまぁーと云うレベルですか。
ノイズフィルターをSMD部品で作ったんだが、老眼の年寄りには辛いな












♪みんなかわいいウサギになって..











ノイズフィルターは、半田に埋もれて部品が判らん















2019年9月12日木曜日

Raspberry Pi 2Bにケースfan追加(制御基板接触危険)







































Mmbt3904 トランジスタを
ユニバーサル1.27mmピッチ基板に実装

連結ピンソケットに挿入(半田つけ無し)出来るようにした

ポリウレタン銅線を
1.27mmピッチ基板のスルーホールの穴径を変えないように端に配線するのが至難の業でした

とりあえず、動いた けど配線がやわで取れそう。。。






2019年8月17日土曜日

Raspberry Pi 3B+にケースfan追加




























           



格安(1コイン以下)のケースとファンのセットを入手したので、試してみました。
とりあえず動きました

[pwm制御]

トランジスタ 2SC1815-GR

配線
E-->Pi GND
C-->fan GND
B-->100Ω抵抗-->Pi GPIO18

fan Vcc --> Pi 5V

sample script

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import RPi.GPIO as GPIO
import time

DEBUG=True

GPIO_PWM = 18
Hz = 60
def get_cpu_temp():
    with open("/sys/class/thermal/thermal_zone0/temp", "r") as f:
        t=f.read()
    return int(t)/1000

def fanctl_pwm():
    """
    cpu temp,duty
    """
    td=(
        (29,0),
        (30,25),
        (35,50),
        (40,60),
        (41,65),
        (43,70),
        (45,75),
        (46,80),
        (48,90),
        (49,95),
        (50,98),
        (51,100),
       )
    """
    td=(
        (45,0),
        (46,100),
       )
    """
    GPIO.setmode(GPIO.BCM)
    GPIO.setup(GPIO_PWM, GPIO.OUT)
    p = GPIO.PWM(GPIO_PWM, Hz)
    try:
        duty = 100
        p.start(duty)
        time.sleep(1)
        while True:
            cpu_temp = get_cpu_temp()
            duty = 100
            for x in td:
               if DEBUG:
                print "x(0)" + str(x[0]) + " C" ,
                print "x(1)" + str(x[1]) + " %"
               if  x[0]  >= cpu_temp:
                  duty = x[1]
                  break
               elif  x[0]  > cpu_temp:
                  duty = 0
                  break         
            if DEBUG:
             print "cpu temp=" + str(cpu_temp) + " C"
             print "fun duty=" + str(duty) + "%"

            p.ChangeDutyCycle(duty)
            time.sleep(30)
    except Exception as e:
        print "Exception : " + str(e)
    finally:
        p.stop()
        GPIO.cleanup()
if __name__ == "__main__":
    time.sleep(1)
    fanctl_pwm()

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

とりあえず......






2019年5月19日日曜日

OpenRD-Client に Debian 9 (stretch) install

もう、10年位電源いれっぱのOpenRD-ClientのOS更新しました。

Fedora 8.0 for armで入れた当時からpkg update出来ないと云う代物
元のHDD(ST91203410AS 120GB) の使用時間 83541 で、9年超ですか。。

[参考(と云うかそのまんま)site]
https://www.cyrius.com/debian/kirkwood/openrd/install/

USB stickは駄目(u-bootで認識しない)で、
TFTPでインストーラ入れてinstallしました

root@openrd:~# uname -a
Linux openrd 4.9.0-9-marvell #1 Debian 4.9.168-1+deb9u2 (2019-05-13) armv5tel GNU/Linux

root@openrd:~# cat /etc/debian_version
9.9
debianのpostfix pkgは楽 install後conf弄らなくてもmail飛びますね
Red Hat系は、その辺不親切だからね

apt install alsa-utils で音も出るようになった 


2019年5月14日火曜日

raspberry pi camera v1.3 試してみる

「カラー図解 Raspberry Piではじめる機械学習 基礎からディープラーニングまで (ブルーバックス)」 演習script 

確認用に、raspberry pi camera v1.3 を付けてみました。

純正品じゃないからか、当該課題には適当ではないようですね。
じゃんけんの手の認識悪すぎ.

camera v1.3  
カメラ部分の裏の両面テープそのままだった
ので剥がして張り付けて固定しました

ケース 
純正品カメラと相性悪いとの情報
ありましたが、当方のは
全然問題無かったですょ


三脚・雲台相当は、大昔のweb camera の奴を流用です