ugnen

git clone https://git.tarina.org/ugnen
Log | Files | Refs

commit dbe5dbe194df431b177e75778c8ed7289ce4f0af
parent 5483c3dd7d64858ec426d645b7eaee7f6b9a4ec1
Author: rbckman <rob@tarina.org>
Date:   Thu,  8 Sep 2022 10:51:35 +0100

Merge branch 'master' of https://git.tarina.org/ugnen

Diffstat:
Amax6675.py | 60++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Atemp_read_1_sensor.py | 39+++++++++++++++++++++++++++++++++++++++
Mugnen.py | 21+++++++++++++++------
3 files changed, 114 insertions(+), 6 deletions(-)

diff --git a/max6675.py b/max6675.py @@ -0,0 +1,60 @@ +import RPi.GPIO as GPIO +import time +GPIO.setmode(GPIO.BOARD) +GPIO.setwarnings(False) + +# set pin number for communicate with MAX6675 +def set_pin (CS, SCK, SO, UNIT): + global sck + sck= SCK + global so + so = SO + global unit + unit = UNIT + + GPIO.setup(CS, GPIO.OUT, initial = GPIO.HIGH) + GPIO.setup(SCK, GPIO.OUT, initial = GPIO.LOW) + GPIO.setup(SO, GPIO.IN) + +def read_temp(cs_no): + + GPIO.output(cs_no, GPIO.LOW) + time.sleep(0.002) + GPIO.output(cs_no, GPIO.HIGH) + time.sleep(0.22) + + GPIO.output(cs_no, GPIO.LOW) + GPIO.output(sck, GPIO.HIGH) + time.sleep(0.001) + GPIO.output(sck, GPIO.LOW) + Value = 0 + for i in range(11, -1, -1): + GPIO.output(sck, GPIO.HIGH) + Value = Value + (GPIO.input(so) * (2 ** i)) + GPIO.output(sck, GPIO.LOW) + + GPIO.output(sck, GPIO.HIGH) + error_tc = GPIO.input(so) + GPIO.output(sck, GPIO.LOW) + + for i in range(2): + GPIO.output(sck, GPIO.HIGH) + time.sleep(0.001) + GPIO.output(sck, GPIO.LOW) + + GPIO.output(cs_no, GPIO.HIGH) + + if unit == 0: + temp = Value + if unit == 1: + temp = Value * 0.25 + if unit == 2: + temp = Value * 0.25 * 9.0 / 5.0 + 32.0 + + if error_tc != 0: + return -cs_no + else: + return temp + +GPIO.cleanup() + diff --git a/temp_read_1_sensor.py b/temp_read_1_sensor.py @@ -0,0 +1,39 @@ +# before import the max6675, you must save the max6675.py file at "/usr/lib/python2.7/dist-packages" + +# wiring +# Raspberry MAX6675 +# GND ------ GND +# 5V ------ VCC +# pin 18 ------ SCK +# pin 22 ------ CS +# pin 16 ------ SO + +# import max6675 module. +import max6675 + +# set the pin for communicate with MAX6675 +cs = 22 +sck = 18 +so = 16 + +# max6675.set_pin(CS, SCK, SO, unit) [unit : 0 - raw, 1 - Celsius, 2 - Fahrenheit] +max6675.set_pin(cs, sck, so, 1) + +try: + while 1: + # read temperature connected at CS 22 + a = max6675.read_temp(cs) + + # print temperature + print a + + # when there are some errors with sensor, it return "-" sign and CS pin number + # in this case it returns "-22" + + max6675.time.sleep(2) + +except KeyboardInterrupt: + pass + + + diff --git a/ugnen.py b/ugnen.py @@ -5,8 +5,16 @@ import requests import socket import os import pickle -import serial +#import serial import blessed +import max6675 + +# set the pin for communicate with MAX6675 +cs = 20 +sck = 26 +so = 16 +# max6675.set_pin(CS, SCK, SO, unit) [unit : 0 - raw, 1 - Celsius, 2 - Fahrenheit] +max6675.set_pin(cs, sck, so, 1) term = blessed.Terminal() @@ -40,14 +48,15 @@ GPIO.setup(relaypin, GPIO.OUT) #RELAY GPIO.output(relaypin, GPIO.LOW) -try: - arduino = serial.Serial(port='/dev/ttyUSB0', baudrate=9600, timeout=.1) -except: - arduino = '' +#try: +# arduino = serial.Serial(port='/dev/ttyUSB0', baudrate=9600, timeout=.1) +#except: +# arduino = '' def read_temp(): try: - temp = arduino.readline().decode('utf-8').rstrip() + temp = max6675.read_temp(cs) + #temp = arduino.readline().decode('utf-8').rstrip() except: return 0 return temp