MySensors weather station
-
@dbemowsk my guess is your sensor tries to communicate on the SPI bus and prevents communication with NRF24.
I don't know what is in you AS5047 files so I'm not sure but I suppose it's taking over the SPI bus at creation, you should try to force the CSN pin used for the as5047 to HIGH in before() method to disable it before MySensors library starts using the radio.@Nca78 ok, so I tried adding this:
void before() { digitalWrite(AS5047_CHIP_SELECT_PIN, HIGH); }This seems to now allow the radio to connect, but I am still having some trouble. I then tried removing setting the CSN pin high in the before(), and adding it to the constructor of the library class here:
AS5047::AS5047(uint16_t SelectPin) : _ss(SelectPin) { pinMode(_ss, OUTPUT); SPCR = (1<<SPE) | (1<<MSTR) | (1<<CPHA) | (1<<SPR1) | (1<<SPR0); // slow down clock speed, set up spi digitalWrite(_ss, HIGH); //<<------------- SPI.begin(); }This seemed to do the same as putting it in the begin() method, but still having some trouble. I am going to see if I can work through the problems on my own, but I may post if I have questions. Let me know if you see problems with what I did to the class.
Thanks.
-
@Nca78 ok, so I tried adding this:
void before() { digitalWrite(AS5047_CHIP_SELECT_PIN, HIGH); }This seems to now allow the radio to connect, but I am still having some trouble. I then tried removing setting the CSN pin high in the before(), and adding it to the constructor of the library class here:
AS5047::AS5047(uint16_t SelectPin) : _ss(SelectPin) { pinMode(_ss, OUTPUT); SPCR = (1<<SPE) | (1<<MSTR) | (1<<CPHA) | (1<<SPR1) | (1<<SPR0); // slow down clock speed, set up spi digitalWrite(_ss, HIGH); //<<------------- SPI.begin(); }This seemed to do the same as putting it in the begin() method, but still having some trouble. I am going to see if I can work through the problems on my own, but I may post if I have questions. Let me know if you see problems with what I did to the class.
Thanks.
-
@dbemowsk it's good practice to have a pull up resistor on each SPI CS line (approx. 10k).
It can save you a lot of hassle when multiple devices share the same SPI bus. -
@Yveaux Thanks, this is easy enough. I have some small 1/8w 10k resistors with a small bit of room in the proto area of the easy newbie board yet, I will add one in.
-
@Yveaux I thought the nRF24 radios would have had it built in to the module, but I never checked. It is just that and the magnetic direction sensor on the SPI bus. After thinking about it too, I may just add the resistor on to the small board I have inside the wind speed and direction sensor case that the wire harness connects to, or do you think it would be better if it was closer to the arduino? If that is the case, then I would stick with my original plan to put it in the little bit of leftover space in the proto area of the easy newbie board. Jumper wires are getting a bit cramped in that space though, so if I can avoid it I will.
-
@Yveaux I thought the nRF24 radios would have had it built in to the module, but I never checked. It is just that and the magnetic direction sensor on the SPI bus. After thinking about it too, I may just add the resistor on to the small board I have inside the wind speed and direction sensor case that the wire harness connects to, or do you think it would be better if it was closer to the arduino? If that is the case, then I would stick with my original plan to put it in the little bit of leftover space in the proto area of the easy newbie board. Jumper wires are getting a bit cramped in that space though, so if I can avoid it I will.
@dbemowsk the nrf module doesn't have a pullup on CS.
Where you put them doesn't really matter. It's just to have a defined, unselected state when the lines are not actively driven by the microcontroller.
If it is too much trouble in your current hardware, then skip the pull-ups and save them for your next piece of hardware. The same can be achieved in software, but you just must make sure all CS lines are made inactive (high) before doing anything with the SPI bus. Before() is a good place to achieve this, but bad designed drivers that use eg the constructor to do spi initialization could still beat you to it...
Therefore pull-ups are preferred. -
@dbemowsk the nrf module doesn't have a pullup on CS.
Where you put them doesn't really matter. It's just to have a defined, unselected state when the lines are not actively driven by the microcontroller.
If it is too much trouble in your current hardware, then skip the pull-ups and save them for your next piece of hardware. The same can be achieved in software, but you just must make sure all CS lines are made inactive (high) before doing anything with the SPI bus. Before() is a good place to achieve this, but bad designed drivers that use eg the constructor to do spi initialization could still beat you to it...
Therefore pull-ups are preferred. -
@dbemowsk the nrf module doesn't have a pullup on CS.
Where you put them doesn't really matter. It's just to have a defined, unselected state when the lines are not actively driven by the microcontroller.
If it is too much trouble in your current hardware, then skip the pull-ups and save them for your next piece of hardware. The same can be achieved in software, but you just must make sure all CS lines are made inactive (high) before doing anything with the SPI bus. Before() is a good place to achieve this, but bad designed drivers that use eg the constructor to do spi initialization could still beat you to it...
Therefore pull-ups are preferred.@Yveaux So if this is done in software, is it better to be done in the before() method rather than the constructor of the library class? If the nRF24 radios do not have a built in pull up on the CS line, does the MySensors library somehow take care of this in one of it's class files? I haven't seen a push to have designers of MySensors hardware include pull-ups on the nRF24's CS line...
-
@Yveaux So if this is done in software, is it better to be done in the before() method rather than the constructor of the library class? If the nRF24 radios do not have a built in pull up on the CS line, does the MySensors library somehow take care of this in one of it's class files? I haven't seen a push to have designers of MySensors hardware include pull-ups on the nRF24's CS line...
@dbemowsk said in MySensors weather station:
@Yveaux So if this is done in software, is it better to be done in the before() method rather than the constructor of the library class?
It all depends on initialization order of the classes, which isn't trivial. For global static instances (declared outside a function like loop()) the constructor will be called before the before() call, but if one places an instance inside a function or dynamically creates it things will be different. So, when designing a library you simply can't be sure when your constructie is called...
I'm not sure right now if the drivers actively pull the CS line high at startup, but IMHO they should.
The fact that some mySensors hardware designs lack pull-ups on CS is probably because the SPI bus isn't shared in many cases, and maybe because people aren't aware.
This would be a good item to add to a design checklist, if only we had one :-) -
@dbemowsk said in MySensors weather station:
@Yveaux So if this is done in software, is it better to be done in the before() method rather than the constructor of the library class?
It all depends on initialization order of the classes, which isn't trivial. For global static instances (declared outside a function like loop()) the constructor will be called before the before() call, but if one places an instance inside a function or dynamically creates it things will be different. So, when designing a library you simply can't be sure when your constructie is called...
I'm not sure right now if the drivers actively pull the CS line high at startup, but IMHO they should.
The fact that some mySensors hardware designs lack pull-ups on CS is probably because the SPI bus isn't shared in many cases, and maybe because people aren't aware.
This would be a good item to add to a design checklist, if only we had one :-) -
OK, so here is my easy newbie board layout showing pin connections and header plug identifications. I am still working on the code a bit. I still need to work in the wind speed and wind gust code and figure out the calculations for that. I am nearing the point of full sensor testing. I will then need to figure out my power situation.

