博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
开发板 闪灯测试_Micropython开发板的首次测试
阅读量:2518 次
发布时间:2019-05-11

本文共 3422 字,大约阅读时间需要 11 分钟。

开发板 闪灯测试

微型Python (Micropython)

Micropython () is an implementation of the Python 3 language for microcontrollers. While this might sound like a stupid idea at first (why use a high level garbage collected language on low level hardware?), the creator Damien George has put a great amount of effort into this project. And it’s safe to say that it turned out great. For more information and implementation details, see the links on the start page of micropython.org.

Micropython( )是用于微控制器的Python 3语言的实现。 虽然一开始听起来像是一个愚蠢的主意(为什么在低级硬件上使用高级垃圾收集语言?),但创建者Damien George为该项目付出了很多努力。 可以肯定地说,结果很好。 有关更多信息和实现细节,请参见micropython.org起始页上的链接。

Micropython is not just a language, there is also a hardware board designed to run Python. The development and production costs were funded . As a backer, I’m one of the lucky people that can already hold one of these things in their hands.

Micropython不仅是一种语言,而且还具有设计用于运行Python的硬件板。 开发和生产成本由资助。 作为支持者,我是幸运的人之一,他们已经可以将这些东西之一掌握在手中。

The micropython board.

To “program” the board, you simply copy a file called main.py to the FAT16 filesytem on the board. This is a regular Python file, but additionally to the standard library, you can also use a module called . This module gives you access to the hardware functions of the board, like LED control, I2C / SPI communication, accelerometer status, interrupt handling and more.

要对板进行“编程”,只需将一个名为main.py的文件复制到板上的FAT16文件系统即可。 这是一个常规的Python文件,但是除了标准库之外,您还可以使用一个名为的模块。 该模块使您可以访问电路板的硬件功能,例如LED控制,I2C / SPI通信,加速度计状态,中断处理等。

The board even provides a REPL if you connect to it via serial console:

如果您通过串行控制台连接到该板,则该板甚至会提供一个REPL:

The micropython REPL.

How awesome is that? This is amazing for debugging purposes.

那有多棒? 对于调试目的而言,这是惊人的。

发光二极管 (Sparkling LEDs)

The board features four LEDs in different colors. Because blinking LEDs are the “Hello World” of microcontrollers, I came up with this quick script:

该板具有四个不同颜色的LED。 由于闪烁的LED是微控制器的“ Hello World”,因此我想到了以下快速脚本:

import import pybpybleds leds = = [[ pybpyb .. LEDLED (( ii ) ) for for i i in in [[ 11 , , 22 , , 33 , , 44 ]]]]def def sparklesparkle (( delaydelay ):    ):    for for led led in in ledsleds :        :        ledled .. onon ()        ()        pybpyb .. delaydelay (( delaydelay )    )    for for led led in in ledsleds :        :        ledled .. offoff ()        ()        pybpyb .. delaydelay (( delaydelay ))while while 11 :    :    sparklesparkle (( 6060 ))

This is what it looks like:

看起来是这样的:

使用加速度计 (Using the Accelerometer)

Another built-in feature that you can use without soldering is the . You first instantiate the pyb.Accel() class and can then request the current value for the x, y and z axis.

无需焊接即可使用的另一个内置功能是 。 您首先实例化pyb.Accel()类,然后可以请求x,y和z轴的当前值。

According to the docs, the values should be between -30 and 30 (although I’ve observed some values outside of that range). To visualize the values, I simply translate the accelerometer range 0-30 to the LEDs 1-4: With an absolute acceleration between 0 and 7.5, one LED lights up while for an acceleration between 22.5 and 30 all four LEDs light up.

根据文档,该值应介于-30到30之间(尽管我观察到了一些超出该范围的值)。 为了直观地显示这些值,我将加速度计范围0-30转换为LED 1-4:在0和7.5之间的绝对加速度下,一个LED点亮,而在22.5和30之间的加速度下,所有四个LED点亮。

An easy way to test this program is to hold the board vertically. This causes gravity to “pull” on the accelerator – the LEDs light up.

测试该程序的一种简单方法是垂直固定电路板。 这会导致重力在加速器上“拉” – LED点亮。

更多资源 (More Resources)

You can find the soucecode .

您可以找到源代码。

If you need more information:

如果您需要更多信息:

翻译自:

开发板 闪灯测试

转载地址:http://dsqwd.baihongyu.com/

你可能感兴趣的文章
软件架构学习小结
查看>>
C语言实现UrlEncode编码/UrlDecode解码
查看>>
返回用户提交的图像工具类
查看>>
树链剖分 BZOJ3589 动态树
查看>>
挑战程序设计竞赛 P131 区间DP
查看>>
【例9.9】最长公共子序列
查看>>
S02_CH02_MIO实验Enter a post title
查看>>
javascript 字符串去空格
查看>>
NSFileManager打印目录下的文件的函数
查看>>
Rails--bundle exec rake db:migrate
查看>>
第二组骆阳洋通信工程三班抓包分析
查看>>
深度优先搜索 之 CODE[VS] 1116 四色问题
查看>>
浏览器渲染过程
查看>>
js遍历Object所有属性
查看>>
再也不学AJAX了!(三)跨域获取资源 ③ - WebSocket & postMessage
查看>>
pycharm设置python文件颜色
查看>>
不换行输出的两种方式
查看>>
贵在坚持不懈
查看>>
hdu 1251 统计难题
查看>>
java中关于String 类型数据 的存储方式
查看>>