Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Golang+Raspiで趣味的IoT入門的な話
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
y_matsuwitter
April 13, 2015
Programming
3k
4
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Golang+Raspiで趣味的IoT入門的な話
Gunosy.go#12にて
y_matsuwitter
April 13, 2015
More Decks by y_matsuwitter
See All by y_matsuwitter
LLMと共に進化するプロセスを目指して
ymatsuwitter
13
4.4k
Building Products in the LLM Era
ymatsuwitter
11
13k
Product Utilization of Large Language Models Starting Today
ymatsuwitter
3
3.4k
経営・意思・エンジニアリング
ymatsuwitter
23
22k
LLM in 2023 and 2024
ymatsuwitter
8
6.3k
Turbulent Technological Changes and Career Strategies
ymatsuwitter
2
3.2k
LLM in toB Service and Its UX
ymatsuwitter
7
12k
Agent and small LLM validation
ymatsuwitter
7
3.1k
Information management for a culture of speed: The story of Notion and LayerX
ymatsuwitter
4
11k
Other Decks in Programming
See All in Programming
Inside Stream API
skrb
1
760
Dataformのリポジトリを立ち上げるときにまずやること / dataform-day0-2026
snhryt
0
180
なぜ型を書くのか? TSKaigi2026で改めて考える #tskaigi_smarthr
kajitack
0
140
例外の正しい扱い方 そのエラー try-catchして大丈夫?
jinwatanabe
0
280
ローカルLLMを使ってB2Bサービスを作っていての学び
yaotti
0
210
PHPで使える日時の表現と、その知り方 #frontend_phpcon_do
o0h
PRO
0
260
OSもどきOS
arkw
0
580
エンジニアと一緒にテストコードの設計と実装を改善した話
mototakatsu
0
220
コンテキストの使い捨てをやめる — ビジネスルール駆動開発と miko —
ioki
0
220
気圧・高度・GPSを記録&可視化するアプリ「Koudo」を作った話
hjmkth
1
320
Oxlintのカスタムルールの現況
syumai
6
1.1k
Agentic UI
manfredsteyer
PRO
0
190
Featured
See All Featured
Ruling the World: When Life Gets Gamed
codingconduct
0
260
From π to Pie charts
rasagy
0
220
Six Lessons from altMBA
skipperchong
29
4.3k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
2.9k
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
1
220
How Software Deployment tools have changed in the past 20 years
geshan
0
34k
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
1
360
Believing is Seeing
oripsolob
1
150
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
2k
First, design no harm
axbom
PRO
2
1.2k
Heart Work Chapter 1 - Part 1
lfama
PRO
7
36k
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/