-
Here are some of the final pics of the wind sensor assembly. The first one shows the circuit board mounting assembly. I have a small channel on the top and bottom sides of the mounting plate to hold rubber O-ring seals to keep water out. The seals can be seen to the left of the image.

Next is just a wide angle shot of all the parts. The connector for the anemometer reed switch feeds through the hole next to the wire harness board and plugs into a header on that board.

The last pic is the fully assembled unit with the wire harness attached. I added a shot of the O-rings sandwiched between the layers to keep water out.

-
Here are some of the final pics of the wind sensor assembly. The first one shows the circuit board mounting assembly. I have a small channel on the top and bottom sides of the mounting plate to hold rubber O-ring seals to keep water out. The seals can be seen to the left of the image.

Next is just a wide angle shot of all the parts. The connector for the anemometer reed switch feeds through the hole next to the wire harness board and plugs into a header on that board.

The last pic is the fully assembled unit with the wire harness attached. I added a shot of the O-rings sandwiched between the layers to keep water out.

-
@dbemowsk great work, thanks for sharing!
My 3D printer does not create watertight prints. Water seems to be able to slowly pass through the walls. Hopefully your printer is better, but it might be something to look out for.
@mfalkvidd The walls of the upper and lower case are pretty thick. I used 100% infill which was probably a bit overboard, but I didn't want any water in it. That is why I also put the rubber O-rings in the middle. With the sides compressing that rubber it gives it a pretty good seal. I was originally going to make gaskets. but I found the O-rings to be a better fit.
-
So for those that have wind sensors on your setups, what are you using for your V_GUST value that you send back to the controller?
@dbemowsk said in MySensors weather station:
what are you using for your V_GUST value that you send back to the controller?
I send a new value every minute. The sensor measures continuously and the wind speed reported is the average speed over this minute. Gust is simply the maximum speed in a minute.
-
This is the official (US)National Weather Service definition of wind gust. It looks like they dont report gusts until wind speed is above a certain amount. I like to overcomplicate things, so I would report the average, max in a minute (like Yveaux), and a standard deviation(just to be fancy)
https://graphical.weather.gov/definitions/defineWindGust.html