WXforum.net

Weather Station Hardware => Other Weather Station Hardware => Topic started by: weathernick on April 23, 2014, 06:57:02 PM

Title: Homemade Weather Station using a Raspberry Pi
Post by: weathernick on April 23, 2014, 06:57:02 PM
Hello all,

I have been lurking around here for some time and have acquired a great deal of knowledge. So time to give some of it back. I have started work on a custom weather station using the Raspberry Pi as the datalogger running 8 meteorological sensors. Those sensors are:
AM2315 (temperature and humidity sensor)
BMP180 (pressure)
Rainew111 (Rain gauge)
MOD-1016 (Lightning Sensor Module)
3 cup Anemometer from Gary Stofer (basically an Inspeed Vortex)
Wind vane from Gary Stofer (basically an Inspeed E-Vane)
Pyranometer build from a kit from the Institute for Earth Science Research and Education

This is a work in progress but I figured I would post my results here in case others try to do something similar.
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: Skywatch on April 23, 2014, 11:50:08 PM
Now I want to get started on one of these. Sounds like an awesome setup. Do you have pictures? This might be my next project.

PS. The Inspeed Vortex and E vane are stripped down Downeaster sensors. My friend I got my Taylor stuff from does a little bit of Downeaster.
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: weathernick on April 24, 2014, 11:13:16 AM
Thank you for the information about Inspeed. Very nice sensors and turned out to be half of my budget on the weather station.

As for pictures, those will have to wait until the weekend but I have plenty to document the entire process. I also have code to post as well.

I also have pictures of my version of the FARS which will house the AM2315 sensor.
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: weathernick on April 25, 2014, 12:25:14 AM
Some pictures of my setup thus far.

(http://i89.photobucket.com/albums/k240/Nickolas_McColl/IMG_2570_zps2c51e8ee.jpg) (http://s89.photobucket.com/user/Nickolas_McColl/media/IMG_2570_zps2c51e8ee.jpg.html)
This is the test platform I made to house all the sensors during testing. This way I can move the device outside to collect data or back to the shop for modifications.

(http://i89.photobucket.com/albums/k240/Nickolas_McColl/IMG_2567_zps69da7b5b.jpg) (http://s89.photobucket.com/user/Nickolas_McColl/media/IMG_2567_zps69da7b5b.jpg.html)
My version of the FARS. 70mm fan pulls air up through both sets of pipes. Will see how she tests.

(http://i89.photobucket.com/albums/k240/Nickolas_McColl/IMG_2555_zpsb29dc1e8.jpg) (http://s89.photobucket.com/user/Nickolas_McColl/media/IMG_2555_zpsb29dc1e8.jpg.html)
An Orbit enclosure makes for a nice home for the electronics. The GPIO port will connect to the protoboard and from their to all the sensors.

For the software side of the house I plan on building my own driver for WEEWX. The first step though is to create code that can read all the sensors. I have pressure and winds working at this time.

Oh what have I gotten myself into.  :grin:
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: Skywatch on April 25, 2014, 04:54:35 PM
Very nice!
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: weathernick on April 29, 2014, 11:51:18 PM
The latest test of the homemade pyro from the Institute for Earth Science Research and Education
(http://i89.photobucket.com/albums/k240/Nickolas_McColl/Solarat5000wattpervolt_zps788a22e5.png) (http://s89.photobucket.com/user/Nickolas_McColl/media/Solarat5000wattpervolt_zps788a22e5.png.html)
Red is the homemade sensor. Blue and Green are PSP sensors. Might need to check to see if mine is level. Correction factor is 5000watts/m^2/volt
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: Skywatch on April 30, 2014, 12:33:58 PM
Cool! Is there a picture of the solar radiation sensor?
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: weathernick on April 30, 2014, 07:49:18 PM
Yea, I have one on my phone. I will see if I can upload it tonight.
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: weathernick on April 30, 2014, 10:15:14 PM
Bam!! One homemade solar sensor. The sensor next to it is a PSP which I used to calibrate mine.

(http://i89.photobucket.com/albums/k240/Nickolas_McColl/Solarsensorcalibration_zps44bd7416.jpg) (http://s89.photobucket.com/user/Nickolas_McColl/media/Solarsensorcalibration_zps44bd7416.jpg.html)

I have the raw data and will analysis the data a little bit more but overall I am pleased with it. This device only has a spectral range of 700 to 1100nm vs Davis's 400 to 1100nm. It will be interesting to compare data during cloudy days or high humidity. Right now it is bone dry and not a cloud in the sky.
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: DaleReid on May 01, 2014, 07:04:18 AM
Weathernik:

Very nice project and I know it takes time away from fiddling around with it to take pix, post, and answer questions.

Your project looks a lot like what I am planning to do with a shed full of precious sensors I have accumulated over the years but my wife calls 'junk'.

What did you use to generate the graph showing the response curve just above this posting?

Thanks. Dale
Oh, is there a reference for the Raspberry Pi that one can read an get a good idea of the work to be done, programming styles, etc. that would be of help if I considered using this device as the engine to drive all the data gathering?  Any one or two books or online material that is good, or is this just jump in and start fiddling to make progress?
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: weathernick on May 01, 2014, 02:30:34 PM
I love questions!!! One of the main reasons for doing this post is to answer questions and perhaps help someone along the way. Worst case I have some pretty pictures to look at.

To your questions:
The data was a screenshot from some campbell scientific software that is collecting the data. It is part of the system that I am using to calibrate my Pyro. I will be using excel to produce some better graphs so I can get the true correction factor.

Ah references... I think I have used the entire internet for this project!!! For me I started by seeing what the RPi could and couldn't do. Here is what the RPI has that is useful for building a weather station:

8 unused GPIO ports: These are digital ports so you can use them for all things digital. For building a weather station these are handy to drive LED lights and count pulses. For me I will use six of them, one for counting precip bucket tips, one for counting pulses from the wind speed sensor, one as an IRQ for the lightning sensor, one for monitoring the FARS fan's RPM, and two for LED lights (status light and lightning activity light)

2 SPI ports: SPI is just a communcation protocal. Some meterological sensors can use SPI but I would avoid it. The RPi only has two ports and doesn't support slave devices. For me I use one port for my MCP3208 (analog to digital converter, 8 ports) and the other is free.

Analog ports: The RPi has no analog ports! So you need to add some. You can get a board that has this kind of stuff or you can just get yourself a MCP3208 IC and add it to a break out board (BOB). The MCP3208 adds 8 ports. I use one for wind direction, one for the pyro (I also amp the signel with a INA122), and two to monitor the 12v(for the FARS fan only) and 5v(RPi) rails. Also I went with the MCP3208 because it is a 12bit ADC. This means it will convert voltages into values from 0 (0volts) to 4095 (3.3volts) giving it a resolution of 0.8mv. If I picked a 10bit ADC the resolution would have been 6mv. The pyro needs the resolution of the 12bit ADC hence why i picked it. The wind direction would have been fine with 10bit.

I2C: Second to analog ports (which the RPi has none hence the MCP3208) this is the most useful ports. I2C allows numerous sensors to be attached to a single set of wires (SDA, SCL) where each device has a unique address. I have the lightning sensor, temperature, humdity and pressure all using this port.

Power: The RPi has 5v and 3v3 (also known as 3.3volts). You can only drive like 50ma off the 3v3 rail but the 5v has well over 150ma. Most of my sensors use 5v (lightning, temperature/humidity, wind sensors). The only sensors using 3v3 is the pressure sensor because the BOB (break out board) was designed that way.

Network: If you get the version B you get additional Memory (RAM), an additional usb port, and a ethernet jack. For me, I use the network jack for debuging and wifi (dongle on the usb port) for production. You could use version A but will have to deal with only have one usb port and no ethernet jack.

Storage: only storage is via an SD memory chip. You will need an 8Gb chip to get the OS loaded. A very good idea to image the memory chips incase you have problems. then you could just buy another chip restore the image and you are back in business.

Programming languange: Since the OS is linux you can program in any language that works well in linux (all but VB perhaps??). RPi developers usally use python2, python3 or c++. I stuck with Python2/3 and it seems to be working well. The main issue with Python is it is slower than C++ (for various reasons). For me I am running a python script that samples all my sensors once a second and still have about 8/10 of a second left for the cpu to just sit idle.

WEEWX: This is the software that actually displays the weather data to a web page and also sends it off to Wunderground, NWS, etc... The only rub is that for a custom station you need to build a custom driver to interface it to your data. There are plenty of examples on how to do this. I picked this software as it runs on the RPi with no issues.


References:
http://www.raspberrypi.org/   For all your general questions about RPi.
https://github.com/adafruit/Adafruit-Raspberry-Pi-Python-Code   Here are some good code examples for a few sensors. I "stole" a lot of good ideas from there.
http://www.weewx.com/  all things related to WEEWX.
https://www.sparkfun.com/ Various BOB of sensors can be found here. Also plenty of other BOB for other common IC.  I picked up the BMP180 BOB from them.
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: weathernick on May 09, 2014, 12:43:07 AM
Things are moving along. Mostly working on building the prototype station with all the sensors nicely integrated together for ease of testing.

Tested the air flow of the FARS and i am getting 4 m/s at the entrance of the inside chamber. That puts it about 4 times the air flow of a Davis and inside the range of the RM Young FARS (http://www.davisnet.com/product_documents/weather/app_notes/AN_24-temp-radiation-shield-comparison.pdf (http://www.davisnet.com/product_documents/weather/app_notes/AN_24-temp-radiation-shield-comparison.pdf)). It helps that a 70mm fan is powering this verses the small fan for the Davis. Also the computer fan is rated for 8 years of use... I will be curious how long it will work outside. For 5 dollars I can afford to burn this up every year.

I did add some code to my datalogger program to measure the fan's rotation and 12 volt power levels. That way I can disable temperature/humidity in the event the fan shuts down. That should get my attention to go fix the fan!

I have a good solid week of data from my Pyro against the calibrated references. I should be able to generate a correction factor from that data. Right now it looks to track better than 5% at this time. Naturally it still isn't a PSP so it won't track as well during cloudy conditions but we did have a dust storm during the week and the data did track well during that.

Measured temperature out in garage for 3 days before my script hit an error and crashed. Lots more debuging to do but things are looking good.
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: weathernick on June 18, 2014, 04:22:28 PM
The station has now been installed outside(only pressure and lightning sensors are installed). I will upload some pictures later. Right now I am dealing with a heat issue. Turns out that having two power bricks (5v and 12v) inside the case with the Pi has resulted in the temperature getting too high. Turns out the Pi can handle the heat(80°C) but the wifi adapter is only rated to 40°C. The summer heat isn't helping either (~45°C) So I am playing around with that. Might have to break down and get a better wifi adapter.

I added a green LED light that flashes when the system is collecting values. Right now I have ran the system continuously for about a week with no problems in the core program.

We will keep moving forward.
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: weathernick on June 25, 2014, 10:37:45 AM
Got Weewx configured for pressure. The rest of the variable should be easy now... but I have to install the sensors. Temp and humidity should be up today.

The site is at http://www.wunderground.com/personal-weather-station/dashboard?ID=KAZYUMA27#history (http://www.wunderground.com/personal-weather-station/dashboard?ID=KAZYUMA27#history)
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: cburkins on August 07, 2014, 09:25:31 AM
Hello WeatherNick,

I'm curious if you've connected/configured your InSpeed Anemometer to your Raspberry Pi ? 

I'm thinking about doing something quite similar, and was hoping to leverage your work.

-Chad
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: weathernick on August 08, 2014, 04:38:54 PM
I have connected the sensor. It is a little tricky with the RPi as there is no ADC on board which is needed for wind direction. I am assuming you have built or installed a ADC to your RPi. I am currently cleaning up my code and tracking down a bug with the lightning/precipitation sensor. I can post the wind code for you if you like? Those wind sensors are very nice and I am most pleased with them. They work extremely well... so well I had to place a 3 second average(wmo standard) because I was getting 1 second instant winds well above anything in the area. You will be happy with the sensor.

Nickolas
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: weathernick on August 08, 2014, 04:55:52 PM
I just realized that I haven't posted any updates on the system. So here we go.

Winds: I have moved the wind sensor to the top of my two story house and it has mad a big different in wind speed and direction. The data is now perfect and shows a SSE flow during our monsoonal surges. Wind speed actually worked too well and I was capturing 1 second gust that were well higher than anything else out there. I now do a three second average per WMO standards and that seems to match up well with the airport and other davis systems.

Temperature/humidity (FARS): This was the second sensor online and has done much better than I thought. I have also used the monsoon to help compare it to the airport and it is perfect (+- 1 degree F dewpoint) I do need to finish the code to shut down the sensor when the fan fails(which I measure its RPM).

Pressure: The first sensor installed. I get spikes in the data during power up which I could filter out, but other than that it is also perfect and matched up well with the airport.

Solar: This has to be my favorite sensor. Primary because it allows me to gauge cloud cover when i am away from the house. Also because it only cost 25 dollars to build. Its resolution is only 4 watt/m^2 but that ends up working perfectly fine.

Precipitation: Well this one is turning out to be were all my engery is going to go to. It works perfectly fine during tests but when it rains I get sporadic errors. Could be a loose wire, could be the lightning sensor interacting with it somehow... Since it rains 10 times a year I don't have a lot of opportunity to test this. Thankfully I have my manual can to measure rain.

Lightning: The sensor works fine by itself, but once I integrate it into my code it fails... Since I don't get a lot of rain it will take some time to figure this one out.

Overall I am pleased with my station. Weewx is perfect for capturing and forwarding the data and I haven't had much issues outside of a few bugs that Weewx fixed quickly. Now I have been transmitting to weather underground and CWOP for 5 weeks now with only a few data dropouts.

Nickolas
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: cburkins on August 10, 2014, 10:12:03 AM
Hi weathernick, thx for the reply.   While being a very experienced software and OS guy, I'm new to small electronics.   My first project was a Raspberry Pi thermometer for my fish tank, which gets logged to a Zabbix instance running in an Amazon virtual machine.

Works great. 

Googled ADC, analog to digital converter.   Looks straightforward, I'll give that a go next.   Have any tutorial to share ?  This is what I just read :  https://learn.adafruit.com/reading-a-analog-in-and-controlling-audio-volume-with-the-raspberry-pi/connecting-the-cobbler-to-a-mcp3008


Then I guess I should pick up one of these weather stations. 

Chad
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: tweatherman on August 10, 2014, 03:03:49 PM
Weathernick,
Just curious if you ever plan on building any of these home made custom stations for possible customers?

Thanks,
tweatherman
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: weathernick on August 10, 2014, 05:15:49 PM
I have had a few people ask me about selling such units. I think the fun would be lost if I started to sell them. Also their cost would only be a little cheaper than a davis unit. I will post whatever information people need to play around with such systems but I will leave selling weather stations to the pros.
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: tweatherman on August 10, 2014, 05:48:00 PM
I understand.

Thanks,
tweatherman
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: weathernick on August 11, 2014, 11:59:15 AM
Chad,

If I had to do things over again I would have just gotten a ADS1015 or ADS1115 breakout boards. All that is needed is a little soldering and you are good to go. 12bit will give you 4096 values which is wind direction to the tenth.

Looks like Adafruit also has code examples for the chips as well. Their shipping is high so make sure you get everything you need on the first try or shipping will kill you. A mistake I had to learn.

Did you get your sensor from Inspeed? if so what version did you get?

Nickolas
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: cburkins on August 12, 2014, 10:57:22 AM
Thanks Nick,

I'm a new father, so my hobby time is a bit limited right now, and I've only recently discovered the joy of small electronics.   So haven't yet ordered my InSpeed :)

Did some googling on the the ADC boards you recommended.   Looks like I would need to solder on the header pins something like this  ?

https://learn.adafruit.com/adafruit-4-channel-adc-breakouts/assembly-and-wiring

I *think* I can handle that.  At any rate, it certainly looks fun :)

-Chad

Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: weathernick on August 13, 2014, 06:54:15 PM
Yep, soldering like that allows you to plug into a breadboard which makes it easy for testing. Then you can solder to your final board when you are done. Or better yet you could use this device http://www.adafruit.com/products/801

This is fun. Are you going to add any other sensors to the RPi?

Nickolas
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: weathernick on August 22, 2014, 11:27:40 AM
More updates:

I have done some massive code clean on my scripts so it actually looks like real code instead of a clobbered mess that it was. I will most likely post the code to my amazon s3 storage or something like that once I get further along in this project. Speaking of amazon s3 I know have my RPi syncing its data so I can recovered the system if there is a failure. I still have to backup the database but that shouldn't take too long.

Precip sensor will be the death of me... I have some sort of malfuntion where I am getting 10x more tips that I should. I thought it was a short but the problem came back. I have since replaced the wire and am now waiting for some more rain. It did seem to work when I showered it with my garden hose...

Lightning sensor. I am not sure if this works or not... I see this being a work in progress for a long time.

Webcam. Not in the original plan for the weather station but I had a spare webcam laying around so I figured I would give that a shot... Well that spiraled out of control and now i have a powered usb hub installed in my case to provide more power to my usb devices. The webcam was crashing my system but I think it might have something to do with the wifi.

Wifi. Well my concern about running the wifi chip above recommend temperatures came true. A few days ago the wifi chip died. I have a replacement on order and I will mount the wifi chip outside the case to help with temperatures. I also extended my wifi network so it was closer to the station. That seems to help with connection problems I was having (although that may have just been related to the dying chip.)


Some interesting information about the Raspberry Pi I have found out while doing this.
1.) Be careful of the SD memory chip you buy. Some chips have very low random 4k writes.  Sandisk Ultra memory seems good but you might want to search to see what other people have found. Ultimately you would like to get a chip that has around 1Mbps for random 4k writes.
2.) The Raspberry Pi has a watchdog circuit that could be helpful to reboot your system if it hangs. This could improve the reliability of the station greatly.
3.) Overclock you must!!! The Pi loves overclocking and it is even approved by the RPi foundation. Just run raspi-config and select 900mhz (medium) overclocking. This will give you upwards of 50% boost in some calculations.
4.) Weewx is great but it does eat up some processing power if you have 1 minute storage intervals and product reports. I find that weewx will eat up about 25% of my cpu if I want it to generate web reports. My datalogger script only takes about 5% to collection all the information from the sensors.
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: cburkins on August 22, 2014, 08:31:07 PM
Nicholas, interesting updates, thanks for sharing your progress, it's fun to follow along !

As for myself, I'm moving along slowly.  I've got an ADS1015.   I did the soldering to attach the pins.  Given that I'm not an experienced solderer, it was pretty touch-and-go, but seems that all four data pins work when wired up to a potentiometer.   Reading it via I2C and the Adafruit Python libraries.  Success !

Next, I setup a DHT22 and am successfully reading both temperature and humidity.  Success again !

Not sure where I'm headed next, but enjoying the journey.

-Chad
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: weathernick on September 08, 2014, 06:43:25 PM
Webcam and temperature/rh fun.

I have added a C500 Logitech web cam to my weather station. The camera is inside a flood light enclosure and mounted near the station facing North. Here are some notes on what I have learned in the process of adding the camera.
1.) USB traffic on the RPi eats up a lot of cpu cycles. I collect one 1280x1024 image every 2 minutes and I am at 85% Load (anything past 70% causes the CPU to overlock to 900mhz) This was a lot more then I originally thought it would be and shattered my dreams of two once a minute web cameras. 85% Load is about the max I want to take the system.

