Controlling Arduino With PHP

Controlling Arduino With PHP

PHPNW2015 Unconference https://joind.in/talk/view/15483

3f2fb8bbcd44609346e1cc0c06d0a39b?s=128

Thomas Weinert

October 03, 2015
Tweet

Transcript

  1. CONTROLLING ARDUINO WITH PHP CONNECTIONS TO THE PHYSICAL WORLD @ThomasWeinert

  2. ARDUINO Arduino is an open-source electronics prototyping platform based on

    flexible, easy-to- use hardware and software. It's intended for artists, designers, hobbyists and anyone interested in creating interactive objects or environments.
  3. ARDUINO UNO

  4. ARDUINO MEGA

  5. SHIELDS HTTP://SHIELDLIST.ORG/

  6. NETWORK

  7. PROTOTYPE

  8. MOTOR

  9. ARDUINO NANO

  10. NANO ON BREADBOARD

  11. NANO ON BASE

  12. BREADBOARD

  13. BREADBOARD HALFSIZE

  14. BREADBOARD SCHEMA

  15. BREADBOARD IN USE

  16. BREADBOARD IN USE

  17. FRITZING http://fritzing.org        

          $ $ % % & & ' ' ( ( ) ) * * + + , , - -
  18. ARDUINO IDE

  19. None
  20. FIRMATA

  21. FIRMATA PROTOCOL Midi Based Pin Status Pin Manipulation Extended Commands

  22. FIRMATA TEST

  23. FIRMATA TEST PHP

  24. None
  25. PHP - SERIAL PORTS + Just streams - Console commands

    for configuration
  26. WINDOWS - fread() blocks until it gets data.

  27. SERPROXY

  28. GORILLA PHPMAKE\SERIALPORT https://github.com/oasynnoum/phpmake_serialport

  29. FIRST PROJECT

  30. COMPOSER CREATE …‘’‘•‡”…”‡ƒ–‡Ş’”‘Œ‡…–…ƒ”‹…ƒŵ…Š‹’Ş•‡Ž‡–‘Ž‡†ŞŞ•–ƒ„‹Ž‹–›ʰ†‡˜ 

  31. None
  32. CONFIGURE BOOTSTRAP ŵƋƋ Ƌ•‡”‹ƒŽŞ•‡”‹ƒŽ…‘‡…–‹‘ Ƌ–…’Ş–…’…‘‡…–‹‘ſ‡–™‘”•Š‹‡Ž†‘”•‡”’”‘š›ƀ Ƌŵ †‡ˆ‹‡ſɐ ɏ ɏɐřɐ•‡”‹ƒŽɐƀŚ †‡ˆ‹‡ſɐ

    ɏ ɏ ɏ ɐřɐŵ†‡˜ŵ––›ɥɐƀŚ †‡ˆ‹‡ſɐ ɏ ɏ ɏɐřɬɮɭɥɥƀŚ †‡ˆ‹‡ſɐ ɏ ɏɏɐřɐɨɩɮŜɥŜɥŜɨɐƀŚ †‡ˆ‹‡ſɐ ɏ ɏɏɐřɬɪɪɰƀŚ 
  33. SKELETON ɛ„‘ƒ”†ʰ‹…Ž—†‡ſɏɏ ɏɏŜɐŵ„‘‘–•–”ƒ’Ŝ’Š’ɐƀŚ —•‡ƒ”‹…ƒɎŠ‹’ƒ•Š‹’Ś ɛ„‘ƒ”† Şʴƒ…–‹˜ƒ–‡ſƀ Şʴ†‘‡ſ ˆ—…–‹‘ſƀ—•‡ſɛ„‘ƒ”†ƀƇ ŵŵ–ƒ”–Š‡”‡Š ƈ

    ƀŚ ƒ”‹…ƒɎ ‘Ɏ˜‡–Ɏ‘‘’Ɏ ƒ…–‘”›śś”—ſƀŚ 
  34. LED OBJECT ɛ„‘ƒ”†ʰ‹…Ž—†‡ſɏɏ ɏɏŜɐŵ„‘‘–•–”ƒ’Ŝ’Š’ɐƀŚ —•‡ƒ”‹…ƒɎŠ‹’ƒ•Š‹’Ś ɛ„‘ƒ”† Şʴƒ…–‹˜ƒ–‡ſƀ Şʴ†‘‡ſ ˆ—…–‹‘ſƀ—•‡ſɛ„‘ƒ”†ƀƇ ɛŽ‡†ʰ‡™Š‹’Ɏ‡†ſɛ„‘ƒ”†Şʴ’‹•ƃɨɪƄƀŚ

    ɛŽ‡†Şʴ•–”‘„‡ſɩɥɥɥƀŞʴ‘ſƀŚ ƈ ƀŚ ƒ”‹…ƒɎ ‘Ɏ˜‡–Ɏ‘‘’Ɏ ƒ…–‘”›śś”—ſƀŚ 
  35. ,R (YHQW/RRS 6HUYHU )LUPDWD 3URWRFRO &KLS 'HYLFHV   

      
  36. BASIC BLINK ɛ„‘ƒ”†Şʴ’‹‘†‡ſɨɪřɥšɥɨƀŚ ™Š‹Ž‡ſƀƇ ɛ„‘ƒ”†Şʴ†‹‰‹–ƒŽ”‹–‡ſɨɪřɥš ƀŚ •Ž‡‡’ſɨƀŚ ɛ„‘ƒ”†Şʴ†‹‰‹–ƒŽ”‹–‡ſɨɪřɥšɥɥƀŚ •Ž‡‡’ſɨƀŚ ƈ

    
  37. BASIC BLINK OOP ɛ„‘ƒ”†Şʴ’‹•ƃɨɪƄŞʴ‘†‡ʰƒ”‹…ƒɎ ‹”ƒ–ƒɎ‹śśɏŚ ™Š‹Ž‡ſƀƇ ɛ„‘ƒ”†Şʴ’‹•ƃɨɪƄŞʴ†‹‰‹–ƒŽʰŠɛ„‘ƒ”†Şʴ’‹•ƃɨɪƄŞʴ†‹‰‹–ƒŽŚ •Ž‡‡’ſɨƀŚ ƈ 

  38. BLINK NONBLOCKING ɛŽ‘‘’ʰ ‘Ɏ˜‡–Ɏ‘‘’Ɏ ƒ…–‘”›śś‰‡–ſƀŚ ɛ„‘ƒ”† Şʴƒ…–‹˜ƒ–‡ſƀ Şʴ†‘‡ſ ˆ—…–‹‘ſƀ—•‡ſɛ„‘ƒ”†řɛŽ‘‘’ƀƇ ɛ’‹ʰɛ„‘ƒ”†Şʴ’‹•ƃɨɪƄŚ

    ɛ’‹Şʴ‘†‡ʰ ‹”ƒ–ƒɎ‹śśɏŚ ɛŽ‘‘’Şʴ•‡– –‡”˜ƒŽſ ˆ—…–‹‘ſƀ—•‡ſɛ’‹ƀƇ ɛ’‹Şʴ†‹‰‹–ƒŽʰŠɛ’‹Şʴ†‹‰‹–ƒŽŚ ƈř ɨɥɥɥ ƀŚ ƈ ƀŚ ɛŽ‘‘’Şʴ”—ſƀŚ 
  39. CARICA CHIP ɛŽ‡†ʰ‡™ƒ”‹…ƒɎŠ‹’Ɏ‡†ſɛ„‘ƒ”†Şʴ’‹•ƃɨɪƄƀŚ ɛŽ‡†Şʴ•–”‘„‡ſƀŞʴ‘ſƀŚ 

  40. CARICA CHIP ɛŽ‡†ʰ‡™ƒ”‹…ƒɎŠ‹’Ɏ‡†ſɛ„‘ƒ”†Şʴ’‹•ƃɨɪƄƀŚ ɛŽ‡†Şʴ’—Ž•‡ſƀŞʴ‘ſƀŚ 

  41. CARICA CHIP ɛŽ‡†ʰ‡™ƒ”‹…ƒɎŠ‹’Ɏ‡†ſɛ„‘ƒ”†Şʴ’‹•ƃɨɪƄƀŚ ɛŽ‡†Şʴ„”‹‰Š–‡••ſɥŜɬƀŞʴ’—Ž•‡ſƀŞʴ‘ſƀŚ 

  42. CARICA IO Event Loop Event Emitter Promises Device Interfaces

  43. EVENT LOOP

  44. JAVASCRIPT EXAMPLE ˜ƒ”‡ʰ†‘…—‡–Ŝ‰‡–Ž‡‡–› †ſɐ‘—–’—–ɐƀŚ ˜ƒ”…‘—–‡”ʰɥŚ ˜ƒ”‹–‡”˜ƒŽʰ™‹†‘™Ŝ•‡– –‡”˜ƒŽſ ˆ—…–‹‘ſƀƇ ‡Ŝ–‡š–‘–‡–ʰ‡Ŝ–‡š–‘–‡–ʫ…‘—–‡”Ŝ–‘–”‹‰ſƀʫɐřɐŚ …‘—–‡”ʫʫŚ

    ƈř ɨɥɥɥ ƀŚ 
  45. PHP EXAMPLE ɛŽ‘‘’ʰƒ”‹…ƒɎ ‘Ɏ˜‡–Ɏ‘‘’Ɏ ƒ…–‘”›śś‰‡–ſƀŚ ɛŽ‘‘’Şʴ•‡– –‡”˜ƒŽſ ˆ—…–‹‘ſƀƇ •–ƒ–‹…ɛ‹ʰɥŚ ‡…Š‘ɛ‹ʫʫŚ

    ƈř ɨɥɥɥ ƀŚ ɛŽ‘‘’Şʴ”—ſƀŚ 
  46. PROMISES They describe an object that acts as a proxy

    for a result that is initially unknown, usually because the computation of its value is yet incomplete.
  47. JAVASCRIPT EXAMPLE Œ—‡”› Ŝ‰‡–ſɐŠ‡ŽŽ‘Ş™‘”Ž†ŜšŽɐƀ Ŝ†‘‡ſ ˆ—…–‹‘ſšŽƀƇ ƒŽ‡”–ſɐŽ‘ƒ†‡†ŜɐƀŚ ƈ ƀ ƀŚ

    
  48. PHP EXAMPLE ɛ›•“Ž‡ʰ‡™ƒ”‹…ƒɎ ‘Ɏ‡ˆ‡””‡†Ɏ›ſ‡™›•“Ž‹ſɐŽ‘…ƒŽŠ‘•–ɐƀƀŚ ɛ›•“Ž™‘ʰ‡™ƒ”‹…ƒɎ ‘Ɏ‡ˆ‡””‡†Ɏ›ſ‡™›•“Ž‹ſɐŽ‘…ƒŽŠ‘•–ɐƀƀŚ ɛ–‹‡ʰ‹…”‘–‹‡ſƀŚ ɛ†‡„—‰ʰˆ—…–‹‘ſɛ”‡•—Ž–ƀ—•‡ſɛ–‹‡ƀƇ ˜ƒ”ɏ†—’ſ‹–‡”ƒ–‘”ɏ–‘ɏƒ””ƒ›ſɛ”‡•—Ž–ƀƀŚ ˜ƒ”ɏ†—’ſ‹…”‘–‹‡ſƀŞɛ–‹‡ƀŚ

    ƈŚ ɛ“—‡”‹‡•ʰƒ”‹…ƒɎ ‘Ɏ‡ˆ‡””‡†śśŠ‡ſ ɛ›•“Ž‡ſɑɐ—‡”›ɨɐřſɬƀɑƀ Şʴ†‘‡ſɛ†‡„—‰ƀř ɛ›•“Ž™‘ſɑɐ—‡”›ɩɐřſɨƀɑƀ Şʴ†‘‡ſɛ†‡„—‰ƀ ƀŚ ƒ”‹…ƒɎ ‘Ɏ˜‡–Ɏ‘‘’Ɏ ƒ…–‘”›śś”—ſɛ“—‡”‹‡•ƀŚ 
  49. EVENT EMITTER ɛ•–”‡ƒʰ‡™–”‡ƒɎ ‹Ž‡ſɐ…śŵ–’ŵ•ƒ’Ž‡Ŝ–š–ɐƀŚ ɛ•–”‡ƒŞʴ‡˜‡–•ſƀŞʴ‘ſ ɐ”‡ƒ†Ş†ƒ–ƒɐř ˆ—…–‹‘ſɛ†ƒ–ƒƀƇ ‡…Š‘ɛ†ƒ–ƒŚ ƈ ƀŚ

    ɛ•–”‡ƒŞʴ‡˜‡–•ſƀŞʴ‘ſ ɐ‡””‘”ɐř ˆ—…–‹‘ſɛ‡””‘”ƀ—•‡ſɛŽ‘‘’ƀƇ ‡…Š‘ɛ‡””‘”Ś ɛŽ‘‘’Şʴ•–‘’ſƀŚ ƈ ƀŚ 
  50. INTERACTION

  51. HTTPSERVER —•‡ƒ”‹…ƒɎ ‘Ɏ‡–™‘”Ɏ ––’Ś ɛ”‘—–‡ʰ‡™ ––’Ɏ‘—–‡ſƀŚ ɛ”‘—–‡Şʴƒ–…Šſ ɐŵŠ‡ŽŽ‘ŵƇƒ‡ƈɐř ˆ—…–‹‘ſ ––’Ɏ‡“—‡•–ɛ”‡“—‡•–řɛ’ƒ”ƒ‡–‡”•ƀƇ

    ɛ”‡•’‘•‡ʰɛ”‡“—‡•–Şʴ…”‡ƒ–‡‡•’‘•‡ſ ‡™ ––’Ɏ‡•’‘•‡Ɏ‘–‡–Ɏ–”‹‰ſ ɑ ‡ŽŽ‘ɑŜɛ’ƒ”ƒ‡–‡”•ƃɐƒ‡ɐƄŜɑŠɎɑ ƀ ƀŚ ”‡–—”ɛ”‡•’‘•‡Ś ƈ ƀŚ 
  52. FILES ɛ”‘—–‡Şʴƒ–…ŠſɐŵŠ‡ŽŽ‘ɐř‡™ ––’Ɏ‘—–‡Ɏ ‹Ž‡ſɏɏ ɏɏŜɐŵˆ‹Ž‡•ŵŠ‡ŽŽ‘ŜŠ–ŽɐƀƀŚ ɛ”‘—–‡Şʴ•–ƒ”–•‹–Šſɐŵˆ‹Ž‡•ɐř‡™ ––’Ɏ‘—–‡Ɏ‹”‡…–‘”›ſɏɏ ɏɏƀƀŚ ɛ•‡”˜‡”ʰ‡™ƒ”‹…ƒɎ ‘Ɏ‡–™‘”Ɏ

    ––’Ɏ‡”˜‡”ſɛ”‘—–‡ƀŚ ɛ•‡”˜‡”ŞʴŽ‹•–‡ſɯɥɯɥƀŚ 
  53. INTERACTIVE LED

  54. HTML FILE ʳŠŠ–Žʴ ʳŠ–Žʴ ʳŠ‡ƒ†ʴ ʳ–‹–Ž‡ʴ‡†™‹–…Šʳŵ–‹–Ž‡ʴ ʳŵŠ‡ƒ†ʴ ʳ„‘†›ʴ ʳˆ‘”ƒ…–‹‘ʰɑŜŵ•™‹–…Šŵ‘ɑ–ƒ”‰‡–ʰɑ‹ˆ”ƒ‡ɑʴ ʳ„—––‘–›’‡ʰɑ•—„‹–ɑʴʳŵ„—––‘ʴ

    ʳŵˆ‘”ʴ ʳˆ‘”ƒ…–‹‘ʰɑŜŵ•™‹–…Šŵ‘ˆˆɑ–ƒ”‰‡–ʰɑ‹ˆ”ƒ‡ɑʴ ʳ„—––‘–›’‡ʰɑ•—„‹–ɑʴˆˆʳŵ„—––‘ʴ ʳŵˆ‘”ʴ ʳ‹ˆ”ƒ‡•–›Ž‡ʰɑ™‹†–Šśɩɥɥ’šŚŠ‡‹‰Š–śɫɥ’šŚ„‘”†‡”ś‘‡Śɑ•”…ʰɑƒ„‘—–ś„Žƒɑƒ‡ʰɑ‹ˆ”ƒ‡ɑ ʳŵ„‘†›ʴ ʳŵŠ–Žʴ 
  55. PHP SERVER —•‡ƒ”‹…ƒɎ ‘Ɏ‡–™‘”Ɏ ––’Ś ɛ„‘ƒ”† Şʴƒ…–‹˜ƒ–‡ſƀ Şʴ†‘‡ſ ˆ—…–‹‘ſƀ—•‡ſɛ„‘ƒ”†ƀƇ ɛŽ‡†ʰ‡™ƒ”‹…ƒɎŠ‹’Ɏ‡†ſɛ„‘ƒ”†Şʴ’‹•ƃɩɥƄƀŚ

    ɛ”‘—–‡ʰ‡™ ––’Ɏ‘—–‡ſƀŚ ɛ”‘—–‡Şʴƒ–…Šſ ɐŵ•™‹–…ŠŵƇ•–ƒ–‡ƈɐř ˆ—…–‹‘ſ ––’Ɏ‡“—‡•–ɛ”‡“—‡•–řƒ””ƒ›ɛ’ƒ”ƒ‡–‡”•ƀ—•‡ſɛŽ‡†ƀƇ ‹ˆſɛ’ƒ”ƒ‡–‡”•ƃɐ•–ƒ–‡ɐƄʰʰɐ‘ɐƀƇ ɛŽ‡†Şʴ‘ſƀŚ ɛ‡••ƒ‰‡ʰɐɐŚ ƈ‡Ž•‡Ƈ ɛŽ‡†Şʴ‘ˆˆſƀŚ
  56. COLOR CIRCLE

  57. SERVER ˆ—…–‹‘ſƀ—•‡ſɛ„‘ƒ”†ƀƇ ɛŽ‡†ʰ‡™ƒ”‹…ƒɎŠ‹’Ɏ‰„Ɏ‡†ſ ɛ„‘ƒ”†Şʴ’‹•ƃɪƄřɛ„‘ƒ”†Şʴ’‹•ƃɬƄřɛ„‘ƒ”†Şʴ’‹•ƃɭƄ ƀŚ ɛ”‘—–‡ʰ‡™ƒ”‹…ƒɎ ‘Ɏ‡–™‘”Ɏ ––’Ɏ‘—–‡ſƀŚ ɛ”‘—–‡Şʴƒ–…Šſ ɐŵ”‰„ɐř

    ˆ—…–‹‘ſ ––’Ɏ‡“—‡•–ɛ”‡“—‡•–ƀ—•‡ſɛŽ‡†ƀƇ ɛ…‘Ž‘”ʰ‹••‡–ſɛ”‡“—‡•–Şʴ“—‡”›ƃɐ…‘Ž‘”ɐƄƀ ţɛ”‡“—‡•–Şʴ“—‡”›ƃɐ…‘Ž‘”ɐƄśɐɤɥɥɥɐŚ ɛŽ‡†Şʴ…‘Ž‘”ſɛ…‘Ž‘”ƀŞʴ‘ſƀŚ ɛ”‡•’‘•‡ʰɛ”‡“—‡•–Şʴ…”‡ƒ–‡‡•’‘•‡ſƀŚ ɛ”‡•’‘•‡Şʴ…‘–‡–ʰ‡™ ––’Ɏ‡•’‘•‡Ɏ‘–‡–Ɏ–”‹‰ſ ɐ‘Ž‘”śɐŜɛ…‘Ž‘” ƀŚ ”‡–—”ɛ”‡•’‘•‡Ś ƈ
  58. REACTPHP Ƈ ɑ”‡“—‹”‡ɑśƇ ɑ”‡ƒ…–ŵ”‡ƒ…–ɑśɑɥŜɫŜƋɑ ƈ ƈ 

  59. RATCHET Ƈ ɑ”‡“—‹”‡ɑśƇ ɑ…„‘†‡ŵ”ƒ–…Š‡–ɑśɑɥŜɪŜƋɑ ƈ ƈ 

  60. SENSOR PHALANX 

  61. SHIFTOUT()

  62. SHIFTOUT() ɛ•Š‹ˆ–—–ʰ‡™ ‹”ƒ–ƒɎŠ‹ˆ–—–ſ ɛ„‘ƒ”†Şʴ’‹•ƃɯƄř ɛ„‘ƒ”†Şʴ’‹•ƃɨɩƄř ɛ„‘ƒ”†Şʴ’‹•ƃɨɨƄ ƀŚ ɛŽ‘‘’Şʴ•‡– –‡”˜ƒŽſ ˆ—…–‹‘ſƀ—•‡ſɛ•Š‹ˆ–—–ƀƇ

    •–ƒ–‹…ɛ—„‡”ʰɥŚ ɛ•Š‹ˆ–—–Şʴ™”‹–‡ſɛ—„‡”ƀŚ ‹ˆſʫʫɛ—„‡”ʴɩɬɬƀƇ ɛ—„‡”ʰɥŚ ƈ ƈř ɨɥɥɥ ƀŚ
  63. 7SEG DISPLAYS 

  64. MAX7219 8 Digit - 7Segment Display 8x8 Matrix Displays

  65. ɛƒšʰ‡™ƒ”‹…ƒɎŠ‹’ɎƒšɮɩɨɰɎƒ–”‹šſ ɛ„‘ƒ”†řɨɨřɨɩřɯ ƀŚ ɛ†‹•’Žƒ›‘—–ʰɫŚ ˆ‘”ſɛ‹ʰɥŚɛ‹ʳɛ†‹•’Žƒ›‘—–Śɛ‹ʫʫƀƇ ɛƒšŞʴƒ††‹•’Žƒ›ſɛ‹ƋɯřɥƀŚ ƈ ɛ‹ƒ‰‡ʰ‹ƒ‰‡…”‡ƒ–‡ˆ”‘’‰ſɏɏ ɏɏŜɐŵ‡Ž‡’Š’ƒ–ރ‹ƒ–‹‘Ŝ’‰ɐƀŚ ɛƒšŞʴ•…”‘ŽŽſɛ‹ƒ‰‡řŞɨɮřɨɬɥƀŞʴ„”‹‰Š–‡••ſɥŜɬƀŞʴ‘ſƀŚ

  66. 

  67. I2C ˆ—…–‹‘ſƀ—•‡ſɛŽ‘‘’řɛ„‘ƒ”†ƀƇ ɛ•‡•‘”ʰ‡™ƒ”‹…ƒɎŠ‹’Ɏ ɩɎɨɨɬɩſ ɛ‹ɩ…ʰ‡™ƒ”‹…ƒɎ ‹”ƒ–ƒɎ ɩſɛ„‘ƒ”†ƀ ƀŚ ɛ•‡•‘” Şʴ”‡ƒ†ſƀ

    Şʴ†‘‡ſ ˆ—…–‹‘ſɛ’”‡••—”‡řɛ–‡’‡”ƒ–—”‡ƀƇ ‡…Š‘ɑ”‡••—”‡śɑř—„‡”ɏˆ‘”ƒ–ſɛ’”‡••—”‡řɫƀřɑƒɎɑŚ ‡…Š‘ɑ‡’‡”ƒ–—”‡śɑř—„‡”ɏˆ‘”ƒ–ſɛ–‡’‡”ƒ–—”‡řɨƀřɑ†‡‰ɎɑŚ ƈ ƀ ƈ
  68. THANKS https://joind .in/15483 https://github.com/ThomasWeinert/carica -chip thomas@weinert.info