adafruit / Adafruit_CircuitPython_EMC2101

CircuitPython driver for EMC2101 brushless fan controller
MIT License
3 stars 9 forks source link

Split file for low mem like samd21 #6

Closed rpavlik closed 3 years ago

rpavlik commented 3 years ago

I figured since this was the second time I poked at this, I should publish it in a better way. A .mpy file of the main library now lets you do basic fan monitoring, temp monitoring, and speed setting on a SAMD21 like the QT Py. The extra functionality (LUT, PWM frequency) was moved to a derived class in a separate file.

I haven't tested the full thing yet, just the small base class.

ladyada commented 3 years ago

@rpavlik i can dig it :) please tag/assign me once its passing CI!

rpavlik commented 3 years ago

Looks like it's passing CI. I'll try the "full version" out on my CP Bluefruit or Clue soon (hopefully tonight) since pushing untested code makes me nervous

ladyada commented 3 years ago

@caternuson do you by chance have one of these? if not i can test it later!

caternuson commented 3 years ago

@ladyada sry, i do not. (but will add to list to snag one eventually)

rpavlik commented 3 years ago

Surprised not everybody is on the adabox list :) (Edit: Oh, they probably don't have the emc2101, not the dev boards)

Interestingly, the current (old) version of the library doesn't work with the LUT example:

code.py output:
Traceback (most recent call last):
  File "code.py", line 16, in <module>
  File "adafruit_emc2101.py", line 142, in __setitem__
  File "adafruit_emc2101.py", line 193, in _set_lut
AttributeError: 'int' object has no attribute '__set__'

The PWM example seems to work in that it does not error, both before and after my change. I can't find my fan at the moment 🤦

rpavlik commented 3 years ago

OK, so I fixed that too, but in the process I found some inefficiencies in that class and managed to save 2640 bytes of ram on an nrf52840

rpavlik commented 3 years ago

OK, I can confirm that this now appears to work (at least that the i2c trace looks OK, my fan is MIA at the moment...), confirmed with and without LUT usage. Ready to review and merge.

I did rebase on top of #9 which should be merged first: that fixes the LUT stuff that was apparently broken when I got here.

caternuson commented 3 years ago

Looks good. Tested with QT PY.

Adafruit CircuitPython 6.1.0 on 2021-01-21; Adafruit QT Py M0 with samd21e18
>>> import board
>>> import adafruit_emc2101
>>> emc = adafruit_emc2101.EMC2101(board.I2C())
>>> emc.fan_speed
737.0
>>> emc.manual_fan_speed = 50
>>> emc.fan_speed
3527.11
>>> emc.fan_speed
2577.57
>>> 

Also made sure emc2101_simpletest.py worked (no external temperature sensor):

Adafruit CircuitPython 6.1.0 on 2021-01-21; Adafruit QT Py M0 with samd21e18
>>> import emc2101_simpletest
Setting fan speed to 25%
Fan speed 1205.63
Setting fan speed to 50%
Fan speed 2543.57
Setting fan speed to 75%
Fan speed 3536.35
Setting fan speed to 100%
Fan speed 3545.63
External temperature: 127.0 C
Internal temperature: 24 C