TeCoEd (Teaching Computing Education)
  • Home
    • Freelance
    • Book
    • Downloading
  • Python
    • Learn Python >
      • Python Modules
    • PyGame Zero
    • Python Programs >
      • Higher or Lower
      • Magic Calculator
      • Password Checker
      • Python Pit
    • What's News App
    • Pixels to Cells
    • Python Mosaics
    • Python OCR
    • L-1-AM
    • Web Scraping >
      • Scraping Trains
    • Weather App
    • Snakes and Windows
    • Python Web Server >
      • Flask
    • Python Picks
  • Ras Pi
    • All About the Pi
    • Getting Started
    • Remote Desktop and VNC
    • Static IP Address
    • Sonic Pi >
      • 3.14
    • Twitter Feed >
      • Tweepy
    • Android & Pi >
      • Advanced Apps
      • Odds
    • A.I on the the Pi
    • CRON
    • Pick Your Own
  • Pi Hardware
    • Pi HATS >
      • Sense Hat Hacks
      • AstroPi HAT
      • Unicorn-HAT >
        • Unicorn Alphabet Disco
        • Uni Codes / Programs
      • Skywriter
      • Piano HAT
    • STS Pi
    • Pi Camera >
      • Pi-Cam, Python & Email >
        • Time Lapse
      • Pi Noir
    • Pipsta >
      • Flask, Input & Printers
    • Raspberry Pi Power >
      • Energenie IR power
    • Pibrella
    • Distance Sensor
    • LCD Screen
    • Pi-Tooth
    • Robot Arm
    • PiGlow
    • PiFM
    • Accelerometer
    • PiFace >
      • Installing PiFace >
        • Python Commands
  • Pi-Hacks
    • Drone Hacks
    • Pi Glue Gun Hack
    • Blinkt!
    • Sonic Pixels
    • R2D2
    • Get to the chopper
    • Astro Bird
    • Twitter Translator
    • Hacking a Robot
    • Nature_Box >
      • Best Nature Photos
    • Wearable Tech >
      • Project New York
      • P.N.Y Part 2 Health
      • P.N.Y Part 3 Games
      • P.N.Y Part 4 Translation
    • Dino-Tweet
    • Other Links
  • Pi-Hacks 2
    • The Joker
    • Hologram Machine
    • Google Vision: Camera Tell
    • Yoda Tweets
    • Pi Phone
    • Darth Beats
    • Twitter Keyword Finder
    • Crimbo Lights Hack
    • Xmas Elf
    • Halloween 2016
    • Halloween Hack 2015
    • Socrative Zombie
    • Voice Translation
    • The Blue-Who Finder
    • GPIO, Twitter
    • Pi Chat Bot >
      • Dictionary Definitions
    • PiGlow & Email
    • Pibrella Alarm System
    • SMS with Python >
      • Spooking a Mobile
  • Pi-Hacks 3
    • LED Dance Suit
    • Ferminal
    • Crypto Tracker
    • David Bowie
    • Lamp Prank >
      • TEST
    • Yoda FM
    • Retro Player
    • LED Pixel Art
    • TARDIS
    • Battleships
    • LED Board
    • Night Vision
    • Enviro+ Weather
  • Minecraft
    • Minecraft API
    • Minecraft Sweeper
    • PiGlove: Minecraft Power Up
    • Minecraft Photo-booth
    • Rendering Pixels
    • Speed Cube
    • Lucky Dip
  • Computing
    • Why Computing?
    • Can You Compute
    • micro:bit
    • Coding Resources
    • Learn to Code >
      • Coding with iPads
      • Apps Creation Tools
      • sKratchInn
      • Sound Editing
    • Cheat Sheets
    • Theory
    • HOUR OF CODING
    • BEBRAS Computing Challange
    • Computer Facts
    • Free Software and Links
  • Contact Me
  • Random Hacks
    • Movile

What is it?


This simple program combines a USB Bluetooth Dongle and the adaFruit LCD screen plus a splash of Python to create a system that tracks who is preset in a building and then outputs to a screen.  This results in a colorful real time system that updates you on who is in and who is out.  It could be used as a clocking in system or a person locator or simple to see if your boss is still out of the office.   If combined with time it could be used to measure the amount of time a customer spends in a shop or record how long a customer has hired an item for and the cost automatically calculated.