2.) Wunderground sucks with respect to updates. I send webcam images every 2 minutes but they are always old or even shows I am offline half the time. Not sure if there is anything better as I do like their weather display so I guess I am stuck.

I also have been working on a sensor lockup issue I have had with the Temp/RH sensor. I have rebooted the RPi to clear the error and it has no effect. I have to shut down the system complete and disconnect the power. Then once powered back up the sensor works again. I think the sensor just locked up and needs to be power cycled. My latest modification involved using the GPIO port to provide power to the sensor. This effectively gives me a switching power port as the GPIO can be turned off and on via software and can power a device up to 16ma (temp/rh sensor is 10ma). I now have code that checks to see if the sesnor is reporting, if not then it turns off the sensor wait 5 seconds and turns it back on. I am hoping this fixes the problem but only time will tell.

Finally buy a good 2am chargers. I got one off Amazon and it turns out it doesn't output the full 2amp so my instability problems a little while back was all around power.

Now the station is mostly done with the only things left is moving the solar and precip sensor to their final home. Now I will see how long the station can go without being power cycled. I am hoping months, but we shall see.
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: weathernick on September 13, 2014, 11:12:32 PM
Using the GPIO(*) interface as "programmable power" to the T/RH sensor(s) is a smart 'power-saving' technique, which can ALSO reduce the sensor(s) susceptibility to noise as well as "self-heating", ie: only "wake-up" the T/RH sensor device when it's time for a reading.


(*) GPIO = General Purpose Input/Ouput, an older, legacy, Hewlett-Packard-originated parallel-interface, characterized by user-defined pin input/output direction assignment.

Exactly!!! I am not sure why it didn't think of it sooner. Granted this only works with low power sensors and only those that are powered by 3v3. But my freezing problems with the sensor has gone away and temperature and humidity have been solid. I thought I would have plenty of GPIO for this project but it is turning out they are very handy and I only have a few left.

I wasn't as worried about sensor heat up as this device is in a FARS and the sensor is only sampled every 5 seconds but still is nice to not give more power than what is required for the temperature sensor. Every little bit helps in getting an accurate reading.
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: weathernick on September 13, 2014, 11:34:31 PM
Here are some more pictures of the setup. The tipping rain gauge and the pyranometer will move next to the manual raingauge in the fall.
(http://static.flickr.com/5582/15201848462_5169736b0d.jpg)
The control center. There is a GFI socket in there along with my homemade datalogger board connected to a Raspberry Pi.

(http://static.flickr.com/5587/15015437379_a237a94191.jpg)
The FARS with the solar sensor attached to the top (temporarily). You can also see the Rainwise tipping rain bucket on the roof while I test it.

(http://static.flickr.com/3855/15015550720_eb3cab9c52.jpg)
My manual gauge and the future home of the tipping gauge and solar sensor.

(http://static.flickr.com/3842/15015439649_f3b36897d4.jpg)
The wind sensor on the roof. It is only about 3-4 feet above the ridgeline and that is as far as my ladder gets me. It will do for now.

Also I am trying out github for posting the weewx web page. You can find it here http://weathernick.github.io (http://weathernick.github.io)

Nickolas
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: danb35 on September 15, 2014, 07:12:39 PM
(*) GPIO = General Purpose Input/Ouput, an older, legacy, Hewlett-Packard-originated parallel-interface, characterized by user-defined pin input/output direction assignment.
I think you're confusing GPIO with GPIB, formerly known as HPIB (the B in both cases representing Bus), which is/was what you described.  GPIO are general purpose I/O pins on the rPi, and don't (as a group) conform to any other specification.  They're described as GPIO to distinguish them from the more specific I/O ports like USB, Ethernet, etc.
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: weathernick on September 23, 2014, 10:44:13 AM
Station is dead!!!

Pause for dramatic effect.

Ok so I was checking the temperature/humidity sensor to find out why my humidity is wrong and I accidentally shorted the GPIO port with 12v.  ](*,) As such the Raspberry Pi is dead... Good thing those are cheap! New one should be here Sept 24th. I am beefing up the wiring in the FARS to prevent the short from happening again. Also running the fan off of 5 volts as it moves plenty of air and is silent. Lesson learned.

I am also working with adafruit to see why my AM2315 is giving me to low an RH value. More to follow i am sure.

Nickolas
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: geofb13 on September 24, 2014, 09:27:06 AM
Oh no, that sucks to hear. Hopefully you can figure out what's going on with your humidity sensor and get it all fixed by the time your new Pi comes.
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: weathernick on September 24, 2014, 10:43:45 AM
Oh no, that sucks to hear. Hopefully you can figure out what's going on with your humidity sensor and get it all fixed by the time your new Pi comes.

Ultimately it looks like the AM2315 just isn't going to work out for me. The first probe was DOA and the second one looks like it has damage to the RH sensor. My plan it to integrate an SHT25 if I can find it on a breakout board. Otherwise I might try the SHT75 but I haven't found any code for it for the Raspberry Pi.

 
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: geofb13 on September 24, 2014, 12:15:23 PM
I haven't used this one, but from the specs it seems similar to the SHT21.

I'd guess that you've probably looked at all of these already though but here's the link.

https://www.sparkfun.com/products/12064 (https://www.sparkfun.com/products/12064)
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: weathernick on September 24, 2014, 12:50:09 PM
I haven't used this one, but from the specs it seems similar to the SHT21.

I'd guess that you've probably looked at all of these already though but here's the link.

https://www.sparkfun.com/products/12064 (https://www.sparkfun.com/products/12064)
Yea I live on sparkfuns site. :) Part of my requirement was an RH probe that was in the 2% or below range. This proble is the HTU21 which has 3% humidity accuracy. In reality I don't think I would care much but still for a few dollars more I can get below 2%. Just not sure how hard it is going to be to intergrate into the RPi.
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: geofb13 on September 24, 2014, 01:40:09 PM
Understandable and I figured you had probably been well aware of that part. I'll keep checking back in to see how things progress, and good luck!

Edit: One last idea haha. Also possible that you've already seen it.

http://www.emartee.com/product/42288/SHT25%20Digital%20Humidity&Temperature%20Sensor (http://www.emartee.com/product/42288/SHT25%20Digital%20Humidity&Temperature%20Sensor)
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: weathernick on September 24, 2014, 05:39:39 PM
This 'train-of-thought' makes me wonder, are there any better (more accurate) Temp / Humidity sensors than the Sensirion SHT25?

http://www.sensirion.com/fileadmin/user_upload/customers/sensirion/Dokumente/Humidity/Sensirion_Humidity_SHT25_Datasheet_V3.pdf (http://www.sensirion.com/fileadmin/user_upload/customers/sensirion/Dokumente/Humidity/Sensirion_Humidity_SHT25_Datasheet_V3.pdf)

Outside of RM young, Vaisala, or Campbell Scientific. I am not sure they make a chip that has better specs than 1.8%. I checked Mouser and Digi-key and all they sell is Honeywell which doesn't beat the SHT25.

We will see if anyone else can find something.
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: drsprite on September 26, 2014, 11:52:19 AM
Sorry to hear your station went down! Hopefully it's back up now!

I'm working on a Raspberry Pi weather station too, and have a question. I'm using the Wind Vane from Sparkfun's Weather Meters. It's an analog reading, but the GPIO is digital.

Do you have any tips on how I can read the analog results from the Vane on the digital Raspberry Pi?
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: weathernick on September 26, 2014, 12:06:25 PM
Sorry to hear your station went down! Hopefully it's back up now!

I'm working on a Raspberry Pi weather station too, and have a question. I'm using the Wind Vane from Sparkfun's Weather Meters. It's an analog reading, but the GPIO is digital.

Do you have any tips on how I can read the analog results from the Vane on the digital Raspberry Pi?

Station just came back up. RH is toast so I need to scope out a new sensor but other than that she is back to her old self.

In my head I am thinking about version 2.0 of my weather station and in it I will have the ADC from adafruit. https://www.adafruit.com/products/1085 Now you can add all kind of chips but this one is I2c and has sample code for the RPi. While expensive it will give 4 16bit analog ports to your RPi. You could get the next model down if you only plan on sampling wind speed and direction. I recommend 16 bit for future expansion.

You could save some money and just buy a ADC chip but it will take some effort to intergrate and coding could be a problem.

Let me know how the wind sensor works. They posted it a few weeks after I already got my stuff.

Nickolas
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: drsprite on September 26, 2014, 10:14:54 PM
I'll check out that board from adafruit. Looks pretty simple and straight forward.

Another question on your setup - how did you integrate with weewx? I can't find any documentation on "3rd party" stations reporting to it.
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: weathernick on September 27, 2014, 11:33:58 PM
I'll check out that board from adafruit. Looks pretty simple and straight forward.

Another question on your setup - how did you integrate with weewx? I can't find any documentation on "3rd party" stations reporting to it.

Intergration with weewx is the tricky part. You need to first collect the data from the sensors via code on the RPi and save it as a ascii file. I have my station do it every second. That file will look like this
2014-09-27 12:00:10,34.3,10.0,340,10.2,900.3, etc....
2014-09-27 12:00:11,34.1,10.2,341,12.4,900.8,etc...
...

Python2 is the language of choice but you can pick whatever works for you.

Second you will need to create a weewx driver that takes the ascii file and transfers it to weewx. At this point weewx takes over and creates the webpage and transfers your data to wunderground and CWOP. I have included my driver, feel free to use it but it is very simple at this point.

Code: [Select]
#
#    $Revision: 1 $
#    $Author: Nickolas McColl $
#    $Date: 2014-08-16 $
#
"""Raspberry Pi driver for the weewx weather system"""

from __future__ import with_statement
# import math
import time
#import weedb
#import weeutil.weeutil
import weewx.abstractstation
import weewx.wxformulas


def loader(config_dict, engine):
    import weewx.units
    altitude_m = weewx.units.getAltitudeM(config_dict)

    station = Raspberry_pi(altitude = altitude_m, **config_dict['Raspberry_pi'])
   
    return station
       
class Raspberry_pi(weewx.abstractstation.AbstractStation):
    """Station using Raspberry Pi"""

    def __init__(self, **stn_dict):
        self.altitude = stn_dict['altitude']
        self.loop_interval = float(stn_dict.get('loop_interval'))

    def genLoopPackets(self):
        import weewx.units

        while True:
            start_time = time.time()

            # Create Loop packet
            f = open('/home/weewx/bin/wxdata.csv')
            input = f.readline()
            f.close()   
            data = input.split(',')
            if len(data) == 13: # data line is complete, process
                for i in range(1, (len(data))):
                    try:
                        data[i] = float(data[i])
                    except ValueError:
                        data[i] = None     
           
                raw_time =time.strptime(data[0], "%Y-%m-%d %H:%M:%S")
           
                _packet = {'dateTime': int(time.mktime(raw_time)),
                           'usUnits' : weewx.METRIC,
                           'pressure' : data[1],
                           'windSpeed' : data[12], #use 3 second average
                           'windGust' : data[12], #use 3 second average
                           'windDir' : data[3],
                           'windGustDir' : data[3],
                           'outTemp' : data[4],
                           'outHumidity' : data[5],
                           'rain': data[6],
                           'radiation' :data[9],
                           'inTemp' : data[11]}
           
                _packet['dewpoint']  = weewx.wxformulas.dewpointC(_packet['outTemp'], _packet['outHumidity'])
                _packet['barometer'] = weewx.wxformulas.sealevel_pressure_Metric(_packet['pressure'], self.altitude, _packet['outTemp'])
                _packet['altimeter'] = weewx.wxformulas.altimeter_pressure_Metric(_packet['pressure'], self.altitude)
                _packet['heatdeg'] = weewx.wxformulas.heating_degrees(_packet['outTemp'], 18.333)
                _packet['cooldeg'] = weewx.wxformulas.cooling_degrees(_packet['outTemp'], 18.333)
                _packet['heatindex'] = weewx.wxformulas.heatindexC(_packet['outTemp'], _packet['outHumidity'])
                 
                yield _packet
     
            sleep_time = (start_time - time.time()) + self.loop_interval
            if sleep_time > 0:
                  time.sleep(sleep_time)
   
    def hardware_name(self):
        return "raspberry_pi"
           
   

Enjoy,
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: vreihen on September 28, 2014, 09:39:18 AM
FWIW, you may be able to find some help toward the end of this writeup by forum user nincehelser, describing how he imported Acu-Rite network bridge data into weewx on a Raspberry Pi:

http://nincehelser.com/ipwx/ (http://nincehelser.com/ipwx/)
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: drsprite on September 28, 2014, 12:53:13 PM
This is all a great help to get started, thanks! I have most of my sensors configured and ready to go. I just need to modify my Python to save to a csv - should be simple enough.

However, I'm still learning Python and weewx is also new to me. Your driver is pretty readable, so I think I follow *most* of it, but I'm stuck on defining it in weewx.conf and getting weewx to start.

I have this set in weewx.conf and it fails to start. Thoughts?


Code: [Select]
station_type = Raspberry_pi
EDIT: Figured it out. I had to add a [Raspberry_pi] section to the weewx.conf file and defined the driver to use as     driver = weewx.drivers.Raspberry_pi
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: weathernick on September 28, 2014, 04:58:40 PM
This is all a great help to get started, thanks! I have most of my sensors configured and ready to go. I just need to modify my Python to save to a csv - should be simple enough.

However, I'm still learning Python and weewx is also new to me. Your driver is pretty readable, so I think I follow *most* of it, but I'm stuck on defining it in weewx.conf and getting weewx to start.

I have this set in weewx.conf and it fails to start. Thoughts?


Code: [Select]
station_type = Raspberry_pi
EDIT: Figured it out. I had to add a [Raspberry_pi] section to the weewx.conf file and defined the driver to use as     driver = weewx.drivers.Raspberry_pi

Excellent. Let me know how it goes and if you find any bugs/issues.

Thanks,

Nickolas
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: weathernick on October 02, 2014, 11:54:37 AM
Oh no, that sucks to hear. Hopefully you can figure out what's going on with your humidity sensor and get it all fixed by the time your new Pi comes.

Ultimately it looks like the AM2315 just isn't going to work out for me. The first probe was DOA and the second one looks like it has damage to the RH sensor. My plan it to integrate an SHT25 if I can find it on a breakout board. Otherwise I might try the SHT75 but I haven't found any code for it for the Raspberry Pi.

 

I have ordered the Embedded Adventures SHT25 temperature and humidity sensor. The Breakout board is just the right size to fit inside my FARS. I will install a SF2 filter to keep the contaminates down. The communications is i2c like the AM2315 but there is support code for Python2. This will allow me to have one piece of code drive all the weather sensors.

Pictures to follow once the sensor arrives.
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: drsprite on October 02, 2014, 12:15:02 PM
Great! Looking forward to it. I am using the DHT22 for temp/humidity, but am open to other suggestions since the DHT can be a little slow on reading intervals.

My weewx driver is coming along as well. Thanks for your help! I tried your CSV solution, but found it to be a little out-of-sync with the Python script that polls the sensors and writes the CSV, and weewx checking the CSV. Sometimes there was stale data in there. So I opted to have all my sensor checks performed in the Python weewx driver itself. So far it's been a couple of days and is working pretty well. I even have an LED wired up to a GPIO pin so I know when the driver begins the poll, and ends the poll (or gets stuck).

Little bit of bad news: I'm using the Sparkfun weather meters and my Wind Vane broke (which also has my anemometer broken, too, since it shares the wiring). :( So I'm working through that (either a replacement, or look to purchase inexpensive upgrades). Another hurdle to overcome :)
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: weathernick on October 02, 2014, 12:40:04 PM
Great! Looking forward to it. I am using the DHT22 for temp/humidity, but am open to other suggestions since the DHT can be a little slow on reading intervals.

My weewx driver is coming along as well. Thanks for your help! I tried your CSV solution, but found it to be a little out-of-sync with the Python script that polls the sensors and writes the CSV, and weewx checking the CSV. Sometimes there was stale data in there. So I opted to have all my sensor checks performed in the Python weewx driver itself. So far it's been a couple of days and is working pretty well. I even have an LED wired up to a GPIO pin so I know when the driver begins the poll, and ends the poll (or gets stuck).

Little bit of bad news: I'm using the Sparkfun weather meters and my Wind Vane broke (which also has my anemometer broken, too, since it shares the wiring). :( So I'm working through that (either a replacement, or look to purchase inexpensive upgrades). Another hurdle to overcome :)

Hmm I never noticed any stale data but than again I sample ever second so I guess I assumed a few stale lines won't really hurt. Also it could be that I sample my sensors at the 1/2 second mark. It takes about 0.05 to 0.08 seconds to collect the data and write the CSV file which will be more than enough time to close the file out before Weewx tries to read. It is possible that hack prevents the stale files but I will check regardless. Also since it takes a fraction of a second to sample the sensors I have it sleep one second minus the fraction of the second. This prevents drift and keeps samples set to the 1/2 second mark.

I love the idea of having the weewx driver do it all, let me know how that goes. That might be helpful to someone who just wants something to work straight out of the gate given a predetermine set of sensors.

Bad news indeed on the wind vane. :( I love my wind sensors but those suckers are not cheap at all. I will have to say they have been the most stable performer in my weather station after I smoothed the gust to 3 second averages. Nice thing about these stations you can just add stuff as you go.

Good luck and thanks for the feedback.
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: thorn on March 07, 2015, 08:16:48 AM


Any updates on your DIY station? I'm thinking about building a DIY weather station also. I have been playing around with some temp, baro, & humidity sensors.

Thanks, Greg
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: weathernick on March 07, 2015, 09:28:55 AM
Some updates:

My station has been running for over 9 months now and here are the list of events that have occurred:

1.) Temperature/humidity sensor is doing great with the new sht sensor. CWOP shows the sensor has been stable for the last 5 months.

2.) Lightning sensor is turned on but I am not sure if it is working well. More debugging will be needed during our thunderstorm season.

3.) I was getting fake precip during thunderstorm events. I debugged this to noise coming in on the precip data line. The GPIO pins are very sensitive and if your cable is long enough you can induce a voltage to trip the sensor. I put a capacitor on the GPIO pin and it has helped. I think I will need to add a resistor which will make it a RC Filter.

4.) Made a mistake in mounting my wind direction sensor and water got into the sensor. Just be careful if you are creative on mounting sensors. They need to be protected from the elements at all cost.

Other than that the system has been running every second with very little down time.

I did mount some of my sensors(precip and pyro) out in the yard and they have been working well. Outside the precip problem but I am close to fixing that.
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: thorn on March 07, 2015, 10:34:30 AM
Some updates:

