From 62c62f33ca2016d52d33741cc275907718efc54e Mon Sep 17 00:00:00 2001 From: Joe2824 Date: Wed, 25 Jul 2018 21:05:47 +0200 Subject: [PATCH 1/9] change to Adafruit SSD1306 --- bartender.py | 69 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 45 insertions(+), 24 deletions(-) diff --git a/bartender.py b/bartender.py index 56de81d..3ebe21b 100644 --- a/bartender.py +++ b/bartender.py @@ -1,6 +1,3 @@ -import gaugette.ssd1306 -import gaugette.platform -import gaugette.gpio import time import sys import RPi.GPIO as GPIO @@ -8,6 +5,13 @@ import threading import traceback +import Adafruit_GPIO.SPI as SPI +import Adafruit_SSD1306 + +from PIL import Image +from PIL import ImageFont +from PIL import ImageDraw + from dotstar import Adafruit_DotStar from menu import MenuItem, Menu, Back, MenuContext, MenuDelegate from drinks import drink_list, drink_options @@ -31,7 +35,15 @@ NEOPIXEL_CLOCK_PIN = 6 NEOPIXEL_BRIGHTNESS = 64 -FLOW_RATE = 60.0/100.0 +FLOW_RATE = 60.0/1500.0 + +# Raspberry Pi pin configuration: +RST = 14 +# Note the following are only used with SPI: +DC = 15 +SPI_PORT = 0 +SPI_DEVICE = 0 + class Bartender(MenuDelegate): def __init__(self): @@ -51,18 +63,27 @@ def __init__(self): # configure screen spi_bus = 0 spi_device = 0 - gpio = gaugette.gpio.GPIO() - spi = gaugette.spi.SPI(spi_bus, spi_device) # Very important... This lets py-gaugette 'know' what pins to use in order to reset the display - self.led = gaugette.ssd1306.SSD1306(gpio, spi, reset_pin=OLED_RESET_PIN, dc_pin=OLED_DC_PIN, rows=self.screen_height, cols=self.screen_width) # Change rows & cols values depending on your display dimensions. + self.led = disp = Adafruit_SSD1306.SSD1306_128_64(rst=RST, dc=DC, spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE, max_speed_hz=8000000)) # Change rows & cols values depending on your display dimensions. + + # Initialize library. self.led.begin() - self.led.clear_display() + + # Clear display. + self.led.clear() self.led.display() - self.led.invert_display() - time.sleep(0.5) - self.led.normal_display() - time.sleep(0.5) + + + # Create image buffer. + # Make sure to create image with mode '1' for 1-bit color. + self.image = Image.new('1', (self.screen_width, self.screen_height)) + + # Load default font. + self.font = ImageFont.load_default() + + # Create drawing object. + self.draw = ImageDraw.Draw(self.image) # load the pump configuration from file self.pump_configuration = Bartender.readPumpConfiguration() @@ -226,8 +247,10 @@ def clean(self): def displayMenuItem(self, menuItem): print menuItem.name - self.led.clear_display() - self.led.draw_text2(0,20,menuItem.name,2) + self.led.clear() + self.draw.rectangle((0,0,self.screen_width,self.screen_height), outline=0, fill=0) + self.draw.text((0,20),str(menuItem.name), font=self.font, fill=255) + self.led.image(self.image) self.led.display() def cycleLights(self): @@ -272,8 +295,10 @@ def pour(self, pin, waitTime): def progressBar(self, waitTime): interval = waitTime / 100.0 for x in range(1, 101): - self.led.clear_display() + self.led.clear() + self.draw.rectangle((0,0,self.screen_width,self.screen_height), outline=0, fill=0) self.updateProgressBar(x, y=35) + self.led.image(self.image) self.led.display() time.sleep(interval) @@ -338,14 +363,14 @@ def updateProgressBar(self, percent, x=15, y=15): height = 10 width = self.screen_width-2*x for w in range(0, width): - self.led.draw_pixel(w + x, y) - self.led.draw_pixel(w + x, y + height) + self.draw.point((w + x, y), fill=255) + self.draw.point((w + x, y + height), fill=255) for h in range(0, height): - self.led.draw_pixel(x, h + y) - self.led.draw_pixel(self.screen_width-x, h + y) + self.draw.point((x, h + y), fill=255) + self.draw.point((self.screen_width-x, h + y), fill=255) for p in range(0, percent): p_loc = int(p/100.0*width) - self.led.draw_pixel(x + p_loc, h + y) + self.draw.point((x + p_loc, h + y), fill=255) def run(self): self.startInterrupts() @@ -364,7 +389,3 @@ def run(self): bartender = Bartender() bartender.buildMenu(drink_list, drink_options) bartender.run() - - - - From 7b4d921239c85229d59ca8c1bff604106242f71e Mon Sep 17 00:00:00 2001 From: Joe2824 Date: Wed, 25 Jul 2018 21:10:48 +0200 Subject: [PATCH 2/9] Update to Adafruit SSD1306 --- README.md | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index c2b31c8..2d7999f 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,6 @@ -# Smart Bartender +# Smart Bartender with Adafruit SSD1306 Why spend lots of money going out for drinks when you can have your own smart personal bartender at your service right in your home?! This bartender is built from a Raspberry Pi 3 and some common DIY electronics. -## Prerequisites for the Raspberry Pi -Make sure you can connect a screen and keyboard to your Raspberry Pi. I like to use VNC to connect to the Pi. I created a [tutorial](https://www.youtube.com/watch?v=2iVK8dn-6x4) about how to set that up on a Mac. Make sure the following are installed: * Python 2.7 (should already be installed on most Raspberry Pi) @@ -38,23 +36,29 @@ i2c-dev press `esc` then `ZZ` to save and exit. ## OLED Setup -The Raspberry Pi Guy has a nice script to setup the OLED screen on your raspberry pi. Download the following repository on your Pi: - -https://github.com/the-raspberry-pi-guy/OLED -then navigate to the folder with the terminal +You need to install the Adafruit Python SSD1306 library with ``` -cd ~/path/to/directory +sudo python -m pip install --upgrade pip setuptools wheel +sudo pip install Adafruit-SSD1306 ``` -and run the installation script +Or alternatively: ``` -sh OLEDinstall.sh +sudo python -m pip install --upgrade pip setuptools wheel +git clone https://github.com/adafruit/Adafruit_Python_SSD1306.git +cd Adafruit_Python_SSD1306 +sudo python setup.py install ``` -There is also a [guide](https://learn.adafruit.com/adafruit-oled-displays-for-raspberry-pi/setting-up) on the Adafruit website if you get stuck. +The Raspberry Pi Guy has a nice script to setup the OLED screen on your raspberry pi. Download the following repository on your Pi: + +https://github.com/the-raspberry-pi-guy/OLED + + +There is also a [guide](https://learn.adafruit.com/ssd1306-oled-displays-with-raspberry-pi-and-beaglebone-black/usage) on the Adafruit website if you get stuck. ## Running the Code From 0f2fc11f71211a2ed36f214911fdabb893d5149e Mon Sep 17 00:00:00 2001 From: Joe2824 Date: Wed, 25 Jul 2018 21:11:36 +0200 Subject: [PATCH 3/9] Update to Adafruit SSD1306 --- README.md | 5 ----- 1 file changed, 5 deletions(-) diff --git a/README.md b/README.md index 2d7999f..158f004 100644 --- a/README.md +++ b/README.md @@ -53,11 +53,6 @@ cd Adafruit_Python_SSD1306 sudo python setup.py install ``` -The Raspberry Pi Guy has a nice script to setup the OLED screen on your raspberry pi. Download the following repository on your Pi: - -https://github.com/the-raspberry-pi-guy/OLED - - There is also a [guide](https://learn.adafruit.com/ssd1306-oled-displays-with-raspberry-pi-and-beaglebone-black/usage) on the Adafruit website if you get stuck. ## Running the Code From b5c32024c10e7df256a3c6c8c401a6b0817731df Mon Sep 17 00:00:00 2001 From: Joe2824 Date: Fri, 27 Jul 2018 09:07:53 +0200 Subject: [PATCH 4/9] Fix Forever-Drinks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Thanks to @Danzibob Code 👍 --- bartender.py | 52 ++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 14 deletions(-) diff --git a/bartender.py b/bartender.py index 3ebe21b..8204f7e 100644 --- a/bartender.py +++ b/bartender.py @@ -1,8 +1,10 @@ +#!/usr/bin/env python +# -*- coding: iso-8859-1 -*- + import time import sys import RPi.GPIO as GPIO import json -import threading import traceback import Adafruit_GPIO.SPI as SPI @@ -22,10 +24,10 @@ SCREEN_HEIGHT = 64 LEFT_BTN_PIN = 13 -LEFT_PIN_BOUNCE = 1000 +LEFT_PIN_BOUNCE = 200 RIGHT_BTN_PIN = 5 -RIGHT_PIN_BOUNCE = 2000 +RIGHT_PIN_BOUNCE = 200 OLED_RESET_PIN = 15 OLED_DC_PIN = 16 @@ -120,10 +122,6 @@ def startInterrupts(self): GPIO.add_event_detect(self.btn1Pin, GPIO.FALLING, callback=self.left_btn, bouncetime=LEFT_PIN_BOUNCE) GPIO.add_event_detect(self.btn2Pin, GPIO.FALLING, callback=self.right_btn, bouncetime=RIGHT_PIN_BOUNCE) - def stopInterrupts(self): - GPIO.remove_event_detect(self.btn1Pin) - GPIO.remove_event_detect(self.btn2Pin) - def buildMenu(self, drink_list, drink_options): # create a new main menu m = Menu("Main Menu") @@ -152,7 +150,7 @@ def buildMenu(self, drink_list, drink_options): # add pump menus to the configuration menu configuration_menu.addOptions(pump_opts) # add a back button to the configuration menu - configuration_menu.addOption(Back("Back")) + configuration_menu.addOption(Back("Zurück")) # adds an option that cleans all pumps to the configuration menu configuration_menu.addOption(MenuItem('clean', 'Clean')) configuration_menu.setParent(m) @@ -241,9 +239,6 @@ def clean(self): # sleep for a couple seconds to make sure the interrupts don't get triggered time.sleep(2); - # reenable interrupts - # self.startInterrupts() - self.running = False def displayMenuItem(self, menuItem): print menuItem.name @@ -352,12 +347,21 @@ def makeDrink(self, drink, ingredients): self.running = False def left_btn(self, ctx): + print("LEFT_BTN pressed") if not self.running: + self.running = True self.menuContext.advance() + print("Finished processing button press") + self.running = False def right_btn(self, ctx): + print("RIGHT_BTN pressed") if not self.running: + self.running = True self.menuContext.select() + print("Finished processing button press") + self.running = 2 + print("Starting button timeout") def updateProgressBar(self, percent, x=15, y=15): height = 10 @@ -375,9 +379,25 @@ def updateProgressBar(self, percent, x=15, y=15): def run(self): self.startInterrupts() # main loop - try: - while True: - time.sleep(0.1) + try: + + try: + + while True: + letter = raw_input(">") + if letter == "l": + self.left_btn(False) + if letter == "r": + self.right_btn(False) + + except EOFError: + while True: + time.sleep(0.1) + if self.running not in (True,False): + self.running -= 0.1 + if self.running == 0: + self.running = False + print("Finished button timeout") except KeyboardInterrupt: GPIO.cleanup() # clean up GPIO on CTRL+C exit @@ -389,3 +409,7 @@ def run(self): bartender = Bartender() bartender.buildMenu(drink_list, drink_options) bartender.run() + + + + From 158019dc6da7af1024ec809758fe3ea0671c23ab Mon Sep 17 00:00:00 2001 From: Joe2824 Date: Fri, 3 Aug 2018 09:25:17 +0200 Subject: [PATCH 5/9] add import threading --- bartender.py | 1 + 1 file changed, 1 insertion(+) diff --git a/bartender.py b/bartender.py index 8204f7e..e6c3d08 100644 --- a/bartender.py +++ b/bartender.py @@ -6,6 +6,7 @@ import RPi.GPIO as GPIO import json import traceback +import threading import Adafruit_GPIO.SPI as SPI import Adafruit_SSD1306 From 00a8e9384a8f0eef39a835daad9398df297c2fe9 Mon Sep 17 00:00:00 2001 From: Joe2824 Date: Sun, 2 Sep 2018 23:37:36 +0200 Subject: [PATCH 6/9] Update README.md --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 158f004..52c1906 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,4 @@ # Smart Bartender with Adafruit SSD1306 -Why spend lots of money going out for drinks when you can have your own smart personal bartender at your service right in your home?! This bartender is built from a Raspberry Pi 3 and some common DIY electronics. - Make sure the following are installed: * Python 2.7 (should already be installed on most Raspberry Pi) From 8741dd4565b949802ae887b4ef60976405e37721 Mon Sep 17 00:00:00 2001 From: Joe2824 Date: Fri, 2 Nov 2018 17:19:05 +0100 Subject: [PATCH 7/9] Update README.md change vim to nano --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 52c1906..acc45cd 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ See this [article](https://www.raspberrypi.org/documentation/hardware/raspberryp Make sure i2c is also configured properly. Type ``` -sudo vim /etc/modules +sudo nano /etc/modules ``` in the terminal @@ -132,7 +132,7 @@ from the repository folder. Copy this to your clipboard. Next, type ``` -sudo vim /etc/rc.local +sudo nano /etc/rc.local ``` to open the rc.local file. Next, press `i` to edit. Before the last line, add the following two lines: From ad29d72dcaed51266f0eb96a9740a6494ff574f6 Mon Sep 17 00:00:00 2001 From: Joe2824 Date: Mon, 23 Dec 2019 10:55:52 +0100 Subject: [PATCH 8/9] Create .travis.yml --- .travis.yml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..e32bd37 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,25 @@ +sudo: false +language: python +python: + - "2.7" + - "3.3" + - "3.4" + - "3.5" + - "3.6" +env: + - DEPS=lowest + - DEPS=release + - DEPS=devel +install: + - '[[ "$DEPS" == "lowest" ]] && pip install jinja2==2.8 || :' + - '[[ "$DEPS" == "lowest" ]] && pip install flask==0.11 || :' + - '[[ "$DEPS" == "devel" ]] && pip install git+https://github.com/mitsuhiko/jinja2.git || :' + - '[[ "$DEPS" == "devel" ]] && pip install git+https://github.com/mitsuhiko/flask.git || :' + - pip install pytest pytest-cov pytest-pep8 coveralls +script: + - python setup.py develop + - py.test --pep8 +after_success: + - coveralls +notifications: + email: false From eb7abb7799f36827287820cb4514fc50c7fc26f7 Mon Sep 17 00:00:00 2001 From: Joe2824 Date: Mon, 23 Dec 2019 10:56:41 +0100 Subject: [PATCH 9/9] Update .travis.yml --- .travis.yml | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/.travis.yml b/.travis.yml index e32bd37..5923709 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,20 +6,3 @@ python: - "3.4" - "3.5" - "3.6" -env: - - DEPS=lowest - - DEPS=release - - DEPS=devel -install: - - '[[ "$DEPS" == "lowest" ]] && pip install jinja2==2.8 || :' - - '[[ "$DEPS" == "lowest" ]] && pip install flask==0.11 || :' - - '[[ "$DEPS" == "devel" ]] && pip install git+https://github.com/mitsuhiko/jinja2.git || :' - - '[[ "$DEPS" == "devel" ]] && pip install git+https://github.com/mitsuhiko/flask.git || :' - - pip install pytest pytest-cov pytest-pep8 coveralls -script: - - python setup.py develop - - py.test --pep8 -after_success: - - coveralls -notifications: - email: false