Abstract Use Lambda and Kinesis to create intelligent T-shirts with LED matrices. The first part will explain how to make a T-shirt.
The T-shirt is linked to the service built on AWS via MQTT, calculates the discomfort index based on the data collected from the temperature / humidity sensor, and sends a message to the LED matrix to display when certain conditions are met. I will.
If the discomfort index is 85 or higher, the T-shirt is hot and steamy, and I would like to display the message "Kuse".
Then, I will explain how to make a T-shirt.
Raspberry Pi Type B+ A Raspberry Pi is used to control the LED matrix and temperature / humidity sensors. A 40-pin IO is available on the Raspberry Pi Type B +. The LED was connected via GPIO and the temperature / humidity sensor was connected via USB. The Raspberry Pi sells for around 5,000 yen. It is convenient to have one in the family (* ´Д`) Raspberry Pi
The LED matrix is connected to 64 (8x8) LEDs and is controlled from the Raspberry Pi via GPIO. You can easily control 64 LEDs with GPIO 16 pin by using a technique called Dynamic lighting.
This time, 64 LEDs were soldered to the board one by one. If you use a flexible board, you will feel less discomfort when you install it on a T-shirt. It is also a good point that you can easily cut it with scissors. Flexible board
The wiring itself is the same as the device sold by Akizuki Denshi, so I think that it can be mounted without difficulty by soldering with reference to the circuit diagram below. However, it takes a lot of time and effort, so I only have patience. Akizuki Denshi LED Matrix
With reference to the above circuit diagram, the LED anode (13,3,4,10,6,11,15,16 on the circuit diagram) and cathode (left 9,14,8,12,1,7, circuit diagram) A total of 16 pins (2,5) will be connected to the GPIO of the Raspberry pi. GPIO has an output of 3.3 V, so convert the LED current and connect a resistor of about 300 Ω directly.
GPIO (19, 13, 16, 5, 22, 27, 17, 4) → R (300Ω) x8 → Anode (13, 3, 4, 10, 6, 11, 15, 16 on the circuit diagram) → LEDx64 → Cathode (Circuit diagram left 9, 14, 8, 12, 1, 7, 2, 5) → GPIO (18, 23, 24, 25, 12, 16, 20, 21)
By the way, I connected the Raspberry pi and the LED matrix with a flat cable. Flat cables are sold in meters at parts stores. The Raspberry pi's GPIO connector is 40 pin, so it's convenient to connect with a 40-core flat cable. Flat cable body
Crimping the connector and flat cable is expensive due to the special equipment, but it is surprisingly easy to crimp with a vise. I put my weight on it with disposable chopsticks and crimped it. Flat Cable Connector
The characters displayed on the LED matrix are 8x8 dots. One way is to create a matrix that represents the characters on your own and display them in dots, but this time we will use an 8-dot font called the Misaki font. Misaki font
Download BDF file to convert it to Python code. Convert in BDF format as follows.
font_converter.py
import sys
print 'codes = {'
data = u''
for line in sys.stdin:
items = line[0:-1].split(' ')
if items[0] == 'STARTCHAR':
code_char = items[1]
if items[0] == 'ENCODING':
code = items[1]
data = u''
#·····to be continued
So, I noticed around here, but as it is, the code list of JIS array is output, so it is necessary to convert it to UTF8 array. However, I didn't have much time, so I decided to support only alphanumeric characters, hiragana, and katakana (not kanji), and converted it to a UTF8 array using the engineer's final secret Excel. Since the conversion was in the middle of the conversion, only the font conversion code of the output result is left.
font.py
codes = {
32: [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ],
33: [ 0x40, 0x40, 0x40, 0x40, 0x00, 0x40, 0x00, 0x00, ],
34: [ 0xa0, 0xa0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ],
35: [ 0xa0, 0xe0, 0xa0, 0xa0, 0xe0, 0xa0, 0x00, 0x00, ],
36: [ 0x40, 0xe0, 0xc0, 0x60, 0xe0, 0x40, 0x00, 0x00, ],
37: [ 0x00, 0x80, 0x20, 0x40, 0x80, 0x20, 0x00, 0x00, ],
#〜〜〜〜〜
8736: [ 0x00, 0x02, 0x04, 0x08, 0x10, 0x20, 0x7e, 0x00, ],
8735: [ 0x00, 0x40, 0x40, 0x40, 0x40, 0x40, 0x7e, 0x00, ],
8895: [ 0x00, 0x02, 0x06, 0x0a, 0x12, 0x22, 0x7e, 0x00, ],
8757: [ 0x00, 0x44, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, ],
8745: [ 0x00, 0x3c, 0x42, 0x42, 0x42, 0x42, 0x42, 0x00, ],
8746: [ 0x42, 0x42, 0x42, 0x42, 0x42, 0x3c, 0x00, 0x00, ],
}
https://gist.github.com/shimy/f23b54c0f57d7b325e23
You can display a message in the LED matrix in GPIO with the following code. The following video will be helpful for the principle of LED matrix. You can also understand GPIO control from Python. Raspberry Pi Project: The LED Matrix
control.py
# -*- coding: utf-8 -*-
import RPi.GPIO as GPIO
import time
import font as font
import os
import sys
###### GPIO Initialization #####
GPIO.cleanup()
GPIO.setmode(GPIO.BCM)
cathodes = [4,17,27,22,5,6,13,19]
anodes = [18,23,24,25,12,16,20,21]
for cathode in cathodes:
GPIO.setup(cathode, GPIO.OUT)
GPIO.output(cathode, 0)
for anode in anodes:
GPIO.setup(anode, GPIO.OUT)
GPIO.output(anode, 0)
###### Display message #####
def display_message(str):
sleeptime = 0.001
speed = 8
half = 4
full = 8
matrix_height = 8
matrix_width = 0
for idx in range(len(str)):
char_code = ord(str[idx])
if char_code < 1000:
matrix_width += half
else:
matrix_width += full
matrixes = matrix_height*['']
for idx in range(len(str)):
char_code = ord(str[idx])
if font.codes.has_key(char_code):
hex_pattern = font.codes[char_code]
else:
hex_pattern = font.codes[9632]
for n in range(matrix_height):
if char_code < 1000:
bits_str = format(hex_pattern[n]>>4, '04b')
else:
bits_str = '{0:08b}'.format(hex_pattern[n])
bits_str = bits_str.replace('0', '.').replace('1', 'o')
bits_str = bits_str.replace('.', '1').replace('o', '0')
matrixes[n] += bits_str
try:
pattern = matrix_height*['']
for cnt in range(len(matrixes[0])-matrix_height):
for row_no in range(matrix_height):
pattern[row_no] = matrixes[row_no][cnt:cnt+matrix_height]
os.system('clear')
print '\n'.join(pattern).replace('0', 'o').replace('1', ' ')
for pause in range(speed):
for i in range(8):
for j in range(8):
GPIO.output(cathodes[j], int(pattern[i][j]))
GPIO.output(anodes[i],1)
time.sleep(sleeptime)
GPIO.output(anodes[i],0)
except KeyboardInterrupt:
GPIO.cleanup()
##### main #####
str = u"Hello Sekai"
display_message(str)
For the temperature / humidity sensor, we used USBRH, which is sold by Straberry Linux Co, Ltd. https://strawberry-linux.com/catalog/items?code=52002
You can get the temperature and humidity by running usbrh as follows:
$ sudo usbrh
$ 29.68 41.41
You can find out how to install and use it by referring to the following articles. http://hitoriblog.com/?p=9835 http://www.infiniteloop.co.jp/blog/2013/02/raspberrypitem/
https://www.youtube.com/watch?v=YxEnnobXkWY
It's an article for the Lambda Advent Calendar, but I haven't talked about Lambda yet ... I'm exhausted, so let's meet in the second part.
This is an individual opinion and has nothing to do with the company.
Recommended Posts