1. Inital Set Up


Load the LX Terminal:
sudo apt-get update
sudo apt-get upgrade

To get stared with this project you are required to setup the adaFruit LCD screen and the Python Bluetooth libraries and enable the Raspberry Pi Bluetooth support.  

Full installations and setup instructions can be found here:
  • adaFruit LCD Screen
  • Bluetooth set up and finding devices

2. Checking to see who is in


The first part of the program involves scanning for Bluetooth devices, returning the MAC address of each device and then comparing the address with a stored address.  If they match then that person or that person's device is in the building, if not then the Bluetooth is off or the person is out of range, or out of the building.  For the sake of this project we will assume that it is company policy to always have your Bluetooth enabled Or each employee is tagged with a Bluetooth chip!

device = bluetooth.lookup_name("38:48:93:3A:BC:7C", timeout=5) 
       if (device != None):
            print "TeCoEd is in"
       else:
           print "Tecoed is out"
           

This code compares the address found in the initial search and responds. Notice the use of the != does not equal.  If it is does not equal nothing, then it equals something or more simply, it has matched that particular address and found that person is in the building          

3. LCD Screen Messages


In this section of the code the LCD screen is programmed to respond to the address found.  If the addresses match then it displays the name of the person and the appropriate colour.  If they are out, i.e. the Bluetooth device is not discovered when scanning, then the screen states that the person is away from he building and changes the LCD screen colour to red.

This uses the simple code lines:
Screen colour to Yellow:         lcd.backlight(lcd.YELLOW)
display the message:              lcd.message("TeCoEd is in his\noffcie on GitHub")
Display for two seconds          sleep(2)
Clear the display                      lcd.clear()

The screen I am using only display up to 16 characters per line so uses the \n to send the rest of the message to the next line underneath.

Combining this with the previous code gives you:

device = bluetooth.lookup_name("66:48:95:3A:AA:7F", timeout=5) 
       if (device != None):
           lcd.clear()
           lcd.backlight(lcd.YELLOW)
           print "TeCoEd is in"
           lcd.message("TeCoEd is in his\noffcie on GitHub")
           sleep(2)
       else:
           lcd.clear()
           lcd.backlight(lcd.RED)
           print "Tecoed is out"
           lcd.message("TeCoEd is out")
           sleep(2)


Blue Who Finder 



 4. Nobody in the Building?


When the program starts it searches for Bluetooth enabled devices and returns the name of the device and its MAC address to a variable called devices.  If no devices are found then the variable devices has no content, the content stored is zero and has no length.  This can be used to indicate that no Bluetooth devices have been found and therefore no one is in the building.

if len (devices) == 0:
            lcd.backlight(lcd.RED)
            lcd.clear()
            print "No one is currently in the building"
            lcd.message("Building Empty")
            sleep(1)

5. Ending the Program


The Blue Who Finder needs to keep checking to update  and notify as various people with their devices arrive and leave the building.  The program has a built in option to end or recheck for devices and the number of times this happens.  This was a logic headache but with some help from @dave_spice it was sorted!

loop = 4
    while loop > 0:
        the_check()  #this is the check definition
        loop -=4
        print loop
        if loop == 0:
            repeat = raw_input("Do you want to check again, Y/N? ")
            repeat = repeat.upper()
            if repeat == "N":
                lcd.clear()
                lcd.backlight(lcd.BLUE)
                print "Bye Bye"
                lcd.message("Bye Bye :-)")
                sleep(3)
                lcd.noDisplay()
                lcd.backlight(lcd.OFF)
            elif repeat == "Y":
                loop = 4
            elif len(repeat)>1 or repeat not in ["yn"]:
                print "You did not make a valid selection..Closing program"


If you are required to to increase or decrease the number of times the program checks for devices then change the value of the loop.  It is set to 4 in this example.  You will also have to change the loop value after the first elif statement.

Code Links


Picture
Picture

The Blue Who Finder in Action


Powered by Create your own unique website with customizable templates.