Alvaro Castillo
Published

Coffee Heater

Tired of drinking your coffee too cold or too hot? Fear no more! This device can keep your coffee at the perfect temperature.

IntermediateFull instructions provided1,339
Coffee Heater

Things used in this project

Hardware components

PocketBeagle
BeagleBoard.org PocketBeagle
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×1
Multi-Turn Precision Potentiometer- 10k ohms (25 Turn)
Multi-Turn Precision Potentiometer- 10k ohms (25 Turn)
×1
Li-Ion Battery 1000mAh
Li-Ion Battery 1000mAh
×1
Darlington High Power Transistor
Darlington High Power Transistor
×1
LEDs (generic)
×3
Resistor 1k ohm
Resistor 1k ohm
×3
Resistor 10k ohm
Resistor 10k ohm
×2
Adafruit Electric Heating Pad
×1
1N4007 – High Voltage, High Current Rated Diode
1N4007 – High Voltage, High Current Rated Diode
×1
Adafruit Hex Display
×1
Adafruit Waterproof DS18B20 Digital temperature sensor
Adafruit Waterproof DS18B20 Digital temperature sensor
×1
DC Voltage Regulator
×1

Hand tools and fabrication machines

Laser Cutter (generic)
Soldering Tool (generic)

Story

Read more

Custom parts and enclosures

Coffee Heater Box

Box that houses the device

Schematics

Wiring Diagram

Code

Project Program

Python
This is the code used for the device. You will need to update the path of the hex display library based on where you include the file (line 36).
"""
--------------------------------------------------------------------------
Coffee Heater Project
--------------------------------------------------------------------------
License:   
Copyright 2018 Alvaro Castillo

Redistribution and use in source and binary forms, with or without 
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this 
list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, 
this list of conditions and the following disclaimer in the documentation 
and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors 
may be used to endorse or promote products derived from this software without 
specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
--------------------------------------------------------------------------

"""
import sys
sys.path.append("/var/lib/cloud9/ENGI301/i2c/") #Path for the hex display library

import time

import Adafruit_BBIO.GPIO as GPIO

import Adafruit_BBIO.ADC as ADC

import ht16k33_i2c as HT16K33

import os

import glob

# ------------------------------------------------------------------------
# Global Variables
# ------------------------------------------------------------------------

base_dir = '/sys/bus/w1/devices/'
device_folder = glob.glob(base_dir + '28*')[0]
device_file = device_folder + '/w1_slave'

# ------------------------------------------------------------------------
# Main Tasks
# ------------------------------------------------------------------------

def setup():
    """Setup the hardware components."""
    
    # Initialize Display
    HT16K33.display_setup()
    HT16K33.display_clear()
    
    #Set up the Analog input
    ADC.setup()
    
    #Set the GPIOS
    GPIO.setup("P2_18", GPIO.OUT)
    GPIO.setup("P2_20", GPIO.OUT)
    GPIO.setup("P2_22", GPIO.OUT)
    GPIO.setup("P2_24", GPIO.OUT)
    
    GPIO.output("P2_24", GPIO.LOW)
    
    
# End def

def read_temp_raw():
    f = open(device_file, 'r')
    lines = f.readlines()
    f.close()
    return lines

#End def

def read_temp():
    lines = read_temp_raw()
    while lines[0].strip()[-3:] != 'YES':
        time.sleep(0.2)
        lines = read_temp_raw()

    equals_pos = lines[1].find('t=')

    if equals_pos != -1:
        temp_string = lines[1][equals_pos+2:]
        temp_c = float(temp_string) / 1000.0
        return temp_c
    
#End def

def cleanup():
    """Cleanup the hardware components."""
    
    # Set Display to something fun to show program is complete
    HT16K33.display_set_digit(0, 13)        # "D"
    HT16K33.display_set_digit(1, 14)        # "E"
    HT16K33.display_set_digit(2, 10)        # "A"
    HT16K33.display_set_digit(3, 13)        # "D"
    
    GPIO.output("P2_22", GPIO.LOW) #Blue LED
    GPIO.output("P2_20", GPIO.LOW) #Green LED
    GPIO.output("P2_18", GPIO.LOW) #Redb LED
    GPIO.output("P2_24", GPIO.LOW)
    
# End def

def temp_test():
    while(1):
        #get the desired temp
        desired_temp = int(round (ADC.read ("P1_19")*100))
        
        
        #Update the display
        HT16K33.update_display(desired_temp)
        time.sleep(1)
        
        #get current temp
        current_temp = read_temp()
        
        # If the temperature is higher than desired temperature
        if(current_temp > desired_temp):
            #Temperetaure is too high, needs to cool down
            if (current_temp > (desired_temp + 5)):
                #Adjust the LEDs
                GPIO.output("P2_22", GPIO.LOW) #Blue LED
                GPIO.output("P2_20", GPIO.LOW) #Green LED
                GPIO.output("P2_18", GPIO.HIGH) #Red LED
                
                #Turn off the heating pad 
                GPIO.output("P2_24", GPIO.LOW)
            
            #Temperature is OK
            else:
                #Adjust the LEDs
                GPIO.output("P2_18", GPIO.LOW) #Red LED
                GPIO.output("P2_22", GPIO.LOW) #Blue LED
                GPIO.output("P2_20", GPIO.HIGH) #Green LED
                
                #Turn off the heating pad 
                GPIO.output("P2_24", GPIO.LOW)
      
        # If temperature is lower than desired temperature
        if(current_temp < desired_temp):
             #Adjust the LEDs 
             GPIO.output("P2_18", GPIO.LOW) #Red LED
             GPIO.output("P2_20", GPIO.LOW) #Green LED
             GPIO.output("P2_22", GPIO.HIGH) #Blue LED
             
             #Turn on the heating pad 
             GPIO.output("P2_24", GPIO.HIGH)
        
# End def
             
# ------------------------------------------------------------------------
# Main script
# ------------------------------------------------------------------------

if __name__ == '__main__':
    #Run the setup function
    setup()
    
    #Run the main function
    try:
        temp_test()
    except KeyboardInterrupt:
        pass
    
    #Run the clean up function
    cleanup()
    print("Program Complete.")

DTS File for the DS18B20 Temperature Sensor

Plain text
Use this file to compile the .dtbo file needed to interact with the temperature sensor.
/*
 * Copyright (C) 2015 Robert Nelson <robertcnelson@gmail.com>
 *
 * Virtual cape for onewire on connector pin P2_31
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */

/dts-v1/;
/plugin/;

#include <dt-bindings/board/am335x-bbw-bbb-base.h>
#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/pinctrl/am33xx.h>

/ {
	
	/*
	 * Free up the pins used by the cape from the pinmux helpers.
	 */
	fragment@0 {
		target = <&ocp>;
		__overlay__ {
			P2_33_pinmux { status = "disabled"; };
		};
	};

	fragment@1 {
		target = <&am33xx_pinmux>;
		__overlay__ {

			dallas_w1_pins: pinmux_dallas_w1_pins {
				pinctrl-single,pins = < 
					0x34 0x37
				>;
			};
		};
	};

	fragment@2 {
		target-path="/";
		__overlay__ {

			onewire {
				status = "okay";
				pinctrl-names = "default";
				pinctrl-0 = <&dallas_w1_pins>;

				compatible = "w1-gpio";
				gpios = <&gpio1 13 GPIO_ACTIVE_HIGH>;
			};
		};
	};
};

Credits

Alvaro Castillo

Alvaro Castillo

1 project • 0 followers

Comments