1. 程式人生 > >樹莓派建一個氣象監測站

樹莓派建一個氣象監測站

Today I’m going to show you how to make sort of a mini weather station with a Raspberry Pi. This is an ongoing project of mine that I’ve been tinkering with so I’ll share my learnings with you. It started with a project I wrote about last month, and is an improvement on it.

How to build a Weather Station Raspberry Pi 2

A core part of the “Internet of Things” movement is the idea of devices that gather data and send it to the Internet. That data is then acted on or observed for later. It’s a simple concept and has been going on for a while but lately it’s been getting cheaper and easier to do. This project is a great example of that.

While this seems like a long tutorial, it only takes about 30 minutes to complete. Let’s get started.

Once you complete this your Raspberry Pi will measure:

  • Temperature
  • Humidity
  • Atmospheric Pressure
  • Lux

You can send your results to:

  • Google Spreadsheet on your Google Drive
  • ASP.Net Web API on your website

What you’ll need

For this project you will need:

  • AM2302 Temperature / Humidity Sensor
  • BMP180 Temperature / Barometric Pressure Sensor
  • DS18B20 Waterproof Temperature Sensor
  • TSL2561 Digital Lumosity Sensor

Optional:

None of this stuff would be anywhere near as easy if it weren’t for companies like 

Adafruit. I recommend getting your sensors from them to support their innovation in this space. Newarkis one of the original distributors of the Raspberry Pi, they are fast and very reputable.

Wiring

The wiring for this project is shown below:

How to build a Weather Station Raspberry Pi 2

While this may look confusing at first, it’s a pretty standard setup for each sensor. Here’s some additional information on how to wire up each one if the diagram isn’t helpful.

Installing the software

This tutorial has been tested with a fresh install of Raspian. The instructions should be fairly accurate for other Linux distributions as well.

SSH into the pi (or open a command window) and get’s start out in your home directory and make a folder for your sources.

1
2
3
cd ~
mkdir sources
cd sources

Now we can start installing sensors.

Setup the AM2302

The AM2302 is a temperature humidity sensor. It is a DHT22 sensor that’s wired with a pullup resistor and casing. I found it easier to use this one than just the DHT22 kit.

For this sensor we’ll be using the Adafruit Python DHT library:

1
2
3
4
5
6
7
8
9
git clone https://github.com/adafruit/Adafruit_Python_DHT.git
cd Adafruit_Python_DHT
sudo apt-get update
sudo apt-get install build-essential python-dev python-openssl
sudo python setup.py install

This will install the software necessary to interact with the AM2302

Test the AM2302

There is a test script you can use to verify the sensor is working. Run AdafruitDHT.py and “2302” is the sensor, and “22” is the pin you’re using. Change it if you hooked it to a different pin.

1
2
cd examples
sudo ./AdafruitDHT.py 2302 22

You should see something that looks like this:

How to build a Weather Station Raspberry Pi 2

DSB18B20

The DSB18B20 is a digital one wire (Dallas one wire protocol) thermometer. If you get it “with extras” it comes with a cord and waterproof casing which is what I went with.

You will need to add one wire Support. Open up your boot config:

1
sudo nano /boot/config.txt

Add the following text to that file: dtoverlay=w1-gpio

Save the file and reboot:

1
sudo reboot

Testing the DSB18B20

To test it you’ll need to load the following modules into your kernel:

1
2
sudo modprobe w1-gpio
sudo modprobe w1-therm

Note: you can do the following to add them to your kernel on boot:

1
sudo nano /etc/modules

add the following lines:

1
2
w1-gpio
w1-therm

Save the file and the next time you start they will be loaded automatically.

To check your device:

1
2
cd /sys/bus/w1/devices
ls -la 

You will see a folder starting with 28- this is your device based on the serial number.

1
2
cd 28-xxxx (change this to match what serial number pops up)
cat w1_slave

You should see something like the following:

How to build a Weather Station Raspberry Pi 2

If it says “YES” it’s working. If not, you may need to check your wiring.

