Slide 1

Slide 1 text

Perl meets Real World 2014-08-29 YAPC::Asia 2014

Slide 2

Slide 2 text

@mackee_w a.k.a Ϛίϐʔ • ໘ന๏ਓΧϠοΫ ٕज़෦ • αʔόαΠυΤϯδχΞ(Perl) • ιʔγϟϧήʔϜͷ։ൃ/ӡ༻ • ࠓ࡞͍ͬͯΔήʔϜ͸ࣄલొ࿥ड෇த

Slide 3

Slide 3 text

ͯ͞

Slide 4

Slide 4 text

WebΤϯδχΞ͕ Կނϋʔυ΢ΣΞ͔ʁ

Slide 5

Slide 5 text

ڈ೥গ͚ͩ͠ϋʔυ΢ΣΞͷ ࢓ࣄΛͨ͠ • ઇࢁͰϥδίϯϔϦΛඈ͹͢࢓ࣄ • Webͷٕज़͔͠ແ͔ͬͨ • ௐ΂ͨΒ࠷ۙͷϋʔυ͸͍͢͜͝ͱʹͳͬ ͍ͯͨ

Slide 6

Slide 6 text

࢖ٕͬͨज़ • RaspberryPi • Arduino • OpenCV • Ansible

Slide 7

Slide 7 text

ϋʔυ΢ΣΞ શ෦ҰൠతʹೖखՄೳ

Slide 8

Slide 8 text

ιϑτ΢ΣΞ “Web”ʹ΋௨ͣΔٕज़ͨͪ

Slide 9

Slide 9 text

ۤ࿑΋͚͋ͬͨΕͲ ָ͔ͬͨ͠ͷͰ”ํ๏”ͷ Ұ෦Λ঺հ͠·͢

Slide 10

Slide 10 text

ࠓ೔࿩͢͜ͱ • RaspberryPiͱArduino • Φʔϓϯιʔεϋʔυ΢ΣΞ • Perl͚ͩͰωΪΛৼΔ • ࣗ࡞ϋʔυ΢ΣΞͱະདྷ

Slide 11

Slide 11 text

ࠓ೔࿩͞ͳ͍͜ͱ • ϋϯμ෇͚ʢձ৔͔Β͓ͦΒౖ͘ΒΕΔʣ • ճ࿏ઃܭʢཁ๬͕͋Ε͹ผͷػձʹʣ • ΨνͷArduinoʢ͍ͨΒ࠙਌ձͱ͔Ͱʣ • ͦͷଞΨνిࢠ޻࡞

Slide 12

Slide 12 text

ୈҰষ Raspberry PiͱArduino

Slide 13

Slide 13 text

Raspberry Pi http://commons.wikimedia.org/wiki/File:Raspberry_Pi_Photo.jpg

Slide 14

Slide 14 text

• ARM 700MHz • 512MB RAM(Model B) • SD CARD • 100BASE-TX LAN • USB2.0 x 2 • HDMI and RCA VIDEO • Audio • Power by USB

Slide 15

Slide 15 text

Q. Ͱɺ͜ΕͰPerl͸ಈ͘ͷʁ

Slide 16

Slide 16 text

A. ΋ͪΖΜಈ͖·͢ʂ

Slide 17

Slide 17 text

ී௨ͷLinux͕ಈ͘ • Raspbian (DebianͷRasPi޲͚ΧελϜ) • NOOBS(for beginner) • Pidora(FedoraͷRasPi޲͚ΧελϜ)

Slide 18

Slide 18 text

ͦ΋ͦ΋ͷRasPiͷ໨త • খதֶੜ΍ൃల్্ࠃ޲͚ͷITڭҭ • RCAϏσΦδϟοΫ͕෇͍͍ͯΔͷ΋ൃల్্ ࠃͷϒϥ΢ϯ؅ςϨϏͰ࢖͏ͨΊ • MinecraftͷRasPi൛ͱ͔΋͋ͬͯPythonͰΧελ ϚΠζͰ͖ͨΓ͢Δ

Slide 19

Slide 19 text

kano ࢠڙ޲͚ͷΦʔϧΠϯϫϯͷPCΩοτ https://www.kickstarter.com/projects/alexklein/kano-a-computer-anyone-can-make

Slide 20

Slide 20 text

͔͠͠େਓ΋஫໨༷ͯ͠ʑͳ ϓϩδΣΫτ͕ڵͬͨ

Slide 21

Slide 21 text

RaspberryPiΛ࢖ͬͨϓϩδΣΫτ

Slide 22

Slide 22 text

Raspberry Pi͸ Կނ஫໨/׆༻͞Ε͔ͨ

