Package: haas-python-max7219
HaaS Python介绍HaaS Python是阿里云IoT团队最新研发的一套低代码编程框架，兼容MicroPython编程规范，依托HaaS平台软硬件积木提供AI、支付、蓝牙配网、云连接、UI等物联网场景常用的能力，从而解决了物联网应用开发难的问题。有了Python轻应用框架，物联网编程不再局限于专业软件开发人员，一般的技术员也可以快速实现复杂的物联网需求。
更多HaaS Python介绍和开发资料见HaaS Python官网,创意案例,硬件积木HaaS Python is a set of low-code programming frameworks newly developed by Alibaba Cloud IoT team. It is compatible with MicroPython programming specifications. It relies on the hardware and software building blocks of the HaaS platform to provide capabilities commonly used in IoT scenarios such as AI, payment, Bluetooth network configuration, cloud connection, and UI. Solve the difficult problem of IoT application development. With the Python light application framework, IoT programming is no longer limited to professional software developers, and general technicians can quickly implement complex IoT requirements.
For more HaaS Python introduction and development materials, seeHaaS Python official website,Creative Case,Hardware Building Blocks安装方法在HaaS Python官网下载开发板对应的固件，并完成固件烧录Download the firmware corresponding to the development board atHaaS Python websiteand complete the firmware burning在开发板上运行以下命令完成安装和使用,如果您在使用过程中遇到问题，欢迎在github上向我们提交issue，我们的工程师会及时解答Run the following commands on the development board to complete the installation and use. If you encounter problems during use, please submit an issue to us ongithub, Our engineers will answer in timeimport upip
upip.install("haas-python-max7219")
import haas-python-max7219数码管点阵屏驱动芯片 - MAX7219一、产品简介MAX7219是MAXIM出品的专门驱动7-段数码管、点阵屏的一款芯片，它内置有BCD code-B 译码器、多路扫描电路、段和点阵驱动电路、以及一个8x8的静态ram来存储输出数字，主要用于工业数码屏、点阵屏的显示场景。数码管点阵屏引脚定义VCC: 5VCLK: host GPIOCS:  host GPIODIN: host GPIOGND: GND二、技术参数温度范围:0摄氏度 - +70摄氏度扫描范围:1-8 数码管三、软件接口MAX7219数码管点阵屏HaaS Python驱动：下载地址MAX7219(clk, cs, din) - 创建MAX7219驱动对象函数原型:displayDev = MAX7219(clk, cs, din)参数说明:参数类型必选参数？说明clkGPIO是调用此函数前需确保clk对象已经处于open状态csGPIO是调用此函数前需确保cs对象已经处于open状态dinGPIO是调用此函数前需确保din对象已经处于open状态返回值:
MAX7219对象成功，返回MAX7219对象；MAX7219对象创建失败，抛出Exception示例代码:fromdriverimportGPIO# 驱动库frommax7219import*# MAX7219驱动库clk=GPIO()clk.open("max7219_clk")cs=GPIO()cs.open("max7219_cs")din=GPIO()din.open("max7219_din")displayDev=MAX7219(clk,clk,din)输出:
无outSegmentDigit - 输出数码管数字函数功能:
输出数码管数字函数原型:MAX7219.outSegmentDigit(position, digit)参数说明:
position: 数码管的位置，从0开始
digit: 数字，0x0-0xf返回值:
无outMatrixChar - 输出点阵屏字符函数功能:
输出数码管数字函数原型:MAX7219.outMatrixChar(charactor)参数说明:
charactor: 要输出的字符，支持0-9，A-Z返回值:
无initSegmentLed - 初始化数码管函数功能:
初始化数码管函数原型:MAX7219.initSegmentLed()参数说明:
无返回值:
无initMatrixLed - 初始化点阵屏函数功能:
初始化点阵屏函数原型:MAX7219.initMatrixLed()参数说明:
无返回值:
无示例:clk=GPIO()clk.open("max7219_clk")cs=GPIO()cs.open("max7219_cs")din=GPIO()din.open("max7219_din")displayDev=MAX7219(clk,cs,din)displayDev.initSegmentLed()displayDev.outSegmentDigit(0,8)displayDev.outSegmentDigit(1,7)displayDev.outSegmentDigit(2,6)displayDev.outSegmentDigit(3,5)displayDev.outSegmentDigit(4,4)displayDev.outSegmentDigit(5,3)displayDev.outSegmentDigit(6,2)displayDev.outSegmentDigit(7,1)输出:
无四、接口案例此使用实例在board.json中定义了名为max5219的GPIO类型的对象。在数码管中输出12345678这个数字。代码：#board.json配置：{"name":"board-name","version":"1.0.0","io":{"max7219_clk":{"type":"GPIO","port":19,"dir":"output","pull":"pullup"},"max7219_cs":{"type":"GPIO","port":27,"dir":"output","pull":"pullup"},"max7219_din":{"type":"GPIO","port":0,"dir":"output","pull":"pullup"}},"debugLevel":"ERROR","repl":"disable"}clk=GPIO()clk.open("max7219_clk")cs=GPIO()cs.open("max7219_cs")din=GPIO()din.open("max7219_din")displayDev=MAX7219(clk,cs,din)displayDev.initSegmentLed()displayDev.outSegmentDigit(0,8)displayDev.outSegmentDigit(1,7)displayDev.outSegmentDigit(2,6)displayDev.outSegmentDigit(3,5)displayDev.outSegmentDigit(4,4)displayDev.outSegmentDigit(5,3)displayDev.outSegmentDigit(6,2)displayDev.outSegmentDigit(7,1)clk.close()cs.close()din.close()deldisplayDev输出：无五、通信协议主控芯片和MAX5219之间通信所用命令字如下表所示：序号功能说明命令字宏定义1CS pin输出低电平CMD_WRITE_CS_LOW2CLK pin输出低电平CMD_WRITE_CLK_LOW3DIN 输出数据bit8CMD_WRITE_DATA_BIT84CLK pin输出高电平CMD_WRITE_CLK_HIGH5CLK pin输出低电平CMD_WRITE_CLK_LOW6DIN 输出数据bit7CMD_WRITE_DATA_BIT77CLK pin输出高电平CMD_WRITE_CLK_HIGH.........23CLK pin输出低电平CMD_WRITE_CLK_LOW24DIN 输出数据bit1CMD_WRITE_DATA_BIT125CLK pin输出高电平CMD_WRITE_CLK_HIGH1CS pin输出高电平CMD_WRITE_CS_HIGH输出数字流程按照主控芯片和MAX7219的通信协议控制CLK、CS和DIN，即可在数码管上显示出对应数字。六、工作原理从如下方框图可以看到 MAX7219 内部集成了数码管段驱动电路、多路扫描电路、8x8 静态ram等。引脚分布如下，DIG0-DIG7一般数码管的段，是输出管脚，CLK，CS，DIN是输入管脚。参考文献及购买链接[1]MAX7219数码管驱动芯片