Pixel Fusion Python coffee collector messenger
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Services
fonts
images
.env.example
.gitignore
.python-version
Dockerfile
README.md
requirements.txt
script.py

README.md

Coffee Collector

Pixel Fusion coffee collector, the ultrasonic distance sensor measures how full the collector is. Based on the level it gives updates on Slack and real time information on the led screen.

Hardware

  • Raspberry pi Zero W
  • Adafruit SSD1306 128*32 led screen
  • HC-SR04 ultrasonic distance ranging module

Wiring

Wiring digram

Color layout:

SENSOR
  • blue=5V
  • purple=GPIO14 | trig
  • grey=Ground
  • white=GPIO23 | echo
LED-SCREEN
  • green=SDA
  • yellow=SCL
  • orange=Ground
  • red=3.3V

Configure Raspberry Pi

  • Follow the installation process described on Raspberry pi install
  • Add an empty file ssh on the boot partition (so we can ssh into the pi)
  • Add an wpa_supplicant.conf file to the boot partition (this will load the wifi config) Example config:
network={
    ssid="wifi_ssid"
    psk="wifi_password"
}
  • Boot the pi and scan your network, SSH into you pi with the default password and username
  • After you logged in you need to update the password with passwd
  • Make sure git is installed on your pi, otherwise run sudo apt-get install git
  • Run the following command to setup the code, mkdir ~/scripts && cd ~/scripts && git clone https://github.com/pixelfusion/coffee-collector-messenger.git
  • Make sure pip and essential tools are installed, otherwise run sudo apt-get install build-essential python-dev python-pip
  • Make sure you have python images installed, otherwise run sudo apt-get install python-imaging python-smbus
  • Install requirements for the python script pip install -r requirements.txt
  • Enable I2C for the display sudo apt-get install -y i2c-tools
  • Setup I2C, sudo vi /etc/modules add:
i2c-bcm2708 
i2c-dev
  • Also edit /boot/config.txt and add or uncomment:
dtparam=i2c1=on
dtparam=i2c_arm=on
  • Reboot the pi and verify that I2C is setup with sudo i2cdetect -y 1

Reference for the I2C setup Adafruit Raspberry pi configuring i2c

Booting the script

  • Setup your .env file, see the .env.example for reference
  • To auto start the script on boot, you can use a cronjob:
@reboot echo "$(date) $(ls -1 | wc -l)" >> ~/scripts/cc-cron.log
@reboot python ~/scripts/coffee-collector-messenger/script.py >> ~/scripts/cc-cron.log 2>&1
  • Reboot the pi, and the script should run now
  • You can also review the logs, if you have any issues tail -f ~/scripts/coffee-collector-messenger/cc.log

Slack notification levels

  • Percentage is calculated with the height of the collector + 10% safety margin.
  • Formula helper
Status CM's left Color Emoticon Percentage of water Special Notification
A > 32 Green 😀 0% - 27.5% x 24h
B > 24 and <= 32 Blue 🙂 30% - 47.5% x 12h
C > 16 and <= 24 Orange 😰 50% - 67.5% x 6h
D >= 16 Red 😱 70% - 100% Tag 3 slack users 3h

The notifications are send bassed on the Status level time (A sends message every 24 hours). There is also a message send when the status level changes, this only happens when: The current and previous reading, are in the same level and the one before that is in a different level.

Gotchas

  • Make the sensor align perfectly downwards, otherwise you get diverse readings