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. 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.
  2. 6.
  3. 8.
  4. 17.

    FRITZING http://fritzing.org        

          $ $ % % & & ' ' ( ( ) ) * * + + , , - -
  5. 19.
  6. 20.
  7. 24.
  8. 27.
  9. 31.
  10. 32.

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

    ɏ ɏ ɏ ɐřɐŵ†‡˜ŵ––›ɥɐƀŚ †‡ˆ‹‡ſɐ ɏ ɏ ɏɐřɬɮɭɥɥƀŚ †‡ˆ‹‡ſɐ ɏ ɏɏɐřɐɨɩɮŜɥŜɥŜɨɐƀŚ †‡ˆ‹‡ſɐ ɏ ɏɏɐřɬɪɪɰƀŚ 
  11. 38.

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

    ɛ’‹Şʴ‘†‡ʰ ‹”ƒ–ƒɎ‹śśɏŚ ɛŽ‘‘’Şʴ•‡– –‡”˜ƒŽſ ˆ—…–‹‘ſƀ—•‡ſɛ’‹ƀƇ ɛ’‹Şʴ†‹‰‹–ƒŽʰŠɛ’‹Şʴ†‹‰‹–ƒŽŚ ƈř ɨɥɥɥ ƀŚ ƈ ƀŚ ɛŽ‘‘’Şʴ”—ſƀŚ 
  12. 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.
  13. 48.

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

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

    EVENT EMITTER ɛ•–”‡ƒʰ‡™–”‡ƒɎ ‹Ž‡ſɐ…śŵ–’ŵ•ƒ’Ž‡Ŝ–š–ɐƀŚ ɛ•–”‡ƒŞʴ‡˜‡–•ſƀŞʴ‘ſ ɐ”‡ƒ†Ş†ƒ–ƒɐř ˆ—…–‹‘ſɛ†ƒ–ƒƀƇ ‡…Š‘ɛ†ƒ–ƒŚ ƈ ƀŚ

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

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

    ɛ”‡•’‘•‡ʰɛ”‡“—‡•–Şʴ…”‡ƒ–‡‡•’‘•‡ſ ‡™ ––’Ɏ‡•’‘•‡Ɏ‘–‡–Ɏ–”‹‰ſ ɑ ‡ŽŽ‘ɑŜɛ’ƒ”ƒ‡–‡”•ƃɐƒ‡ɐƄŜɑŠɎɑ ƀ ƀŚ ”‡–—”ɛ”‡•’‘•‡Ś ƈ ƀŚ 
  16. 54.

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

    ʳŵˆ‘”ʴ ʳˆ‘”ƒ…–‹‘ʰɑŜŵ•™‹–…Šŵ‘ˆˆɑ–ƒ”‰‡–ʰɑ‹ˆ”ƒ‡ɑʴ ʳ„—––‘–›’‡ʰɑ•—„‹–ɑʴˆˆʳŵ„—––‘ʴ ʳŵˆ‘”ʴ ʳ‹ˆ”ƒ‡•–›Ž‡ʰɑ™‹†–Šśɩɥɥ’šŚŠ‡‹‰Š–śɫɥ’šŚ„‘”†‡”ś‘‡Śɑ•”…ʰɑƒ„‘—–ś„Žƒɑƒ‡ʰɑ‹ˆ”ƒ‡ɑ ʳŵ„‘†›ʴ ʳŵŠ–Žʴ 
  17. 55.

    PHP SERVER —•‡ƒ”‹…ƒɎ ‘Ɏ‡–™‘”Ɏ ––’Ś ɛ„‘ƒ”† Şʴƒ…–‹˜ƒ–‡ſƀ Şʴ†‘‡ſ ˆ—…–‹‘ſƀ—•‡ſɛ„‘ƒ”†ƀƇ ɛŽ‡†ʰ‡™ƒ”‹…ƒɎŠ‹’Ɏ‡†ſɛ„‘ƒ”†Şʴ’‹•ƃɩɥƄƀŚ

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

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

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

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

    •–ƒ–‹…ɛ—„‡”ʰɥŚ ɛ•Š‹ˆ–—–Şʴ™”‹–‡ſɛ—„‡”ƀŚ ‹ˆſʫʫɛ—„‡”ʴɩɬɬƀƇ ɛ—„‡”ʰɥŚ ƈ ƈř ɨɥɥɥ ƀŚ
  20. 66.
  21. 67.

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

    Şʴ†‘‡ſ ˆ—…–‹‘ſɛ’”‡••—”‡řɛ–‡’‡”ƒ–—”‡ƀƇ ‡…Š‘ɑ”‡••—”‡śɑř—„‡”ɏˆ‘”ƒ–ſɛ’”‡••—”‡řɫƀřɑƒɎɑŚ ‡…Š‘ɑ‡’‡”ƒ–—”‡śɑř—„‡”ɏˆ‘”ƒ–ſɛ–‡’‡”ƒ–—”‡řɨƀřɑ†‡‰ɎɑŚ ƈ ƀ ƈ