My station has been running for over 9 months now and here are the list of events that have occurred:
...

4.) Made a mistake in mounting my wind direction sensor and water got into the sensor. Just be careful if you are creative on mounting sensors. They need to be protected from the elements at all cost

Thanks for the update.

I thought the wind direction sensors were sealed. How did the Rasp Pi do in the hot weather? I worry that it might get too hot in a case during the summer. There are lots of details to work out! Do you have a detail description online?

Thanks, Greg

Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: weathernick on March 07, 2015, 11:46:45 PM
Yea those sensors are sealed... I just broke the seal when mounting it. The only description I have is via this forum.

As for the heat. Turns out the Rasp Pi can take a lot of heat and does perfectly fine in the summer out here. I had to get a better wifi usb adapter because of the heat but that might have been a power issue that I resolved by getting a 2amp powered hub. As long as you keep the RPi out of direct sunlight you should be fine.

Nick
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: thorn on March 08, 2015, 03:04:53 PM
I guess the Rasp PIs are pretty rugged. I was going to try to run mine off a 12v battery hooked to a trickle charger or possible solar setup, I worry about power going out and corrupting the SD card. I got a couple of 12v regulated adjustable (1-12v) power supplies off ebay.  I also bought 4 of the latest Pi 2s to experiment with.  I'm going to use one to display the weather data inside with a small HDMI display.

I might have missed it in the forum, I'm wondering how you did the wind speed and the rain bucket. The Inspeed E-VANE2 can use a A/D converter but how did you manage to query the pulses from the anemometer? I see they have one that gives 8 pulses per rotation:

http://www.inspeed.com/anemometers/8-Pulse%20Anemometer.asp

I installed Weewx to see how everything works. It's really nice, gives you lots of flexibility. I mounted a network drive to store the data and web pages to save writes to the card.

Thanks again, I hope you don't mind all the questions.
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: geofb13 on March 08, 2015, 06:55:23 PM
Some updates:

My station has been running for over 9 months now and here are the list of events that have occurred:

....

Thanks for the update Nick! I'm glad to see everything is still running well for the most part.

I guess the Rasp PIs are pretty rugged. I was going to try to run mine off a 12v battery hooked to a trickle charger or possible solar setup, I worry about power going out and corrupting the SD card. I got a couple of 12v regulated adjustable (1-12v) power supplies off ebay.  I also bought 4 of the latest Pi 2s to experiment with.  I'm going to use one to display the weather data inside with a small HDMI display.

I might have missed it in the forum, I'm wondering how you did the wind speed and the rain bucket. The Inspeed E-VANE2 can use a A/D converter but how did you manage to query the pulses from the anemometer? I see they have one that gives 8 pulses per rotation:

http://www.inspeed.com/anemometers/8-Pulse%20Anemometer.asp

Thorn I have a couple raspberry pi & arduino based stations running off a 12v battery/solar set up. Generally the only problem that I've come across with using the Pi it which is probably in the coding I got, is that I have it set to restart the pi every few days. For whatever reason it was having a hiccup and recorded the data coming from the sensors but wasn't sending it out anymore. Other then that, I think the other big issue this one related to the battery connection was one of the batteries did run dry and shorted something. That's now been fixed with some extra code on our side to get the voltage sent over along with the sensor data. That way hopefully that won't happen again, but I've got at least 1-3 extra SD cards with the same coding already loaded on it so I can just pop in  and go for the most part in the event of another similar issue.

Hope that helps give you some more ideas!

Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: thorn on March 08, 2015, 07:46:56 PM


Thorn I have a couple raspberry pi & arduino based stations running off a 12v battery/solar set up. Generally the only problem that I've come across with using the Pi it which is probably in the coding I got, is that I have it set to restart the pi every few days. For whatever reason it was having a hiccup and recorded the data coming from the sensors but wasn't sending it out anymore. Other then that, I think the other big issue this one related to the battery connection was one of the batteries did run dry and shorted something. That's now been fixed with some extra code on our side to get the voltage sent over along with the sensor data. That way hopefully that won't happen again, but I've got at least 1-3 extra SD cards with the same coding already loaded on it so I can just pop in  and go for the most part in the event of another similar issue.

Hope that helps give you some more ideas!

I have a Rasp Pi running a VOIP application and it's been running since April on the grid with a UPS, I have not had to replace a  SD card in it yet.  It doesn't do as much as one that would be collecting data. I also have a couple PIs running motion for security cameras 24/7. I lost 2 cards because I unplugged them by accident. The were cheaper cards.

How do you monitor battery voltage? I would guess a sensor.  :-)

Thanks, Greg
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: geofb13 on March 08, 2015, 10:26:42 PM
I have a Rasp Pi running a VOIP application and it's been running since April on the grid with a UPS, I have not had to replace a  SD card in it yet.  It doesn't do as much as one that would be collecting data. I also have a couple PIs running motion for security cameras 24/7. I lost 2 cards because I unplugged them by accident. The were cheaper cards.

How do you monitor battery voltage? I would guess a sensor.  :-)

Thanks, Greg

There's two seperate ways that I monitor it depending on if the Pi is out in the field or for one that is close enough to use WiFi but is still running off a battery.