Configuring I2C

Next you will need to configure I2C for your system:

1
2
sudo apt-get install python-smbus
sudo apt-get install i2c-tools

You may get “already installed” messages from this, depending on how your system is setup.

Add the modules to your kernel on startup. Open up /etc/modules

1
sudo nano /etc/modules

Add the following to it:

1
2
i2c-bcm2708 
i2c-dev

Now you will need to modify your boot config:

1
sudo nano /boot/config.txt

Add the following:

1
2
dtparam=i2c1=on
dtparam=i2c_arm=on

Reboot your Pi:

1
sudo reboot

相關推薦

樹莓一個氣象監測站

Today I’m going to show you how to make sort of a mini weather station with a Raspberry Pi. This is an ongoing project of mine that I’ve been tinkering w

PHP和樹莓開發一個以太坊/比特幣交易機器人

con 買賣 start mount his p s linu 訪問 nba 我最近得到了Raspberry Pi Zero Wifi,我告訴你這個東西是改變遊戲規則的。我之前使用過RasPis,但由於該設備的占地面積小得多,耗電少,價格便宜且無線上網,因此非常適合低端或物

使用PHP和樹莓開發一個比特幣和以太坊交易機器人

我最近得到了Raspberry Pi Zero Wifi,我告訴你這個東西是改變遊戲規則的。我之前使用過RasPis,但由於該裝置的佔地面積小得多,耗電少,價格便宜且無線上網,因此非常適合低端或物聯網專案。 注:目前我已經擴充套件了機器人以便能夠交易以太坊! 我希望它能夠在不必太多關注的情況下做事,而我想到

樹莓一個簡單c++小程式教程

我用的是樹莓派3代b型,所使用的是Debian系統的衍生系統raspbian(對系統不太瞭解不清楚)。樹莓派開發c++程式需要的工具有編輯器vim,偵錯程式gdb,編譯器gcc或者g++.(大神飄過就行~~ 記錄一下)用紅筆塗得地方是我命令敲錯的地方,大家忽略就行。 安裝vim   執行

樹梅派應用23:QT+樹莓實現一個簡單的播放器

說起樹莓派,買了也有一段時間了,但是始終都沒有做出什麼好玩的裝置出來,恰好最近在學C++,看到樹莓派放在牆角吃了一年多灰,為何不利用它來學一下程式設計呢? 先給我的工作臺來個特寫: 說幹就幹,在經歷了一番折騰以後,先準備所需的器材和必要的零部件,在這裡我簡單的羅列一下:先是

樹梅派應用18:用樹莓DIY一個智慧家居伺服器

其實這東西我自己已經用了一年了~現在就來寫個教程~嘿嘿…… 先上個圖 有點亂23333 這是我的房間書櫃,也是我的工作臺……書櫃的側邊是樹莓派搭建的物聯網伺服器~ 來一隻近圖~ 這就是伺服器的近照啦~ 我用的是樹莓派A+作為伺服器的主控,所有的工作都由它完成。 樹莓派A+是

樹莓一個關於教育的故事

作者:Vamei 出處:http://www.cnblogs.com/vamei 嚴禁轉載。  埃本·厄普頓 2006年,劍橋大學。年輕的助教埃本·厄普頓在為新入學的本科生頭痛。 無疑,那些敢於申請劍橋大學的新生都有聰明的腦瓜。他們拿著傲人的A-Level考試成績進入計算機系。從成績上看

基於樹莓3B+,一個可以遙控的小車(一)

#include <linux/init.h> #include <linux/module.h> #include <linux/slab.h> #include <linux/platform_device.h> #include <linux/gpi

樹莓一個python指令碼作為服務執行,配置開機自動啟動

週六黑客馬拉松做了個樹莓派遙控船,發現簡單的把python指令碼加到rc.local好像無法自動啟動,於是找到了下面的方法,做成一個服務。首先寫個Python指令碼檔案儲存在/home/pi/script/ledblink.py123456789101112131415#!/

樹莓實現一個下載機

