Skip to content
Merged
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
6 changes: 3 additions & 3 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
This library supports the complete API exposed by the Nicla Sense Env sensor board over I2C.

- 🌈 RGB LED control
- ⚪️ White LED control
- ⚪️ Orange LED control
- 💤 Board control (sleep, reset, factory reset)
- 🔧 Board configuration (e.g. changing the I2C address)
- 🏠 Indoor Air Quality Sensor control
Expand Down Expand Up @@ -46,7 +46,7 @@ if device.connected:
# ...
rgb_led = device.rgb_led
# ...
white_led = device.white_led
orange_led = device.orange_led
# ...
```
Once the desired object is obtained you can call functions and query properties on these objects such as `temperature_sensor.temperature`.
Expand All @@ -65,4 +65,4 @@ The following scripts are examples of how to use the Nicla Sense Env board with
- [rgb_led.py](../examples/rgb_led.py): Demonstrates how to control the board's RGB LED.
- [temperature_humidity.py](../examples/temperature_humidity.py): Demonstrates how to read the temperature and humidity data from the board's sensors.
- [uart_read.py](../examples/uart_read.py): Shows how to read data from the UART port on the board when not connecting to it over I2C.
- [white_led.py](../examples/white_led.py): Demonstrates how to control the board's white LED.
- [orange_led.py](../examples/orange_led.py): Demonstrates how to control the board's orange LED.
34 changes: 34 additions & 0 deletions examples/orange_led.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""
This example shows how to control the orange LED on the Nicla Sense Env board.
"""

from arduino_nicla_sense_env import NiclaSenseEnv, IndoorAirQualitySensorMode
from time import sleep_ms

def pulse_led(led):
"""
Pulses the LED.
"""
# Fade in
for i in range(0, 255):
led.brightness = i
sleep_ms(10)

# Fade out
for i in range(255, -1, -1):
led.brightness = i
sleep_ms(10)

device = NiclaSenseEnv()

if device.connected:
orange_led = device.orange_led

print(f"🔢 Orange LED error status enabled: {orange_led.error_status_enabled}")
print(f"💡 Orange LED brightness: {orange_led.brightness}")
pulse_led(orange_led)

# Enable sensor error indication on orange LED (LED should turn off if sensors are okay)
orange_led.error_status_enabled = True
else:
print("🤷 Device could not be found. Please double check the wiring.")
34 changes: 0 additions & 34 deletions examples/white_led.py

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
["arduino_nicla_sense_env/outdoor_air_quality_sensor.py", "github:arduino/arduino-nicla-sense-env-mpy/src/arduino_nicla_sense_env/outdoor_air_quality_sensor.py"],
["arduino_nicla_sense_env/rgb_led.py", "github:arduino/arduino-nicla-sense-env-mpy/src/arduino_nicla_sense_env/rgb_led.py"],
["arduino_nicla_sense_env/temperature_humidity_sensor.py", "github:arduino/arduino-nicla-sense-env-mpy/src/arduino_nicla_sense_env/temperature_humidity_sensor.py"],
["arduino_nicla_sense_env/white_led.py", "github:arduino/arduino-nicla-sense-env-mpy/src/arduino_nicla_sense_env/white_led.py"]
["arduino_nicla_sense_env/orange_led.py", "github:arduino/arduino-nicla-sense-env-mpy/src/arduino_nicla_sense_env/orange_led.py"]
],
"deps": [
],
Expand Down
2 changes: 1 addition & 1 deletion src/arduino_nicla_sense_env/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"status": {"address": 0x00, "type": "uint8", "bytes": 1}, # Board Status Register
"slave_address": {"address": 0x01, "type": "uint8", "bytes": 1}, # Board Slave Address Register (valid immediately after writing)
"control": {"address": 0x02, "type": "uint8", "bytes": 1}, # Board Control Register
"white_led": {"address": 0x03, "type": "uint8", "bytes": 1}, # White LED Control Register
"orange_led": {"address": 0x03, "type": "uint8", "bytes": 1}, # Orange LED Control Register
"rgb_led_red": {"address": 0x04, "type": "uint8", "bytes": 1}, # RGB LED Control Register RED (4x uint8)
"rgb_led_green": {"address": 0x05, "type": "uint8", "bytes": 1}, # GREEN
"rgb_led_blue": {"address": 0x06, "type": "uint8", "bytes": 1}, # BLUE
Expand Down
14 changes: 7 additions & 7 deletions src/arduino_nicla_sense_env/nicla_sense_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from .indoor_air_quality_sensor import IndoorAirQualitySensor
from .outdoor_air_quality_sensor import OutdoorAirQualitySensor
from .rgb_led import RGBLED
from .white_led import WhiteLED
from .orange_led import OrangeLED
from .i2c_device import I2CDevice
from .constants import REGISTERS

Expand All @@ -29,8 +29,8 @@ def store_settings_in_flash(self):
- Indoor air quality sensor mode
- Outdoor air quality sensor mode
- Temperature sensor enabled
- White LED brightness
- White LED error status enabled
- Orange LED brightness
- Orange LED error status enabled
- RGB LED brightness
- RGB LED color

Expand Down Expand Up @@ -138,14 +138,14 @@ def rgb_led(self):
return RGBLED(self.bus, self.device_address)

@property
def white_led(self):
def orange_led(self):
"""
Gets the white LED control interface.
Gets the orange LED control interface.

Returns:
WhiteLED: The white LED.
OrangeLED: The orange LED.
"""
return WhiteLED(self.bus, self.device_address)
return OrangeLED(self.bus, self.device_address)

def reset(self):
"""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,62 +1,62 @@
from .i2c_device import I2CDevice
from .constants import REGISTERS

class WhiteLED(I2CDevice):
class OrangeLED(I2CDevice):
"""
This class allows to control the white LED on the Nicla Sense Env board.
This class allows to control the orange LED on the Nicla Sense Env board.
"""

@property
def brightness(self) -> int:
"""
Gets the brightness of the white LED.
Gets the brightness of the orange LED.

Returns
----
int: The brightness of the white LED. Range is 0 to 63.
int: The brightness of the orange LED. Range is 0 to 63.
"""
# Read bits 0 - 5 from white_led register
data = self._read_from_register(REGISTERS["white_led"])
# Read bits 0 - 5 from orange_led register
data = self._read_from_register(REGISTERS["orange_led"])
return data & 63

@brightness.setter
def brightness(self, led_brightness = 63) -> None:
"""
Sets the brightness of the white LED.
Call store_settings_in_flash() on NiclaSenseEnv instance after changing the white LED brightness to make the change persistent.
Sets the brightness of the orange LED.
Call store_settings_in_flash() on NiclaSenseEnv instance after changing the orange LED brightness to make the change persistent.

Parameters
----
led_brightness (int):
The brightness of the white LED. Range is 0 to 63.
The brightness of the orange LED. Range is 0 to 63.
"""
if led_brightness < 0 or led_brightness > 63:
raise ValueError("Brightness must be between 0 and 63")
current_register_data = self._read_from_register(REGISTERS["white_led"])
current_register_data = self._read_from_register(REGISTERS["orange_led"])
# Overwrite bits 0 - 5 with the new value by clearing the bits and then setting them
self._write_to_register(REGISTERS["white_led"], (current_register_data & 0b11000000) | led_brightness)
self._write_to_register(REGISTERS["orange_led"], (current_register_data & 0b11000000) | led_brightness)

@property
def error_status_enabled(self) -> bool:
"""
Determines whether the white LED is used to indicate an error status of one of the sensors.
Determines whether the orange LED is used to indicate an error status of one of the sensors.
"""
# Read bit 7 from white_led register
data = self._read_from_register(REGISTERS["white_led"])
# Read bit 7 from orange_led register
data = self._read_from_register(REGISTERS["orange_led"])
return bool(data & (1 << 7))

@error_status_enabled.setter
def error_status_enabled(self, enabled: bool) -> None:
"""
Enables or disables the white LED to indicate an error status of one of the sensors.
Call store_settings_in_flash() on NiclaSenseEnv instance after enabling/disabling the white LED error status to make the change persistent.
Enables or disables the orange LED to indicate an error status of one of the sensors.
Call store_settings_in_flash() on NiclaSenseEnv instance after enabling/disabling the orange LED error status to make the change persistent.

Parameters
----
enabled (bool):
Whether to enable or disable the white LED error status.
Whether to enable or disable the orange LED error status.
"""
current_register_data = self._read_from_register(REGISTERS["white_led"])
current_register_data = self._read_from_register(REGISTERS["orange_led"])
# Set bit 7 to 1 if enabled or 0 if disabled while keeping the other bits unchanged
# by clearing bit 7 and then setting it to the desired value
self._write_to_register(REGISTERS["white_led"], current_register_data & 0b01111111 | (int(enabled) << 7))
self._write_to_register(REGISTERS["orange_led"], current_register_data & 0b01111111 | (int(enabled) << 7))