Simple test

Ensure your device works with this simple test.

examples/emc2101_simpletest.py
 1# SPDX-FileCopyrightText: 2020 Bryan Siepert, written for Adafruit Industries
 2#
 3# SPDX-License-Identifier: MIT
 4import time
 5import board
 6from adafruit_emc2101 import EMC2101
 7
 8i2c = board.I2C()  # uses board.SCL and board.SDA
 9emc = EMC2101(i2c)
10while True:
11    print("Setting fan speed to 25%")
12    emc.manual_fan_speed = 25
13    time.sleep(2)  # longer sleep to let it spin down from 100%
14    print("Fan speed", emc.fan_speed)
15    time.sleep(1)
16
17    print("Setting fan speed to 50%")
18    emc.manual_fan_speed = 50
19    time.sleep(1.5)
20    print("Fan speed", emc.fan_speed)
21    time.sleep(1)
22
23    print("Setting fan speed to 75%")
24    emc.manual_fan_speed = 75
25    time.sleep(1.5)
26    print("Fan speed", emc.fan_speed)
27    time.sleep(1)
28
29    print("Setting fan speed to 100%")
30    emc.manual_fan_speed = 100
31    time.sleep(1.5)
32    print("Fan speed", emc.fan_speed)
33    time.sleep(1)
34
35    print("External temperature:", emc.external_temperature, "C")
36    print("Internal temperature:", emc.internal_temperature, "C")
37
38    print("")
39    time.sleep(0.5)

LUT Usage Example

Use the temperature to fan speed Look Up Table to automatically control the fan speed. This example requires more memory than the first one because it needs to use the extended adafruit_emc2101.emc2101_lut.EMC2101_LUT driver to access LUT functionality.

examples/emc2101_lut_example.py
 1# SPDX-FileCopyrightText: 2020 Bryan Siepert, written for Adafruit Industries
 2#
 3# SPDX-License-Identifier: MIT
 4import time
 5import board
 6from adafruit_emc2101.emc2101_lut import EMC2101_LUT as EMC2101
 7
 8i2c = board.I2C()  # uses board.SCL and board.SDA
 9
10FAN_MAX_RPM = 1700
11emc = EMC2101(i2c)
12emc.manual_fan_speed = 50
13time.sleep(1)
14emc.lut[27] = 25
15emc.lut[34] = 50
16emc.lut[42] = 75
17emc.lut_enabled = True
18emc.forced_temp_enabled = True
19print("Lut:", emc.lut)
20emc.forced_ext_temp = 28  # over 25, should be 25%
21time.sleep(3)
22print("25%% duty cycle is %f RPM:" % emc.fan_speed)
23
24
25emc.forced_ext_temp = 35  # over 30, should be 50%
26time.sleep(3)
27print("50%% duty cycle is %f RPM:" % emc.fan_speed)
28
29emc.forced_ext_temp = 43  # over 42, should be 75%
30time.sleep(3)
31print("75%% duty cycle is %f RPM:" % emc.fan_speed)

PWM Tuning

Adjust the EMC2101s PWM settings to fit your application. This example requires more memory than the first one because it needs to use the extended adafruit_emc2101.emc2101_lut.EMC2101_LUT driver to access LUT functionality.

examples/emc2101_set_pwm_freq.py
 1# SPDX-FileCopyrightText: 2020 Bryan Siepert, written for Adafruit Industries
 2#
 3# SPDX-License-Identifier: MIT
 4import time
 5import board
 6from adafruit_emc2101.emc2101_lut import EMC2101_LUT as EMC2101
 7
 8i2c = board.I2C()  # uses board.SCL and board.SDA
 9
10emc = EMC2101(i2c)
11emc.set_pwm_clock(use_preset=False)
12# Datasheet recommends using the maximum value of 31 (0x1F)
13# to provide the highest effective resolution.
14# The PWM frequency must be set before changing `manual_fan_speed` or LUT entries.
15# Otherwise the PWM duty cycle won't be configured correctly.
16emc.pwm_frequency = 14
17
18# This divides the pwm frequency down to a smaller number
19# so larger divisor = lower frequency
20emc.pwm_frequency_divisor = 127
21
22while True:
23    print("External temperature:", emc.external_temperature, "C")
24    emc.manual_fan_speed = 50
25    time.sleep(1.5)
26    print("Fan speed:", emc.fan_speed, "RPM")
27    time.sleep(1)