It's easy to use the EMC2101 with Python or CircuitPython, and the Adafruit CircuitPython EMC2101 module. This module allows you to easily write Python code that reads temperature and fan speed from the EMC2101 sensor, as well as setting the fan speed.
You can use this sensor with any CircuitPython microcontroller board or with a computer that has GPIO and Python thanks to Adafruit_Blinka, our CircuitPython-for-Python compatibility library.
We will show how to wire up the EMC2101 to a microcontroller and fan, along with a NPN Bipolar Junction Transistor (BJT) as a makeshift temperature diode.
CircuitPython Microcontroller Wiring
First wire up a EMC2101 to your board exactly as shown below. Here's an example of wiring a Feather M4 to the sensor with I2C using standard 0.100" pitch headers to wire it up on a breadboard:
- Connect board VIN (red wire) to Feather 3V
- Connect board GND (black wire) to Feather GND
- Connect board SCL (yellow wire) to Feather SCL
- Connect board SDA (blue wire) to Feather SDA
- Connect board DP (orange wire) to Transistor Base
- Connect board DN (gray wire) to Transistor Emitter
- Connect transistor Collector (orange wire) to Transistor Base
- Connect board FAN (blue wire) to fan PWM input
- Connect board TACH (green wire) to fan Tach output
- Connect DC jack positive pin to Fan V+ input
- Connect DC jack GND to Fan V-/GND input
- Connect DC jack GND to Feather GND
Python Computer Wiring
Since there's dozens of Linux computers/boards you can use, we will show wiring for Raspberry Pi. For other platforms, please visit the guide for CircuitPython on Linux to see whether your platform is supported.
Here is an example of how to wire up a Raspberry Pi to the EMC2101 and fan, along with a NPN Bipolar Junction Transistor (BJT) as a makeshift temperature diode.
- Connect board VIN (red wire) to RPi 3V
- Connect board GND (black wire) to RPi GND
- Connect board SCL (yellow wire) to RPi SCL
- Connect board SDA (blue wire) to RPi SDA
- Connect board DP (orange wire) to Transistor Base
- Connect board DN (gray wire) to Transistor Emitter
- Connect transistor Collector (orange wire) to Transistor Base
- Connect board FAN (blue wire) to fan PWM input
- Connect board TACH (green wire) to fan Tach output
- Connect DC jack positive pin to Fan V+ input
- Connect DC jack GND to Fan V-/GND input
- Connect DC jack GND to RPi GND
CircuitPython Installation of EMC2101 Library
You'll need to install the Adafruit CircuitPython EMC2101 library on your CircuitPython board.
First make sure you are running the latest version of Adafruit CircuitPython for your board.
Next you'll need to install the necessary libraries to use the hardware--carefully follow the steps to find and install these libraries from Adafruit's CircuitPython library bundle. Our CircuitPython starter guide has a great page on how to install the library bundle.
Before continuing make sure your board's lib folder or root filesystem has the adafruit_EMC2101.mpy file as well as the adafruit_register and adafruit_bus_device folders.
Next connect to the board's serial REPL so you are at the CircuitPython
>>>
prompt.
Python Installation of EMC2101 Library
You'll need to install the Adafruit_Blinka library that provides the CircuitPython support in Python. This may also require enabling I2C on your platform and verifying you are running Python 3. Since each platform is a little different, and Linux changes often, please visit the CircuitPython on Linux guide to get your computer ready!
Once that's done, from your command line run the following command:
sudo pip3 install adafruit-circuitpython-emc2101
If your default Python is version 3 you may need to run 'pip' instead. Just make sure you aren't trying to use CircuitPython on Python 2.x, it isn't supported!
To demonstrate the usage of the sensor we'll initialize it to set and read the fan speed and read the external and internal temperatures from the board's Python REPL.
Run the following code to import the necessary modules and initialize the I2C connection with the sensor:
import board from adafruit_emc2101 import EMC2101 i2c = board.I2C() emc = EMC2101(i2c)
Now you're ready to read values from the sensor using these properties:
- internal_temperature - The temperature of the EMC2101 itself, a value in degrees Celsius.
- external_temperature - The temperature measured by the external sensor, a value in degrees Celsius.
print("External temperature:", emc.external_temperature, "C") print("Internal temperature:", emc.internal_temperature, "C")
And of course you can also use the corresponding properties to read and set the fan speed:
- manual_fan_speed - The speed of the fan when not controlled by the LUT
- fan_speed - The speed of the fan in Revolutions Per Minute (RPM)
emc.manual_fan_speed = 25 print("Fan speed:", emc.fan_speed, "RPM")
# 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 # i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller 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)
Text editor powered by tinymce.