Facebook Twitter Instagram Pinterest YouTube
    Trending
    • Add Kodi to RetroPie Menu
    • Disable Auto-login in Raspberry Pi OS
    • Raspberry Pi Cloud Storage with MEGA
    • RetroPie Temperature Monitor from Menu
    • Pi Pico Pinout and Power Pins
    • Install Arduino IDE on Raspberry Pi
    • Raspberry Pi 400 SSD Upgrade
    • Raspberry Pi Temperature Monitoring
    Facebook Twitter Instagram Pinterest YouTube RSS
    Raspberry Pi SpyRaspberry Pi Spy
    • Home
    • Categories
      • General
      • Hardware
      • Programming
      • Python
      • Software
      • Tutorials & Help
    • BerryClip
      • BerryClip Instructions
      • BerryClip Plus Instructions
      • Videos & Reviews
    • Buy
      • Buy Pi
      • Buy Pi Accessories
      • Buy Books
    • Tools
      • Ultimate Raspberry Pi Alexa Skill
      • Pi Power Estimator App
      • Pi-Lite 14×9 LED Matrix Sprite Editor
      • RPiREF Pin-out Reference App
      • Simple Ohm’s Law Calculator
      • Web Sites & Links
    • Tutorials & Help
        Featured
        November 9, 20200

        Raspberry Pi Temperature Monitoring

        Recent
        May 6, 2022

        Add Kodi to RetroPie Menu

        February 26, 2022

        Disable Auto-login in Raspberry Pi OS

        February 2, 2022

        Raspberry Pi Cloud Storage with MEGA

      1. Contact Us
      2. Site Map
      Raspberry Pi SpyRaspberry Pi Spy
      You are at:Home»Hardware»Interfaces»I2C»Raspberry Pi Temperature Logger MkII
      Templogger Mk2

      Raspberry Pi Temperature Logger MkII

      3
      By Matt on October 13, 2015 I2C, Model A+, Sensors

      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 Raspberry Pi Model A+ which provides :

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

      Hardware

      The device consists of :

      • Raspberry Pi Model A+
      • Basic case
      • retroScreen by Arthur Amarra
      • BMP180 sensor module
      • 3 tactile switches
      • PiHut WiFi dongle

      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 GPIO 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 https://github.com/adafruit/Adafruit_Nokia_LCD
      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 https://bitbucket.org/MattHawkinsUK/rpispy-misc/raw/master/python/bmp180.py
      wget https://bitbucket.org/MattHawkinsUK/rpispy-misc/raw/master/python/templogger2.py
      wget https://bitbucket.org/MattHawkinsUK/rpispy-misc/raw/master/python/templogger2_cfg.py

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

      wget https://bitbucket.org/MattHawkinsUK/rpispy-misc/raw/master/python/5x7_practical.ttf
      wget https://bitbucket.org/MattHawkinsUK/rpispy-misc/raw/master/python/F25_Bank_Printer_Bold.ttf

      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://www.fonts2u.com/5×7-practical-regular.font
      F25 Bank Printer Bold from http://www.fonts2u.com/f25-bank-printer-bold.font

      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. Facebook Twitter Pinterest LinkedIn Tumblr Email
      Previous ArticleHow To Autorun A Python Script On Boot Using systemd
      Next Article Raspberry Pi microSD Card Shoot-out

      Related Posts

      Raspberry Pi Temperature Monitoring

      Raspberry Pi 7-Segment LED Display Module using Python

      Create an I2C OLED Display Slideshow with Python

      3 Comments

      1. William Miller on January 8, 2016 1:46 pm

        I can’t seem to figure out how to physically hook up the display to the RPi. Can you point me to the details for the connections?

        Reply
        • Matt on January 12, 2016 11:39 pm

          The screen is part of the retroScreen addon board which just plugs onto the GPIO header. So in this case the screen was easy to attach. At some point I will do a quick tutorial on connecting a 5110 screen directly.

          Reply
      2. Ian on January 9, 2016 2:57 am

        Works great!
        Thank you!

        Reply

      Leave A Reply Cancel Reply

      This site uses Akismet to reduce spam. Learn how your comment data is processed.

      Recent Posts
      May 6, 2022

      Add Kodi to RetroPie Menu

      February 26, 2022

      Disable Auto-login in Raspberry Pi OS

      February 2, 2022

      Raspberry Pi Cloud Storage with MEGA

      January 7, 2022

      RetroPie Temperature Monitor from Menu

      January 24, 2021

      Pi Pico Pinout and Power Pins

      Categories
      • 1-wire
      • 3D Printing
      • Add-ons
      • BBC Micro:bit
      • BerryClip
      • Books
      • Camera Module
      • Cases
      • Events
      • General
      • Hardware
      • I2C
      • Infographics
      • Interfaces
      • Minecraft
      • Model A+
      • Model B+
      • News
      • Pi Models
      • Pi Zero
      • Power
      • Programming
      • Python
      • Raspberry Pi OS
      • Raspbian
      • RetroGaming
      • Robotics
      • Sensors
      • Software
      • SPI
      • Tutorials & Help
      Tags
      3D Printing Arduino audio battery berryclip Birthday bluetooth cambridge camera CamJam DigiMakers display games GPIO I2C interface Kickstarter LCD LED Linux media Minecraft Model A Model B motionEyeOS PCB photography photos Pi-Lite portable power python Raspberry Jam Raspberry Pi Bootcamp raspbian Retrogaming retroPie screen SD card security sensor SPI temperature ultrasonic video
      Raspberry PI Related
      • Adafruit Blog
      • Average Maker
      • Official RaspBerry Pi Site
      • Raspberry Pi Pod
      • RasPi.tv
      • RaspTut
      • Stuff About Code
      Tech Resources
      • MattsBits – Pi Resources
      • Microbit Spy
      • Technology Spy
      Archives
      About

      Unofficial site devoted to the Raspberry Pi credit card sized computer offering tutorials, guides, resources,scripts and downloads. We hope to help everyone get the most out of their Pi by providing clear, simple articles on configuring, programming and operating it.

      Popular Posts
      September 19, 2014

      Top 5 Reasons The Raspberry Pi Sucks

      July 27, 2012

      16×2 LCD Module Control Using Python

      October 20, 2013

      Analogue Sensors On The Raspberry Pi Using An MCP3008

      Recent Posts
      May 6, 2022

      Add Kodi to RetroPie Menu

      February 26, 2022

      Disable Auto-login in Raspberry Pi OS

      February 2, 2022

      Raspberry Pi Cloud Storage with MEGA

      Facebook Twitter Instagram Pinterest YouTube RSS

      Entries RSS | Comments RSS

      This site is not associated with the official Raspberrypi.org site or the Raspberry Pi Foundation. Raspberry Pi is a trademark of the Raspberry Pi Foundation.

      Copyright © 2022 - All Rights Reserved - Matt Hawkins

      Type above and press Enter to search. Press Esc to cancel.