Introduction: Remote Temperature Monitor, Using Arduino, Raspberry Pi and XBee Modules
I have always wanted to create a home automation system around sensors. So I've decided to start this project by creating a temperature monitor as a first base of my projet.
The project consists in one sensor and one gateway. The gateway will regularly ask the sensor for its temperature, which will be displayed on the gateway's screen.
I have decided to use:
- an Arduino as a base for my sensor
- a Raspberry Pi as a gateway with a 7 inches touch screen to display the received data.
- XBee modules (serie 1) as communication medium between the sensor and the gateway
- Qt framework to make the gateway
As I want to use Qt on the gateway side, I have started to develop a library to use XBee modules in a very simple way thanks to the power of the Qt framework. You can check my library's repository here on my GitHub: QtXBee
Step 1: System Architecture
Step 2: What Will You Need ?
Hardware:
- Getaway:
- 1x Raspberry Pi
- 1x Official 7" touch screen
- 1x XBee module Serie 1
- 1x XBee explorer (USB)
- Sensor:
- 1x Arduino Uno
- 1x XBee modules Serie 1
- 1x DS18S20 temperature sensor (1 Wire)
- 1x 4.7 kΩ resistor
- 1x 10 kΩ resistor
- 1x 18 kΩ resistor
- 1x Arduino Uno proto shield with headers
Software:
- Qt framework
- QtXBee (XBee library in Qt style API)
- QChartJS (chart.js Qt binding)
- xbee-arduino (XBee library for Arduino)
- Arduino IDE
- XCTU (XBee modules configuration sotfware)
Step 3: Hardware: the Temperature Sensor
As seen before, the temperature sensor is based on an Arduino and 1-Wire temperature sensor.
1-Wire is a device communications bus system designed by Dallas Semiconductor Corp. that provides low-speed data, signaling, and power over a single signal. 1-Wire is similar in concept to I²C, but with lower data rates and longer range. It is typically used to communicate with small inexpensive devices such as digital thermometers and weather instruments. A network of 1-Wire devices with an associated master device is called a MicroLAN [Definition from Wikipedia]
The temperature sensor I choosen is the DS18S20 from Maxim. It has the follwing key features:
- Measures Temperatures from -55°C to +125°C (-67°F to +257°F)
- ±0.5°C Accuracy from -10°C to +85°C
- 9-Bit Resolution
- No External Components Required
As the XBee module works in 3.3V and the Arduino UNO in 5V, we will have to adjust the voltages levels for the serial interface between the XBee module and the Arduino
Step 4: Hardware: the Gateway
For the gateway there is no electronic to be made. The only thing to do is to assemble the touch screen and plug it on the Raspberry Pi. For this, check this good article: Raspberry Pi 7" touch screen assembly guide
Step 5: Software: Program the Sensor (Arduino)
Use Arduino IDE to program your Arduino.
Create a new Sketch with the code you can find on my GitHub
Attachments
Step 6: Software: Install the Gateway
This step describes the easiest way to install and setup the gateway (Raspberry Pi), but it is not the lightest one. For advanced users, go to the next step.
Install Raspbian (with PIXEL):
First we need to install the OS on our RPi. Follow this guide which is very well explained: https://www.raspberrypi.org/documentation/installa...
Install build depencencies:
In order to build the Temperature monitor application, we have first to install the build dependencies.
sudo apt-get update && sudo apt-get install git-core qt5-qmake qt5-default libqt5opengl5-dev libqt5serialport5-dev libqt5qml5 libqt5quick5 qtquick1-5-dev qtdeclarative5-dev qml-module-qtquick-window2 qml-module-qtquick2
Get the sources:
cd ~/
git clone https://github.com/ThomArmax/QtXBee.git
Build the sources:
cd ~/QtXBee
qmake -recursive
make
sudo make install
Launch the application:
LD_LIBRARY_PATH=/usr/lib/QtXBee /op/example_temp_monitor/bin/example_temp_monitor
Step 7: Software: [Advanced Users] Install the Gateway (Rapsberry Pi) Using Yocto Project
I'm quite familiar with Yocto. As I use a lot my Raspberry Pi for personal projets, I have published some yocto layers on my GitHub, espacially the meta-armax layer I've created to build all my librairies and programs.
In the meta-armax layer, I have created a demo image, which boot and starts directly the temperature monitor application thanks to SysV init script.
You can find the code of the temperature monitor application here on my GitHub.
Environmnent setup:
Run the following command to install the environment:
sudo apt-get install gawk wget git-core diffstat unzip texinfo gcc-multilib build-essential chrpath socat libsdl1.2-dev xterm
Get Yocto:
cd ~/
mkdir yocto && cd yocto
git clone http://git.yoctoproject.org/git/poky -b jethro
cd poky
git clone https://github.com/ThomArmax/meta-armax.git
git clone https://github.com/ThomArmax/meta-hyperion.git
git clone git://git.openembedded.org/meta-openembedded -b jethro
git clone https://github.com/agherzan/meta-raspberrypi.git -b jethro
git clone https://github.com/meta-qt5/meta-qt5.git -b jethro
source oe-init-build-env
Then edit conf/bblayer.conf:
# LAYER_CONF_VERSION is increased each time build/conf/bblayers.conf
# changes incompatibly
LCONF_VERSION = "6"
BBPATH = "${TOPDIR}"
BBFILES ?= ""
BBLAYERS ?= " \
/home/thomas/yocto/poky/meta \
/home/thomas/yocto/poky/meta-yocto \
/home/thomas/yocto/poky/meta-openembedded/meta-oe \
/home/thomas/yocto/poky/meta-qt5 \
/home/thomas/yocto/poky/meta-armax \
/home/thomas/yocto/poky/meta-raspberrypi \
/home/thomas/yocto/poky/meta-hyperion \
/home/thomas/yocto/poky/meta-hyperion/meta-raspberrypi \
"
BBLAYERS_NON_REMOVABLE ?= " \
/home/thomas/yocto/poky-jethro-14.0/meta \
/home/thomas/yocto/poky-jethro-14.0/meta-yocto \
"
The edit conf/local.conf:
Set MACHINE = "raspberrypi2" for RPi2
Build the image:
Run: bitbake qtxbee-demo-image
Flash the generated image on the SD card:
- Plug the SD card
- Identify its node using dmesg command
- Then type: sudo dd if=tmp/deploy/images/raspberrypi2/qtxbee-demo-image-raspberrypi2.rpi-sdimg of=/dev/sdd
Step 8: XBee Modules Configuration
In order to be able to communicate, we have to create a XBee "network". So our modules must be configured.
The configuration is possible with the XCTU software
The XBee module used on the Gateway will be the coordinator. It's configuration MUST be:
- MY = 0
- ID = 3332
- AP = 1
- CE = 1 (Coordinator enabled)
The XBee module used for the sensor is en End Device. It MUST be configured as followed:
- MY = 2
- ID = 3332
- AP = 1
- CE = 0 (Coordinator disabled)
Step 9: Launch
Now all steps are done, you just have to power on both gateway and sensor, and you are done :)
If you have any question, request and issues, feel free to ask
If you liked my project, please vote for me :)