Simple test

Ensure your device works with this simple test.

examples/emc2101_simpletest.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# SPDX-FileCopyrightText: 2020 Bryan Siepert, written for Adafruit Industries
#
# SPDX-License-Identifier: MIT
import time
import board
from adafruit_emc2101 import EMC2101

i2c = board.I2C()  # uses board.SCL and board.SDA
emc = EMC2101(i2c)
while True:
    print("Setting fan speed to 25%")
    emc.manual_fan_speed = 25
    time.sleep(2)  # longer sleep to let it spin down from 100%
    print("Fan speed", emc.fan_speed)
    time.sleep(1)

    print("Setting fan speed to 50%")
    emc.manual_fan_speed = 50
    time.sleep(1.5)
    print("Fan speed", emc.fan_speed)
    time.sleep(1)

    print("Setting fan speed to 75%")
    emc.manual_fan_speed = 75
    time.sleep(1.5)
    print("Fan speed", emc.fan_speed)
    time.sleep(1)

    print("Setting fan speed to 100%")
    emc.manual_fan_speed = 100
    time.sleep(1.5)
    print("Fan speed", emc.fan_speed)
    time.sleep(1)

    print("External temperature:", emc.external_temperature, "C")
    print("Internal temperature:", emc.internal_temperature, "C")

    print("")
    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
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# SPDX-FileCopyrightText: 2020 Bryan Siepert, written for Adafruit Industries
#
# SPDX-License-Identifier: MIT
import time
import board
from adafruit_emc2101.emc2101_lut import EMC2101_LUT as EMC2101

i2c = board.I2C()  # uses board.SCL and board.SDA

FAN_MAX_RPM = 1700
emc = EMC2101(i2c)
emc.manual_fan_speed = 50
time.sleep(1)
emc.lut[27] = 25
emc.lut[34] = 50
emc.lut[42] = 75
emc.lut_enabled = True
emc.forced_temp_enabled = True
print("Lut:", emc.lut)
emc.forced_ext_temp = 28  # over 25, should be 25%
time.sleep(3)
print("25%% duty cycle is %f RPM:" % emc.fan_speed)


emc.forced_ext_temp = 35  # over 30, should be 50%
time.sleep(3)
print("50%% duty cycle is %f RPM:" % emc.fan_speed)

emc.forced_ext_temp = 43  # over 42, should be 75%
time.sleep(3)
print("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
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# SPDX-FileCopyrightText: 2020 Bryan Siepert, written for Adafruit Industries
#
# SPDX-License-Identifier: MIT
import time
import board
from adafruit_emc2101.emc2101_lut import EMC2101_LUT as EMC2101

i2c = board.I2C()  # uses board.SCL and board.SDA

emc = EMC2101(i2c)
emc.set_pwm_clock(use_preset=False)
# Datasheet recommends using the maximum value of 31 (0x1F)
# to provide the highest effective resolution
emc.pwm_frequency = 14

# This divides the pwm frequency down to a smaller number
# so larger divisor = lower frequency
emc.pwm_frequency_divisor = 127

while True:
    print("External temperature:", emc.external_temperature, "C")
    emc.manual_fan_speed = 50
    time.sleep(1.5)
    print("Fan speed:", emc.fan_speed, "RPM")
    time.sleep(1)