Package: haas-python-sn74hc595
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-sn74hc595")
import haas-python-sn74hc595数码管驱动芯片 - SN74HC595一、产品简介SN74HC595是TI出品的一种能将串行信号转为并行信号芯片，常用在各种数码管或点阵屏的驱动芯片，使用SN74HC595可以节约单片机的IO资源，用3个io就可以控制8个数码管的管脚，它还具有一定的驱动能力，可以免掉三极管等放大电路。引脚定义VCC:  5VSCLK: host GPIORCLK: host GPIODIO:  host GPIOGND:  GND二、技术参数供电电压:2V~6V驱动能力:6mA(5V)3-bit串行数据转换成8-bit并行数据三、软件接口SN74HC595数码管驱动芯片HaaS Python驱动：下载地址SN74HC595(rclk, sclk, dio) - 创建SN74HC595驱动对象函数原型:displayDev = SN74HC595(rclk, sclk, dio)参数说明:参数类型必选参数？说明rclkGPIO是调用此函数前需确保rclk对象已经处于open状态sclkGPIO是调用此函数前需确保sclk对象已经处于open状态dioGPIO是调用此函数前需确保dio对象已经处于open状态返回值:
SN74HC595对象成功，返回SN74HC595对象；SN74HC595对象创建失败，抛出Exception示例代码:fromdriverimportGPIO# 驱动库formsn74hc595import*# SN74HC595驱动库rclk=GPIO()rclk.open("sn74hc595_rclk")sclk=GPIO()sclk.open("sn74hc595_sclk")dio=GPIO()dio.open("sn74hc595_dio")displayDev=SN74HC595(rclk,sclk,dio)输出:
无outSegmentDigit - 输出数码管数字函数功能:
输出数码管数字函数原型:SN74HC595.outSegmentDigit(position, digit)参数说明:
position: 数码管的位置，从0开始
digit: 数字，0x0-0xf返回值:
无示例:fromsn74hc595import*rclk=GPIO()rclk.open("sn74hc595_rclk")sclk=GPIO()sclk.open("sn74hc595_sclk")dio=GPIO()dio.open("sn74hc595_dio")displayDev=SN74HC595(rclk,sclk,dio)displayDev.outSegmentDigit(0,6)sleep_ms(1000)rclk.close()sclk.close()dio.close()deldisplayDev输出:无四、接口案例此使用实例在board.json中定义了名为sn74hc595的GPIO类型的对象。在Python脚本中依次在四个数码管上输出
0-f数字。代码:#board.json配置：{"name":"board-name","version":"1.0.0","io":{"sn74hc595_rclk":{"type":"GPIO","port":19,"dir":"output","pull":"pullup"},"sn74hc595_sclk":{"type":"GPIO","port":27,"dir":"output","pull":"pullup"},"sn74hc595_dio":{"type":"GPIO","port":0,"dir":"output","pull":"pullup"}},"debugLevel":"ERROR","repl":"disable"}fromsn74hc595import*rclk=GPIO()rclk.open("sn74hc595_rclk")sclk=GPIO()sclk.open("sn74hc595_sclk")dio=GPIO()dio.open("sn74hc595_dio")displayDev=SN74HC595(rclk,sclk,dio)foriinrange(4):forjinrange(0x10):displayDev.out_digit(i,j)sleep_ms(1000)rclk.close()sclk.close()dio.close()deldisplayDev输出:无五、通信协议主控芯片和SN74HC595之间通信所用命令字如下表所示：序号功能说明命令字宏定义1SER pin输出数据bit8CMD_WRITE_DATA_BIT82SRCLK pin输出低电平CMD_WRITE_SRCLK_LOW3SRCLK pin输出高电平CMD_WRITE_SRCLK HIGH4SER pin输出数据bit7CMD_WRITE_DATA_BIT75SRCLK pin输出低电平CMD_WRITE_SRCLK_LOW6SRCLK pin输出高电平CMD_WRITE_SRCLK HIGH7SER pin输出数据bit6CMD_WRITE_DATA_BIT68SRCLK pin输出低电平CMD_WRITE_SRCLK_LOW9SRCLK pin输出高电平CMD_WRITE_SRCLK HIGH.........22SER pin输出数据bit1CMD_WRITE_DATA_BIT123SRCLK pin输出低电平CMD_WRITE_SRCLK_LOW24SRCLK pin输出高电平CMD_WRITE_SRCLK HIGH25RCLK pin输出低电平CMD_WRITE_RCLK_LOW26SRCLK pin输出高电平CMD_WRITE_RCLK_HIGH输出数字流程对数字进行编码，按照主控芯片和SN74HC595的通信协议控制SER、SRCLK和RCLK，即可在数码管上显示出对应数字。六、工作原理从如下方框图可以看到 SN74HC595 内部集成了一个8-bit 移位寄存器和一个8-bit D-type 锁存寄存器，8-bit 移位寄存器输出到8-bit D-type锁存寄存器，通过移位寄存器可以将串行数据转换成并行数据，并且通过锁存寄存器可以将输出的数字锁存下来，所以使用SN74HC595要同时显示多个数字需要利用余晖效应。引脚分布如下，QA-QH一般数码管的段，RCLK，SRCLK，SER分别是锁存clock，移位clock，和数据输入。参考文献及购买链接[1]SN74HC595数码管驱动芯片[2]购买链接