Skip to content
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

Update weather.py to show 16 wind directions #221

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

MrDrem
Copy link

@MrDrem MrDrem commented Apr 24, 2024

This also resolves the issue with having to tare readings more than once.

This also resolves the issue with having to tare readings more than once.
@Gadgetoid Gadgetoid added bug Something isn't working enhancement New feature or request labels Apr 24, 2024
@MrDrem
Copy link
Author

MrDrem commented Apr 25, 2024

This seems to crash my enviro-weather when the wind parts are plugged in. I am trying to work out what the issue is, but the board seems to need to be reflashed, so I can't get to the log file sadly.

MrDrem added 3 commits April 25, 2024 23:21
Taken the earlier code from @Gadgetoid and cleaned it up a little, as it's better than mine was. I'm also going to update the config.py file to add in the required config.wind_direction_offset which is a nice touch
I think that I have updated this correctly so that the wind direction offset will be set to 0 if not defined
updated to add in weather specific area for the wind_direction_offset
@MrDrem
Copy link
Author

MrDrem commented Apr 25, 2024

I've updated the code to try and improve pull #163 slightly.

I'm not certain why there is the addition of an extra 360 at line 157, and suspect that this could be removed.

I've not yet tested this again with the board connected to the the anemometer.

@MrDrem
Copy link
Author

MrDrem commented Apr 25, 2024

I've now been running this code for ~1 hour, and it's returning good wind directions. WIll update again in the morning, but it looks good to include.

@MrDrem
Copy link
Author

MrDrem commented Apr 26, 2024

I now understand why the extra 360 degrees is added

(The addition of 360 degrees is a common technique used in programming to handle negative numbers when calculating directions or angles.

In this case, config.wind_direction_offset could potentially be a negative number. If wind_direction (which is non-negative) is added to a negative offset, the result could be a negative angle, which doesn’t make sense in this context because angles are typically expressed in the range of 0 to 360 degrees.

By adding 360 before adding the offset, we ensure that the intermediate result is always non-negative, even if the offset is negative. The modulus operation (% 360) at the end then brings the final result back into the range of 0 to 360 degrees.

So, the expression (wind_direction + 360 + config.wind_direction_offset) % 360 ensures that the final wind direction is a non-negative number less than 360, regardless of the value of config.wind_direction_offset. This is a standard way to normalize an angle to the range of 0 to 360 degrees.)

My board crashed when the wind sensors were added last night, I'm not sure which part of the code causes this issue, or if it's a physical hardware issue. When there are no sensors connected, it's fine, but when they are it regularly crashes.

@sjefferson99
Copy link
Contributor

@MrDrem As #163 was working ok when I last tested it I wanted to see what improvements you were making and see if I could help get one of these PRs in. I note you caught my copy paste error on the default wind direction config, which I have fixed in my branch and I have also rebased my PR branch against main to make comparisons easier. Comparing yours and my branch I can only see some comments removed which I failed to remove with the associated code (will adjust in my branch as well), am I messing up the compare and there's other changes made I should take a look at? I can then test both branches with mine and see if it's code or board specific.

@MrDrem
Copy link
Author

MrDrem commented Apr 26, 2024

@sjefferson99 I'd done it slightly differently initially, but looking at your method yours seemed better so I changed it to match that and bring it up to the new codebase. The changes in the end were just the tidying.

I'm fairly sure that my issues are board specific, but as my board was gifted by in-laws, and it works intermittently (no issues for the last ~5 hours, but it will stop soon I suspect), getting hold of Pimorini to try and exchange it is a bit of a hassle that I've not had time to do, and I've had it for so long now that it's going to be out of warranty.

@sjefferson99
Copy link
Contributor

@MrDrem OK, as I've rebased mine on updated main and committed the bits I missed first time (Thanks for catching), my original PR should be the same. I'll copy the code from it to my board and test when I get a minute and see if it still runs...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants