用Python3模块控制雷电探测器AS3935芯片

as3935的Python项目详细描述


欢迎来到python_as3935!在

这个Python模块让您控制AS3935闪电探测器。这个 使用的电路板是来自 EmbeddedAdventures。在

  1. 它使用Pigpio,而不是 公共的RPi.GPIO,在 为了能够使用它而不是根。在
  2. 与设备的通信通过I2C串行协议完成。在
  3. 它允许您执行 datasheet。在

要从Pypi安装它:

$ pip install as3935

1。设备的连接

如果使用40-pin GPIO 树莓皮,设备应按如下方式连接:

Pin on AS3935Pin name on RPiPin number (BCM)
Vcc3.3VAny
IRQAny available GPIOe.g. 4
SCLClock3
SDAData2
GNDGroundAny

2。必要条件

2.1猪瘟

从源或通过以下方式安装Pigpio守护程序:

^{pr2}$

使用(如果在Raspbian上)配置Remote GPIO

$ sudo raspi-config

启用守护程序并立即启动:

$ sudo systemctl enable pigpiod
$ sudo systemctl start pigpiod

安装Python interface

$ pip install pigpio

更多信息,请访问 Pigpio’s网页。在

2.2 Python

这个模块已经在python3.7上进行了测试。可能对其他人有用 版本也是。使用的唯一库是Pigpio的一个部分,time

3。使用

它使用起来非常简单。只需导入它并用 你需要的配置。在

import as3935
import pigpio

irq_pin_number = 4    # BCM number (code after GPIO)
bus = 1               # On newer Raspberrys is 1
address = 0x03        # If using MOD-1016 this is the address

sensor = as3935.AS3935(irq_pin_number, bus, address)

# We need to calibrate the sensor first. Use the tuning cap provided
# or calculate it using sensor.calculate_tuning_cap(*args)
sensor.full_calibration(12)

sensor.set_indoors(True)

# Every time you sense a pulse on IRQ it means there is an
# interruption request. You can read it like this:
def irq_callback(gpio, level, tick):
    interruption = sensor.get_interrupt()
    if interruption == as3935.INT_NH:
        print("Noise floor too high")
    elif interruption == as3935.INT_D:
        print("Disturbance detected. Mask it?")
    elif interruption == as3935.INT_L:
        print("Lightning detected!")
        distance = sensor.get_distance()

try:
    cb = sensor.pi.callback(irq_pin_number, pigpio.RISING_EDGE, irq_callback)
    while True:
        pass
finally:
    cb.cancel()
    sensor.pi.stop()

上面这是一个非常简单的例子。查看完整的文档 学习所有你可以调用的方法。在

4。学分

由Eloi Codina于2019年12月创建。还有其他的Python 允许您使用AS3935传感器的模块。但是,他们都没有 使用Pigpio它是根据GNU通用公共许可v3.0授权的 (请阅读许可证.txt)在

python_AS3935
Copyright (C) 2019  Eloi Codina Torras

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <https://www.gnu.org/licenses/>.

5。完整的文档

5.1常数(中断)

  • INT_NH:噪声级太高
  • INT\u D:检测到人为干扰
  • INT\u L:检测到闪电

5.2 AS3935级

它提供了一个对象来控制AS3935。在

  • irq:(int)irq连接的GPIO引脚号(BCM编号)
  • bus:(int,可选)AS3935连接的总线。违约 =1
  • address:(int,可选)AS3935的地址。违约= 0x03号

您可以从此对象访问以下属性:

  • address:AS3935的地址
  • bus:AS3935的总线
  • irq:irq连接的GPIO管脚号
  • pi:猪皮尤.pi实例。你可以与GPIO通信 这个。在
  • i2c_设备:表示与 AS3935

5.2.1方法
5.2.1.1交叉法
read_byte(self, address)

     Returns the value of the byte stored at address.

      :param address: (int) the address to read from
      :return: (int) the value of the address
write_byte(self, address, value)

     Writes value at address. Raises ValueError if the value is not correct. It sleeps for 2 ms after writing the value

      :param address: (int) the address to write to  :param value: (int) the byte value (between 0x00 and 0xFF)