Most of it is just using an Analog to Digital Converter and two voltage dividers  and connect it to a GPIO pin if I'm remembering correctly. Here's an example (http://raspi.tv/2013/controlled-shutdown-duration-test-of-pi-model-a-with-2-cell-lipo) of one that was just running on a LiPo battery and needed to shut off before the power got too low. The idea is similar if you're using a non-LiPo battery, or something connected to a solar panel with a charge controller. The only difference would be how you'd connect the dividers to the battery and what the dividers are rated at.

The other way I monitor it is with one that's connected to a Xbee transmitter. You can ping the pin that the Xbee has connected to the power. They are basically the same idea as the Xbee already has the ADC in it so if it's connected to something like that you can remove a piece. With that said you'd probably have an ADC for the Pi anyway for some of the sensors.

Afterwards it would just be the code to have the Pi to shut off, send an email or add a message with the data sent to notify you.
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: Bushman on March 08, 2015, 10:45:03 PM
I would caution anyone that  EACH cell in a lipo needs to be monitored for LVC.  It is possible to have say, a 3S (three cells) where one discharges past LVC and then you gots probs!
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: weathernick on March 09, 2015, 03:37:52 PM
I might have missed it in the forum, I'm wondering how you did the wind speed and the rain bucket. The Inspeed E-VANE2 can use a A/D converter but how did you manage to query the pulses from the anemometer? I see they have one that gives 8 pulses per rotation:

http://www.inspeed.com/anemometers/8-Pulse%20Anemometer.asp

Pulses from the anemometer and the precip sensor are taken care of via the GPIO pins on the RPi. You can think of pulses as digital inputs. The wind sensor will produce 8 pulse per rotation. So in the code you listen to the wind sensor and count the pulses. I do per second but you can do any time period. At the end of the time period just count the pulses and apply some math to get it to mph. The precip sensor creates pulses everytime the tipping bucket empties, so 0.01" for each pulse.

You will need to remember to use a basic RC filter if you want to rid your self of noises on the GPIO. Otherwise lightning will induce all kinds of errors. You won't see it much in the wind data but you will see it in the precip. :)

The wind sensor was the easiest and fastest sensor to code for in this project.

Nickolas
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: thorn on March 10, 2015, 01:00:34 PM
I might have missed it in the forum, I'm wondering how you did the wind speed and the rain bucket. The Inspeed E-VANE2 can use a A/D converter but how did you manage to query the pulses from the anemometer? I see they have one that gives 8 pulses per rotation:

http://www.inspeed.com/anemometers/8-Pulse%20Anemometer.asp

Pulses from the anemometer and the precip sensor are taken care of via the GPIO pins on the RPi. You can think of pulses as digital inputs. The wind sensor will produce 8 pulse per rotation. So in the code you listen to the wind sensor and count the pulses. I do per second but you can do any time period. At the end of the time period just count the pulses and apply some math to get it to mph. The precip sensor creates pulses everytime the tipping bucket empties, so 0.01" for each pulse.

You will need to remember to use a basic RC filter if you want to rid your self of noises on the GPIO. Otherwise lightning will induce all kinds of errors. You won't see it much in the wind data but you will see it in the precip. :)

The wind sensor was the easiest and fastest sensor to code for in this project.

Nickolas


Thanks, I'll have to read up some more on how the GPIOs work. I built a Geiger counter from a kit and I'm reading it through the USB for now. I saw some info on how to wire it directly to the Pi. I also got a UV sensor that should work through the I2C, I have the baro/temp and humidty working through the I2C.

But the rain sensor signal/pulse could come at any time. Do you have to have a interrupt of some sort to keep an eye on it?  The wind you can just sample every sec. or so.

Thanks!
Greg
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: thorn on March 10, 2015, 01:07:50 PM


There's two seperate ways that I monitor it depending on if the Pi is out in the field or for one that is close enough to use WiFi but is still running off a battery.

Most of it is just using an Analog to Digital Converter and two voltage dividers  and connect it to a GPIO pin if I'm remembering correctly. Here's an example (http://raspi.tv/2013/controlled-shutdown-duration-test-of-pi-model-a-with-2-cell-lipo) of one that was just running on a LiPo battery and needed to shut off before the power got too low. The idea is similar if you're using a non-LiPo battery, or something connected to a solar panel with a charge controller. The only difference would be how you'd connect the dividers to the battery and what the dividers are rated at.

The other way I monitor it is with one that's connected to a Xbee transmitter. You can ping the pin that the Xbee has connected to the power. They are basically the same idea as the Xbee already has the ADC in it so if it's connected to something like that you can remove a piece. With that said you'd probably have an ADC for the Pi anyway for some of the sensors.

Afterwards it would just be the code to have the Pi to shut off, send an email or add a message with the data sent to notify you.

That's neat. I have a couple of those adjustable power supplies that I see in the one photo. They were only $2. The battery would make a good UPS on other Pi projects I have. I have a large sealed spare 12v battery that I plan  to use and it would be nice to have the Pi shutdown nicely.

Greg
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: DaleReid on March 10, 2015, 04:44:02 PM
As far as monitoring to count pulses, I've got the same question that Greg (thorn) does on how to do this.

Do you go to a set routine that counts for exactly one second, and then returns to doing other stuff?  No sense in monitoring the temperature or barometric pressure too often, but wind and wind gusts are likely the most variable and could 'hijack' the system entirely for a second to count pulses every now and then and do OK.

Just curious as to what solution you worked out.
Dale
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: thorn on March 10, 2015, 05:56:36 PM
As far as monitoring to count pulses, I've got the same question that Greg (thorn) does on how to do this.

Do you go to a set routine that counts for exactly one second, and then returns to doing other stuff?  No sense in monitoring the temperature or barometric pressure too often, but wind and wind gusts are likely the most variable and could 'hijack' the system entirely for a second to count pulses every now and then and do OK.

Just curious as to what solution you worked out.
Dale


Here's something about it: http://sourceforge.net/p/raspberry-gpio-python/wiki/Inputs/

http://raspi.tv/2013/how-to-use-interrupts-with-python-on-the-raspberry-pi-and-rpi-gpio-part-3

I have used interrupts in C using threads before.

With the rainfall you would need to accumulate the values if it is already raining or it would be a new rain event so one would have keep track of it. Or does weewx keep track of it?

Greg
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: thorn on April 03, 2015, 10:50:26 PM
I have been working on my wx station and have some of it ready to mount in the waterproof case I got.  Now I need to do some of the programming to save the data to a text file.

Here's a photo of it:

(http://162.218.236.116/photos/GT2_3090.jpg)
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: thorn on April 13, 2015, 01:25:04 PM


I put my DIY weather station outside temporarily, I have temp, hum, baro, light, wind speed and dir. I have been trying to get the wind speed to work. Yesterday there were light winds and everything seem to be working, Today it's around 10mph (according to my older Davis station) but it's only recording 1-2 mph even though it's spinning like crazy. I guess it must be missing pulses on the GPIO.  I Googled but did not find much. I thought it might be related to bounce but I guess that's false extra sensing. 

Does anyone have some code posted somewhere so I can see how you guys have done it? I tried both the "add_event_detect" as a thread and "wait_for_edge" with the same results. I guess the Pi 2 should be able to count pretty fast. I have the 8 pulse/revolution anemometer from Inspeed (0.31 factor to convert to Mph). 

I just have Python scripts for now to get it working. I may try to put the code calling the sensors directly into the driver.

Thanks, Greg
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: weathernick on June 10, 2015, 12:57:12 PM
Sorry I was gone for a little bit. Here is my code that uses Python to interface into the 8 pulse wind sensor. I basically setup an GPIO.add_event_detect to count the pulses from the wind sensor. Then every "second" I sum the count and apply the correct multipliers. I time stamp every "second" as that tends to drift based on the load on the system. I than take the correct time interval (normally 1 second but can be as long as 1.7 seconds) to correct my value. Here is the code.
Code: [Select]
import math
import spidev
import RPi.GPIO as GPIO
import time
from time import strftime, localtime

# Global variables
wind_start_time = time.time()
wind_pulse_cnt = 0
peak_3s_wind = []
wind_dir_adc_min = float(.15)  # Zero degree wind dir is around .1 volts
wind_dir_adc_max = float(3.05)  # 360 degree wind dir is around 3 volts

# ------------------CONFIGURATION--------------------------
# Wind speed
wind_10m_multiplier = float(4.02336) / float(8)  # km/h
wind_10m_GPIO_port = 22

# Wind Direction
wind_dir_channel = 0
wind_dir_offset = 171  # Degrees to rotate CC to equal actual direction.
# ------------------END OF CONFIGURATION --------------------

# Configure the GPIO for the RPi
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)

# Open spi port to ADC
spi = spidev.SpiDev()
spi.open(0, 0)  # 12bit ADC MCP3208
spi.max_speed_hz = (500000)

# Function that counts pulses from 10m wind sensor
def callback_windsp_10m(channel):
    global wind_pulse_cnt
    wind_pulse_cnt += 1

# monitor GPIO for pulses from wind sensor
GPIO.add_event_detect(wind_10m_GPIO_port,
                      GPIO.FALLING,
                      callback=callback_windsp_10m,
                      bouncetime=1)

# Function to get data from Wind Speed Sensor
# Wind speed sends 8 pulses per revolution. Time is need to complete
# calculations. Normally this is one second but delays in program
# run time can change that. We use wind_end_time and wind_start_time
# to correctly get the time inverval between obs.
def get_10m_wind_speed():
    global wind_pulse_cnt
    global wind_start_time
    global peak_3s_wind
    wind_end_time = time.time()
    wind_speed = ((wind_pulse_cnt * wind_10m_multiplier) /
                  (wind_end_time - wind_start_time))
    wind_pulse_cnt = 0  # reset counter
    wind_start_time = wind_end_time  # Reset timer for winds
    peak_3s_wind.insert(0, wind_speed)
    if len(peak_3s_wind) == 4:
        peak_3s_wind.pop()
    avg_peak_wind = 0
    for peak_wind in peak_3s_wind:
        avg_peak_wind = avg_peak_wind + peak_wind
    avg_peak_wind = float(avg_peak_wind / len(peak_3s_wind))
    return wind_speed, avg_peak_wind


# Function to get data from Wind Vane Sensor
def get_10m_wind_dir():
    global wind_dir_adc_min, wind_dir_adc_max
    # single-ended measurement see mcp3208_test for differental code
    r1 = spi.xfer2([6 + (wind_dir_channel >> 2),
                   (wind_dir_channel & 3) << 6,
                   0])
    adcout1 = float(((r1[1] & 15) << 8) + r1[2]) / float(4095) * 3.3

    # This dynamically changes the range of the sensor since it might change.
    f = open('/home/weewx/bin/wind_adjustment.txt', 'a')
    datetime = strftime("%Y-%m-%d %H:%M:%S", localtime())
    if adcout1 < wind_dir_adc_min:
        wind_dir_adc_min = adcout1
        data = "%s Wind adc min changed to : %.2f\n" % (datetime, adcout1)
        f.write(data)
    if adcout1 > wind_dir_adc_max:
        wind_dir_adc_max = adcout1
        data = "%s Wind adc max changed to : %.2f\n" % (datetime, adcout1)
        f.write(data)
    f.close()
    wind_dir = round(float((adcout1 - wind_dir_adc_min) /
                     float(wind_dir_adc_max - wind_dir_adc_min)) *
                     float(360), 0)

    # Apply offset
    wind_dir = wind_dir + wind_dir_offset
    if wind_dir > 360:
        wind_dir = wind_dir - 360

    return wind_dir

# Main Program. Sample all the sensors and created data file.
# This data file can then be picked up by ingester (WEEWX)
while True:
    # Get time
    start_time = time.time()
    datetime = strftime("%Y-%m-%d %H:%M:%S", localtime())

    # Get Wind Direction
    winddir_10m = get_10m_wind_dir()
    # Get wind speed and three second peak. (WMO standard)
    windspd_10m, windspd_peak_10m = get_10m_wind_speed()
    if windspd_10m < 0.01:  # Wind speed is zero
        winddir_10m = None

    # Get End Times and calculate program pause to next collection
    end_time = time.time()
    proc_time = round(end_time - start_time, 4)
    if (proc_time > 1) or (math.ceil(end_time) > math.ceil(start_time)):
        sleep_time = 0 
    else:
        sleep_time = math.ceil(end_time) - end_time
    time.sleep(sleep_time)  # Sleep until beginning of next second


My full code is here for anyone who uses similar sensors.

Code: [Select]
#!/usr/bin/python
# This datalogger script is responsible for collecting meteorological
# information from the following sensors and  creating a named pipe that
# streams that information over to the weewx driver.
# Installed sensors:
#  SHT25 (Temperature/Humidity sensor) [i2c]
#  BMP180 (Pressure) [i2c]
#  Pyronometer (homemade) [ADC]
#  AS3935 (Lightning sensor) [i2c]
#  wxunderweatherstation Wind direction (inspeed) [ADC]
#  wxunderweatherstation Wind sensor (Inspeed) [GPIO, pulse]
#  Rainwise RAINEW 111 Tipping Bucket Rain Gauge [pulse]

# Last updated: 2015-04-28
# Created by Nickolas McColl


import math
import spidev
import RPi.GPIO as GPIO
import time
from time import strftime, localtime
from Adafruit_BMP085 import BMP085
import sht21
from RPi_AS3935 import RPi_AS3935  # Lightning Sensor

# Global variables
wind_start_time = time.time()
wind_pulse_cnt = 0
peak_3s_wind = []
precip_pulse_cnt = 0
lightning_cnt = 0
distance_sum = 0
wind_dir_adc_min = float(.15)  # Zero degree wind dir is around .1 volts
wind_dir_adc_max = float(3.05)  # 360 degree wind dir is around 3 volts
current_time = time.time()
temp = None
rh = None
precip_pulse_start_time = 0
precip_pulse_stop_time = 0

# ------------------CONFIGURATION--------------------------
# pressure
pres_mode = 1  # (0 ultralow power, 1 std, 2 high res, 3 ultrahigh res)
bmp = BMP085(0x77, pres_mode)  # BMP085 and BMP180 are identical

# Solar
solar_channel = 4
solar_multi = 5113  # taken from calibration at work

# Wind speed
wind_10m_multiplier = float(4.02336) / float(8)  # km/h
wind_10m_GPIO_port = 22

# Wind Direction
wind_dir_channel = 0
wind_dir_offset = 171  # Degrees to rotate CC to equal actual direction.

# Lightning Sensor
GPIO.setmode(GPIO.BCM)
sensor = RPi_AS3935(address=0x03, bus=1)
sensor.calibrate(tun_cap=0x0F)
sensor.set_indoors(False)
sensor.set_noise_floor(0)
lightning_port = 23   #   

# Precipitation
precip_port = 27
precip_multi = 0.0254  # Centimeters per tip

# ------------------END OF CONFIGURATION --------------------

# Configure the GPIO for the RPi
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(17, GPIO.OUT)  # Rain activity (Blue)
GPIO.setup(18, GPIO.OUT)  # Status activity (green)
GPIO.setup(wind_10m_GPIO_port, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(lightning_port, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(precip_port, GPIO.IN, pull_up_down=GPIO.PUD_UP)

# Open spi port to ADC
spi = spidev.SpiDev()
spi.open(0, 0)  # 12bit ADC MCP3208
spi.max_speed_hz = (500000)


# Function that counts pulses from 10m wind sensor
def callback_windsp_10m(channel):
    global wind_pulse_cnt
    wind_pulse_cnt += 1


# Function that counts rain
def callback_precip(channel):

    global precip_pulse_cnt
    #precip_pulse_cnt = precip_pulse_cnt + 1  # each tip 1/100 inch
    f = open('/home/weewx/bin/rain.log', 'a')
    datetime = strftime("%Y-%m-%d %H:%M:%S ", localtime())
    f.write(datetime + ' Precip detected 0.01 \n')
    f.close()

    # turn off precip until error fixed. Make sure to turn it on below as well
    precip_pulse_cnt = 0

# Function that counts lightning strikes
def handle_interrupt(channel):
    time.sleep(0.003)
    global sensor
    reason = sensor.get_interrupt()
    f = open('/home/weewx/bin/lightning', 'a')
    datetime = strftime("%Y-%m-%d %H:%M:%S", localtime())
    if reason == 0x01:
        f.write(datetime + ': Noise level too high - adjusting \n')
        sensor.raise_noise_floor()  # Too much noise adjust
    elif reason == 0x04:
        f.write(datetime + ': Masking disturber\n')
        sensor.set_mask_disturber(True)  # Masking disturber
    elif reason == 0x08:
        f.write(
            datetime + ': Storm is ' +
            sensor.get_distance() + ' miles away!\n')
        global lightning_cnt, distance_sum
        GPIO.output(17, True)
        distance_sum = distance_sum + sensor.get_distance()
        lightning_cnt = lightning_cnt + 1
        GPIO.output(17, False)
    else:
        f.write(datetime + 'Called but nothing to do\n')
    f.close()

# monitor GPIO for pulses from wind sensor
GPIO.add_event_detect(wind_10m_GPIO_port,
                      GPIO.FALLING,
                      callback=callback_windsp_10m,
                      bouncetime=1)

# Monitor GPIO for lightning
GPIO.add_event_detect(lightning_port,
                      GPIO.FALLING,
                      callback=handle_interrupt)

# Monitor GPIO for Rain
GPIO.add_event_detect(precip_port,
                      GPIO.FALLING,
                      callback=callback_precip,
                      bouncetime=300)


# function to get data from SHT25.
def get_sfc_temprh():
    # Sample temp/rh ever 2 seconds. Alternate measurements.
    global temp, rh
    if (math.floor(time.time()) % 2) == 0:
        temp = sht21.SHT21(1).read_temperature()
    else:
        rh = sht21.SHT21(1).read_humidity()
        if (rh > 100):
            rh = 100

    return temp, rh


# Function to get data from Pressure sensor
def get_sfc_pres():
    global bmp
    if bmp:
        pres = bmp.readPressure()
        pres = (pres / float(100))  # Converts to hPa
    else:
        pres = None
    return pres


# Function to get data from Solar Sensor
def get_solar():
    # Single ended measurement
    samples = 100
    value_sum = 0
    for i in range(0, samples):
        r2 = spi.xfer2([6 + (solar_channel >> 2), (solar_channel & 3) << 6, 0])
        adcout2 = ((r2[1] & 15) << 8) + r2[2]
        value_sum = adcout2 + value_sum
    value_avg = float(float(value_sum / samples))
    solar = round(float(value_avg) / (4095) * float(3.3) *
                  float(solar_multi), 1)
    if solar < 5:
        solar = 0

    return solar


# Function to get data from Rain Gauge
def get_precip():
    global precip_pulse_cnt
#    precip = precip_pulse_cnt * precip_multi
#    precip_pulse_cnt = 0
    precip = None   
    return precip


# Function to get data from Wind Speed Sensor
# Wind speed sends 8 pulses per revolution. Time is need to complete
# calculations. Normally this is one second but delays in program
# run time can change that. We use wind_end_time and wind_start_time
# to correctly get the time inverval between obs.
def get_10m_wind_speed():
    global wind_pulse_cnt
    global wind_start_time
    global peak_3s_wind
    wind_end_time = time.time()
    wind_speed = ((wind_pulse_cnt * wind_10m_multiplier) /
                  (wind_end_time - wind_start_time))
    wind_pulse_cnt = 0  # reset counter
    wind_start_time = wind_end_time  # Reset timer for winds
    peak_3s_wind.insert(0, wind_speed)
    if len(peak_3s_wind) == 4:
        peak_3s_wind.pop()
    avg_peak_wind = 0
    for peak_wind in peak_3s_wind:
        avg_peak_wind = avg_peak_wind + peak_wind
    avg_peak_wind = float(avg_peak_wind / len(peak_3s_wind))
    return wind_speed, avg_peak_wind


# Function to get data from Wind Vane Sensor
def get_10m_wind_dir():
    global wind_dir_adc_min, wind_dir_adc_max
    # single-ended measurement see mcp3208_test for differental code
    r1 = spi.xfer2([6 + (wind_dir_channel >> 2),
                   (wind_dir_channel & 3) << 6,
                   0])
    adcout1 = float(((r1[1] & 15) << 8) + r1[2]) / float(4095) * 3.3

    # This dynamically changes the range of the sensor since it might change.
    f = open('/home/weewx/bin/wind_adjustment.txt', 'a')
    datetime = strftime("%Y-%m-%d %H:%M:%S", localtime())
    if adcout1 < wind_dir_adc_min:
        wind_dir_adc_min = adcout1
        data = "%s Wind adc min changed to : %.2f\n" % (datetime, adcout1)
        f.write(data)
    if adcout1 > wind_dir_adc_max:
        wind_dir_adc_max = adcout1
        data = "%s Wind adc max changed to : %.2f\n" % (datetime, adcout1)
        f.write(data)
    f.close()
    wind_dir = round(float((adcout1 - wind_dir_adc_min) /
                     float(wind_dir_adc_max - wind_dir_adc_min)) *
                     float(360), 0)

    # Apply offset
    wind_dir = wind_dir + wind_dir_offset
    if wind_dir > 360:
        wind_dir = wind_dir - 360

    return wind_dir


# Function to monitor for lightning
def get_lightning():
    global lightning_cnt
    count = lightning_cnt
    lightning_cnt = 0
    global distance_sum
    if count > 0:
        storm_distance = float(distance_sum / count)
    else:
        storm_distance = 0
    distance_sum = 0
#   count = None
#   storm_distance = None
    return count, storm_distance


# Function to get RPi's temperature
def get_pi_temp():
    f = open('/sys/class/thermal/thermal_zone0/temp', 'r')
    input = f.readline()
    if input:
        system_temp = float(input) / 1000
    else:
        system_temp = None
    return system_temp


# Main Program. Sample all the sensors and created data file.
# This data file can then be picked up by ingester (WEEWX)
while True:
    GPIO.output(18, True)  # turn led status light on.
    GPIO.output(17, False)  # turn lightning status light off.
    # Get time
    start_time = time.time()
    datetime = strftime("%Y-%m-%d %H:%M:%S", localtime())

    # Get Temperature and Humidity
    temperature_sfc, humidity_sfc = get_sfc_temprh()
    # Get Pressure
    pressure_sfc = get_sfc_pres()
    # Get Wind Direction
    winddir_10m = get_10m_wind_dir()
    # Get wind speed and three second peak. (WMO standard)
    windspd_10m, windspd_peak_10m = get_10m_wind_speed()
    if windspd_10m < 0.01:  # Wind speed is zero
        winddir_10m = None
    # Get Solar
    solar_sfc = get_solar()
    # Get Precip
    precip_sfc = get_precip()
    # Get Lightning Data
    total_lightning, lightning_distance = get_lightning()
    # Get System temperature
    system_temp = get_pi_temp()

    # Get End Times and calculate program pause to next collection
    end_time = time.time()
    proc_time = round(end_time - start_time, 4)
    if (proc_time > 1) or (math.ceil(end_time) > math.ceil(start_time)):
        sleep_time = 0 
    else:
        sleep_time = math.ceil(end_time) - end_time

#   Build data string
    data = "%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s\n" % (
           datetime, pressure_sfc, windspd_10m,
           winddir_10m, temperature_sfc, humidity_sfc,
           precip_sfc, total_lightning, lightning_distance,
           solar_sfc, proc_time, system_temp, windspd_peak_10m)
    filename = time.strftime("%Y-%m-%d")

#   Write data to archive
    log = open('/home/weewx/data/' + filename + '.csv', 'a')
    log.write(data)
    log.close()

#   Write current data
    log2 = open('/home/weewx/bin/wxdata.csv', 'w')
    log2.write(data)
    log2.close()

    GPIO.output(18, False)  # turn led status light off
    time.sleep(sleep_time)  # Sleep until beginning of next second


Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: thorn on June 10, 2015, 09:27:11 PM

Thanks weathernick. I kind of got it working using the file parse code in Weewx. I just check it (count pulses) every 20 secs, but I get a "kernel:[18311.296290] Disabling IRQ #49" error and it goes to 2mph always. After a reboot all is well for a day or so. All the other sensors work fine.  I couldn't find much about it searching Google.  I'll take a look at your code to see if it there's something I'm doing to cause my error. I still need to hook up the rain gauge. I'm in the middle of moving to a better location from my temp one. I do notice I get "downward" spikes on temp and humidity. It will record 32F for a low when it didn't get below 60F. I'm not sure if it's the sensor or my code, it happens on the humidity side of the same sensor.

Thanks again for posting the code!
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: geofb13 on June 11, 2015, 07:22:34 AM
I do notice I get "downward" spikes on temp and humidity. It will record 32F for a low when it didn't get below 60F. I'm not sure if it's the sensor or my code, it happens on the humidity side of the same sensor.

There are two issues that I know of with the AM2315's (or actually any of the versions from them): one of them is that like most cheap sensors there are malfunctioning issues that apparently send out spikes in the signal and thus the data. The second issue is with the timing which if off can give you the random drops or spikes in the temperature and humidity. I've had issues myself with the second one especially if the sensor is reading at a more continuous rate and it only ever seemed to happen after a certain length of time doing it. Hopefully Nick can give you more insight when he responds if he's had any issues but I just wanted to throw in my own two cents with what I've experienced.
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: thorn on June 12, 2015, 05:41:36 PM

There are two issues that I know of with the AM2315's (or actually any of the versions from them): one of them is that like most cheap sensors there are malfunctioning issues that apparently send out spikes in the signal and thus the data. The second issue is with the timing which if off can give you the random drops or spikes in the temperature and humidity. I've had issues myself with the second one especially if the sensor is reading at a more continuous rate and it only ever seemed to happen after a certain length of time doing it. Hopefully Nick can give you more insight when he responds if he's had any issues but I just wanted to throw in my own two cents with what I've experienced.


Thanks. I'll have to experiment with taking 2 readings and if one is way off ignore it. I did order a couple extras, the AM2301, from ebay. I can try to see if it is better. 

Thanks for the help.
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: Josiah on June 12, 2015, 06:20:26 PM
If your going to experiment with taking 2 readings, Why don't you take 3 then you can compare all 3 to each other and have a better idea of which 1, if any are off.
e.g. if you get these with 2 readings:
Reading A: °72
Reading B: °78

You may be able to tell which one is off by comparing them to previous readings. But if you take 3, you could then compare them to each other and get a more definitive idea on which one (if any) are incorrect.
So, in the above example if you took a third and got °73 so you now have:
Reading A: °72
Reading B: °78
Reading C: °73

You can see that readings A and C are close, meaning that B is almost certainly incorrect.

Just wanted to throw this out there.
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: weathernick on June 12, 2015, 11:04:29 PM
Man I so wanted that AM2315 sensor to work... but in the end the humidity failed and I ended up replacing it with a SHT25. Got the sensor from http://www.embeddedadventures.com/sht25_humidity_temperature_sensor_MOD-1018.html since it had the extremely small sensor on a break out board. Good luck with the AM2315 but keep in mind that it is a squirrelly sensor and it may never really work for you. The SHT sensor are those found in the Davis weather station so they are great sensors. Ok I will get off my sensor soapbox...

Nickolas
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: thorn on June 13, 2015, 12:23:50 PM
Man I so wanted that AM2315 sensor to work... but in the end the humidity failed and I ended up replacing it with a SHT25. Got the sensor from http://www.embeddedadventures.com/sht25_humidity_temperature_sensor_MOD-1018.html since it had the extremely small sensor on a break out board. Good luck with the AM2315 but keep in mind that it is a squirrelly sensor and it may never really work for you. The SHT sensor are those found in the Davis weather station so they are great sensors. Ok I will get off my sensor soapbox...

Nickolas

I'll try taking 3 readings like Josiah suggested and see what happens. If that doesn't work, I'll replace it with one like yours.

Here's a SHT21 for $7 :http://www.ebay.com/itm/SHT21-Digital-Humidity-And-Temperature-Sensor-Module-Replace-SHT11-SHT15-/200941266522?pt=LH_DefaultDomain_0&hash=item2ec908665a

Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: sroof on June 19, 2015, 11:30:17 AM
Greetings from a new user here!
Very impressive project and great discussion in this forum thread!
I’ve been managing a Campbell Scientific weather station for over 10 years.  Now I’d like to send its data to Weather Underground using a Raspberry Pi and custom Python code.  I have studied the Wunderground PWS Upload Protocol site but have some questions on formatting the data for uploading.   Since many of you have experience with the nitty-gritty data formatting, I’m hoping you can provide some help.

My first question, is there another helpful online forum for Wunderground PWS users, particularly those using custom weather stations?

My specific data formatting questions:

Can I upload data in metric units?  (doesn’t look like it, but sure would be nice!)

For precipitation, I was expecting to upload the interval precipitation, i.e., accumulation since the last data upload.  However, “rainin” is described as “rain inches over the past hour” and “the accumulated rainfall in the past 60 min”.  So it seems “rainin” must be just used to report precip rate, right?  And the “dailyrainin” is used for totalizing precipitation?

Can I upload snow depth? (there’s no field listed for snow depth, but it shown for some PWS)

Finally, is there a way to edit or delete entries that have already been uploaded to a PWS?

Many thanks!
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: nincehelser on June 19, 2015, 12:17:04 PM
Greetings from a new user here!
Very impressive project and great discussion in this forum thread!
I’ve been managing a Campbell Scientific weather station for over 10 years.  Now I’d like to send its data to Weather Underground using a Raspberry Pi and custom Python code.  I have studied the Wunderground PWS Upload Protocol site but have some questions on formatting the data for uploading.   Since many of you have experience with the nitty-gritty data formatting, I’m hoping you can provide some help.

My first question, is there another helpful online forum for Wunderground PWS users, particularly those using custom weather stations?

My specific data formatting questions:

Can I upload data in metric units?  (doesn’t look like it, but sure would be nice!)

For precipitation, I was expecting to upload the interval precipitation, i.e., accumulation since the last data upload.  However, “rainin” is described as “rain inches over the past hour” and “the accumulated rainfall in the past 60 min”.  So it seems “rainin” must be just used to report precip rate, right?  And the “dailyrainin” is used for totalizing precipitation?

Can I upload snow depth? (there’s no field listed for snow depth, but it shown for some PWS)

Finally, is there a way to edit or delete entries that have already been uploaded to a PWS?

Many thanks!

It's english-only units as far as I know.  I haven't seen any metric parameters published.

Rainin is used to compute a rain rate.  There wouldn't be much of a reason for it otherwise.

No idea on snow depth.  I haven't seen a published parameter for that, either.

You can delete entries from wunderground by looking up your station and looking at the table data.  From there you can delete bad data.

Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: weathernick on July 14, 2015, 11:37:45 PM
One year update on my station.
- Finally fixed the precipitation error where a lightning strike would cause interference and give me 100 tips in a few seconds. The solution is to build an Resistor Capacitor filter (RC filter, or low level filter). I got the specs here: http://www.wetter-garching.de/howto.html (http://www.wetter-garching.de/howto.html)

- Temperature/humidity sensor and the FARS has been solid for about 10 months ever since I switched to the SHT sensor.

- Wind direction sensor developed a crack that allowed water to enter the electronics and fried it twice. Isolated the problem and repaired. In the process raised the sensor to 10 meters.

- Solar sensor has worked flawlessly. No issues.

- Pressure sensor has also worked flawlessly.

-  Lightning sensor still doesn't work but the filter I build for precip might also help it out as well...

-  Two web cameras have been added . One usb camera to the original station and a second HD Raspberry pi camera in an enclosure. Timelapse video can be viewed on my youtube channel. https://www.youtube.com/channel/UC2X3uvFF1hiKrTccpNh_2VQ/feed (https://www.youtube.com/channel/UC2X3uvFF1hiKrTccpNh_2VQ/feed)

-  The raspberry pi weather station has been online 99.4% of the time this year. Most of that was associated with fixes to the wind sensor.

Now time for some updated pics:

(http://i89.photobucket.com/albums/k240/Nickolas_McColl/IMG_1722_zps5zbixznf.jpg)

(http://i89.photobucket.com/albums/k240/Nickolas_McColl/IMG_1720_zpspaoukgee.jpg)

(http://i89.photobucket.com/albums/k240/Nickolas_McColl/IMG_1714_zpsvuokjzhe.jpg)

(http://i89.photobucket.com/albums/k240/Nickolas_McColl/IMG_1721_zpsayzm0qmu.jpg)

(http://i89.photobucket.com/albums/k240/Nickolas_McColl/IMG_1711_zpsyrn4dmok.jpg)

(http://i89.photobucket.com/albums/k240/Nickolas_McColl/IMG_1710_zpsivkfanlc.jpg)
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: thorn on July 15, 2015, 10:59:02 AM
That looks nice! Thanks for the update.

I was able to get the temp/hum readings without spikes from the AM2315 just comparing 2 readings in a while loop. The ebay ones were really bad, almost every reading was way off, 3,000% humidity at times. I did order a SHT21.

I am experimenting with a couple of UV sensors. One from Adafruit which works well and one like the light sensor:

http://www.ebay.com/itm/REYAX-UVI-01-Ultraviolet-rays-detector-UVI-UV-sensor-/180846474255

I just have to figure out how to mount them outdoors.

I lost a channel from my Adafruit ADC, I'm not sure what happened, static? I just switched to another, there are 4 on it. I would get the same voltages even with nothing on it.

Greg
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: Red Dragon on August 14, 2015, 12:34:44 AM
I'm planning on building my own weather station too once I get the money for it. I'm thinking of using the Arduino Yún instead of the Raspberry Pi. What do you guys think?
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: weathernick on August 14, 2015, 11:04:10 AM
I'm planning on building my own weather station too once I get the money for it. I'm thinking of using the Arduino Yún instead of the Raspberry Pi. What do you guys think?

Personally I love the raspberry pi and now with the raspberry pi 2 out for only 35 dollars you can't go wrong.  But here are some pros and cons for each system as I see them. Note this is not an extensive list and really depends on what you are trying to do in the end.

Raspberry Pi Pros:
- Fully blown linux OS onboard. Whatever you can do on your desktop you can do here. Example, I connected my old usb webcam for a sky cam via the usb port.
- Cost 42 dollars on Amazon.
- The RPi 2 has quad core processing and clams to be 6 times faster than the old RPi. I can do a heck of a lot with my single core. Quad core should be fantastic!
- Creating programs in Python is very easy and there are plenty of examples.
- Has a camera port. Spend $25 and you can get a camera module that gives you HD video. It uses the GPU for processing so there is very little overhead.
- Has 40 GPIO ports. Some of these ports are used for digital comms like SPI and I2C but the rest are your normal digital pulse input/output. You can measure pulses from a tipping rain gauge, a wind speed sensors, or anything else that sends a 3.3v signal. Also you can drive LEDs via these ports.

Raspberry Pi Cons:
- No Wifi. Might not be a big deal but for me I use wifi for everything so I need to buy usb wifi adapters everything I buy a RPi.
- No ADC. If you are measuring analog signal which you most likely will with a weather station you will need to add a ADC board to the Raspberry Pi. Not hard to do but again another expense.
- Not a realtime system. Because it is running linux you won’t have realtime access to the CPU. There are ways around this if you really need it but normally having to wait a few ms on a measurement because Linux is doing something else isn’t bad.

Arduino Yun Pros:
- Intergraded solution. It has ADC ports, Digital ports and Wifi all wrapped up in one package.
- User community is extensive. I noticed this while looking for stuff for the Raspberry pi. There are plenty of examples to do anything with an Arduino.
-Arduino Yun Cons:
- Its ADC is only 10 bits which means it can only resolve 1024 points. This might not be a problem unless you are trying to measure something low power or want high precision. For me I measure voltage from my Pyranometer which needs the extra precision from a 12bit ADC.
- It looks like the Arduino Yun is running linux on it as well. Arduino are normally known for their realtime access. Looks like you would lose that here.

Of course I am a RPi user so I know a lot more about that system than Arduino. With that said, part of building weather stations is the joy of learning something new and having fun. You can easily build a weather station with the Arduino just as you can with the Raspberry pi or Intel Galileo or any other embedded linux board. Take my information with a grain of salt and remember to post your results here so we can see all the cool stuff you end up doing.

Nickolas 
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: Bushman on August 14, 2015, 11:38:06 AM
Looks like a bit of an All-in-one (wifi etc.)  Interesting.  The RPi of course is a bit more standalone - HDMI out etc. plus there are currently a zillion accessories for it.  But the YUN does look interesting...  I suspect it would make a really nice remote wx station.
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: Red Dragon on August 14, 2015, 03:47:04 PM
I was thinking of using it because I plan to use lots of sensors both analog and i2c and the Arduino has all that built in. How many i2c devices can I have connected?
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: weathernick on August 14, 2015, 04:06:33 PM
I was thinking of using it because I plan to use lots of sensors both analog and i2c and the Arduino has all that built in. How many i2c devices can I have connected?

i2c sensors are digital sensors that have unique ids attached to them. You connect them all up to the same port and the device (RPi or Aduinio) will query that device. I forgot how many devices you can have but  it is a lot( >32). the issue of course is that you can only query one device at a time. I have three I2c devices, pressure, lightning sensor and temp/rh. I only sample them every second so I have plenty of time to do all three... If you are going to do high frequency on a large number of sensors then this isn't going to work for you. I believe i2c works the same on both systems.

If you are going to do a lot of analog sensors and the 10bit resolution is ok for you then the Arduino might be your better choice. Adding analog ports to the RPi can cost up to 10 dollars per 8 channels. You could be cheap and build your own board and use the MCP3208 which cost like 4 dollars but extra skill is required for that.

Nickolas
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: thorn on August 15, 2015, 08:59:52 AM
I'm planning on building my own weather station too once I get the money for it. I'm thinking of using the Arduino Yún instead of the Raspberry Pi. What do you guys think?

The one problem I am having is that the Pi gives me an error and the wind sensor reads 2 mph until I reboot.

"kernel:[376818.053540] Disabling IRQ #49"

It was happening ever few days but it has been over a week now.  Very odd. I have not found much about it online.
I may swap out the Pi with another to see if that fixes it.

Greg
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: weathernick on August 15, 2015, 02:53:41 PM
Greg, How is your system configured? Are you using python to read the port? If so what modules are you using to read the GPIO port.

A search on the internet shows that this could be a driver problem or perhaps a module problem. I would rule out software before going to hardware.

I can assist where i can. Do you have code?
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: thorn on August 15, 2015, 03:28:45 PM
Greg, How is your system configured? Are you using python to read the port? If so what modules are you using to read the GPIO port.

A search on the internet shows that this could be a driver problem or perhaps a module problem. I would rule out software before going to hardware.

I can assist where i can. Do you have code?



Hi, thanks. I am using python. I'll try to attached it. I have a copy of your code you had posted before, but I have not had much time to look at it and compare. I'm just letting weewx call the script every 20 seconds, so it could miss wind gusts etc. I'm using the weewx fileparse module.

I still need to add the code for my rain gauge.  I did get those better quality temp sensors also, I just need to wire it up to the Pi.  Which I may try to do this weekend. I made a simple radiation shield out of a couple of yogurt cups for now. I also have a UV sensor and I got some Teflon sheets to make a housing for it. I'm just using the radiation value for UV for now. Thanks, Greg

My wind code is :

####### Wind speed
count = 0
GPIO.setmode(GPIO.BCM)     # set up BCM GPIO numbering
GPIO.setup(18, GPIO.IN)    # set GPIO18 as input


# Define a threaded callback function to run in another thread when events are detected
def my_callback(channel):
    global count
   # print GPIO.input(channel)
    if GPIO.input(18):     # if port 25 == 1
       # print "Rising edge detected"
        count = count +1

windspeed = 0
conversion = 1
factor = 0.31
count = 0

GPIO.add_event_detect(18, GPIO.BOTH, callback=my_callback)

try:
    start = time.time()
    delay = 4
    sleep(delay)         # wait
    stop = time.time()
    timeI = stop - start
    #print ' time = ' + str(timeI)
    finalcount = count

    rev = finalcount/timeI/8
    rev2 = finalcount/timeI
    windspeed = (rev2 * 0.31)
#    print 'count='+ str(finalcount)
#    print 'total revolutions = ' +str(finalcount/8)
#    print 'revolutions per sec= ' +str(rev)
#    print " wind speed = %.3f mph" % (windspeed)

finally:                   # this block will run no matter how the try block exits
      GPIO.cleanup()         # clean up after yourself


Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: thorn on August 15, 2015, 03:29:40 PM
Here's the whole script file.
Thanks, Greg
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: weathernick on August 15, 2015, 04:56:26 PM
Greg,

I am not sure exactly how you run it but is it possible weewx is running this script back to back. If this script is currently running and weewx summons it again it will fail because the GPIO ports will be in use from the first script.

Running your script once at start up and having it loop every 20 seconds via a while loop would only initiate the hardware once and might fix your IRQ issues.

I like the fact you detect rising and falling pulses and then check its status to verify the pulse is real. This is a software filter that I just added to my code to increase its robustness. You will need such code for your precip sensor. Great minds must think alike.

The more I am thinking of your problem the more I am thinking your script is not the problem. Do you have wifi? How much power can your power supply give? I had problems with mine until I got to 2Amp output on my supply. Of course that is with a B (no plus) so it uses a lot more power than say a A+. I am thinking you check your power supply and if you have something beefier give it a shot. Also if you have a voltmeter use it to measure the 5 volt rail on the raspberry pi. You should be around 4.8v or higher when the system is running.
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: thorn on August 15, 2015, 05:45:20 PM
Greg,

I am not sure exactly how you run it but is it possible weewx is running this script back to back. If this script is currently running and weewx summons it again it will fail because the GPIO ports will be in use from the first script.

Running your script once at start up and having it loop every 20 seconds via a while loop would only initiate the hardware once and might fix your IRQ issues.

I like the fact you detect rising and falling pulses and then check its status to verify the pulse is real. This is a software filter that I just added to my code to increase its robustness. You will need such code for your precip sensor. Great minds must think alike.

The more I am thinking of your problem the more I am thinking your script is not the problem. Do you have wifi? How much power can your power supply give? I had problems with mine until I got to 2Amp output on my supply. Of course that is with a B (no plus) so it uses a lot more power than say a A+. I am thinking you check your power supply and if you have something beefier give it a shot. Also if you have a voltmeter use it to measure the 5 volt rail on the raspberry pi. You should be around 4.8v or higher when the system is running.

I had it outside with a wifi dongle but it would disconnect once in a while. I moved it inside and ran wires from the sensors. So it's hooked up directly. I have a 2amp power supply and I checked the voltage a while back, if I remember, it was 5.0v. This one is a Pi 2.

When it gives the error the other sensors work fine, just the wind speed.  I have a couple of other Pis that have cameras on for security and the only problems I had with them were cheap cards that failed after a couple of months.

I still wonder if the add_event_detect and clean up being called all the time would cause trouble? Vs a while loop running all the time like you have?

Thanks for the help.

Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: thorn on August 15, 2015, 08:42:08 PM


My AdaFruit ADC stopped working.  :-( All I did was look to see where I need to hook up my new temp/hum sensor and turn the Pi back on. I posted something on the Adafruit forum. I had lost one channel a couple of months ago. I just unsolder from the one to a working one since there are 4 channels. But now,"Error accessing 0x48: Check your I2C address" . Using i2cdetect command it's not there.  I had bought a spare to play with but I have to remove it from the board.

Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: weathernick on August 16, 2015, 12:35:14 AM


My AdaFruit ADC stopped working.  :-( All I did was look to see where I need to hook up my new temp/hum sensor and turn the Pi back on. I posted something on the Adafruit forum. I had lost one channel a couple of months ago. I just unsolder from the one to a working one since there are 4 channels. But now,"Error accessing 0x48: Check your I2C address" . Using i2cdetect command it's not there.  I had bought a spare to play with but I have to remove it from the board.

Well that isn't good. Perhaps that was causing your problems with the wind speed as well? Either way I have had adafruit replace bad hardware before. They are very good and stand behind what they sell. Sounds like you got a bad board.
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: thorn on August 16, 2015, 08:24:38 AM

Well that isn't good. Perhaps that was causing your problems with the wind speed as well? Either way I have had adafruit replace bad hardware before. They are very good and stand behind what they sell. Sounds like you got a bad board.

I'm not sure if that was causing the wind speed problem, it is on GIPO 18 vs the ADC on I2C.  I posted in their forum and they want me to take a photo.
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: thorn on August 16, 2015, 10:09:41 AM
Strange, I took some photos and put it back together and it's working again. I wonder if I have a bad connection or something is intermittent on the breakout board?
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: TejasBob on August 22, 2015, 10:25:45 PM
Can you paste or send your current script please, Nick?  I'm trying to get my SHT25 working and am using a script I found for the SHT21.  The math seems to match but I'd like to make sure.  Also I'm curious about setting it to 12/14 bits.

Thanks.
Bob
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: weathernick on August 25, 2015, 05:24:43 PM
Can you paste or send your current script please, Nick?  I'm trying to get my SHT25 working and am using a script I found for the SHT21.  The math seems to match but I'd like to make sure.  Also I'm curious about setting it to 12/14 bits.

Thanks.
Bob

The code I posted here a little while back is current. I just noticed I called it AM2315 instead of the SHT25, typo on my part(which I corrected). The script for SHT21 is the same for SHT25. I just used a module from someone and I don't even remember who. I believe it might be this code: https://github.com/jaques/sht21_python

Also per the Datasheet the default measurement is 14(temp)/12(RH). I have no idea how to change back and forth between resolution.

Good luck with the SHT25. I have had it for almost a year outside in my FARS and it has worked flawlessly.

Nickolas
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: thorn on August 26, 2015, 08:54:09 PM
Nick, how does the rain gauge work in weewx with your station?  I see your code saves  a time stamp and a string to a log file:

# Function that counts rain
def callback_precip(channel):

    global precip_pulse_cnt
    #precip_pulse_cnt = precip_pulse_cnt + 1  # each tip 1/100 inch
    f = open('/home/weewx/bin/rain.log', 'a')
    datetime = strftime("%Y-%m-%d %H:%M:%S ", localtime())
    f.write(datetime + ' Precip detected 0.01 \n')
    f.close()

    # turn off precip until error fixed. Make sure to turn it on below as well
    precip_pulse_cnt = 0



 I'm using fileparse with weewx. Does weewx figure out a new rain gauge tip/event based on the time stamp?

My Davis wind sensors stopped working, I'll have to open it up to see what's going on, it's more than 10 years old. At least my DIY works until I get that error.

Thanks, Greg
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: weathernick on August 26, 2015, 10:53:32 PM
Nick, how does the rain gauge work in weewx with your station?  I see your code saves  a time stamp and a string to a log file:

# Function that counts rain
def callback_precip(channel):

    global precip_pulse_cnt
    #precip_pulse_cnt = precip_pulse_cnt + 1  # each tip 1/100 inch
    f = open('/home/weewx/bin/rain.log', 'a')
    datetime = strftime("%Y-%m-%d %H:%M:%S ", localtime())
    f.write(datetime + ' Precip detected 0.01 \n')
    f.close()

    # turn off precip until error fixed. Make sure to turn it on below as well
    precip_pulse_cnt = 0



 I'm using fileparse with weewx. Does weewx figure out a new rain gauge tip/event based on the time stamp?

My Davis wind sensors stopped working, I'll have to open it up to see what's going on, it's more than 10 years old. At least my DIY works until I get that error.

Thanks, Greg

Well it looks like I posted my code with the rain sensor commented out. I had a heck of a time getting precip to work because it uses the GPIO port which turns out to be very sensitive to lightning and other sources of interference.

The code should read like this:

# Function that counts rain
def callback_precip(channel):

    global precip_pulse_cnt
    precip_pulse_cnt = precip_pulse_cnt + 1  # each tip 1/100 inch
    f = open('/home/weewx/bin/rain.log', 'a')
    datetime = strftime("%Y-%m-%d %H:%M:%S ", localtime())
    f.write(datetime + ' Precip detected 0.01 \n')
    f.close()

    # turn off precip until error fixed. Make sure to turn it on below as well
    #precip_pulse_cnt = 0


I timestamp it because I have other debug code to help me figure out the noise problem I was having. You could simpify the code to read like this:

# Function that counts rain
def callback_precip(channel):

    global precip_pulse_cnt
    precip_pulse_cnt = precip_pulse_cnt + 1  # each tip 1/100 inch[\i]

So the logic is as such:
1.) rain tips the bucket and closes the circuit
2.) The closed circuit is a pulsed measured by the GPIO port.
3.) The code is set to trigger the callback_precip funtion on every tip.
4.) Ever second, the code counts how much rain has fell and resets the counter to 0
5.) The code outputs a one second loop file that gets read by weewx.

Hope that helps.

Nickolas
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: Red Dragon on August 27, 2015, 09:44:27 PM
I found a article about how to increase the sampling bits for the adc on the Ardiuno by using oversampling. http://www.electricrcaircraftguy.com/2014/05/using-arduino-unos-built-in-16-bit-adc.html
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: thorn on August 28, 2015, 08:23:51 AM

So the logic is as such:
1.) rain tips the bucket and closes the circuit
2.) The closed circuit is a pulsed measured by the GPIO port.
3.) The code is set to trigger the callback_precip funtion on every tip.
4.) Ever second, the code counts how much rain has fell and resets the counter to 0
5.) The code outputs a one second loop file that gets read by weewx.

Hope that helps.

Nickolas

Thanks Nicolas. I need to look at the weewx loop code for rain. I'm still not sure how that works. If it gets set to 0 too early will weewx miss the event?

Greg
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: weathernick on August 28, 2015, 05:08:24 PM

So the logic is as such:
1.) rain tips the bucket and closes the circuit
2.) The closed circuit is a pulsed measured by the GPIO port.
3.) The code is set to trigger the callback_precip funtion on every tip.
4.) Ever second, the code counts how much rain has fell and resets the counter to 0
5.) The code outputs a one second loop file that gets read by weewx.

