Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Rust初心者がArduinoをLチカしてみた

 Rust初心者がArduinoをLチカしてみた

2021.4.27 RustのLT会 Shinjuku.rs #15 @オンラインの発表資料

84931a5617d844ecfda982721de3a9e9?s=128

grace2riku

April 28, 2021
Tweet

Transcript

  1. Rustॳ৺ऀ͕ArduinoΛLνΧͯ͠Έͨ Ѩ෦ߞೋ/2021.4.27 RustͷLTձ Shinjuku.rs #15 @ΦϯϥΠϯ 1

  2. • ࣗݾ঺հ • ຊ೔ͷςʔϚ • Կނɺλʔήοτ͸Arduino? • ࢼͯ͠Έͨ͜ͱ • ײ૝

    ໨࣍ 2
  3. • ໊લɿѨ෦ߞೋ(͋΂ɹ͜͏͡) • ύʔιϧςΫϊϩδʔελοϑגࣜձࣾʹॴଐɻݸਓݟղɻ • ೿ݣͰҩྍػثϝʔΧʹͯबۀதɻ • ૊ࠐΈιϑτ΢ΣΞ։ൃɻ • ݴޠɿCݴޠ

    • Rustྺɿࠓ೥ͷ3݄ࠒ͔Βຊࠊ͍Εֶͯश։࢝ • ϒϩάɿhttps://k-abe.hatenablog.com/ • Twitterɿ@juraruming ࣗݾ঺հ
  4. • RustͰArduino UNO(ͱಉ͡ϚΠίϯ)ͷLνΧɺͦͷଞपลػೳͷ੍ޚ͕ Ͱ͖ͨͷͰ৘ใڞ༗ɻ ຊ೔ͷςʔϚ

  5. ૊ࠐΈͰRustΛࢼ͢৔߹ͷλʔήοτج൘ͷબ୒ࢶͷྫ • Arduino • ϥζύΠ • STϚΠΫϩɹNucleoγϦʔζ ARM Cortex-MγϦʔζ •

    GR-PEACH ARM Cortex-A • micro:bit • LEGO EV3 • GBA • PSP • ͦͷଞ Կނɺλʔήοτ͸Arduino?
  6. ͍Ζ͍Ζબ୒ࢶ͕͋Δ͕ArduinoΛબΜͩཧ༝͸ɾɾɾ • ҎલArduinoΛ࢖ͬͨ͜ͱ͕͋ͬͨɻ • Arduino UNOͰ΋ྑ͍͚Ͳ֎෦σόΠεΛ֎෇͚͢Δख͕ؒ͋Δɾɾɾɻ • Leafonyͱ͍͏ʮ͍Ζ͍Ζࢼͤͦ͏ͳʯج൘͕ͨ·ͨ·खݩʹ͋ͬͨɻ • LeafonyɾɾɾIoTΤοδσόΠεͱͯ͠ྑ͍ײ͡͡Όͳ͍͔???খͯ͘͞

    ֨޷͍͍ɻαϯϓϧίʔυ΋ެ։͞Ε͍ͯͨɻ͢͜͠ͷมߋͰRustͰಈ ͔ͤͦ͏ͳײ͡ɻ Կނɺλʔήοτ͸Arduino?
  7. ݁Ռɺ࣍ͷ͜ͱ͕֬ೝͰ͖·ͨ͠ɻ ▪Leafony Basic KitʹͯʮόοςϦిѹಡΈऔΓʯαϯϓϧϓϩάϥϜΛ֬ೝͰ͖ͨɻ • I2CϚελͰϥΠτɾϦʔυɻ ɹI2CεϨʔϒͷADίϯόʔλ͔ΒϘλϯి஑ͷిѹΛಡΈग़ͤͨɻ • γϦΞϧ௨৴(ૹ৴) •

    LνΧ • ms୯Ґͷ࣌ؒ଴ͪ(delay) ※Arduino UNOɺArduino MEGAͰ΋LνΧ֬ೝͰ͖·ͨ͠ɻ Կނɺλʔήοτ͸Arduino?
  8. Leafonyͱ͸? Կނɺλʔήοτ͸Arduino?

  9. Leafony Basic Kitͱ͸? Կނɺλʔήοτ͸Arduino?

  10. • ʲavr-halʳͷιʔείʔυΛར༻ͤͯ͞΋Β͍֬ೝͨ͠ɻ ɹhttps://github.com/Rahix/avr-hal • ࠷ॳ͸ʲThe AVR-Rust projectʳΛmacͰࢼ͕ͨ͠։ൃ؀ڥߏஙͰ͖ͣʹ࠳ંɻavr- halʹҠߦͨ͠ɻ ࢼͨ͜͠ͱ

  11. • ʲavr-halʳ͸Լهͷϋʔυ΢ΣΞΛαϙʔτɻ ࢼͨ͜͠ͱ ɾLeafony͸Arduino UNOͱಉ ͡ϚΠίϯatmega328pΛ࢖༻͠ ͍ͯΔɻ গ͠มߋͯ͠RustͰಈ͔ͤͳ͍ ͔ͳͱࢥͬͨͷͰௐࠪͨ͠ɻ

  12. • LeafonyͷʮόοςϦిѹಡΈऔΓʯαϯϓϧϓϩάϥϜ(Arduino IDE C Ͱ࣮૷͞Ε͍ͯΔ)ΛRustʹॻ͖׵͑Δɻ ɹϚΠίϯͱిݯϦʔϑͷADίϯόʔλ͸I2CͰ઀ଓ͞Ε͍ͯΔɻ ɹArduino IDE൛͸I2CͷWireϥΠϒϥϦͰ࣮૷͞Ε͍ͯΔɻ ɹRust͸arduino_uno::I2cMasterͰI2CΛ࣮ݱ͢Δɻ •

    ΫϩοΫʹґଘ͢Δॲཧ෦෼(γϦΞϧɺI2Cɺdelayؔ਺)Λ16MHz͔Β 8MHzʹมߋɻarduino UNO͸16MHz, Leafony͸8MHzͷͨΊɻ ࢼͨ͜͠ͱ
  13. • ݁Ռ ɹavr-hal Arduino UNOͷαϯϓϧϓϩάϥϜΛLeafonyʹ߹Θͤͯগ͠ม ߋͨ͠ͱ͜ΖɺLeafonyͷʮόοςϦిѹಡΈऔΓʯαϯϓϧϓϩάϥϜΛ ࣮ߦͰ͖ͨɻ ࢼͨ͜͠ͱ

  14. • ݁Ռ Լਤ͸όοςϦిѹ(mV୯Ґ)ͷγϦΞϧσʔλΛද͍ࣔͯ͠Δͱ͜Ζɻ Ϙλϯి஑ͷిѹ(໿3V)ΛಡΈग़͍ͤͯΔ໛༷ɻ ࢼͨ͜͠ͱ

  15. • ϒϩάʹগ͠ৄ͘͠ॻ͍ͨͷͰΑ͚Ε͹ࢀর͍ͩ͘͞ɻ https://k-abe.hatenablog.com/entry/2021/04/14/125312 • ιʔείʔυ͸GitHubΛࢀরɻ https://github.com/grace2riku/avr-hal/tree/add_leafony ࢼͨ͜͠ͱ

  16. • ҰԠɺRustͰArduinoͱಉ͡ϚΠίϯΛಈ͔ͤͨͷͰྑ͔ͬͨɻ • Arduino IDEಉ༷ɺRustͷavr-halͰ΋ϚΠίϯͷϨδελΛҙࣝͤͣʹ ϋʔυ΢ΣΞ੍ޚͰ͖ͨɻ • RustͷجຊΛཧղͰ͖͍ͯͳ͍ͨΊɺ͓·͡ͳ͍ͷΑ͏ʹײ͡Δهड़΋ ͋Δɻ͜Ε͔ΒֶΜͰ͍͖͍ͨɻ •

    RustͰArduinoɺબ୒ࢶͱͯ͠Ͳ͏Ͱ͔͢? ײ૝
  17. • avr-hal https://github.com/Rahix/avr-hal • Leafony https://docs.leafony.com/docs/overview/ • Leafony Bacic Kit

    https://docs.leafony.com/docs/products/basic/ • Leafony όοςϦిѹಡΈऔΓαϯϓϧϓϩάϥϜղઆ https://docs.leafony.com/docs/examples/beginner/1_p/basic/read_battery/ ࢀরɾҾ༻
  18. ͝ਗ਼ௌɺ͋Γ͕ͱ͏ ͍͟͝·ͨ͠ɻ ऴΘΓ