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 UpLoad 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: 2. Checking to see who is inThe 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 MessagesIn 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 Finder4. 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 ProgramThe 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 |
The Blue Who Finder in Action
|
|