Hope that helps.

Nickolas

Thanks Nicolas. I need to look at the weewx loop code for rain. I'm still not sure how that works. If it gets set to 0 too early will weewx miss the event?

Greg


The beauty of sensors on the GPIO port is that they are monitoring via separate threads. So while my main code loops every second, wind pulses and rain pulses are measured independently. I just read the global variables every second and then set to 0 so it could start counting again. 

Nickolas
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: weathernick on August 28, 2015, 05:17:40 PM
I found a article about how to increase the sampling bits for the adc on the Ardiuno by using oversampling. http://www.electricrcaircraftguy.com/2014/05/using-arduino-unos-built-in-16-bit-adc.html

In my analog to digital code for the solar sensor you can see I pull 100 samples than average to get the result. It turns out I may have inadvertent stumbled on oversampling.

Thanks for pointing this out so I actually know what I am doing instead of guessing. I thought I was doing something wrong by having to sample so many time to get a good value (especially when the value was very small) turns out this is how it is done unless I wanted to upgrade to a 14/16bit ADC.

Nickolas
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: weathernick on September 17, 2015, 06:55:35 PM
Quote
The beauty of sensors on the GPIO port is that they are monitoring via separate threads. So while my main code loops every second, wind pulses and rain pulses are measured independently. I just read the global variables every second and then set to 0 so it could start counting again. 

Well it turns out this is a lie... Python doesn't do real threads unless you do some extra work. All code will be executed sequentially. This normally shouldn't be a problem unless you do something that ties up the CPU. The detection of GPIO pulse might be independent of the code but once it triggers the subroutine it is done sequentially. 

Turns out the RPi can sample through my code many times over per second so I am good.

