Metadata-Version: 2.1
Name: haas-python-magnetron_sensor
Version: 0.0.1
Summary: This is magnetron_sensor driver for HaaS Python. HaaS Python is forked from micropython.
Home-page: https://haas.iot.aliyun.com/?from=corp
Author: HaaS Python
Author-email: yinsuo.mys@alibaba-inc.com
License: Apache License, Version 2.0
Project-URL: Source Code, https://github.com/alibaba/AliOS-Things
Project-URL: Bug Tracker, https://github.com/alibaba/AliOS-Things/issues
Project-URL: Documentation, https://haas.iot.aliyun.com/haasapi/index.html?spm=a2cpu.b16145223.0.0.81b460b1lzwYKw#/?from=corp
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: OS Independent
Description-Content-Type: text/markdown
License-File: LICENSE


## HaaS Python介绍
HaaS Python是阿里云IoT团队最新研发的一套低代码编程框架，兼容MicroPython编程规范，依托HaaS平台软硬件积木提供AI、支付、蓝牙配网、云连接、UI等物联网场景常用的能力，从而解决了物联网应用开发难的问题。有了Python轻应用框架，物联网编程不再局限于专业软件开发人员，一般的技术员也可以快速实现复杂的物联网需求。
更多HaaS Python介绍和开发资料见[HaaS Python官网](https://haas.iot.aliyun.com/haasapi/index.html?spm=a2cpu.b16145223.0.0.595660b1dZDX71#/?from=corp),[创意案例](https://haas.iot.aliyun.com/solution?from=crop), [硬件积木](https://haas.iot.aliyun.com/solution/hardware?from=corp)

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](https://haas.iot.aliyun.com/haasapi/index.html?spm=a2cpu.b16145223.0.0.595660b1dZDX71#/?from=corp), [Creative Case](https://haas.iot.aliyun.com/solution?from=crop), [Hardware Building Blocks](https://haas.iot.aliyun.com/solution/hardware?from=corp)

## 安装方法
* 在[HaaS Python官网](https://haas.iot.aliyun.com/haasapi/index.html?spm=a2cpu.b50127119.0.0.4e1260b1ebMIf1#/)下载开发板对应的固件，并完成固件烧录

Download the firmware corresponding to the development board at [HaaS Python website](https://haas.iot.aliyun.com/haasapi/index.html?spm=a2cpu.b50127119.0.0.4e1260b1ebMIf1#/) and complete the firmware burning

* 在开发板上运行以下命令完成安装和使用,如果您在使用过程中遇到问题，欢迎在[github上向我们提交issue](https://github.com/alibaba/AliOS-Things/issues)，我们的工程师会及时解答

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](https://github.com/alibaba/AliOS-Things/issues), Our engineers will answer in time
```
import upip
upip.install("haas-python-magnetron_sensor")
import haas-python-magnetron_sensor
```
# MagnetronSensor 磁控管开关

## 一、产品简介
&emsp;&emsp;
干簧管是干式舌簧管的简称，是一种有触点的无源电子开关元件，具有结构简单，体积小便于控制等优点，其外壳一般是一根密封的玻璃管，管中装有两个铁质的弹性簧片电板，还灌有一种叫金属铑的惰性气体，平时，玻璃管中的两个簧片是分开的。当有磁性物质靠近玻璃管时，在磁场的作用下，管内的两个簧片被磁化而互相吸引接触，簧片就会吸合在一起使结点所接的电路连通。外磁力消失后，两个簧片由于本身的弹性而分开，线路也就断开了。因此，作为一种利用磁场信号来控制的线路开关器件，干簧管可以作为传感器用，用于计数，限位等等（在安防系统中主要用于门磁、窗磁的制作），同时还被广泛使用于各种通信设备中。在实际运用中，通常用磁铁控制这两根金属片的接通与否，所以又被称为“磁控管”。

&emsp;&emsp;
磁控管开关在程控交换机、复印机、洗衣机、电冰箱、照相机、消毒碗柜、门磁、窗磁、电磁继电器、电子衡器、液位计、煤气表、水表中等等都得到了很好的应用。

<div align="center">
<img src=./../../docs/images/磁控管.jpeg width=60%/>
</div>


引脚定义

* VCC：电源正 3.3V~5V
* GND：电源地
* DO：数字信号输出

## 二、技术参数
* 干簧管需要和磁铁配合使用，在感应到有一定的磁力的时候，会呈导通状态，模块输出低电平，无磁力时，呈断开状态，输出高电平，干簧管与磁铁的感应距离在1.5cm之内，超出不灵敏或会无触发现象；
* 模块DO输出端可以单片机IO口直接相连，通过单片机可以检测干簧管的触发状态；
* 模块DO输出端可与继电器IN端相连，组成大功率干簧管开关，直接控制高电压。

## 三、软件接口

干簧管HaaS Python驱动：[下载地址](https://github.com/alibaba/AliOS-Things/tree/master/haas_lib_bundles/python/libraries/magnetron_sensor)
<br>

### MagnetronSensor - 创建磁控管开关对象

* 函数原型

> sensorObj = MagnetronSensor(gpioObj)

* 参数说明

该方法初始化一个 MagnetronSensor 对象，用于磁控管开关数据读取。

|  参数   | 类型  | 必选参数？ | 说明                                             |
| :-----: | :---: | :--------: | :----------------------------------------------- |
| gpioObj | GPIO  |     是     | DO引脚的GPIO对象。调用此函数前需确保对象已被open |

* 返回值

若MagnetronSensor对象创建成功，返回ibrationSensor对象；否则抛出Exception

* 示例代码
```python
from MagnetronSensor import MagnetronSensor
from driver import GPIO

doPin = GPIO()
doPin.open("MagnetronSensor")

sensor = MagnetronSensor(doPin)
```

### isMagnetic() - 获取磁控管开关状态
<br>

* 函数功能：

获取磁控管开关状态。

* 函数原型：

> MagnetronSensor.isMagnetic()

* 参数说明：

无

* 返回值：

若检测到磁性，则返回1；否则返回0.

* 示例代码
```python
from MagnetronSensor import MagnetronSensor
from driver import GPIO

doPin = GPIO()
doPin.open("MagnetronSensor")

sensor = MagnetronSensor(doPin)
print(sensor.isMagnetic())
```

## 四、接口案例

* board.json
```json
{
    "name": "board-name",
    "version": "1.0.0",
    "io": {
        "MagnetronSensor": {
            "type": "GPIO",
            "port": 28,
            "dir": "input",
        },
    }
}
```

* Python代码
```python
from MagnetronSensor import MagnetronSensor
from driver import GPIO

doPin = GPIO()
doPin.open("MagnetronSensor")

sensor = MagnetronSensor(doPin)

while True:
    utime.sleep(1)
    print(sensor.isMagnetic())
```

## 参考文献及购买链接
[1] [购买链接](https://detail.tmall.com/item.htm?id=41236271649)
