Fan v1.1 Module
This is the driver library of Fan Module, which is used to control the fan.
Support the following products:
UiFlow2 Example
control module fan v1.1
Open the fan_cores3_example.m5f2 project in UiFlow2.
Initializes the fan module, sets the fan status, PWM frequency and duty cycle, and displays the fan status, speed, PWM frequency and duty cycle on the screen in real time. When the user touches the screen, the fan status toggles on/off.
UiFlow2 Code Block:
Example output:
None
MicroPython Example
control module fan v1.1
Initializes the fan module, sets the fan status, PWM frequency and duty cycle, and displays the fan status, speed, PWM frequency and duty cycle on the screen in real time. When the user touches the screen, the fan status toggles on/off.
MicroPython Code Block:
1# SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD 2# 3# SPDX-License-Identifier: MIT 4 5import os, sys, io 6import M5 7from M5 import * 8from module import FanModule 9import time 10 11 12title0 = None 13label0 = None 14label1 = None 15label2 = None 16label3 = None 17fan_v11_0 = None 18 19 20def setup(): 21 global title0, label0, label1, label2, label3, fan_v11_0 22 23 M5.begin() 24 Widgets.fillScreen(0x222222) 25 title0 = Widgets.Title( 26 "FanModuleV1.1 CoreS3 Example", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18 27 ) 28 label0 = Widgets.Label("label0", 0, 57, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) 29 label1 = Widgets.Label("label1", 0, 94, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) 30 label2 = Widgets.Label("label2", 0, 133, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) 31 label3 = Widgets.Label("label3", 0, 168, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) 32 33 fan_v11_0 = FanModule(address=0x18) 34 fan_v11_0.set_fan_state(True) 35 fan_v11_0.set_pwm_frequency(0) 36 fan_v11_0.set_pwm_duty_cycle(80) 37 38 39def loop(): 40 global title0, label0, label1, label2, label3, fan_v11_0 41 M5.update() 42 label0.setText(str((str("Fan State:") + str((fan_v11_0.get_fan_state()))))) 43 label1.setText(str((str("Fan PWM Freq:") + str((fan_v11_0.get_single_frequency()))))) 44 label2.setText(str((str("Fan PWM duty cycle:") + str((fan_v11_0.get_pwm_duty_cycle()))))) 45 label3.setText(str((str("Fan rpm:") + str((fan_v11_0.get_fan_rpm()))))) 46 if M5.Touch.getCount(): 47 fan_v11_0.set_fan_state(not (fan_v11_0.get_fan_state())) 48 time.sleep_ms(50) 49 50 51if __name__ == "__main__": 52 try: 53 setup() 54 while True: 55 loop() 56 except (Exception, KeyboardInterrupt) as e: 57 try: 58 from utility import print_error_msg 59 60 print_error_msg(e) 61 except ImportError: 62 print("please update to latest firmware")
Example output:
None
API
FanModule
- class module.fan.FanModule(address=24)
Bases:
object
- set_fan_state(state)
Set the fan state to on or off.
- Parameters:
state (bool) – The state of the fan.
UiFlow2 Code Block:
MicroPython Code Block:
fan_v11_0.set_fan_state(True)
- get_fan_state()
Get current fan state.
- Returns:
The current fan state.
- Return type:
UiFlow2 Code Block:
MicroPython Code Block:
fan_v11_0.get_fan_state()
- set_pwm_frequency(freq=2)
Set the PWM frequency of the fan.
- Parameters:
freq (int) – The PWM frequency of the fan.
- Return type:
None
UiFlow2 Code Block:
MicroPython Code Block:
fan_v11_0.set_pwm_frequency(2)
- get_pwm_frequency()
Get current PWM frequency.
- Returns:
The current PWM frequency.
- Return type:
UiFlow2 Code Block:
MicroPython Code Block:
fan_v11_0.get_pwm_frequency()
- set_pwm_duty_cycle(duty_cycle)
Set the PWM duty cycle of the fan.
- Parameters:
duty_cycle (int) – The PWM duty cycle of the fan.
- Return type:
None
UiFlow2 Code Block:
MicroPython Code Block:
fan_v11_0.set_pwm_duty_cycle(50)
- get_pwm_duty_cycle()
Get current PWM duty cycle.
- Returns:
The current PWM duty cycle.
- Return type:
UiFlow2 Code Block:
MicroPython Code Block:
fan_v11_0.get_pwm_duty_cycle()
- get_fan_rpm()
Get current fan RPM.
- Returns:
The current fan RPM.
- Return type:
UiFlow2 Code Block:
MicroPython Code Block:
fan_v11_0.get_fan_rpm()
- get_single_frequency()
Get current single frequency.
- Returns:
The current single frequency.
- Return type:
UiFlow2 Code Block:
MicroPython Code Block:
fan_v11_0.get_single_frequency()
- write_flash()
Save the current configuration(fan status, PWM frequency, and PWM duty cycle) to the flash.
UiFlow2 Code Block:
MicroPython Code Block:
fan_v11_0.write_flash()
- Return type:
None
- get_firmware_version()
Get current firmware version.
- Returns:
The current firmware version.
- Return type:
UiFlow2 Code Block:
MicroPython Code Block:
fan_v11_0.get_firmware_version()
- get_i2c_address()
Get current I2C address.
- Returns:
The current I2C address.
- Return type:
UiFlow2 Code Block:
MicroPython Code Block:
fan_v11_0.get_i2c_address()