Nickolas
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: Bushman on September 17, 2015, 07:56:37 PM
You got the first part right.  GIL prevents simultaneous thread execution.  But I guarantee you that you can  execute multiple threads concurrently or in parallel and it can really speed things up.  Not a big deal either.  But not what you would expect if you were say, a C++ programmer.  (Not I am talking about v3.n and up) 
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: thorn on November 12, 2015, 05:44:42 PM

The code I posted here a little while back is current. I just noticed I called it AM2315 instead of the SHT25, typo on my part(which I corrected). The script for SHT21 is the same for SHT25. I just used a module from someone and I don't even remember who. I believe it might be this code: https://github.com/jaques/sht21_python

Also per the Datasheet the default measurement is 14(temp)/12(RH). I have no idea how to change back and forth between resolution.

Good luck with the SHT25. I have had it for almost a year outside in my FARS and it has worked flawlessly.

Nickolas


My AM2315 from AdaFruiit finally failed too. So I got it working with a SHT21 and so far so good. Also, I have not seen the wind error since I did an update to the Pi. Going on 3 months. I guess they must have fixed a bug.

I did have some trouble with the AdaFruit ADC again after I added the SHT21. It gave me the same error. I moved some of the wires around and away from each other and it is OK. I don't think AdaFruit will replace it, they claim it's from "environmental damage". Most likely it is from being outside or static they said. I have it inside now and before it was in a water proof box. I guess they don't stand by their products.

Now I need to take the time to the rain bucket code to work.

Greg
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: Crannog on April 11, 2016, 04:07:14 AM
Hi,

I'm new to this forum but based on this thread I've been constructing a stand alone raspberry pi based weather station (for use in a rock on a large lake!) using my redundant Weather Wizard hardware (SHT11, platinum thermistor and wind sensors) and a spare Temp/RH Vantage Pro2 sensor. I've prototype each sensor on a bread board to test each bit of code and finally put it all together on a cut up humble pi. I've attached pictures of set-up.

I've got two problems,

1. Pi-SHT1x module (1.0.8) seems to re-set GPIO's screwing up the wind sensor and status light. (gives GPIO BCM/Board not define error) I've deleted the GPIO Cleanup in the routine but it still seems to mess up the GPIO's. Any ideas?
2. My status LED seems to barely flicker. I was wondering if it was a voltage issue. A multi meter shows 3.29V on power rail. Is it a timing issue, on too short a time? I'm concerned that a hidden voltage drop would effect readings

Any help would be greatly appreciated. I plan to include the old WWIII temperature thermistor as a lake water temperature measurement. (TEMP in picture)

After I fix the above issues I need to link to install WeeWx, link to Wunderground, install Huawei E122 for internet access away from home then size solar power and battery!

Thanks

Donall
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: weathernick on April 11, 2016, 04:19:04 PM
Welcome Donall,

Cool setup! I wish I had answers to your questions but I never ran into any issues with my temperature sensor and coding... Had enough issues elsewhere.

With that said if I saw the code for your LED I might be able to help. You did say too short of a time and that might be it. You need to delay the code for a little bit in order to get the flashing to be useful. Otherwise you may never see it on. for my setup I just turn the LED on than sample all my sensors and turn the LED off. This give is about a 50% on/off time which looks nice for a status LED.

Thanks,

Nickolas
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: Crannog on April 15, 2016, 06:52:47 PM
Thanks Nickolas, I'm trying to keep it small  :grin:

I finally got the SHT11 to work using another module. Your suggestion of a delay for LED worked great. A 10 ms delay is about right.

I can post the code if I can figure how. Working on thermistor code for the lake water temperature.

I've to figure out where to post the custom driver for the weather station. Where does Weewx pick it up for a option in the config file?

Thanks again,

Donall
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: thorn on April 15, 2016, 08:08:40 PM

I used file parse:

https://github.com/weewx/weewx/blob/master/extensions/fileparse/bin/user/fileparse.py

I couldn't find the documentation about it. I thought there was some examples.



Thanks Nickolas, I'm trying to keep it small  :grin:

I finally got the SHT11 to work using another module. Your suggestion of a delay for LED worked great. A 10 ms delay is about right.

I can post the code if I can figure how. Working on thermistor code for the lake water temperature.

I've to figure out where to post the custom driver for the weather station. Where does Weewx pick it up for a option in the config file?

Thanks again,

Donall
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: weathernick on April 16, 2016, 10:09:58 AM

I used file parse:

https://github.com/weewx/weewx/blob/master/extensions/fileparse/bin/user/fileparse.py

I couldn't find the documentation about it. I thought there was some examples.


I use a modified version of this. Good place to start. You have to look into the code and figure it out. If you need any help I am sure Thorn and myself can help you decode that fileparse.py is doing.

Nickolas
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: mwall on April 16, 2016, 08:41:25 PM

I used file parse:

https://github.com/weewx/weewx/blob/master/extensions/fileparse/bin/user/fileparse.py

I couldn't find the documentation about it. I thought there was some examples.

The fileparse extension will read any number of name=value pairs.  The comments in fileparse.py explain how to use it.

The weewx wiki has instructions for reading a file with a single value.

https://github.com/weewx/weewx/wiki/add-sensor

In either case, you will have to put the data somewhere.  The easiest approach is to use existing columns in the database schema, for example outTemp or extraTemp1.  In fileparse this is done automatically using the name part of name=value, or using the label_map if you cannot control the name.  The possible column names are listed in the schema:

https://github.com/weewx/weewx/blob/master/bin/schemas/wview.py

If you are already using all of them, or your observations use a different type of units or different type of accumulation, then you can extend the schema as explained in the weewx customization guide:

http://weewx.com/docs/customizing.htm#Adding_a_new_observation_type

Labels are applied at the presentation layer, i.e., in templates and skins.  That is where you would map 'extraTemp1' to 'Pond Temperature', for example.

m
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: Crannog on April 27, 2016, 06:19:37 PM
Thanks guys for all the help,

ILIMERIC20 is up and running on test! =D&gt; I have a "station last reported" glitch I've to figure out the reason for but so far so good. I'm thinking of putting a I2C RTC on the circuit board to improve time if it goes offline etc. I'd be interested to know what you think.

Does anyone know which soiltemp parameter displays in Wunderground? I'm trying "soilTemp1" but it does not appear on Wunderground.
 
I picked up a Pi camera which hope to add to the pi and send upload to Wunderground. Any idea of things to watch out for?
ILIMERIC17 is my home station for data comparison etc.

Thanks again,

Donall



Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: Bushman on April 27, 2016, 06:23:51 PM
WU is petty over the size of the image.  You MUST follow the guidelines.  Go over once and they drop your cam.
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: thorn on May 06, 2016, 12:46:52 PM

Well it looks like I posted my code with the rain sensor commented out. I had a heck of a time getting precip to work because it uses the GPIO port which turns out to be very sensitive to lightning and other sources of interference.

So the logic is as such:
1.) rain tips the bucket and closes the circuit
2.) The closed circuit is a pulsed measured by the GPIO port.
3.) The code is set to trigger the callback_precip funtion on every tip.
4.) Ever second, the code counts how much rain has fell and resets the counter to 0
5.) The code outputs a one second loop file that gets read by weewx.




Hi Nick, I'm finally working on the rain code. And it's been raining a lot here in the east! I have the rain code (that checks for the rain gauge interrupt) running separately (while loop) and it writes a '1' to a file. My loop code which I have run every 20 sec called by fileparse will read in the file and count the '1's and then reset the file. The weewx parsefile code then reads in that file that it generated with all the wx data.

I wonder if that's a OK way to do it?

They only problem is the forever loop code that watches for the rain gauge interrupt, if it dies how to restart it. cron job or something like that?

I have not had much luck with WU. I gave up on it.

Thanks, Greg
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: weathernick on May 09, 2016, 12:50:14 PM
Hi Nick, I'm finally working on the rain code. And it's been raining a lot here in the east! I have the rain code (that checks for the rain gauge interrupt) running separately (while loop) and it writes a '1' to a file. My loop code which I have run every 20 sec called by fileparse will read in the file and count the '1's and then reset the file. The weewx parsefile code then reads in that file that it generated with all the wx data.

I wonder if that's a OK way to do it?

They only problem is the forever loop code that watches for the rain gauge interrupt, if it dies how to restart it. cron job or something like that?

I have not had much luck with WU. I gave up on it.

Thanks, Greg
My precipitation code has changed so much it isn't even funny. The way you are doing it I believe will work. (I am assuming you have tested it with manual tips). The only issue I had was the RPi GPIO ports are so sensitive that during thunderstorms I would get some extra pulses. So if you get extra tips here is how I fixed it.
1.) Enclose the RPi in a metal box. This acts like a Faraday's cage and helps cut down on the noise. I saw an order of magnitude decrease in noise by doing this.
2.) Add RC (Resistor Capacitor) filter to the input line just before the GPIO pin. This will help smooth the data and give cleaner pulses.
3.) Finally for the last 1% of noise, I did a software filter. I added code to check the status of the GPIO port. I found I could ping the port about every 5ms with my code. This means I don't use events anymore.  Turns out my Precip can will produce a 80ms pulse per tip, but lightning will produce a <5ms pulse. When I check the port and see it is currently high I start recording the number of 5ms checks that show the port high. If it is lightning then when I check it again after 5ms I will see it is low and will disregard the pulse. If I check the port 16 times (80ms) and 8 of them are high than I call that a good pulse and mark it as a tip. This works well if there is noise in the 80ms pulse as I only need 40ms to validate the pulse. If interested I can post that code. The big disadvantage to this software filter is it is dependent on the OS. If the OS blocks my call for a long period of time I could miss a tip. I am not sure it is happening but I at least know I am not getting any extra tips cause by lightning. (had a strike within a few miles and it did nothing)

As always this is a work in progress and your mileage may vary.

Nickolas
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: thorn on May 11, 2016, 08:53:52 PM

Thanks for the help. I always like to look at code if you feel like posting it.   :-)

I am getting some random tips during the day with no storms.  :sad: It's about 2-4 hours.  I'll have to try to do what you did. I may try the RC filter first, what values did you use for R and C. I saw someone used a 0.1 uF for a capacitor for another Pi project.  I guess R is in series and C across ground.

Thanks, Greg





My precipitation code has changed so much it isn't even funny. The way you are doing it I believe will work. (I am assuming you have tested it with manual tips). The only issue I had was the RPi GPIO ports are so sensitive that during thunderstorms I would get some extra pulses. So if you get extra tips here is how I fixed it.
1.) Enclose the RPi in a metal box. This acts like a Faraday's cage and helps cut down on the noise. I saw an order of magnitude decrease in noise by doing this.
2.) Add RC (Resistor Capacitor) filter to the input line just before the GPIO pin. This will help smooth the data and give cleaner pulses.
3.) Finally for the last 1% of noise, I did a software filter. I added code to check the status of the GPIO port. I found I could ping the port about every 5ms with my code. This means I don't use events anymore.  Turns out my Precip can will produce a 80ms pulse per tip, but lightning will produce a <5ms pulse. When I check the port and see it is currently high I start recording the number of 5ms checks that show the port high. If it is lightning then when I check it again after 5ms I will see it is low and will disregard the pulse. If I check the port 16 times (80ms) and 8 of them are high than I call that a good pulse and mark it as a tip. This works well if there is noise in the 80ms pulse as I only need 40ms to validate the pulse. If interested I can post that code. The big disadvantage to this software filter is it is dependent on the OS. If the OS blocks my call for a long period of time I could miss a tip. I am not sure it is happening but I at least know I am not getting any extra tips cause by lightning. (had a strike within a few miles and it did nothing)

As always this is a work in progress and your mileage may vary.

Nickolas
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: weathernick on May 12, 2016, 10:58:23 AM
Greg,

I designed my circuit to use 1k, 10k and 100k resistors, I would test each one with your application. I picked 10k for my finally solution. Also you are correct C is 0.1uf. Make sure you test tips to make sure you are not filtering out the tips as well as the noise.

Also I found a BBQ lighter ignite to be a great way to test if you are still getting noise.

How far away is your precipitation sensor?

Finally how about some code to look at? This is my latest creation it isn't getting simpler that is for sure.

Code: [Select]
#!/usr/bin/python
# This datalogger script is responsible for collecting meteorological
# information from the following sensors and creating a CSV ascii file
# that is read by the weewx driver (raspberry_pi).
# Installed sensors:
#  SHT25 (Temperature/Humidity sensor) [i2c]
#  BMP180 (Pressure) [i2c]
#  Pyronometer (homemade based on instesre.org design) [ADC]
#  AS3935 (Lightning sensor) [i2c]
#  wxunderweatherstation Wind direction  [ADC]
#  wxunderweatherstation Wind sensor (Optical, 8p/s) [GPIO, pulse]
#  Rainwise RAINEW 111 Tipping Bucket Rain Gauge [pulse]

# Last updated: 2015-09-18
# Created by Nickolas McColl

import math
import spidev
import RPi.GPIO as GPIO
import time
from time import strftime, localtime
from datetime import datetime
import Adafruit_BMP.BMP085 as BMP085
import sht21
import threading   # For precip counting and measuring ADC chip

# Global variables
wind_start_time = time.time()
wind_pulse_cnt = 0
peak_3s_wind = []
precip_pulse_cnt = 0
wind_dir_adc_min = float(0.32)  # Zero degree wind dir is around .1 volts
wind_dir_adc_max = float(3.1)  # 360 degree wind dir is around 3 volts
temp = None
rh = None
solar_avg = 0
wind_dir_avg = 0

# ------------------CONFIGURATION--------------------------
# pressure
bmp = BMP085.BMP085(mode=BMP085.BMP085_ULTRAHIGHRES)

# Solar
solar_channel = 4
solar_multi = float(5113)  # taken from calibration at work

# Wind speed
wind_10m_multiplier = float(4.02336) / float(8)  # km/h
wind_10m_GPIO_port = 22

# Wind Direction
wind_dir_channel = 0
wind_dir_offset = 300   # Degrees to rotate CW to equal actual direction.

# Precipitation
precip_port = 24
precip_multi = 0.0254  # Centimeters per tip

# ------------------END OF CONFIGURATION --------------------

# Configure the GPIO for the RPi
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.OUT)  # Rain activity (Blue)
GPIO.setup(18, GPIO.OUT)  # Status activity (green)