這回又買了一塊樹莓派,這次用的是B+。樹莓派做BT下載器的特性就是省電啊。 原來想買一個路由器刷openwrt,後來覺得路由器可能效能有限,而且稍有不慎會刷壞uboot,所以暫且不考慮了。 搭建過程網上都有,但是很零碎,這裡整理一下步驟,下面分為幾個步驟吧: 準備工

如何用樹莓打造一個家庭影院

準備Raspbmc 為了安裝Raspbmc,需要準備幾件東西。第一件是一張新的SD卡——之前的那張要用在普通環境下;SD卡事實上

樹莓】做一個備份鏡像

運行 using clas 準備 prim 初始化 per ole nac 在做樹莓派鏡像時候,遇到了一點問題,參考這篇文章,再重試一下。 Adafruit的樹莓派教程第一課福利:做一個備份鏡像 04/08/2014 Boyd Wang A

樹莓進階之路 (032) -字符問題(2) - 用c語言怎樣得到一個漢字的GB2312編碼(轉)

十六進制 字符串 c++ gb2 十進制 轉換 tails 表示 blog C/C++支持的是ASCII,不過漢字編碼中,GB2312與ASCII是兼容的,所以可以在C中獲得漢字的GB2312編碼 GB2312是兩個字節的,第一字節是高八位,第二字節是低八位,比如下面的程序

樹莓WiFi熱點

開機 iproute util 使用 TP wifi ins clone reat 將代碼clone到本地 git clone https://github.com/oblique/create_ap cd create_ap make install 安裝依賴的庫 有些源

樹莓Raspberry Pi和Micro:bit做一個自拍器

clear microsoft 編程 告訴 pac 文本編程 裝配 -a 按鈕 在這個項目中,我們將使用Python來構建一個由Micro:bit觸發樹莓派Raspberry Pi和相機模塊的自拍器。這是開始使用硬件和簡單文本編程的好方法。 我們將學習: 如何設置Raspb

厲害了!小夥自學Python一個月,利用樹莓製作了黑客優盤工具!

  最近一直在學習Python爬蟲,可能隨著研究的深入,受到爬蟲技術的感染,開始對獲取別人的資料產生了興趣,Python寫網頁爬蟲是獲取別人網站上的資料,那可不可以用Python寫一個程式獲取別人U盤上的資料呢!   研究了網上的一些程式,結合手上的這塊可

樹莓3B+QT5(安裝與相關配置),附帶一個小介面

首先,我們需要安裝樹莓派,一些教程在安裝QT5時,推薦更新樹莓派上的韌體之類的, 也就是這兩句程式碼: sudo apt-get upgrade sudo rpi-update 說多了就是淚,我的樹莓派因為更新上面兩句,導致系統崩潰,所以,我一般不建議去更新(這個坑我已經躺了)

樹莓用於YAAW離線下載的Mass Storage U盤用虛擬目錄到Vsftpd的子目錄裡去

web遠端操控,投種子,小水管離線下載;等果實成熟了,ftp檢視或者遠端收回來,爽歪歪。 參考博文:http://sarsgetaway.iteye.com/blog/1056800 ssh連線樹莓派之後操作如下: 因為我的32GBu盤是mount在了/home/pi/usb目錄下

樹莓上跑一個opencv小程式(沒有使用makefile)

前提opencv已經在樹莓派上配置好了(我用的庫是opencv-3.3.0) 新建opencv_test.cpp檔案  執行命令 vim opencv_test.cpp   編輯程式碼 為了方便複製貼上 #include<opencv2/core/core.

img檔案掛載成一個檔案系統,修改樹莓的映象檔案,寫入映象———後續

昨天寫了一篇文章。但是當時對於這個的理解還不夠,以至於我後面又遇到了一些問題。這裡再重新整理一下,供大家參考。 我先重述一下我要做的事情。 我電腦系統是windows,裡面安裝了一個Ubuntu虛擬機器。我從官網上下載了一個樹莓派img映象。但是因為工作的需要,我得修改這個i