开发板 闪灯测试_Micropython开发板的首次测试

开发板 闪灯测试

微型Python (Micropython)

Micropython (https://micropython.org/) 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( https://micropython.org/ )是用于微控制器的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 via Kickstarter. As a backer, I’m one of the lucky people that can already hold one of these things in their hands.

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

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 pyb. 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文件,但是除了标准库之外,您还可以使用一个名为pyb的模块。 该模块使您可以访问电路板的硬件功能,例如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 pyb

pyb

leds 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 accelerometer. 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点亮。

翻译自: https://www.pybloggers.com/2014/05/first-tests-with-the-micropython-board/

开发板 闪灯测试

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值