Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: add noise sensor library and README #74

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions lib/sensor/click_boards/noise/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
noise click Library
===============

MicroPython library for I2C interface to Texas Instruments noise click noise
sensor.

Supported platforms
-------------------

* Digi XBee3 Zigbee 3 - minimum firmware version: 1006
* Digi XBee3 802.15.4 - minimum firmware version: 2003
* Digi XBee3 DigiMesh 2.4 - minimum firmware version: 3002
* Digi XBee3 Cellular LTE-M/NB-IoT - minimum firmware version: 11410
* Digi XBee3 Cellular LTE Cat 1 - minimum firmware version: x10
* Digi XBee Cellular 3G - minimum firmware version: 1130B
* Digi XBee Cellular LTE Cat 1 - minimum firmware version: 100B
54 changes: 54 additions & 0 deletions lib/sensor/click_boards/noise/noise.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from umachine import ADC, Pin
import time

# PINS
ADC_PIN_ID = "D2"
DIO_PIN_INT = "D4"

# CONSTANTS
THRESHOLD = 50

# 12 bits --> 4096 values
adc_pin = ADC(ADC_PIN_ID)
int_pin_in = Pin(DIO_PIN_INT, Pin.IN)
int_pin_out = Pin(DIO_PIN_INT, Pin.OUT)


class noiseClick:

def __init__(self, THRESHOLD):
self.THRESHOLD = THRESHOLD
int_pin_in.value(0)

def noise_command_value(self):
"""
Sets the **interruption value** to 1 if the noise level is above the threshold, otherwise is set to 0
"""
if self.noise_read() > self.THRESHOLD:
int_pin_in.value(1)

else:
int_pin_in.value(0)

def check_int_pin(self):
"""
Returns the value of the interruption pin

:return: returns the value of the interruption pin
"""
return int_pin_out.value()

def noise_read(self):
"""
Returns the value of the noise level

:return: returns the value of the noise level
"""
return adc_pin.read()

def set_threshold(self, value):
"""
Sets a new threshold
"""
self.THRESHOLD = value