full_calibration(self, tuning_cap):

     Performs a full calibration: antenna and RCO

      :param tuning_cap: int: tuning number for the antenna. Can be calculated with self.calculate_tuning_cap()
5.2.1.3操作模式
power_down_mode(self):

   Sets the AS3935 on power down mode (PWD)
listening_mode(self)

     Sets the AS3935 on listening mode (PWD)
5.2.1.3直接命令
set_default_values(self)

     Sends a direct command to 0x3C to reset to default values.
calibrate_rco(self)

     Sends a direct command to 0x3D to calibrate the RCO (CALIB_RCO)
5.2.1.4 AFE和看门狗
get_indoors(self)

     Checks whether the device is configured to be run indoors. (AFE_GB)

      :return: (bool) whether the device is configured to be run indoors
set_indoors(self, indoors)

     Configures the device to be run indoors or outdoors. (AFE_GB)

      :param indoors: (bool) configure the AS3935 to be run indoors
get_watchdog_threshold(self)

     Returns the watchdog threshold (WDTH)

      :return: (int) the current watchdog threshold
set_watchdog_threshold(self, value=0b0001):

     Sets the watchdog threshold to value (WDTH). If called without parameters, it sets it to the default configuration. Can raise a ValueError if not 0 <= value <= 0b1111

      :param value: (int, optional) The value to be set. From 0b0000 to 0b1111. Default=0b0001
5.2.1.5地板噪声发生器
get_noise_floor(self)

     Checks the current noise floor threshold (NF_LEV).

      :return: (int) the current noise floor threshold
set_noise_floor(self, noise_floor=0b010)

     Sets a new noise floor threshold (NF_LEV). If called without parameters, it sets it to the default configuration. Can raise a ValueError if not 0 <= noise_floor <= 0b111

      :param noise_floor: (int, optional) The value to be set. From 0b000 to 0b111
^{pr21}$
raise_noise_floor(self, max_noise=0b111)

     Raises the noise floor threshold by one step (adds 1 to the current NF_LEV) if it is currently lower than max_noise Can raise a ValueError if not 0 <= max_noise <= 0b111

      :param max_noise: (int, optional) the maximum  NF_LEV the device should be set at. Default 0b111  :return: (int) the new noise floor threshold

5.2.1.6信号验证

get_spike_rejection(self)

     Checks the current spike rejection settings (SREJ)

      :return: (int) the current spike rejection setting (SREJ)
set_spike_rejection(self, value=0b0010)

     Sets a new setting for the spike rejection algorithm (SREJ). If the function is called without any parameter, it sets it to the default value of 0b0010 Can raise a ValueError if not 0 <= value <= 0b1111

     :param value: (int, optional) the value to set SREJ. Default = 0b0010
5.2.1.7能量计算
get_energy(self)

     Checks the last lightning strike's energy calculation. It does not have any physical meaning. (Energy of the Single Lightning *SBYTE)

      :return: (int) last strike's energy

5.2.1.8距离估计

def get_distance(self)

     Checks the estimation of the last lightning strike's distance in km (DISTANCE).

      :return: (int/None) last strike's distance in km. None if out of range, 0 if overhead
get_interrupt(self)

     Checks the reason of the interruption (INT). To know what it is, use the constants: INT_NH: noise level too high INT_D: disturber detected INT_L: lightning strike detected

     It sleeps for 2 ms before retrieving the value, as specified at the datasheet.

      :return: (int) the interruption reason
set_mask_disturber(self, mask_dist)

     Sets whether disturbers should be masked (MASK_DIST).

      :param mask_dist: (bool) whether disturbers should be masked
get_mask_disturber(self)

     Checks whether disturbers are currently masked (MASK_DIST).

      :return: (bool) whether disturbers are currently masked
get_min_strikes(self)

     Checks the current configuration of how many strikes AS3935 has to detect in 15 minutes to issue an interrupt (MIN_NUM_LIG). In case of an error, it raises a LookupError

      :return: (int) number of strikes. Possible values: 1, 5, 9, 16
^{pr31}$
clear_lightning_stats(self)

     Clears the statistics built up by the lightning distance estimation algorithm (CL_STAT)

#####5.2.1.10天线调谐

