Wall's Corners Wall's Corners Author
Title: Raspberry Pi Temperature Logger MkII
Author: Wall's Corners
Rating 5 of 5 Des:
Following on from my  Basic Temperature Logging To The Internet With Raspberry Pi  article I decided to upgrade my logging device. By coinci...

Following on from my Basic Temperature Logging To The Internet With Raspberry Pi article I decided to upgrade my logging device. By coincidence Arthur Amarra launched a Kickstarter campaign for a “retroScreen” HAT which provided a Nokia 5110 screen, i2c header and four switches. This was exactly what I needed.

So here is a slightly modified temperature and pressure logger based on a Model A+ which provides :

  • Temperature and pressure logging
  • 84×48 screen
  • 3 buttons
  • 5 display modes
  • Backlight switch

Hardware

The device consists of :

Templogger Mk2

Sensor

The BMP180 sensor is described in my BMP180 I2C Digital Barometric Pressure Sensor article. This sensor is small, cheap and provides temperature and pressure. The retroScreen provides a compatible header on its PCB so it’s a natural choice.

WiFi Dongle

In my previous version I used an Edimax EW-7811UN WiFi dongle but this time I decided to use a PiHut branded product. It was equally easy to setup using my Setting Up WiFi On The Raspberry Pi guide.

Switches

Previously I added a single switch to allow the device to be powered down gracefully. The retroScreen provides space for four switches so I soldered in three 2-pin tactile switches. This was a neater solution and gave me some more options for user input.

The switches connect the pins to ground so in the Python script they are pulled high. When the switches are pressed they are connected to Ground and pulled LOW. The script uses “callbacks” to take appropriate action when it detects these falling edges.

  • Switch #1 (GPIO 22) allows the user to cycle through the 5 available display modes.
  • Switch #2 (GPIO 27) allow the user to cycle through a set of contrast values so the screen can be fine tuned.
  • Switch #3 (GPIO 17) tells the script to exit and/or shutdown the Pi. By setting the AUTO_SHUTDOWN flag to 1 the Pi can also shut itself down if required.

Thingspeak and The Internet of Things

To log data to the Internet I use the Thingspeak service. I explain this in a bit more detail in the previous article.

To use my example script you will need to setup a Thingspeak account, create a new channel and acquire the “Write API Key” from the API settings. See the official documentation for help.

Initial Preparation

Here are the sequence of steps I used to build the device :

  • Created a fresh SD card using the latest Raspbian
  • Configured WiFi via the LXDE desktop
  • Ran “sudo apt-get update”
  • Ran “sudo apt-get upgrade”
  • Enabled SPI using this guide (including “py-spidev” and “python-dev”)
  • Enabled i2c using this guide (including “python-smbus” and “i2c-tools”)

retroScreen Installation

The Nokia screen needed a few more bits and pieces installed. I didn’t need all the retroScreen examples to work so I used a simplified installation procedure than the one described on the retroScreen site. Obviously if you want to explore the board in more detail you can follow the full process and try out the examples.

git clone http://ift.tt/1tvfgRw
cd Adafruit_Nokia_LCD
sudo python setup.py install

Temperature Logging Script

Make sure you are in your home directory :

cd ~

Then download three files from my BitBucket repository direct to the Pi :

wget http://ift.tt/1KfFbXk
wget http://ift.tt/1WLPCaV
wget http://ift.tt/1LK8gzk

The script also uses two font files (from fonts2u.com) which must be downloaded :

wget http://ift.tt/1WLPCaX
wget http://ift.tt/1LK8jeJ

Note : On the command line you can use the Up/Down arrow keys to cycle through previous commands and then just retype the file names to save a lot of typing!

Edit the config file and add your Thingspeak API key to the THINGSPEAKKEY parameter.

nano templogger2_cfg.py

You can save and exit the nano editor using [CTRL-X], [Y] then [ENTER].

Running The Script

in your home directory when you run the “ls” command you should have the following files :

  • templogger2.py
  • templogger2_cfg.py
  • 5x7_practical.ttf
  • F25_Bank_Printer_Bold.ttf

You should also have an “Adafruit_Nokia_LCD” directory.

You can run the logger using

sudo python templogger2.py

You can quit using CTRL-C or press Switch #3 to stop the script. If AUTO_SHUTDOWN is set to 1 then the Pi will shutdown. After 20 seconds the power can be disconnected.

Automatically Run On Boot

In order to avoid having to start the script manually you can configure it to launch when the Pi boots up. It was at this point I had problems using my usual “autoboot” techniques and instead used the systemd method for starting Python scripts.

I followed this tutorial : How to Autorun A Python Script On Boot Using systemd

My Unit file, templogger2.service looks like this :

Description=Templogger2 Service
After=multi-user.target
[Service]
Type=idle
ExecStart=/usr/bin/python /home/pi/templogger2.py > /home/pi/templogger2.log 2>&1
[Install]
WantedBy=multi-user.target

Display Modes

Button 1 allows you to scroll through 5 different display modes. They look like this :

Templogger Display Modes Templogger Display Modes Templogger Display Modes Templogger Display Modes Templogger Display Modes

Final Results

Once the device is up and running and you’ve configured your Thingspeak Channel you can produce outputs like this :

Temperature and Pressure graphs

The graphs update these in realtime as new data arrives. The channel also allows you to download your data in CSV, XML and Json formats.

With an interval of 10 minutes that gives you 144 data points every 24 hours. You can set the graphs to display a set number of data points so you can adjust this to give you a suitable spread of data.

I only used two streams of data in my example (temperature and pressure) but Thingspeak will accept a total of eight.

Here is my public RPiSpy Temp Logger Channel.

Alternative Fonts

In order to clearly display text on the screen I made use of two fonts :

5×7 Practical Regular from http://ift.tt/22InXLA
F25 Bank Printer Bold from http://ift.tt/1WLPCrq

You can use other fonts as long as you adjust the appropriate sections of Python. Some work better than others and there is plenty of room for experimenting.

Share This:

View more at: http://yoursmart.mobi

About Author

Advertisement

Post a Comment

 
Top