Slide 23

Slide 23 text

·͍͋ΖΜͳཧ༝͸͋Δ • ͍҆ (B/B+͕4000ԁఔ౓) • ΫϨδοτΧʔυαΠζ • ଞʹ΋طʹಉछͷ΋ͷ͸͋ͬͨ • ؀ڥ͕੔͍ͬͯΔ(ग़͕ࣗॳ৺ऀ޲͚) • ࡞ྫ͕ଟ͍

Slide 24

Slide 24 text

GPIO

Slide 25

Slide 25 text

GPIO - ݱ࣮ੈքʹհೖ͢ΔͨΊͷखஈ

Slide 26

Slide 26 text

ిؾΛݟฉ͖͠ɺ͠Ό΂Δ • ϞʔλʔͳͲͷۦಈػثͷಈ࡞ -> ࢛ࢶ • ηϯαʔͰͷपғঢ়گͷݕ஌ -> ޒײ

Slide 27

Slide 27 text

ిؾͱ͍͏࠷΋௿ϨΠϠʔΛ खܰʹѻ͑Δͷ͕RasPi

Slide 28

Slide 28 text

Arduinoͷ࿩

Slide 29

Slide 29 text

• ిؾΛѻ͏͜ͱʹಛԽ • 8bit ϚΠίϯΛ౥ࡌ • ॲཧೳྗ͸ඇৗʹখ͍͞ • USB͸ೖྗઐ༻ • ྫ֎΋͋Δ • LinuxͳͲ౸ఈಈ͔ͳ͍ • ௚઀ϐϯΛૢ࡞͢Δ

Slide 30

Slide 30 text

Q. Ͱɺ͜ΕͰPerl͸ಈ͘ͷʁ

Slide 31

Slide 31 text

