Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use FirmATA to operate hardware

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how to use FirmATA to operate hardware". In daily operation, I believe many people have doubts about how to use FirmATA to operate hardware. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to use FirmATA to operate hardware". Next, please follow the editor to study!

Firmata for Python

There are two existing Python Firmata libraries:

Pyduino: http://code.google.com/p/pyduino/ (dependent on pySerial to implement v2.0)

PyFirmata: https://github.com/tino/pyFirmata (relies on pySerial, implements v2.1, supports Python3)

Both codes are visually tested. Pyduino's library pyduino.py is only 10KB, and was last updated in 2009 (which can be used as an important reference). More like what MCU developers wrote.

PyFirmata, on the other hand, is more complete, most recently updated in 2013, and seems to use some advanced Python techniques. Like automated testing. And you can customize the BOARDS parameters. It is more suitable for our testing. Because LPC812MiniKit can support multiple Profile.

Both define the Arduino class, but we can refer to the pyFirmata implementation of the GAPmini class. Although Firmata is indeed customized for Arduino. But if it is extended to other platforms, it should have a more independent name.

The use of pyFirmata

Add several LPC812Min/LPC812Max/LPC812MixMin board configurations (Profile) to boards.py and _ _ init__.py.

Thanks to Tino (Dutch), author of pyFirmata, for providing several testing procedures.

The most basic test program LPC812_Firmata_Blink.py:

From pyfirmata import LPC812Min, utilfrom pyfirmata import BOARDSimport timeprint'> 5 second delay for firmata initial'print'> Press reset to go'board = LPC812Min ('COM27', baudrate=115200) print' >', str (board) board.sp.setDTR (1) # set LOWtime.sleep (0.1) board.sp.setDTR (0) # set HIGH, LOW to High to resetlayout = BOARDS ['lpc812_min'] print "> Board layout" print str (layout) board.setup_layout (layout) (major) Minor) = board.get_firmata_version () print "> Version:% d.% d"% (major) Minor) print "> Firmware name:% s"% (board.firmware) pin17 = board.get_pin ('d board.firmware 17 board.pass_time') while True: try: pin17.write (1) board.pass_time (2) pin17.write (0) board.pass_time (2) except KeyboardInterrupt "> User interrupt." board.exit () print 'Exit it.'

It has been tested to pass basic Firmata communication.

[update]

Basic Digital In (for keyboard processing) and Digital Out (for LED flicker) have been completed. PWM outputs (such as LED brightness and color changes) and analog inputs (such as ADC samples) need to be updated for firmware support.

At this point, the study on "how to use FirmATA to operate hardware" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report