element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Raspberry Pi
  • Products
  • More
Raspberry Pi
Raspberry Pi Forum PiFace CAD Temperature Monitoring
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Raspberry Pi to participate - click to join for free!
Featured Articles
Announcing Pi
Technical Specifications
Raspberry Pi FAQs
Win a Pi
Raspberry Pi Wishlist
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Verified Answer
  • Replies 2 replies
  • Subscribers 674 subscribers
  • Views 494 views
  • Users 0 members are here
  • raspberry
  • temperature
  • cad
  • raspberry_pi
  • piface
Related

PiFace CAD Temperature Monitoring

markdoll01
markdoll01 over 11 years ago

Good Day All,

 

I am quite new to Python scripting and recently received my PiFace CAD which is working quite nicely.  I am having problems creating a loop for updating information on the Display while still checking for an input from the buttons.

 

I have a RPi with PiFace CAD where I soldiered two DHT-11 Temperature and Humidity sensors on and all that is working perfect.  I created a PiFace CAD menu that allows me to switch the Display from Temperature to Humidity and switch the Display Backlight Off and that works as well but I cannot get the Display to update the temperature or humidity reading say every 5 minutes or so.  The moment I include a While loop, the script does not read button presses anymore.

 

If somebody can please help me out here - I tried to Google a lot but could not find anything.  Here is my full code (Copied bits and peaces from all over :-) ):

 

#!/usr/bin/env python3

import sys

import threading

import subprocess

from time import sleep

import pifacecad

 

 

UPDATE_INTERVAL = 5 * 1  # 5 mins

TEMP_IN = "cat /root/sen1.out | awk '{print $7}'"

TEMP_OUT = "cat /root/sen2.out | awk '{print $7}'"

HUMID_IN = "cat /root/sen1.out | awk '{print $3}'"

HUMID_OUT = "cat /root/sen2.out | awk '{print $3}'"

DATE = "date"

 

temperature_symbol = pifacecad.LCDBitmap(

    [0x4, 0x4, 0x4, 0x4, 0xe, 0xe, 0xe, 0x0])

temp_symbol_index = 0

 

 

#class Weather(object):

 

def run_cmd(cmd):

      return subprocess.check_output(cmd, shell=True).decode('utf-8')

 

 

def get_my_temp1():

      return run_cmd(TEMP_IN)[:-1]

 

def get_my_temp2():

      return run_cmd(TEMP_OUT)[:-1]

 

def get_my_humid1():

      return run_cmd(HUMID_IN)[:-1]

 

def get_my_humid2():

      return run_cmd(HUMID_OUT)[:-1]

 

def get_date():

      return run_cmd(DATE)[11:16]

 

def show_tempinfo(event):

  event.chip.lcd.write(str(event.pin_num))

  choice = event.pin_num

  if choice ==6:

          cad.lcd.clear()

          cad.lcd.backlight_on()

          cad.lcd.write_custom_bitmap(temp_symbol_index)

          cad.lcd.write("In:{}C ".format(get_my_temp1()))

          cad.lcd.write("{}\n".format(get_date()))

          cad.lcd.write_custom_bitmap(temp_symbol_index)

          cad.lcd.write("Out:{}C".format(get_my_temp2()))

  if choice ==7:

          cad.lcd.clear()

          cad.lcd.backlight_on()

          cad.lcd.write("In:{}% ".format(get_my_humid1()))

          cad.lcd.write("{}\n".format(get_date()))

          cad.lcd.write("Out:{}%".format(get_my_humid2()))

  if choice ==5:

          cad.lcd.backlight_off()

 

cad = pifacecad.PiFaceCAD()

cad.lcd.store_custom_bitmap(temp_symbol_index, temperature_symbol)

cad.lcd.blink_off()

cad.lcd.cursor_off()

cad.lcd.write("Waiting for Sensors..")

 

switchlistener = pifacecad.SwitchEventListener(chip=cad)

for i in range(8):

    switchlistener.register(i, pifacecad.IODIR_FALLING_EDGE, show_tempinfo)

 

switchlistener.activate()

  • Sign in to reply
  • Cancel
  • markdoll01
    0 markdoll01 over 11 years ago

    Just want to let know that I got it sorted by using 'threading' but then ran into a problem with the LCD "freezing" or just showing garbage.  Also managed to get it sorted by using 'threading.Lock' .

     

    All working now :-)

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Reject Answer
    • Cancel
  • markdoll01
    0 markdoll01 over 11 years ago

    Hi All - Just would like to update this post.  My PifaCAD Display works perfectly now.  I soldiered a motion sensor to the board now and it works 100%.  The setup I have now are two DHT22 modules and a Motion sensor soldiered to the PiFaceCAD.  One DHT22 monitors Temperature and Humidity Inside and the second modules checks Outside.  Whenever I walk passed the display, the backlight turns on for 10sec triggered by the motion sensor.  Also the buttons work for manually switching between temp and humidity and backlight. ;-)

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube