Skip to main content

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, see HaaS Python official website, Creative Case, Hardware Building Blocks

安装方法

Download the firmware corresponding to the development board at HaaS Python website and 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 on github, Our engineers will answer in time

import upip
upip.install("haas-python-ttp224")
import haas-python-ttp224

4路触摸电容模块-TTP224

一、产品简介

板载TTP224电容式4键触摸感应IC,开发者通过触摸该电容模块获取对应的高低电平状态,可以广泛应用于灯光控制、玩具、家用电器等产品中。

引脚定义:

  • VCC:接 3.3V
  • GND:接 GND
  • OUT1:接 GPIO
  • OUT2:接 GPIO
  • OUT3:接 GPIO
  • OUT4:接 GPIO

二、技术参数

  • 工作电压:2.3V-5.5V DC
  • TTP224电流(3V):2.5uA-9.0uA
  • 板载4路电平状态指示灯
  • 模式:设置输出模式、键输出模式、上限输出时间和快速/低功耗选择
  • 规格尺寸:35mm * 29mm

三、软件接口

4路触摸电容模块HaaS Python驱动:下载地址

TTP224(ttp01Obj,ttp02Obj,ttp03Obj,ttp04Obj) - 创建TTP224驱动对象

  • 函数原型:

ttp224Obj = TTP224(ttp01Obj,ttp02Obj,ttp03Obj,ttp04Obj)

  • 参数说明:
参数 类型 必选参数? 说明
ttp01Obj GPIO 否
ttp02Obj GPIO 否
ttp03Obj GPIO 否
ttp04Obj GPIO 否
  • 返回值: TTP224对象创建成功,返回TTP224对象;TTP224对象创建失败,抛出Exception

  • 示例代码:

import ttp224
from driver import GPIO

ttp01Dev = GPIO()
ttp01Dev.open("ttp01")
ttp02Dev = GPIO()
ttp02Dev.open("ttp02")
ttp03Dev = GPIO()
ttp03Dev.open("ttp03")
ttp04Dev = GPIO()
ttp04Dev.open("ttp04")
ttp = ttp224.TTP224(ttp01Dev,None,ttp03Dev)
print("ttp224 inited!")
  • 输出:
ttp224 inited!

getStatus() - 获取TTP224的电容触摸状态值

  • 函数功能: 获取TTP224的电容触摸状态值

  • 函数原型:

TTP224.getStatus()

  • 参数说明: 无

  • 返回值:

返回值 类型 说明
cntobj 整型 返回创建了几路TTP对象,0-没有创建对象
ttp01 整型 None-该路未创建,0-未触摸,1-触摸
ttp02 整型 None-该路未创建,0-未触摸,1-触摸
ttp03 整型 None-该路未创建,0-未触摸,1-触摸
ttp04 整型 None-该路未创建,0-未触摸,1-触摸
  • 示例:
import ttp224
from driver import GPIO
import utime

ttp01Dev = GPIO()
ttp01Dev.open("ttp01")
ttp02Dev = GPIO()
ttp02Dev.open("ttp02")
ttp03Dev = GPIO()
ttp03Dev.open("ttp03")
ttp04Dev = GPIO()
ttp04Dev.open("ttp04")
ttp = ttp224.TTP224(ttp01Dev,None,ttp03Dev)
print("ttp224 Init!")
while True:             # 无限循环
    cnt,ttp01,ttp02,ttp03,ttp04 = ttp.getStatus()
    print(cnt,ttp01,ttp02,ttp03,ttp04)
    utime.sleep(1)
  • 输出:
ttp224 Init!
2 0 None 0 None
2 0 None 0 None
2 0 None 0 None
2 0 None 0 None
2 0 None 0 None
2 1 None 0 None
2 1 None 0 None
2 0 None 0 None
2 0 None 1 None
2 1 None 1 None
2 0 None 0 None
2 0 None 0 None
2 0 None 0 None

四、接口案例

此使用实例在board.json中定义了名为tTTP224的I2C类型的对象。在Python脚本中周期性的获取TTP224各路触摸电容的状态并打印在日志中。

  • 代码:
# board.json配置:
{
    "name": "board-name",
    "version": "1.0.0",
    "io": {
      "ttp01": {
        "type": "GPIO",
        "port": 2,
        "dir": "input",
        "pull": "pullup"
      },
      "ttp02": {
        "type": "GPIO",
        "port": 12,
        "dir": "input",
        "pull": "pullup"
      },
      "ttp03": {
        "type": "GPIO",
        "port": 13,
        "dir": "input",
        "pull": "pullup"
      },
      "ttp04": {
        "type": "GPIO",
        "port": 14,
        "dir": "input",
        "pull": "pullup"
      }
    },
    "debugLevel": "ERROR",
    "repl": "disable"
}
# Python代码
import ttp224
from driver import GPIO
import utime

ttp01Dev = GPIO()
ttp01Dev.open("ttp01")
ttp02Dev = GPIO()
ttp02Dev.open("ttp02")
ttp03Dev = GPIO()
ttp03Dev.open("ttp03")
ttp04Dev = GPIO()
ttp04Dev.open("ttp04")
ttp = ttp224.TTP224(ttp01Dev,ttp02Dev,ttp03Dev,ttp04Dev)
print("ttp224 Init!")
while True:             # 无限循环
    cnt,ttp01,ttp02,ttp03,ttp04 = ttp.getStatus()
    print(cnt,ttp01,ttp02,ttp03,ttp04)
    utime.sleep(1)
  • 输出:
ttp224 Init!
4 0 0 0 0
4 0 0 0 0
4 0 0 0 0
4 0 0 0 0
4 1 0 0 0
4 1 1 0 0
4 0 0 1 0

参考文献及购买链接

Release files for haas-python-ttp224 0.0.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for haas-python-ttp224 0.0.7
File Size Uploaded
haas-python-ttp224-0.0.7.tar.gz 7.7 kB Details

Release files / haas-python-ttp224-0.0.7.tar.gz

Download URL haas-python-ttp224-0.0.7.tar.gz
Size 7.7 kB
Tags Source
SHA-256 checksum
How to use checksums
cd424fd0ed272847c8aa06bb5136bb6a7707a8ce3de374a8f59f7d2ea80f6419
BLAKE2b-256 checksum
How to use checksums
8f580974e801036d741573be7e4f96a81850f03c0203e6b5f17213872d72d25b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.8.5

Release history Release notifications | RSS feed

This release

0.0.7 This release

1 release file

0.0.6

1 release file

0.0.5

1 release file

0.0.4

1 release file

0.0.3

1 release file

0.0.2

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page