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
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.9k
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
AI駆動開発を妨げる技術的負債の解消アプローチ / ai-refactoring-approach
minodriven
17
9.1k
act1-costs.pdf
sumedhbala
0
230
吝嗇家のためのAI活用 / AI development for miser - ChatGPT + Issue Driven Development
tooppoo
0
190
Generative UI & AI-Assistants for Your Angular Solutions
manfredsteyer
PRO
1
180
SREは、MCPとSRE Agentをこう使え!
kazumax55
0
150
琵琶湖の水は止められてもNet--HTTPのリトライは止められない / You might be able to stop the water flow of Lake Biwa but you can't stop Net::HTTP retries
luccafort
PRO
0
380
LaravelLive Japan の裏方のすべて — 第188回 PHP勉強会@東京 (2026-06-24)
suguruooki
2
150
【やさしく解説 設計編・中級 #6】良いアーキテクチャとは ~ 一本の登り道の、行き先 ~
panda728
PRO
0
160
壊れたパーサから始める関数型設計と構成的なパーサ #fp_matsuri
raiga0310
2
230
1年で人数1.5倍、PR数5.5倍増。 品質とアウトカムはどうなったか、 何が効いたか
ike002jp
0
130
ローカルLLMでどこまでコードが書けるか -拡張版 / How much code can be written on a local LLM Extended
kishida
12
4.8k
自作OSでスライド発表する
uyuki234
1
3.8k
Featured
See All Featured
The Art of Programming - Codeland 2020
erikaheidi
57
14k
SERP Conf. Vienna - Web Accessibility: Optimizing for Inclusivity and SEO
sarafernandez
2
1.5k
Optimising Largest Contentful Paint
csswizardry
37
3.8k
Principles of Awesome APIs and How to Build Them.
keavy
128
18k
Writing Fast Ruby
sferik
630
63k
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
420
AI: The stuff that nobody shows you
jnunemaker
PRO
8
830
sira's awesome portfolio website redesign presentation
elsirapls
0
300
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.5k
Heart Work Chapter 1 - Part 1
lfama
PRO
8
36k
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
190
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
1k
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/