-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
memory_optimization #52
Conversation
@tannewt please review and comments, and then I wil proceed to all the code cleanup and examples, and references check. Thanks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of having copies of code in advanced.py please have is subclass the basic version to add additional features. Thanks!
adafruit_bme280/basic.py
Outdated
"""iir_filter values""" | ||
IIR_FILTER_DISABLE = const(0) | ||
|
||
"""overscan values for temperature, pressure, and humidity""" | ||
OVERSCAN_DISABLE = const(0x00) | ||
OVERSCAN_X1 = const(0x01) | ||
OVERSCAN_X2 = const(0x02) | ||
OVERSCAN_X4 = const(0x03) | ||
OVERSCAN_X8 = const(0x04) | ||
OVERSCAN_X16 = const(0x05) | ||
|
||
_BME280_OVERSCANS = { | ||
OVERSCAN_DISABLE: 0, | ||
OVERSCAN_X1: 1, | ||
OVERSCAN_X2: 2, | ||
OVERSCAN_X4: 4, | ||
OVERSCAN_X8: 8, | ||
OVERSCAN_X16: 16, | ||
} | ||
|
||
"""mode values""" | ||
MODE_SLEEP = const(0x00) | ||
MODE_FORCE = const(0x01) | ||
MODE_NORMAL = const(0x03) | ||
|
||
_BME280_MODES = (MODE_SLEEP, MODE_FORCE, MODE_NORMAL) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd probably move these to advanced. In the internal init just use the value. These cost memory for each variable name.
will do |
TEST 7 Removing all the variable in the basic file and only working with values as per suggestion>>> import bme280_simpletest
Loading only gc 18800
After importing BME280 module 12784
After importing time module 12768
After importing board module 12768
After gc collect 12784
After initiating i2c module 12768
After defining bm280 sensor 8544
After defining sea level pressure 8544
Temperature: 26.3 C
Humidity: 43.2 %
Pressure: 1002.5 hPa
Altitude = 89.93 meters
After print instructions 9728 Improvement From 9.5k to 6k |
I decided for maintenability purposes to keep the Variables definitions, that way we could use the functions in both basic and advanced. |
before doing test in some boards please review :) Thanks. |
I tested this on for the
and with the
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I ran both the simpletest and normal_mode on a feather_m0_rfm9x -- I created .mpys of the advanced.py and basic.py.
Both tests ran normally.
All run with 7.0 alpha.2
Ran the test code from the top of this PR (using basic)
I'm not really below sea-level ;-) |
Also ran the demo using RFM9x radio and BME280 together-- see #37 |
@jerryneedell interesting I will take a look at the altitude. Thanks for testing. |
I'm not worried about it -- I ddi not set the offset. |
Co-authored-by: Scott Shawcroft <[email protected]>
This was tested on RP 4 using Pyton 3.7.3 and blinka Also this was tested on Raspberry Pi Pico with RP2040 Using Blinka and the MicroPython v1.15 on 2021-04-18; Raspberry Pi Pico with RP2040
Type "help()" for more information.
>>> %Run -c $EDITOR_CONTENT
Temperature: 25.8 C
Humidity: 44.6 %
Pressure: 1017.1 hPa
Altitude = -32.61 meters |
@tannewt I think we are ready, I will need to modify the learning guide for the library and the Micropython with Blinka learning guide also, as it includes this sensor. If you are ok with the changes I will marge when I do the learning guide changes. Thanks as always |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! This looks great!
Updating https://github.com/adafruit/Adafruit_CircuitPython_BME280 to 2.6.5 from 2.6.4: > Moved default branch to main > Merge pull request adafruit/Adafruit_CircuitPython_BME280#52 from jposada202020/memory_otimization > Moved CI to Python 3.7 Updating https://github.com/adafruit/Adafruit_CircuitPython_HTU31D to 1.1.1 from 1.1.0: > Merge pull request adafruit/Adafruit_CircuitPython_HTU31D#6 from gmparis/main > Moved CI to Python 3.7 > Added help text and problem matcher > Added pull request template Updating https://github.com/adafruit/Adafruit_CircuitPython_ICM20X to 2.0.8 from 2.0.7: > Linted > Moved default branch to main > Moved CI to Python 3.7 > Added help text and problem matcher > Added pull request template Updating https://github.com/adafruit/Adafruit_CircuitPython_IRRemote to 4.1.0 from 4.0.6: > Moved default branch to main > Merge pull request adafruit/Adafruit_CircuitPython_IRRemote#42 from danielballan/nonblocking > Moved CI to Python 3.7 > Added help text and problem matcher > Added pull request template Updating https://github.com/adafruit/Adafruit_CircuitPython_L3GD20 to 2.3.6 from 2.3.5: > Merge pull request adafruit/Adafruit_CircuitPython_L3GD20#23 from jposada202020/correcting_measuremnt_units > Moved default branch to main > Moved CI to Python 3.7 > Added help text and problem matcher > Added pull request template Updating https://github.com/adafruit/Adafruit_CircuitPython_SGP40 to 1.1.0 from 1.0.3: > Merge pull request adafruit/Adafruit_CircuitPython_SGP40#4 from CrakeNotSnowman/voc_algorithm_dev > Moved CI to Python 3.7 > Added help text and problem matcher > Added pull request template Updating https://github.com/adafruit/Adafruit_CircuitPython_SHTC3 to 1.1.2 from 1.1.1: > Moved default branch to main > Merge pull request adafruit/Adafruit_CircuitPython_SHTC3#11 from jposada202020/master > Moved CI to Python 3.7 > Added help text and problem matcher > Added pull request template Updating https://github.com/adafruit/Adafruit_CircuitPython_SI4713 to 1.3.2 from 1.3.1: > Moved default branch to main > Merge pull request adafruit/Adafruit_CircuitPython_SI4713#20 from jposada202020/solving_station_information Updating https://github.com/adafruit/Adafruit_CircuitPython_SSD1306 to 2.11.6 from 2.11.5: > Corrected url > Merge pull request adafruit/Adafruit_CircuitPython_SSD1306#64 from jposada202020/correcting_example_link Updating https://github.com/adafruit/Adafruit_CircuitPython_Colorsys to 2.0.1 from 2.0.0: > Moved default branch to main > Merge pull request adafruit/Adafruit_CircuitPython_Colorsys#17 from GomiHgy/patch-1 > Moved CI to Python 3.7 > Added help text and problem matcher > Added pull request template Updating https://github.com/adafruit/Adafruit_CircuitPython_FunHouse to 2.1.4 from 2.1.3: > Merge pull request adafruit/Adafruit_CircuitPython_FunHouse#17 from jposada202020/adding_new_guides
Initial test
Register and Bus_device mpy
test code
Test Code
Results
Test 2 Doing a gc before loading the bme280 module
Test 3 trying to load the module from the REPL
Test 4 New module without the I2C and SPI classes
Test 5. Lean Basic file and using mpy file
Test 6 using basic.mpy and Using GC after each print statement