Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Speaker Deck
PRO
Sign in
Sign up for free
Golang+Raspiで趣味的IoT入門的な話
y_matsuwitter
April 13, 2015
Programming
4
2.4k
Golang+Raspiで趣味的IoT入門的な話
Gunosy.go#12にて
y_matsuwitter
April 13, 2015
Tweet
Share
More Decks by y_matsuwitter
See All by y_matsuwitter
DXD2021 Insights From CTOA reports.
ymatsuwitter
1
470
What is a Tech Company
ymatsuwitter
23
10k
The future from software technology
ymatsuwitter
2
3.1k
Cloud Native and Monorepo
ymatsuwitter
2
1.5k
2019-12-12 DMM meetup
ymatsuwitter
0
1.9k
A year of DMM reformation
ymatsuwitter
31
50k
Management And Software Engineering
ymatsuwitter
1
940
About DMM.com new business development
ymatsuwitter
2
2.3k
DMM.comの改革とAWS
ymatsuwitter
3
7.5k
Other Decks in Programming
See All in Programming
tfcon2022_Web3Dひとめぐり.pdf
emadurandal
0
960
SRE NEXT 2022: Sensible Incident Management for Software Startups
takanabe
2
340
byte列のbit表現を得るencodingライブラリ作った
convto
1
130
Go API クライアントの実装 〜Go Conference に載せれなかったTIPS〜
yyoshiki41
0
190
Is Rust a great language for building Kubernetes ecosystem
deepu105
0
140
機能横断型チームにおける技術改善
takeshiakutsu
3
470
クリエイティブ系のウェブサイト制作で役立つCSS技法 / CSS for develop creative website
clockmaker
2
1.6k
プログラミングを勉強したいと言われたら
yuba_4
0
400
未経験QAの私が、よきQA(Question Asker) になっていく物語
atamaplus
0
140
よりUXに近いSLI・SLOの運用による可用性の再設計
kazumanagano
3
570
SPA/MPA 議論の俯瞰と 現代における設計のポイント - #tfcon 2022 フロントエンド設計
ahomu
3
1.8k
脱オブジェクト指向講座(5分LT資料)
kishida
8
11k
Featured
See All Featured
A Tale of Four Properties
chriscoyier
149
20k
Visualization
eitanlees
124
11k
The Invisible Customer
myddelton
110
11k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
350
21k
Building Applications with DynamoDB
mza
83
4.6k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
103
16k
Producing Creativity
orderedlist
PRO
333
37k
Practical Orchestrator
shlominoach
178
8.6k
WebSockets: Embracing the real-time Web
robhawkes
57
5k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
37
3.2k
A designer walks into a library…
pauljervisheath
196
16k
Six Lessons from altMBA
skipperchong
14
1.3k
Transcript
Golang+RaspiͰझຯత IoTೖతͳ @y_matsuwitter
ࣗݾհ • ։ൃຊ෦ࣥߦһࡶ༻ • iOS, Android, Infrastructure, Web • Golangڭ
• ਖ਼࠲ • ࠷ۙؾʹͳΔͷ: MQTT
ࠓͷ • GolangͰݸਓझຯతʹIoTʹ৮Εͨ w/RaspberryPi • Gobotͱembdͷհ
: ిࢠ࡞ૉਓͷͰ͢
IoT(Internet of Things) • ༷ʑͳϞϊ͕ΠϯλʔωοτΛհͯ͠ܨ͕Δٕज़ͷ૯শ • ࠷᷿ۙͰେਓؾ
RaspberryPiͱ
Spec • খܕɾ҆Ձͳڭҭ͚LinuxϚγϯ • RaspberryPi Foundation͕։ൃ • CPU: ARM •
Memory: 256 ~ 1GB • USB microBͰڅి • GPIOϐϯ͕༻ҙ͞Ε͍ͯΔ
ARMͳͷͰ Golang͕ಈ͘ʂʂ GOARCH=arm go build
GPIO(General Purpose Input/ Output)ͱʁ • ଞσόΠεɺճ࿏ͱೖग़ྗΛߦ͏ͨΊͷΠϯλʔϑΣʔε • ιϑτΣΞଆͷࢦఆͰಈ࡞ΛΓସ͑Δࣄ͕Ͱ͖Δ
ࠓճͬͨͷ • SHT21 ... Թɾ࣪ηϯα • I2Cͱ͍͏ํࣜͰԹɺ࣪ΛΓͱ Γ͢Δ
I2Cͱ • ΈࠐΈػثͰར༻͞ΕΔγϦΞϧ௨৴ن֨ͷҰͭ • ͳ௨৴͕ڐ͞ΕΔ༻్͚ • Ұͭͷܦ࿏্ͰෳͷػثͱΓͱΓͰ͖Δ
GolangͰI2C • Gobotembdͷར༻ਪ
Gobot
About Gobot • GolangͰϋʔυΣΞϓϩάϥϛϯάશൠΛߦ͏ͨΊͷϑϨ ʔϜϫʔΫ • RaspberryPi, Arduino, AR.DroneͳͲͷαϙʔτ •
MQTT·ΘΓͷΞμϓλΛॳظ͔Βαϙʔτ • ͍͔ͭ͘ͷηϯαྨ͙͢ʹ͑ΔΑ͏υϥΠό༻ҙ͞Εͯ ͍Δ
Sample: ArduinoͰLEDͷ໓ package main import ( "time" "github.com/hybridgroup/gobot" "github.com/hybridgroup/gobot/platforms/firmata" "github.com/hybridgroup/gobot/platforms/gpio"
) func main() { gbot := gobot.NewGobot() firmataAdaptor := firmata.NewFirmataAdaptor("arduino", "/dev/ttyACM0") led := gpio.NewLedDriver(firmataAdaptor, "led", "13") work := func() { gobot.Every(1*time.Second, func() { led.Toggle() }) } gbot.AddRobot(gobot.NewRobot("bot", []gobot.Connection{firmataAdaptor}, []gobot.Device{led}, work, )) gbot.Start() }
kidoman/embd
About embd • ΈࠐΈϓϩάϥϛϯά͚ϑϨʔϜϫʔΫ • GobotͱൺΔͱ͏গ͠ϨΠϠ? • ରԠগͳ͍ • ֤छBusΛ৮Γ͍͢
• Ұ෦ηϯαͷυϥΠό༻ҙ͞Ε͍ͯΔ
Sample: RasPiͰLED໓ package main import ( "time" "github.com/kidoman/embd" _ "github.com/kidoman/embd/host/rpi"
// This loads the RPi driver ) func main() { for { embd.LEDToggle("LED0") time.Sleep(250 * time.Millisecond) } }
embdͰSHT21͔ΒԹΛऔಘ • ࠓճEmbdͷI2CBusΛར༻ // Busʢܦ࿏ʣͷ࡞ bus := embd.NewI2CBus(1) // ॳظԽ
bus.WriteByte(addr, byte(softreset)) // ॳظԽྃͪ time.Sleep(500 * time.Millisecond)
ଓ͖ // ԹΛૹͬͯΒ͏Α͏৴߸ૹ৴ bus.WriteByte(addr, triggerTemperatureNoHold) // ϋʔυΣΞଆͷ৴߸ͪ time.Sleep(temperatureWait * time.Millisecond)
// 1όΠτಡΈग़͠ first, _ := bus.ReadByte(addr) // 2όΠτಡΈग़͠ second, _ := bus.ReadByte(addr) // ̎ͭͷΛݩʹηϧγεʹม temp := (175.72*float64((int64(first)<<8+int64(second))&statusBitMusk))/float64(1<<16) - 46.85
Ռ ఆظతʹࣨԹΛChatʹ͛ͯ͘ΕΔBot
ײ • Golangࣗମ͕ܰྔͳͷͰݸਓ࡞ͰͷΈࠐΈʹ͍͢ ͦ͏ • ίʔσΟϯάΑΓ֤छηϯαͷ༷ॻͱͷ֨ಆ • ֤छϑϨʔϜϫʔΫ͕༻ҙ͍ͯ͠ΔυϥΠό͑ΔηϯαΛ બͿํָ͕
ࢀߟ • RaspberryPi https://www.raspberrypi.org/ • Gobot http://gobot.io/ • embd http://embd.kidoman.io/