# Monitor free GPIO ports for noise.
GPIO.setup(04, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(27, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(25, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

GPIO.setup(wind_10m_GPIO_port, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(precip_port, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

# Open spi port to ADC
spi = spidev.SpiDev()
spi.open(0, 0)  # 12bit ADC MCP3208
spi.max_speed_hz = (1000000)


# Start monitoring the precip port
def precip_thread():
    global precip_pulse_cnt
    integrator = 0
    threshold = 4
    rain = False
    f4 = open('/home/weewx/bin/lowlevel_rain.log', 'a')

    while True:
        if GPIO.input(precip_port) == 1:
            # pulse detected
            integrator += 1
            f4.write(str(datetime.now()) + 'Rain?' + str(integrator) + '\n')

            # Check if threshold has been reached.
            if ((integrator >= threshold) and (not rain)):
                f4.write(str(datetime.now()) + 'Rain!' +
                         str(integrator) + '\n')
                precip_pulse_cnt += 1
                rain = True
        else:
            # No pulse detected
            if integrator > 0:
                integrator -= 1
                f4.write(str(datetime.now()) + 'Rain going away' +
                         str(integrator) + '\n')
                if integrator == 0:
                    # Event over, force file write
                    f4.flush()
            else:
                rain = False

        time.sleep(0.01)

    f4.close()


# Start the measurement on the ADC.
def adc_thread():
    global solar_avg, wind_dir_avg

    obtime = math.ceil(time.time())
    solar_sum = 0
    solar_cnt = 0
    wind_dir_sum = 0
    wind_dir_cnt = 0
    while True:
        # Sample solar analog input
        r2 = spi.xfer2([6 + (solar_channel >> 2),
                       (solar_channel & 3) << 6, 0])
        adcout2 = float(((r2[1] & 15) << 8) + r2[2]) / float(4095) * 3.3
        solar_sum = adcout2 + solar_sum
        solar_cnt = 1 + solar_cnt

        # Sample wind direction analog input
        r1 = spi.xfer2([6 + (wind_dir_channel >> 2),
                       (wind_dir_channel & 3) << 6, 0])
        adcout = float(((r1[1] & 15) << 8) + r1[2]) / float(4095) * 3.3
        wind_dir_sum = adcout + wind_dir_sum
        wind_dir_cnt = 1 + wind_dir_cnt

        # Update global variable once a second.
        if (time.time() > obtime):
            if (solar_cnt > 0):
                solar_avg = float(solar_sum / solar_cnt)
                solar_sum = 0
                solar_cnt = 0
            if (wind_dir_cnt > 0):
                wind_dir_avg = float(wind_dir_sum / wind_dir_cnt)
                wind_dir_sum = 0
                wind_dir_cnt = 0
            obtime = math.ceil(time.time())
        time.sleep(0.01)


# Counts noise
def callback_noise(channel):
    GPIO.output(17, True)
    date_time = strftime("%Y-%m-%d %H:%M:%S ", localtime())
    f3 = open('/home/weewx/bin/noise.log', 'a')
    f3.write(date_time + ' Noise detected, none sensor ports\n')
    f3.close()
    GPIO.output(17, False)


# Function that counts pulses from 10m wind sensor
def callback_windsp_10m(channel):
    global wind_pulse_cnt
    if GPIO.input(wind_10m_GPIO_port):
        wind_pulse_cnt += 1

# monitor GPIO for pulses from wind sensor
GPIO.add_event_detect(wind_10m_GPIO_port,
                      GPIO.RISING,
                      callback=callback_windsp_10m)

# Monitor GPIO for Noise. This port isn't connected to anything
GPIO.add_event_detect(04,
                      GPIO.BOTH,
                      callback=callback_noise)

# Start ADC sampling
t = threading.Thread(name='ADC', target=adc_thread)
t.setDaemon(True)
t.start()

# Start Precip monitoring
p = threading.Thread(name='PRECIP', target=precip_thread)
p.setDaemon(True)
p.start()


# function to get data from SHT25.
def get_sfc_temprh():
    # Sample temp/rh.
    global temp, rh
    temp = sht21.SHT21(1).read_temperature()
    rh = sht21.SHT21(1).read_humidity()
    if (rh > 100):
        rh = 100

    return temp, rh


# Function to get data from Pressure sensor
def get_sfc_pres():
    global bmp
    if bmp:
        pres = bmp.read_pressure()
        pres = (pres / float(100))  # Converts to hPa
    else:
        pres = None

    return pres


# Function to get data from Solar Sensor
def get_solar():
    global solar_avg
    solar = round(float(solar_avg) * float(solar_multi), 1)

    return solar


# Function to get data from Rain Gauge
def get_precip():
    global precip_pulse_cnt
    precip = precip_pulse_cnt * precip_multi
    precip_pulse_cnt = 0

    return precip


# Function to get data from Wind Speed Sensor
# Wind speed sends 8 pulses per revolution. Time is need to complete
# calculations. Normally this is one second but delays in program
# run time can change that. We use wind_end_time and wind_start_time
# to correctly get the time inverval between obs.
def get_10m_wind_speed():
    global wind_pulse_cnt, wind_start_time, peak_3s_wind

    # Calculate 1 second average wind speed.
    wind_end_time = time.time()  # Stop timer for winds
    # window for wind measurement should be 1 second but Linux
    # cant ensure that so we divide by the real interval.
    wind_speed = ((wind_pulse_cnt * wind_10m_multiplier) /
                  (wind_end_time - wind_start_time))
    wind_pulse_cnt = 0
    wind_start_time = wind_end_time  # Start timer for winds again

    # Calculate 3 second peak wind speed. WMO Standard.
    peak_3s_wind.insert(0, wind_speed)
    if len(peak_3s_wind) == 4:
        peak_3s_wind.pop()
    avg_peak_wind = 0
    for peak_wind in peak_3s_wind:
        avg_peak_wind = avg_peak_wind + peak_wind
    avg_peak_wind = float(avg_peak_wind / len(peak_3s_wind))

    return wind_speed, avg_peak_wind


# Function to get data from Wind Vane Sensor
def get_10m_wind_dir():
    global wind_dir_adc_min, wind_dir_adc_max, wind_dir_avg

    # This dynamically changes the range of the sensor since it might change.
    date_time = strftime("%Y-%m-%d %H:%M:%S", localtime())
    if wind_dir_avg < wind_dir_adc_min and wind_dir_avg > 0:
        f = open('/home/weewx/bin/wind_adjustment.txt', 'a')
        wind_dir_adc_min = wind_dir_avg
        data = "%s Adc min changed to : %.2f\n" % (date_time, wind_dir_avg)
        f.write(data)
        f.close()
    if wind_dir_avg > wind_dir_adc_max:
        f = open('/home/weewx/bin/wind_adjustment.txt', 'a')
        wind_dir_adc_max = wind_dir_avg
        data = "%s Adc max changed to : %.2f\n" % (date_time, wind_dir_avg)
        f.write(data)
        f.close()
    wind_dir = round(float((wind_dir_avg - wind_dir_adc_min) /
                     float(wind_dir_adc_max - wind_dir_adc_min)) *
                     float(360), 0)

    # Apply offset
    wind_dir = wind_dir + wind_dir_offset
    if wind_dir > 360:
        wind_dir = wind_dir - 360

    return wind_dir


# Function to get RPi's temperature
def get_pi_temp():
    f = open('/sys/class/thermal/thermal_zone0/temp', 'r')
    input = f.readline()
    if input:
        system_temp = float(input) / 1000
    else:
        system_temp = None

    return system_temp


# Main Program. Sample all the sensors and created data file.
# This data file can then be picked up by ingester (WEEWX)
proc_time = 0
while True:
    GPIO.output(18, True)  # turn led status light on.
    GPIO.output(17, False)  # turn lightning status light off.

    # Get time
    start_time = time.time()
    date_time = strftime("%Y-%m-%d %H:%M:%S", localtime())

    try:
        # Get Temperature and Humidity
        temperature_sfc, humidity_sfc = get_sfc_temprh()

        # Get Pressure
        pressure_sfc = get_sfc_pres()

        # Get Wind Direction
        winddir_10m = get_10m_wind_dir()

        # Get wind speed and three second peak. (WMO standard)
        windspd_10m, windspd_peak_10m = get_10m_wind_speed()

        # Get Solar
        solar_sfc = get_solar()
        if solar_sfc < 4:
            solar_sfc = 0

        # Get Precip
        precip_sfc = get_precip()
#       precip_sfc = None

        # Get System temperature
        system_temp = get_pi_temp()

        # Old variables that are not longer delt with inside this program
        total_lightning = None
        lightning_distance = None

        # Build data string
        data = "%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s\n" % (
           date_time, pressure_sfc, windspd_10m,
           winddir_10m, temperature_sfc, humidity_sfc,
           precip_sfc, total_lightning, lightning_distance,
           solar_sfc, proc_time, system_temp, windspd_peak_10m)
        filename = time.strftime("%Y-%m-%d")

        # Write data to archive
        log = open('/home/weewx/data/' + filename + '.csv', 'a')
        log.write(data)
        log.close()

        # Write current data
        log2 = open('/home/weewx/bin/wxdata.csv', 'w')
        log2.write(data)
        log2.close()

    except:
        log =  open('/home/weewx/station_error.log', 'a')
        text = yuma.date + 'error\n'
        log.write(text)
        log.close()





    # Get End Times and calculate program pause to next collection
    end_time = time.time()
    proc_time = round(end_time - start_time, 4)
    if (proc_time > 1) or (math.ceil(end_time) > math.ceil(start_time)):
        sleep_time = 0
    else:
        sleep_time = math.ceil(end_time) - end_time
    GPIO.output(18, False)  # turn led status light off

    time.sleep(sleep_time)  # Sleep until beginning of next second


Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: thorn on May 12, 2016, 10:49:11 PM


Nick, my rain gauge and wind sensors are about 50ft away. :-(  I had trouble with the wifi so I used some rotor cable that I'm not using to small tower I had a ham antenna on, it's under ground, to connect with the Pi which is inside. My solar and temp/humid are just outside the window.

I'll try experimenting with some different resistors. We have been getting rain almost every day here in MD so there's no problem getting tips.  :grin:

I'll take a look at your code, it looks nice and neat. thanks!

Greg

Greg,

I designed my circuit to use 1k, 10k and 100k resistors, I would test each one with your application. I picked 10k for my finally solution. Also you are correct C is 0.1uf. Make sure you test tips to make sure you are not filtering out the tips as well as the noise.

Also I found a BBQ lighter ignite to be a great way to test if you are still getting noise.

How far away is your precipitation sensor?

Finally how about some code to look at? This is my latest creation it isn't getting simpler that is for sure.

Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: Crannog on May 21, 2016, 04:18:24 AM

Thanks for all the help so far. Do you know if you can get the sunrise and sunset times into Phyton? I'd like to write some code to turn camera loop off a hour after sunset and back on a hour before sunrise. This would save power.

I've attached picture of work to date and the wiring diagram etc for anyone who's interested.

Cheers

Donall
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: weathernick on May 21, 2016, 07:54:31 AM

Thanks for all the help so far. Do you know if you can get the sunrise and sunset times into Phyton? I'd like to write some code to turn camera loop off a hour after sunset and back on a hour before sunrise. This would save power.

I've attached picture of work to date and the wiring diagram etc for anyone who's interested.

Cheers

Donall

Now that is one nice weather station! Good job. Just so happens I do have sunset and sunrise code. see below.
Code: [Select]
#!/usr/bin/env python
import ephem
import time
from datetime import datetime, date

yuma = ephem.Observer()
yuma.pressure = 0 # assume no refraction
yuma.horizon = '-8' # Twillight
yuma.lat, yuma.lon = '32.643356', '-114.523051'
yuma.date = datetime.utcnow()
sunset = yuma.next_setting(ephem.Sun(), use_center=True)
sunrise = yuma.next_rising(ephem.Sun(), use_center=True)

Naturally adjust the yuma variables (lat long) to your liking. Also you might need to play around with the horizon variable to get the times you need. Check the documentation on ephem for more information.

Nickolas
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: thorn on May 22, 2016, 04:53:09 PM


I've attached picture of work to date and the wiring diagram etc for anyone who's interested.


That looks great. Where did you get the board that mounts on the Pi? I have seen the PiFace ones, but they have relays, switches and LEDs on top. I have the one that uses a ribbon cable for the interface to the GIPO.

I have an extra Pi and I think I'll try to make another one (least the computer/GIPO) side that's more compact and move the rain bucket closer or Pi closer.  I put the RC filter on but it's still putting out noise. I'll make the new version so I can mount it in a metal box like Nick suggested. The longer run to the rain bucket is probably introducing noise.

Greg

Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: Crannog on May 22, 2016, 06:52:36 PM
It's called a  "Humble Pi kit", I'd to chop it down to suit the Pi 3. Getting the USB modem to work is my biggest issue at the moment. The station is down from WU while I work on this.

I finished the mounting setup, pic attached showing enclosure setup on a temporary pole. The solar panel and battery will be in a separate enclosure at base of pole.
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: thorn on May 22, 2016, 07:17:01 PM
It's called a  "Humble Pi kit", I'd to chop it down to suit the Pi 3. Getting the USB modem to work is my biggest issue at the moment. The station is down from WU while I work on this.

I finished the mounting setup, pic attached showing enclosure setup on a temporary pole. The solar panel and battery will be in a separate enclosure at base of pole.

How big of a battery and PV array to do have?

I started looking around and found this one:
http://www.mcmelectronics.com/product/ALCHEMY-POWER-83-17316-/83-17316 (http://www.mcmelectronics.com/product/ALCHEMY-POWER-83-17316-/83-17316)

It has the green screw down connectors built in. Doesn't seem to have a lot of room to mount the baro and temp sensor on top.

I had trouble with the USB wifi dongles with a couple of PIs. It would stop communicating with the router after while and I would have connect a monitor & keyboard and reboot.

Thanks, Greg
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: Crannog on May 23, 2016, 02:30:16 AM
The humble pi has the advantage of no terminal blocks etc but does not connect to the full number  GPIO's on a pi 3. I bought the terminals seperately, they fit on the pitch spacing of the humble pi.

http://www.amazon.com/Humble-Pi-Kit-Raspberry/dp/B00C45IMH2 (http://www.amazon.com/Humble-Pi-Kit-Raspberry/dp/B00C45IMH2)

I've not got the PV array yet as I'd planned to run for a couple of weeks with a USB power monitor and get a better idea of power usage.

The USB dongle issues you experienced is a problem. Where the station is planned to be installed it is difficult to get access to re-boot etc. I need a reliable option. It's about 2 miles from land which rules out wireless. Any ideas? I thought about a  SIM900 GSM/GPRS breakout but I don't know if it would work.

I've just managed to get a Pi Zero, if I can get the current station to work I might try a Zero upgrade!

Cheers

Donall

Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: thorn on May 23, 2016, 12:16:09 PM
The humble pi has the advantage of no terminal blocks etc but does not connect to the full number  GPIO's on a pi 3. I bought the terminals seperately, they fit on the pitch spacing of the humble pi.

http://www.amazon.com/Humble-Pi-Kit-Raspberry/dp/B00C45IMH2 (http://www.amazon.com/Humble-Pi-Kit-Raspberry/dp/B00C45IMH2)

I've not got the PV array yet as I'd planned to run for a couple of weeks with a USB power monitor and get a better idea of power usage.

The USB dongle issues you experienced is a problem. Where the station is planned to be installed it is difficult to get access to re-boot etc. I need a reliable option. It's about 2 miles from land which rules out wireless. Any ideas? I thought about a  SIM900 GSM/GPRS breakout but I don't know if it would work.

I've just managed to get a Pi Zero, if I can get the current station to work I might try a Zero upgrade!



Some local hams setup a 6GHz network. They put up a dish at my house (I'm 600 ft above the valley) last summer for field day (experimenting) and I was able to link into the system over 10 miles away. It works better than 2.4GHz. I think you need line of sight for it to work.

https://www.ubnt.com/airmax/rocketdish-antenna/ (https://www.ubnt.com/airmax/rocketdish-antenna/)

Everything is built into the disk. We just mounted it, plugged it in to a switch and I was able to get into their network and out to the Internet. It was close to 96Mbps.  I'm not sure how much power it draws.

The Pi Zero is interesting, only $5!

Greg




Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: Crannog on June 01, 2016, 05:51:49 PM
Hi Greg,

Rocket dish looks very interesting, I'd been thinking around the Adafruit FONA GSM/GPRS breakout. Any experience of these?
https://www.adafruit.com/product/1946 (https://www.adafruit.com/product/1946)

I decided to 'Zero' the weather station! The cost of field failures will be a lot less! Attached is the planned layout based around the 'ProtoZero' breakout.

https://thepihut.com/products/protozero (https://thepihut.com/products/protozero)

I've not built it yet as we're waiting on a decision the local authority if we can proceed based on our proposal.

Cheers

Donall
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: thorn on June 04, 2016, 11:07:02 PM

Hi, I have not used one of those Adafruit cell phone boards, but that might be the way to go.  My home alarm I setup has one in case the Internet goes down. It even detects if someone is trying to jam the cell freqs.

Those zero boards are a lot cheaper than the Pis, they are $5 here in the states. They don't have ethernet but if you use the cell phone boards I guess it won't be needed. I have not lost a Pi yet.

They are going to setup the rocket dishes at my place next weekend. I'll post so photos if you are interested.

Greg

Hi Greg,

Rocket dish looks very interesting, I'd been thinking around the Adafruit FONA GSM/GPRS breakout. Any experience of these?
https://www.adafruit.com/product/1946 (https://www.adafruit.com/product/1946)

I decided to 'Zero' the weather station! The cost of field failures will be a lot less! Attached is the planned layout based around the 'ProtoZero' breakout.

https://thepihut.com/products/protozero (https://thepihut.com/products/protozero)

I've not built it yet as we're waiting on a decision the local authority if we can proceed based on our proposal.

Cheers

Donall
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: Crannog on June 08, 2016, 02:04:03 AM
Hi,

That would be great. It would be good to get a idea of size.

I plan to put together the pi zero board this weekend and run on the pi3 to test.  It'll take a couple of weeks to get the Fona board delivered.

Donall
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: thorn on June 21, 2016, 08:30:21 PM

Unfortunately we had a close strike today and it fried my wx Rasp Pi and I think some sensors, the memory card was corrupt and would not boot on a new pi.  :-(  I had saved  a recent image and put it on my backup pi and now the sensors are giving me errors. I started to comment the baro and inside temp out but more storms are coming so I shut it off and unplugged the pi.  I have a feeling some of the sensors are fried too. Once the storms pass I'll see what works. 

My Vantage Pro is acting up, I lost the wind a while ago but now it's not updating the html even though the file time stamps are updated. The data is not updating.

Here are the images of the dishes. I luckily I had unplugged the dishes before the storms.



(http://kd3su.crabdance.com/photos/20160613-GT3_6619.jpg)

(http://kd3su.crabdance.com/photos/20160613-GT3_6620.jpg)

The van they have for microwaves :)
(http://kd3su.crabdance.com/photos/20160613-GT3_6621.jpg)

(http://kd3su.crabdance.com/photos/20160613-GT3_6622.jpg)



Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: Crannog on June 27, 2016, 04:48:57 AM
Hi Greg,

Sorry to hear about the weather station. Opportunity for a new build??

The dishes look bigger than I expected. These may be a visual issue with where we're planning to put the station. I received the FONA, battery & SIM etc and working through the setup. Luckily if I switch to a Zero, it'll all fit in the same box!

I built the ProtoZero version while waiting but haven't tested it yet. I've attached a couple of pictures of it. I got the Ephem logic to work based on sun altitude at our location. Thanks Nickolas!. The camera takes pictures when the sun is greater than -6 deg to the horizon. (Twilight)

Power usage is next concern as the FONA is supposed to draw 500mA. When running I'll put the USB power monitor on it when I get it going. Ideally I'd like to go for a LiPo battery & a small solar panel but it will be driven by power usage.

Has anyone tried changing WebEx sampling interval from a Python program when its running? It would be great to change update frequency to WU at night to 30 or 60 mins and shut down the FONA between these times. The frequency could be increased to every 5 minutes during daylight.

Thanks

Donall



Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: thorn on July 03, 2016, 09:32:43 PM


I was able to get it back together on the "face" board that mounts on top of the Pi. The only thing that went out was the Pi and A/D converter. I had an extra A/D that I got before. All the other sensors were OK. I shorten the wires and I'm going to use a solar panel and a large 12v gel battery (I got 6 of them for free, they are heavy, 50lbs!)  I'll post some photos when I get it done.

I may use a Zero Pi and one of the packet radio boards (443 MHz) https://www.adafruit.com/products/3071 (https://www.adafruit.com/products/3071)  to send data to a Pi inside. That way if it happens again it should only be $5 vs $30. All the Zero will have to do is read the sensors and send the data via RF. Once everything is working,  I wouldn't need a wifi connection either.

Those dishes are large but will go many miles.

Greg








Hi Greg,

Sorry to hear about the weather station. Opportunity for a new build??

The dishes look bigger than I expected. These may be a visual issue with where we're planning to put the station. I received the FONA, battery & SIM etc and working through the setup. Luckily if I switch to a Zero, it'll all fit in the same box!

I built the ProtoZero version while waiting but haven't tested it yet. I've attached a couple of pictures of it. I got the Ephem logic to work based on sun altitude at our location. Thanks Nickolas!. The camera takes pictures when the sun is greater than -6 deg to the horizon. (Twilight)

Power usage is next concern as the FONA is supposed to draw 500mA. When running I'll put the USB power monitor on it when I get it going. Ideally I'd like to go for a LiPo battery & a small solar panel but it will be driven by power usage.

Has anyone tried changing WebEx sampling interval from a Python program when its running? It would be great to change update frequency to WU at night to 30 or 60 mins and shut down the FONA between these times. The frequency could be increased to every 5 minutes during daylight.

Thanks

Donall
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: Crannog on July 19, 2016, 06:54:34 AM
I couldn't get the FONA 808 to run on the Pi3, seems to be a hardware/OS issue, the serial ports have been changed around to accommodate the onboard wireless.

I've switched to the Pi Zero and the FONA is working great, uploading data to WU! Camera needs some debugging. Smaller footprint of Zero means it'll all still fit in the current box!

I think the processor is under pressure as the 'cycling' LED is staying on at times for >1 sec of cycle time. When the camera will be running it will be worse. I was thinking therefore of not using WeeWx on it but writing directly to WU and/or a 'Server' Pi / PC with Weewx to WU. This would also give me control of write intervals as I plan to switch on connection, upload data then switch off connection. Have you tried this? It sounds similar to your planned RF connection. I think it would save alot on power as FONA is power thirsty.

I plan to cycle measurements every 3 seconds with uploads every 5 minutes for data and 15 minutes during daylight hours for images

Nick's code has code below to alternate readings, I' struggling a bit to understand condition of IF argument.
    if (math.floor(time.time()) % 2) == 0:
Can you explain? I need to code alternate every 6 seconds.

Thanks

Donall



Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: weathernick on July 20, 2016, 10:08:54 AM
I couldn't get the FONA 808 to run on the Pi3, seems to be a hardware/OS issue, the serial ports have been changed around to accommodate the onboard wireless.

I've switched to the Pi Zero and the FONA is working great, uploading data to WU! Camera needs some debugging. Smaller footprint of Zero means it'll all still fit in the current box!

I think the processor is under pressure as the 'cycling' LED is staying on at times for >1 sec of cycle time. When the camera will be running it will be worse. I was thinking therefore of not using WeeWx on it but writing directly to WU and/or a 'Server' Pi / PC with Weewx to WU. This would also give me control of write intervals as I plan to switch on connection, upload data then switch off connection. Have you tried this? It sounds similar to your planned RF connection. I think it would save alot on power as FONA is power thirsty.

I plan to cycle measurements every 3 seconds with uploads every 5 minutes for data and 15 minutes during daylight hours for images

Nick's code has code below to alternate readings, I' struggling a bit to understand condition of IF argument.
    if (math.floor(time.time()) % 2) == 0:
Can you explain? I need to code alternate every 6 seconds.

Thanks

Donall

% is the modulo operation. Basically it returns the remainder of the divide. In this case I divide by two and when the remainder is 0 I am at an even second. So for your code you will need 6 instead of 2.

Thanks,

Nickolas
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: Crannog on July 30, 2016, 06:53:30 AM
Thanks Nick, makes sense.

Finally got the whole thing working on GSM/GPRS. I've removed camera option for now to reduce data upload time. I also uninstalled Weewx and write directly to WU with "GET" command. This greatly improved Zero performance. The station now cycles measurements  every second again. It stops every 5 minutes, turns on "PPP" connection on Fona, uploads data, then turns off the "PPP" connection. I discovered running the PPP crashes the I2C BMP180, hence the stop to upload. The "PPP" is only connected for 20 seconds so power usage is low.

Power usage seems very good, 70mA on Zero, less on Fona (it has a 1000mA LiPo)!! I'm thinking of the Sparkfun Lipo / solar setup if possible rather than a 12v lead/acid if I can. Any experienceof these?

I've attached a picture of the setup so far.  [ You are not allowed to view attachments ]
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: Crannog on August 04, 2016, 07:30:21 AM
Hi Greg,

Do you have any signal conditioning on your wind speed sensor? I've the Davis anemometer which triggers once per revolution. I've used your edge detect code and software debounce value. I've noticed spurious event detects after cycling FONA power (switch on then off) or when FONA is on. I'm running off 12V DC battery. I've tried re-setting GPIO before turning FONA on  then re-configuring it for the sensor after FONA is switched off but problem persists. 

Have you used any hardware filtering?

Thanks again,

Donall
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: thorn on August 04, 2016, 06:02:36 PM
Hi, I didn't put anything on the wind sensor. It has 8 pulses per rotation. I have not noticed anything wrong vs the rain got false signals. I'm still trying to get it to work. On it I have a RC filter. I shortened the wire and it's not reading it at all now, there may be a short in the wire. I took it off and I need to put it on the display it came with. I short the gipo and it reads the rise OK.

I have a Pi 3 for another project that's been running the wifi for a couple of weeks without any trouble. I may swap the wx pi2 with a 3 and try the wifi. I have a router in with the wx pi outside for now.

I did get the solar working for the wx pi, I'll post some photos soon. I have a 40w panel. The battery is overkill too (it weighs 70lbs), but it was free.  :-)

Greg
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: Crannog on August 21, 2016, 05:21:22 PM
That would be great. I put a RC filter on the wind counter to no effect. I got it working by running the FONA switching and uploading on a separate script. The same way the WeeWx driver works. Not sure why!

I tried the Pi3 Wifi earlier. It works great but I found the range is limited. The  radio transmitters looked very interesting.

I still have the old issue of the BMP180 pressure reading crashing (IO error ) occasionally when turning on the PPP connection. I fixed this before by stopping readings when uploading but can't do this with separate programs.
I think it is a power dip or CPU overload (hits 70% when turning on PPP!)

Could I use a capacitor on 5V supply to damp out dips? Any idea what size? I've read Davis use a super capacitor to power transmitter over night when there is no power from the solar array.

Is there a way to "handle" a IO error and carry on to next reading cycle?

I picked up a 7Ah 12V battery, controller and 20Wsolar panel which I calculate should work. I've it put together and will post a picture shortly.

Donall



Donall
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: Crannog on August 26, 2016, 06:15:06 AM
A 1000uF across the solar panel controller load supply seems to have fixed all BMP180 & I2C issues. I upped it to 4700uF for the final build. I've to change the sensor connections from the Davis RJ12 to basic wires to fit through IP68 cable glands. It's going to be pretty wet where its going.

The 20W panel seems to be able to re-charge the battery after overnight running. It'll be interesting to see how it manages on dull & wet days.  I'm working on reducing power usage to help panel & battery.

Attached are some pic's of work to date.

 [ You are not allowed to view attachments ]  [ You are not allowed to view attachments ]  
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: thorn on September 22, 2016, 07:47:19 AM

That looks good, nice and compact. Mine takes up a lot more space. I still need to take some photos. I have been busy and have not had time. I still need to work on my rain gauge.
Thanks for posting.
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: Jáchym on September 22, 2016, 07:51:27 AM
When it comes to mechanical stuff I am an absolute anti-talent so it always amazes me when someone is able to build something like this. I made my own DYI solar shield which I have on my PWS and thats about the best and most sophisticated thing i can "create" :D
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: Crannog on September 27, 2016, 04:10:43 PM
Thanks guys,

The 20W panel seems to be able to re-charge battery ok. I've attached a picture of the overall setup. The pole will be attached to pillar on rock with steel cables. We hope to install this weekend. :grin:
 [ You are not allowed to view attachments ]  [ You are not allowed to view attachments ]  [ You are not allowed to view attachments ]
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: thorn on September 27, 2016, 06:41:56 PM
Here's my setup. I have 2 water proof boxes, one has a router/bridge and the other the Pi WX station. I have a fan that the one smaller panel powers to force air past the temp/humidity sensor. I need to out it on a Pi 3 so I can use the built in wifi instead of the router. The last image is the battery in a black case with a couple of rocks on top to clock the sun ( I should have taken them off for the photo). It's a large AGM battery that someone gave me, bigger than I need but it works.

(http://162.218.236.116/photos/wx5-2016.jpg)
(http://162.218.236.116/photos/wx2-2016.jpg)
(http://162.218.236.116/photos/wx3-2016.jpg)
(http://162.218.236.116/photos/wx1-2016.jpg)

Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: johnd on September 28, 2016, 12:57:19 PM
Hmm. I'm getting a malware warning when I open this particular forum page. Infected jpegs maybe?
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: thorn on September 28, 2016, 01:01:35 PM
Hmm. I'm getting a malware warning when I open this particular forum page. Infected jpegs maybe?

I have a free DNS name for my website. It sometimes gives people warnings. I guess I should use the numeric IP address. Or is there a better way to post images?
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: Bushman on September 28, 2016, 02:00:35 PM
Crabdance.com is on the known malware supporters list.
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: Crannog on October 04, 2016, 06:09:00 PM
Looks good, any issues with overheating? From initial analysis the BMP180 inside the box is 10 Deg C higher than outside and pi is running 10 Deg C higher again. I fear it may cook in the summer. I like the idea of a separate cooling fan and panel.

We installed last weekend  :grin:

Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: thorn on October 07, 2016, 07:48:29 PM

It gets warmer than outside, inside it got up to 101F this summer, but so far no problems. The fan blows from the bottom up past the temp sensor into the box and there are vents on the sides to let air and heat out.

I used a DC-DC buck converter connected directly to the solar panel for the fan:

http://www.riorand.com/riorand-lm2596-dc-dc-buck-converter-step-down-module-power-supply-output-1-23v-30v-1pcs-lm2596.html (http://www.riorand.com/riorand-lm2596-dc-dc-buck-converter-step-down-module-power-supply-output-1-23v-30v-1pcs-lm2596.html)

I got them cheaper on Amazon.

Greg
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: Crannog on November 19, 2016, 05:13:26 PM
Hi,

Station has been up and running for 7 weeks.   Solar panel seems to be working OK. I'll probably take it down over Christmas and see if I can get camera upload to work with Gprs and add the SHT11 sensor. I noticed that the temp above lake at night is 4 degrees C warmer than surrounding area. It would be interesting to put temperature probe in lake water as well.
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: weathernick on February 24, 2017, 03:54:51 PM
Just another update on my station.  The temperature/Humidity sensor failed a month ago. Turns out corrosion destroyed the sensor. I have since installed a second sensor and have sprayed the board with a conformal spray (I covered the humidity sensor naturally as I didn't want to coat that). Everything is back together and working great. The station is working so well I am placing most of my energy these days on my four homemade weather cameras. Amazing what you can do with Raspberry pi and now the new zero!

As for stability I have gone 6 months without the system rebooting. Would have gone another month had I not lost the temp/rh probe. Solar sensor is still working although I expect that sensor to failed here sometime.

Nickolas
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: thorn on March 04, 2017, 11:36:50 AM

I had got an extra sensor just in case.

Mine has been running fine. The solar panel has been keeping the batt.  charged. I still need to setup the rain gauge.

How does your wifi work? I have not had much luck before with another Pi.

I need to get that going. I have a wifi router in the station.  :grin: But thunderstorm season will be here soon.
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: Bushman on March 04, 2017, 04:18:32 PM
I have 4 Pi 3s and the wifi is rock solid.  Far better than my experience with Pi using external USB wifi
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: thorn on March 04, 2017, 05:09:28 PM

I just got 2 more Pi 3s to experiment with, I wonder if I could just put the card I have from the Pi 2 to a Pi3? And then setup the wifi. I guess I could make a copy and try it.


I have 4 Pi 3s and the wifi is rock solid.  Far better than my experience with Pi using external USB wifi
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: Bushman on March 04, 2017, 05:32:40 PM
Yup!  Will work - BTDT.  Then use raspi-config or the graphic version to set up wifi/
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: weathernick on March 05, 2017, 06:20:02 PM
With the new Raspberry Pi Zero W released I am going to have to grab one of those and try out the wifi. I have my doubts I can make them work in my application but perhaps they will surprise me. If my weather station dies I will replace it with a Raspberry Pi 3 but hopefully that won't be for a while.

Nickolas
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: thorn on March 05, 2017, 07:30:12 PM

I saved an image of my pi wx station, just in case. When I booted up it went into simulation mode for some reason. The fileparse was not the default in teh conf file. I'm not sure how it changed.

 I'll try swapping the Pi 3 when I get a chance. I setup the wifi on the new pi 3 and it seems to go 20ft with a good signal.

I got one the of the $5 zeros a while back to play around with, the wifi version would be much easier to use.
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: TejasBob on June 06, 2017, 02:51:24 PM

Second you will need to create a weewx driver that takes the ascii file and transfers it to weewx. At this point weewx takes over and creates the webpage and transfers your data to wunderground and CWOP. I have included my driver, feel free to use it but it is very simple at this point.

Code: [Select]
#
#    $Revision: 1 $
#    $Author: Nickolas McColl $
#    $Date: 2014-08-16 $
#
"""Raspberry Pi driver for the weewx weather system"""

from __future__ import with_statement
# import math
import time
#import weedb
#import weeutil.weeutil
import weewx.abstractstation
import weewx.wxformulas


def loader(config_dict, engine):
    import weewx.units
    altitude_m = weewx.units.getAltitudeM(config_dict)

    station = Raspberry_pi(altitude = altitude_m, **config_dict['Raspberry_pi'])
   
    return station
       
class Raspberry_pi(weewx.abstractstation.AbstractStation):
    """Station using Raspberry Pi"""

    def __init__(self, **stn_dict):
        self.altitude = stn_dict['altitude']
        self.loop_interval = float(stn_dict.get('loop_interval'))

    def genLoopPackets(self):
        import weewx.units

        while True:
            start_time = time.time()

            # Create Loop packet
            f = open('/home/weewx/bin/wxdata.csv')
            input = f.readline()
            f.close()   
            data = input.split(',')
            if len(data) == 13: # data line is complete, process
                for i in range(1, (len(data))):
                    try:
                        data[i] = float(data[i])
                    except ValueError:
                        data[i] = None     
           
                raw_time =time.strptime(data[0], "%Y-%m-%d %H:%M:%S")
           
                _packet = {'dateTime': int(time.mktime(raw_time)),
                           'usUnits' : weewx.METRIC,
                           'pressure' : data[1],
                           'windSpeed' : data[12], #use 3 second average
                           'windGust' : data[12], #use 3 second average
                           'windDir' : data[3],
                           'windGustDir' : data[3],
                           'outTemp' : data[4],
                           'outHumidity' : data[5],
                           'rain': data[6],
                           'radiation' :data[9],
                           'inTemp' : data[11]}
           
                _packet['dewpoint']  = weewx.wxformulas.dewpointC(_packet['outTemp'], _packet['outHumidity'])
                _packet['barometer'] = weewx.wxformulas.sealevel_pressure_Metric(_packet['pressure'], self.altitude, _packet['outTemp'])
                _packet['altimeter'] = weewx.wxformulas.altimeter_pressure_Metric(_packet['pressure'], self.altitude)
                _packet['heatdeg'] = weewx.wxformulas.heating_degrees(_packet['outTemp'], 18.333)
                _packet['cooldeg'] = weewx.wxformulas.cooling_degrees(_packet['outTemp'], 18.333)
                _packet['heatindex'] = weewx.wxformulas.heatindexC(_packet['outTemp'], _packet['outHumidity'])
                 
                yield _packet
     
            sleep_time = (start_time - time.time()) + self.loop_interval
            if sleep_time > 0:
                  time.sleep(sleep_time)
   
    def hardware_name(self):
        return "raspberry_pi"
           
   

Enjoy,

The missing part of the puzzle! One step closer. :)  Thanks!!!

I see you abandoned the lightning detector.  Any particular reason?  Been thinking about how to feel that to weewx.
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: weathernick on June 06, 2017, 04:51:03 PM
I could never get the lightning sensor to work to my liking...Ended up spending too much time with it so I focused on the core sensors and my wxcams. I did noticed that future versions of WEEWX does have native support for that sensor. So ultimately we don't need code for that.

Nickolas
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: TejasBob on June 06, 2017, 07:17:35 PM
I could never get the lightning sensor to work to my liking...Ended up spending too much time with it so I focused on the core sensors and my wxcams. I did noticed that future versions of WEEWX does have native support for that sensor. So ultimately we don't need code for that.

Nickolas

Did you ever try this? https://github.com/weewx/weewx/wiki/as3935
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: TejasBob on June 21, 2017, 09:22:32 AM
Nickolas.  Do you have a more recent copy of your raspberry_pi.py driver code?  The one I copied from you looks like it is for weewx v2.x and won't run on 3.  I'm chasing down module import errors.
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: Crannog on June 28, 2017, 05:49:08 AM
Hi Guys,

Great to see this thread still active. My remote station has been running now for 12 weeks. It originally crashed due to a power failure in Oct after a week of wet and dull weather, the solar controller failing to turn of load when battery ran down. I got a better controller and re-installed the station, with a few features disabled on PI ZERO to reduce power requirements. I fear it will die again next winter with 20W panel.

I have been working on a Arduino mini pro version which requires much less power and has good low power sleep modes. Have ye tried this? I have the sensors working (except wind as I don't have a second anemometer) and a SIM800L breakout uploading to WU. I plan to try and get a cheap VGA camera to upload images via the SIM800L. I think I will need a SD drive added to the assembly to store image prior to upload as memory is limited on Arduino's.

Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: TejasBob on June 28, 2017, 08:31:59 AM
I have been working on a Arduino mini pro version which requires much less power and has good low power sleep modes.

I have thought about this but was considering using it only as a remote sensor package.  I was thinking of transmitting data back via a zigbee interface to a rPi running WeeWx.  I haven't looked at what the power requirements would be however.
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: henryhunt on September 16, 2017, 09:37:27 AM
Hi guys! I’ve been building a weather station from scratch too (using a raspberry pi and python), and have found this thread great to read when I found it a few months ago. I can do a post about my station at some point if you’d like? I just have a few questions about final things that need to be done before the station can be considered finished.

Nick, I’m using the same wind speed (inspeed - though it's the 1 pulse per rotation one instead of the 8 pulse) and rainfall (rainwise) sensors as you, and you’ve said you’re using an RC filter on both of them, based on the diagram at this link http://www.wetter-garching.de/howto.html (http://www.wetter-garching.de/howto.html), to remove noise. What I wanted to know is if you used all of the exact components in the diagram (470 ohm resistor, 1N4148 diode, 10 kohm resistor and 100nf capacitor) in the same setup, because in previous posts you have said that you just need to add a resistor and capacitor to remove the noise.

Also, did you use the same RC filter with the same component values for both rainfall and wind speed or does one have slightly different values?

One other thing: the diagram uses 5 volt power supply, but I’m using the 3.3 volt one on the pi, and was wondering if this would require any changes to the RC filter components?

Please forgive my detailed question. I don’t do very much electronics, so I always like to properly check that things are correct and will work before implementing them, as I know how easy it is to completely fry things.

Henry  :grin:
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: JohnG on September 22, 2017, 08:54:48 AM
Not to hijack or create cross-posting.....

I have a similar set-up documented in a thread in this sub-forum that may provide the detail you are seeking.

https://www.wxforum.net/index.php?topic=32635.0 (https://www.wxforum.net/index.php?topic=32635.0)

All the filtering I did was with software, although I did need pull-up resistors for the I2C circuit due to the number of devices connected and capacitance of the circuit (long runs).
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: chadn on December 15, 2017, 03:18:51 PM
Hello, I had a question regarding your Rainew 111 Rain gauge/tipping bucket. How is the cable connected to the pi? Is it a rj11 cable that just passes two wires to the pi that could be wired directly to the GPIO pins?

Also has anyone added a surface water/ground water logger at all to their applications?
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: JohnG on December 17, 2017, 11:05:54 AM
Here is my set-up for the tipping bucket.

The sensor is connected to Pin 21 of the RPi and Vref thru a resistor.

 [ You are not allowed to view attachments ]
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: thorn on January 15, 2018, 09:57:04 AM
I have not been getting email notices for the thread. My station has been running fine.

I see that weewx has a I2C interface.

https://github.com/weewx/weewx/wiki/Raspberry-Pi-weather-station-with-i2C-sensors

I still need to get my rain gauge working. I was getting false positives. Just had not had the time to work on it. I did hook it up to a PiFace interface and it worked. But it would require a separate Pi.
Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: Crannog on December 12, 2018, 06:19:27 PM
Quick update for those interested. The arduino station has been running for 7 months without failure. Power usage about 0.2w compared to 1w for Pi. Below is a picture of the final design bench testing with 9v battery. The original Davis sensor failed so replaced with a Closed Cube SHT31 breakout. Working good so far. (https://uploads.tapatalk-cdn.com/20181212/8a28e71b864268f78fbbedfa4ba8e5a7.jpg)(https://uploads.tapatalk-cdn.com/20181212/4fc43ce72c6d6266277eb00a6ccdb97f.jpg)

Sent from my G3121 using Tapatalk

Title: Re: Homemade Weather Station using a Raspberry Pi
Post by: thorn on January 02, 2019, 01:00:12 PM

Crannog, that's look great.

My system stopped working the other day. The card was corrupted but I was able to get the data off OK. I re-imaged another card with a image from last year and it won't boot up on the Pi that's in the station. It works OK on another pi I have inside. I'll have to swap out the Pi from the station.  I might try using the zero, they are cheaper that a regular pi.
 
I have been transmitting on HF (ham radio), I wonder if RF could into the the Pi? The antenna is about 100ft away.