A. (‘A`) ಈ͔ͳ͍ɻɻɻ

Slide 32

Slide 32 text

ϋʔυ΢ΣΞ୯ମͰ͸ඇྗ͕ͩ ΤίγεςϜ͕ڧྗ

Slide 33

Slide 33 text

Arduino IDE Arduinoʹඞཁͳ΋ͷΛશͯ٧ΊࠐΜͩιϑτ΢ΣΞ

Slide 34

Slide 34 text

γʔϧυ ਌ُࢠُํࣜͰ֦ு͢ΔΞλονϝϯτ

Slide 35

Slide 35 text

ϥΠϒϥϦ΍ArduinoΛલఏͱͨ͠Ωοτ

Slide 36

Slide 36 text

๻͸͜͏࢖͍෼͚Δ

Slide 37

Slide 37 text

RaspberryPiͰ΍Γ͍ͨ͜ͱ • ը૾ॲཧͱ͔Τϯίʔυͱ͔ॏ͍ͨॲཧ • ෳࡶͳΞϧΰϦζϜΛཁ͢Δ΋ͷ • PC޲͚ͷϥΠϒϥϦ͕͙͢ಈ͖΍͍͢ • ௒؆୯ͳΦϯΦϑఔ౓ͷϋʔυ΢ΣΞ੍ޚ

Slide 38

Slide 38 text

ArduinoͰ΍Γ͍ͨ͜ͱ • ࣗ࡞ͷిࢠ෦඼ͳͲͱ࿈ܞ͢Δέʔε • Arduino޲͚ϥΠϒϥϦ͕͢Ͱʹ͋Δ৔߹ • PWM੍ޚͳͲͷߴ଎ʹΦϯɾΦϑΛ΍Δ৔߹ • RasPiͩͱ͜͏͍͏͜ͱΛ΍ΔͱCPUΛΊͬ ͪΌ৯͏

Slide 39

Slide 39 text

ීஈ͸2ͭΛ૊Έ߹ΘͤΔ͜ͱ ͕ଟ͍Ͱ͕͢ɺͦΕ͸ޙͷষͰ

Slide 40

Slide 40 text

ୈೋষ Φʔϓϯϋʔυ΢ΣΞ

Slide 41

Slide 41 text

ΦʔϓϯιʔεϥΠηϯε • ࣗ༝ͳ࠶൦෍͕Մೳ • ιʔείʔυ͕ೖखͰ͖Δ • ೿ੜ෺Λ࡞ͬͯ΋ྑ͍ • ͦͷଞϥΠηϯε͕ܧঝ͞ΕΔͱ͔

Slide 42

Slide 42 text

ϋʔυ΢ΣΞʹ͓͚Δ Φʔϓϯιʔεͱ͸

Slide 43

Slide 43 text

ϋʔυ΢ΣΞͷιʔε • ϑΝʔϜ΢ΣΞ • ճ࿏ਤ • ෦඼৘ใ • ج൘഑ஔਤ

Slide 44

Slide 44 text

Arduinoͷྫ

Slide 45

Slide 45 text

ճ࿏ਤ(Arduino Unoͷ৔߹) http://arduino.cc/en/Main/ArduinoBoardUno

Slide 46

Slide 46 text

ج൘഑ஔਤ΋Eagleͱ͍͏ ճ࿏ਤ/ج൘ΤσΟλͷܗࣜͰ ൦෍͞Ε͍ͯΔ

Slide 47

Slide 47 text

ͭ·Γ؆୯ʹArduinoΛ ࣗ࡞͢Δ͜ͱ͕ग़དྷΔ

Slide 48

Slide 48 text

ݱʹΫϩʔϯ͕͍ͬͺ͍ଘࡏ͢Δ

Slide 49

Slide 49 text

ArduinoΛࣗ࡞͢ΔϝϦοτ • ػೳͷ௥Ճ • Ϟʔλʔ੍ޚճ࿏Λ૊ΈࠐΉͱ͔ • ϑοτϓϦϯτͷݮগ • ΊͬͪΌখ͍͞ػثʹੵΈ͍ͨ • ArduinoͷΤίγεςϜͷԸܙΛड͚ΒΕΔ

Slide 50

Slide 50 text

ϋʔυΛΦʔϓϯʹ͢Δ͜ͱ • ϋοΫΛଅ͢ • ΤίγεςϜ͕ൃల͠΍͍͢ • ྲྀߦΔͱ໛଄඼͕ͨ͘͞Μग़ͯ͘Δ • Arduino΍RasPi͸໊લΛ࢖͏ͷΛϥΠη ϯεͰ੍ݶ͍ͯ͠Δ

Slide 51

Slide 51 text

ΦʔϓϯʹͳΕ͹ϋʔυ΢ΣΞ Ͱ΋ϚογϡΞοϓ(ࢮޠ) ग़དྷΔͱ͍͏͜ͱͰ͢Ͷ

Slide 52

Slide 52 text

ୈࡾষ Perl͚ͩͰωΪΛৼΔ

Slide 53

Slide 53 text

No content

Slide 54

Slide 54 text

ωΪΛৼΔͱ͸ʁʁʁ • ݩʑχίχίಈըͷॳԻϛΫಈըͰωΪΛ ৼΔ΋ͷ͕͋Δ • χίχίٕज़෦Ͱೖ໳ಈըͰΑ͘୊ࡐʹͳ Δ • ͍ΖΜͳ΋ͷͰωΪΛৼ͍ͬͯΔ

Slide 55

Slide 55 text

ҎԼͷറΓͰ࡞Δ • ϋϯμ෇͚ͳ͠ ϒϨουϘʔυͳ͠ • Arduinoݴޠ͸ॻ͔ͳ͍ • Perl͸ॻ͘(YAPCͳͷͰ)

Slide 56

Slide 56 text

ࡐྉ • Raspberry Pi Model B • Arduino Leonardo(Ոʹ͋ͬͨ) • GROVE System

Slide 57

Slide 57 text

GROVE Systemͱ͸

Slide 58

Slide 58 text

͜͏͍͏ͪͬͪΌ͍෦඼͕͋ͬͯ

Slide 59

Slide 59 text

͜͏͍͏γʔϧυΛArduinoʹࡌ͚ͬͯ

Slide 60

Slide 60 text

͜Μͳ͔Μ͡Ͱͭͳ͛ͯ࢖͏

Slide 61

Slide 61 text

࢖͏ͨΊͷϥΠϒϥϦ΋طʹ ׬උ͞Ε͍ͯΔ

Slide 62

Slide 62 text

Step 1 Raspberry PiͱArduinoͰ ͓͠Ό΂Γ͢Δ

Slide 63

Slide 63 text

Firmata͍ͬͯ͏ͷΛ࢖͍·͢ • Firmata͸Arduinoͱ͔ͷϚΠίϯͱPCؒ Ͱ͓͠Ό΂Γ͢ΔͨΊͷϓϩτίϧ • ͓खܰಋೖՄೳ

Slide 64

Slide 64 text

ࠓ౓͸FirmataͰLEDΛޫΒ͢

Slide 65

Slide 65 text

PerlͰFirmataΛ͠Ό΂Δ

Slide 66

Slide 66 text

ArduinoʹFirmataͷ εέονΛॻ͖ࠐΉ

Slide 67

Slide 67 text

ϋʔυͷ΄͏ͷ४උ • ArduinoͱGROVE Base ShieldΛ઀ଓ • γʔϧυͷD4ʹLEDϞδϡʔϧΛ઀ଓ • ArduinoͱRaspberry PiΛͭͳ͛Δ

Slide 68

Slide 68 text

Step 2 αʔϘϞʔλΛ࢖͏

Slide 69

Slide 69 text

GROVEͷαʔϘϞʔλ D3ʹͭͳ͍ͩ

Slide 70

Slide 70 text

Step 3 WebΞϓϦԽ͢Δ

Slide 71

Slide 71 text

Amon2Ͱ࡞Δ

Slide 72

Slide 72 text

WebΞϓϦͷػೳ • WebSocketͰ֯౓৘ใΛड৴ • ͦͷ஋ΛRedisʹॻ͖ࠐΉ

Slide 73

Slide 73 text

ผϓϩηεͷϫʔΧʔ • ແݶϧʔϓͰRedisͷ஋Λ؂ࢹ • มԽ͕͋Ε͹FirmataͰArduinoʹૹ৴

Slide 74

Slide 74 text

σϞ

Slide 75

Slide 75 text

࠷ऴষ ࣗ࡞ϋʔυ΢ΣΞͱະདྷ

Slide 76

Slide 76 text

ϋʔυ΢ΣΞΛࣗ෼Ͱ࡞ΕΔ ࣌୅͸࣮֬ʹདྷ͍ͯΔ • 3DϓϦϯλͱ͔ੲ͸ߟ͑ΒΕͳ͔ͬͨ • ᝑମΛ͔ͬ͜ྑ͘࡞Δ໰୊͕ૉૣ͘ղܾ • ϋʔυ΢ΣΞΛखചΓ͢Δ࣌୅ʹͳͬͨ • Make Fairͱ͔Ͷ

Slide 77

Slide 77 text

IRKit http://getirkit.com/

Slide 78

Slide 78 text

IRKit • த਎͸Arduinoޓ׵ج൘ • ͢΂ͯΦʔϓϯ • ճ࿏ઃܭ΍ᝑମͷઃܭΛݸਓͰߦ͏

Slide 79

Slide 79 text

ϋʔυ΢ΣΞΛ͕ͬͭΓ΍Β ͣʹ࡞ΕΔ࣌୅ • ࣗ෼ͷख׳ΕͨݴޠͰهड़Ͱ͖Δ • ϋϯμ෇͚ෆཁ • εςοϓΞοϓ͢ΔͱϒϨουϘʔυ΍ ϋϯμ෇͚͕ඞཁʹͳΔ͚ΕͲ

Slide 80

Slide 80 text

·ͩ·ͩ଍Γͳ͍͜ͱ (๻͕஌Βͳ͍͚͔ͩ΋) • ΤϯδχΞϦϯάͱͯ͠ͷ࢓૊ΈԽ • PerlͰݴ͏CPANΈ͍ͨͳ΍ͭ • ษڧձɺϫʔΫγϣοϓ • ςετ؀ڥ

Slide 81

Slide 81 text

ϋʔυ΢ΣΞͳਓͱग़ձ͍͍ͨʂ • Webͷਓͱ͸Α͘ձ͏͚ΕͲɺ͜͏͍͏͜ ͱ΍͍ͬͯΔਓͳ͔ͳ͔ग़ձΘͳ͍ • ͍ͨΒ঺հͯ͠ཉ͍͠͠ɺ͋ͳ͕ͨͦ͏Ͱ ͋Ε͹༑ͩͪʹͳ͍ͬͯͩ͘͞

Slide 82

Slide 82 text

͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠

Slide 83

Slide 83 text

࣭ٙԠ౴΍ ͕࣌ؒ༨ͬͨΒ΍Δ༻

Slide 84

Slide 84 text

ແઢԽ

Slide 85

Slide 85 text

γϦΞϧΛແઢԽ • XBee/XBee WiFi΍ͦͷଞແઢLANϞδϡʔϧ • γϦΞϧΛZigBee΍WiFiʹม׵Ͱ͖Δ • ٕదʹ஫ҙ • ւ֎੡Ϟδϡʔϧ͸ి೾๏ͰҾ͔͔ͬΔͱ ͔͋Δ

Slide 86

Slide 86 text

RasPi Cam

Slide 87

Slide 87 text

Raspberry Piઐ༻Χϝϥ • খ͍͍ͦͦ҆͜͜͞͠(2000ԁ୆) • ͨͩ͠RasPiઐ༻ • RasPiΛϥΠϒΧϝϥͱ͔ʹग़དྷΔ • ϔϦͰ΋࢖͍·ͨ͠ʢখ͍͞͠USB৯Θͳ͍