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月23日月曜日
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
(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)
[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経由でワンコイン
ないんですよね。3A+が人気なさそうなので。
AliExpressのを調達してみました。Fanも付いてました。
china post経由でワンコイン
登録:
投稿 (Atom)