get_display_lco(self)

     Checks whether the antenna resonance frequency is currently displayed on the IRQ pin (DISP_LCO)

      :return: (bool) whether the antenna resonance frequency is currently displayed
set_display_lco(self, display_lco)

     Sets whether the antenna resonance frequency should be displayed on the IRQ pin(DISP_LCO).

      :param display_lco: (bool) whether the antenna resonance frequency should be displayed
^{pr35}$
calculate_tuning_cap(self, frequency_divisor=16, tries_frequency=3, seconds_try=4)

     Measures the frequency of the LC resonator for every possible tuning_cap and returns the best value. If possible, use the default values for frequency_divisor, tries_frequency and seconds_try. This function takes a long time. It should take about tries_frequency*seconds_try*16 seconds given that there are 16 tuning possibilities.
     The ideal frequency is of 500 kHz
     Can raise ValueError if frequency_divisor is not a valid number.

      :param frequency_divisor: (int) the divisor the AS3935 uses to divide the frequency before displaying it on the IRQ
      :param tries_frequency: (int) number of times the current frequency is calculated during *seconds_try* seconds to calculate an average
      :param seconds_try: (float) seconds during which pulses on IRQ will be counted to calculate the internal frequency
      :return: (int) a tuning number between 0 and 15
calculate_resonance_frequency(self, seconds)

     Sets the AS3935 to display the antenna resonance frequency on the IRQ during *seconds* and counts the number of pulses in this time to calculate the internal frequency. To get the real frequency multiply this value by the frequency divisor ratio.

      :param seconds: (int) number of seconds while it should count spikes  :return: (int) internal frequency
get_frequency_division_ratio(self)

     Gets the current frequency division ratio. Number by which the real antenna resonance frequency is divided to display on the IRQ pin (LCO_FDIV). Can raise a LookupError if there is an error checkig the configuration.

      :return: (int) frequency division ratio. Possible numbers: 16, 32, 64, 128
set_frequency_division_ratio(self, divisor=16)

     Sets a new frequency division ration by which the antenna resonance frequency is divided to display on the IRQ pin (LCO_FDIV).If called with no parameter, it defaults to 16. Can raise a ValueError if *divisor* is not an accepted number.

      :param divisor: (int, optional) frequency divisor ratio. Accepted values = (16, 32, 64, 128). Default = 16
5.2.1.11时钟生成
get_display_srco(self)

     Checks whether the SRCO frequency is being displayed on the IRQ pin.

      :return: (bool) whether the SRCO frequency is currently displayed
set_display_srco(self, display_srco)

     Sets whether the SRCO frequency should be displayed on the IRQ pin.

      :param display_srco: (bool) whether the SRCO frequency should be displayed
get_display_trco(self)

     Checks' whether the TRCO frequency is being displayed on the IRQ pin.

      :return: (bool) whether the TRCO frequency is currently displayed
set_display_trco(self, display_trco)

     Sets whether the TRCO frequency should be displayed on the IRQ pin.

      :param display_srco: (bool) whether the TRCO frequency should be displayed
calibrate_trco(self)

     Calibrates the TRCO by sending the direct command CALIB_RCO and toggling the DIS_TRCO bit (low-high-low)

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java为游戏添加声音。需要帮助   java在获取数据时忽略模型类中的forign键映射   java为什么Microsoft JDBC驱动程序忽略failoverPartner主机名   java可以下载mozswing文件   java等价于ObjectOutputStream,不仅保存其状态,还保存整个对象?   Java Android LiveData根据其他LiveData调用房间查询   java如何使用jackson jsonNode实现这一点并获得所需的输出   在web服务器上作为web应用程序运行java应用程序?   groovy中java类的元类属性   返回空指针的java图形对象   标头中包含用户名和密码的java SOAP客户端请求   具有堆栈实现和递归的Hanoi算法塔(Java)   java当我运行这两个类时,我的老鼠不会移动   使用图像进行java相似图像搜索   Java8并行流机制   使用单例对象作为枚举元素的java Scala枚举,是否有可能对它们进行迭代?   java Webview更改高度大小   不可序列化对象和函数的java Spark Scala编程   java my app在eclipse中运行良好,而不是在jar中