-
Notifications
You must be signed in to change notification settings - Fork 5
memory_reduction #15
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_reduction #15
Conversation
Please feel free to suggest name changes, and comments @tannewt Notes:I have it working alone for the Qt-Py with a Adafruit CircuitPython 6.1.0 on 2021-01-21; Adafruit QT Py M0 with samd21e18
>>> import dps310_simpletest
Temperature = 25.01 *C
Pressure = 1020.45 hPa However when I added the code for the Full Featured class in the same file, I got a memory error. So I decided to separate the files and include the light class in the So two things here:
ConclusionThe present change will have memory allocation error, if loaded with th py file, however it tested ok with the mpy files. Adafruit CircuitPython 6.1.0 on 2021-01-21; Adafruit QT Py M0 with samd21e18
>>> import dps310_simpletest
Temperature = 31.04 *C
Pressure = 1021.47 hPa
|
If you get a memory error on import then use an mpy. It'll strip the white space and comments. Comments take space when parsing I believe. I think the resulting imported size is still the same. To measure the memory footprint after import use
It'll only parse the file that matches the import statement. That file may also import which would cause more files to be parsed. |
Just to be clear, in our options here. Fail means= Memory Error - allocation Error
So according to this, we have two options. Two differents files, one for the Qtpy, or the library with the general methods in the |
@jposada202020 what is the difference between the qtpy version that works with py and the |
I tailored the class, to have only basic configuration for the QTpy and nothing else. the
No it does not, I tried but it does not, do not understand why, that is why I asking about the parsing in the import, I do not have an explanation on why it does not work. I am not importing the Class CV and other properties if I am only using the class in the init, however it does not work. |
@tannewt it worked!!! 🛩️ works with py files. Tested in QTPY and Feather RP2040. Could you please propose a better name for the Featured class, I used Configurable, but I do not like it. Documentation is good, I add another example, so once you propose a better name I could polish and do the little details |
How about |
Good Idea, will do changes as suggested. I like the idea of basic and advanced... and have the basic file without a name |
Test were done using different boards, and different versions of CircuitPython Tests done for the RP2040
Adafruit CircuitPython 6.2.0 on 2021-04-05; Adafruit Feather RP2040 with rp2040
>>> import dps310_simpletest_advanced
Temperature = 26.55 *C
Pressure = 1025.00 hPa Adafruit CircuitPython 6.2.0 on 2021-04-05; Adafruit Feather RP2040 with rp2040
>>> import dps310_low_power_weather_station
Temperature = 26.46 *C
Pressure = 1025.00 hPa Adafruit CircuitPython 6.2.0 on 2021-04-05; Adafruit Feather RP2040 with rp2040
>>> import dps310_simpletest
Temperature = 26.37 *C
Pressure = 1025.02 hPa Tests done for the QTPY MOOnly the Adafruit CircuitPython 6.1.0 on 2021-01-21; Adafruit QT Py M0 with samd21e18
>>> import dps310_simpletest
Temperature = 26.55 *C
Pressure = 1025.01 hPa NOTE For I do not what reason I had to change the import order for the QTPY in the example code to avoid the memory Error. I let the designers explain that to me. ThanksTests done for the Metro ESP32S2Adafruit CircuitPython 7.0.0-alpha.1-853-gcbe1aa74f on 2021-04-26; Adafruit Metro ESP32S2 with ESP32S2
>>> import dps310_simpletest
Temperature = 26.21 *C
Pressure = 1025.00 hPa Adafruit CircuitPython 7.0.0-alpha.1-853-gcbe1aa74f on 2021-04-26; Adafruit Metro ESP32S2 with ESP32S2
>>> import dps310_simpletest_advanced
Temperature = 26.28 *C
Pressure = 1024.97 hPa Adafruit CircuitPython 7.0.0-alpha.1-853-gcbe1aa74f on 2021-04-26; Adafruit Metro ESP32S2 with ESP32S2
>>> import dps310_low_power_weather_station
Temperature = 26.34 *C
Pressure = 1024.93 hPa Tests done for the FeatherS2Adafruit CircuitPython 6.1.0-beta.2 on 2020-12-03; FeatherS2 with ESP32S2
>>> import dps310_simpletest
Temperature = 26.20 *C
Pressure = 1024.91 hPa Adafruit CircuitPython 6.1.0-beta.2 on 2020-12-03; FeatherS2 with ESP32S2
>>> import dps310_simpletest_advanced
Temperature = 26.22 *C
Pressure = 1024.89 hPa Adafruit CircuitPython 6.1.0-beta.2 on 2020-12-03; FeatherS2 with ESP32S2
>>> import dps310_low_power_weather_station
Temperature = 26.18 *C
Pressure = 1024.89 hPa NOTE: FOR RELEASING PURPOSES THIS IS A MAJOR CHANGE, IT WILL REQUIRE VERSION CHANGE |
I think you should have |
Will do :) Thanks |
Final test was done with RP2040 and Qtpy M0. the simpletest did not load with a py, however with the mpy files was ok Adafruit CircuitPython 6.2.0 on 2021-04-05; Adafruit QT Py M0 with samd21e18
>>> import dps310_simpletest
Temperature = 24.78 *C
Pressure = 1016.48 hPa
Temperature = 24.79 *C
Pressure = 1016.48 hPa When extracting the basic file from the directory the memory error go away, and before changing the import order also correct the memory error, but when testing today this did not happened. To discuss in Discor. (was my two questions las friday :) ) |
@jposada202020 want to do anything else on this? |
@tannewt I think we are good to merge,however if you agree, could we wait until I do the BME280?, I want to see if I could learn/have some other elements that maybe could help here also. |
Up to you. :-) |
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.
Also, please consider adding sea_level_pressure
as a property to basic.py
. It is referenced in multiple places but there is no getter/setter for it.
For the elevation property, please add some documentation stating that the sea_level_pressure needs to be set accurately and daily (or more frequently if the pressure is changing quickly) to give accurate results. If they are only using the pressure and not the elevation then this does not need set. Unfortunately, I do not know of a good source of sea-level pressure values to recommend.
Note: My Garmin feinx 6 can drift by almost 100m of elevation (usually less than 50m) if I have not used GPS to record an activity or manually calibrate it in a while.
Circup
There should also be instructions explaining that circup
may fail on a small board (as it will try to install everything) and explain how to download the library from github/PyPI and only install the basic.py
.
Co-authored-by: James Carr <70200140+lesamouraipourpre@users.noreply.github.com>
Co-authored-by: James Carr <70200140+lesamouraipourpre@users.noreply.github.com>
Co-authored-by: James Carr <70200140+lesamouraipourpre@users.noreply.github.com>
Co-authored-by: James Carr <70200140+lesamouraipourpre@users.noreply.github.com>
Co-authored-by: James Carr <70200140+lesamouraipourpre@users.noreply.github.com>
Co-authored-by: James Carr <70200140+lesamouraipourpre@users.noreply.github.com>
Co-authored-by: James Carr <70200140+lesamouraipourpre@users.noreply.github.com>
I see, let see if it fits in the basic running in a QtPy, but I like it very much, hopefully it will fit :) |
@lesamouraipourpre the sea_level_pressure property fits, so I added. Could you help me with a fgood explanation on the Readme regarding how to use the library. Adafruit CircuitPython 6.2.0 on 2021-04-05; Adafruit QT Py M0 with samd21e18
>>> import dps310_simpletest
Temperature = 27.15 *C
Pressure = 1015.92 hPa
Sea Level Pressure = 1013.25 |
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've tested the changes and they work fine on a QT-PY (with only the basic installed).
Attached is diff against README.rst with a possible explanation of how to install on memory-limited boards.
dps310.diff.txt
Oh..... I love the comments and the explanation, make me laugh, it was very good 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.
Thanks everyone for contributing to this! For the README update, I viewed the diff, and there are some minor issues with it that can be addressed once it's included in this or a future PR. Please decide how you want to handle that, and get it added here if that's the plan so I can request changes.
I also want to make sure folks are aware that these changes affect at least one guide. @jposada202020 are you prepared to update the guide, or did you have a plan for that? I can't remember if we got you added to the Learn system or not.
@kattni Yes I have been added. more details on that.. |
@lesamouraipourpre While looking at the learning guide to make the changes, something came up I would like to test this with Blinka, (both in the RP and the Pico with Micropython). what do you think? |
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.
As long as the guide is updated in tandem, I'm prepared to approve this. Please try to remember to tag me on the PR for the README update.
Thanks!
Will do thanks |
If I remember tomorrow I can try it on my RPi3 with the new library, seeing as that's its normal home for logging to adafruit.io. |
RaspberryPi 3 All examples run correctly. import board
import busio
import time
# pip install adafruit-io
from Adafruit_IO import *
from adafruit_dps310.advanced import DPS310_Advanced as DPS310
def configure_dps310_sensor(i2c):
dps310 = DPS310(i2c)
dps310.wait_temperature_ready()
dps310.wait_pressure_ready()
# Use the figure from your local forecast for today.
# hPa (hectoPascals) == millibars
dps310.sea_level_pressure = 1015.0
print("Altitude: {:.0f}m".format(dps310.altitude))
return dps310
def configure_adafruit_io():
try:
from secrets import secrets
except ImportError:
print ("secrets are kept in secrets.py, please add them there!")
raise
return Client(secrets["aio_username"], secrets["aio_key"])
def main():
i2c = board.I2C()
# i2c = busio.I2C(board.SCL, board.SDA)
room_sensor = configure_dps310_sensor(i2c)
io = configure_adafruit_io()
while True:
temperature = room_sensor.temperature
pressure = room_sensor.pressure
print ("{:.1f}° {:.1f}".format(temperature, pressure))
try:
io.send_data("room-temperature", temperature)
io.send_data("room-pressure", pressure)
except Exception:
# IOError, so wait longer
time.sleep(300)
time.sleep(30)
if __name__ == "__main__":
main() |
That is a nice example, would you mind if we use it? for the library? |
Go for it. License is Unlicense to keep example secrets.py: secrets = {
"aio_username" : "YOUR_USERNAME",
"aio_key" : "YOUR_AIO_TOKEN",
} |
Will do in a different PR, thanks |
Micropython on RP Pico is a no-go. There seem's to be an issue with @tannewt Is there any reason that you can think of that Register wouldn't work on MicroPython. If you think it should work, I'll work up minimal example code to file |
I found the same problem, Did not go as deep as yourself in the troubleshooting. See issue here adafruit/Adafruit_Blinka#482. |
Thanks for finding that @lesamouraipourpre and @jposada202020. I'm working on finishing up a guide, but am curious to look more into that right after. I suspect register is using some feature of Blinka that's perhaps implemented differently. If either of you want to take a deeper look, that would be awesome. |
Using the pending PR on Blinka (adafruit/Adafruit_Blinka#483) this library works on Blinka/MicroPython on RP2040. |
That is good news, I think I will merge over the weekend, that way when releasing next week I could correct the learning guide. |
# Conflicts: # adafruit_dps310/advanced.py
I merged main and resolved conflicts to get this passing CI. Successfully tested the basic and advanced simpletest scripts with a Feather RP2040 and DPS310. I'm going to merge this and update the relevant parts of the guide page now |
thanks! |
Updating https://github.com/adafruit/Adafruit_CircuitPython_DPS310 to 2.0.0 from 1.2.7: > Merge pull request adafruit/Adafruit_CircuitPython_DPS310#15 from jposada202020/light_class > update rtd py version
This fixes this after the latest DPS310 release. I assumed we want the advanced by default on the Fun House. ```py Traceback (most recent call last): File "code.py", line 13, in <module> File "adafruit_funhouse/__init__.py", line 110, in __init__ File "adafruit_funhouse/peripherals.py", line 86, in __init__ AttributeError: 'module' object has no attribute 'DPS310' ``` adafruit/Adafruit_CircuitPython_DPS310#15
No description provided.