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
 9# i2c = board.STEMMA_I2C()  # For using the built-in STEMMA QT connector on a microcontroller
10emc = EMC2101(i2c)
11while True:
12    print("Setting fan speed to 25%")
13    emc.manual_fan_speed = 25
14    time.sleep(2)  # longer sleep to let it spin down from 100%
15    print("Fan speed", emc.fan_speed)
16    time.sleep(1)
17
18    print("Setting fan speed to 50%")
19    emc.manual_fan_speed = 50
20    time.sleep(1.5)
21    print("Fan speed", emc.fan_speed)
22    time.sleep(1)
23
24    print("Setting fan speed to 75%")
25    emc.manual_fan_speed = 75
26    time.sleep(1.5)
27    print("Fan speed", emc.fan_speed)
28    time.sleep(1)
29
30    print("Setting fan speed to 100%")
31    emc.manual_fan_speed = 100
32    time.sleep(1.5)
33    print("Fan speed", emc.fan_speed)
34    time.sleep(1)
35
36    print("External temperature:", emc.external_temperature, "C")
37    print("Internal temperature:", emc.internal_temperature, "C")
38
39    print("")
40    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# i2c = board.STEMMA_I2C()  # For using the built-in STEMMA QT connector on a microcontroller
10
11FAN_MAX_RPM = 1700
12emc = EMC2101(i2c)
13emc.manual_fan_speed = 50
14time.sleep(1)
15emc.lut[27] = 25
16emc.lut[34] = 50
17emc.lut[42] = 75
18emc.lut_enabled = True
19emc.forced_temp_enabled = True
20print("Lut:", emc.lut)
21emc.forced_ext_temp = 28  # over 25, should be 25%
22time.sleep(3)
23print("25%% duty cycle is %f RPM:" % emc.fan_speed)
24
25
26emc.forced_ext_temp = 35  # over 30, should be 50%
27time.sleep(3)
28print("50%% duty cycle is %f RPM:" % emc.fan_speed)
29
30emc.forced_ext_temp = 43  # over 42, should be 75%
31time.sleep(3)
32print("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# i2c = board.STEMMA_I2C()  # For using the built-in STEMMA QT connector on a microcontroller
10
11emc = EMC2101(i2c)
12emc.set_pwm_clock(use_preset=False)
13# Datasheet recommends using the maximum value of 31 (0x1F)
14# to provide the highest effective resolution.
15# The PWM frequency must be set before changing `manual_fan_speed` or LUT entries.
16# Otherwise the PWM duty cycle won't be configured correctly.
17emc.pwm_frequency = 14
18
19# This divides the pwm frequency down to a smaller number
20# so larger divisor = lower frequency
21emc.pwm_frequency_divisor = 127
22
23while True:
24    print("External temperature:", emc.external_temperature, "C")
25    emc.manual_fan_speed = 50
26    time.sleep(1.5)
27    print("Fan speed:", emc.fan_speed, "RPM")
28    time.sleep(1)