Last active
May 12, 2022 15:28
-
-
Save arpadtamasi/67255f39e1e5465fa8f76e06394668be to your computer and use it in GitHub Desktop.
MAX6675 micropython driver. Tested on ESP32 WROOM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from machine import Pin | |
import utime | |
class MAX6675(): | |
def __init__(self, so_pin=21, cs_pin=22, sck_pin=23): | |
self.cs = Pin(cs_pin, Pin.OUT) | |
self.so = Pin(so_pin, Pin.IN) | |
self.sck = Pin(sck_pin, Pin.OUT) | |
self.cs.on() | |
self.so.off() | |
self.sck.off() | |
self.last_read_time = utime.ticks_ms() | |
def readFahrenheit(self): | |
return self.readCelsius() * 9.0 / 5.0 + 32 | |
def readCelsius(self): | |
data = self.__read_data() | |
volts = sum([b * (1 << i) for i, b in enumerate(reversed(data))]) | |
print(volts) | |
return volts * 0.25 | |
def __read_data(self): | |
# CS down, read bytes then cs up | |
self.cs.off() | |
utime.sleep_us(10) | |
data = self.__read_word() # (self.__read_byte() << 8) | self.__read_byte() | |
self.cs.on() | |
print(data) | |
print(data[1:-3]) | |
if data[-3] == 1: | |
raise NoThermocoupleAttached() | |
return data[1:-3] | |
def __read_word(self): | |
return [self.__read_bit() for _ in range(16)] | |
def __read_bit(self): | |
self.sck.off() | |
utime.sleep_us(10) | |
bit = self.so.value() | |
self.sck.on() | |
utime.sleep_us(10) | |
return bit | |
class NoThermocoupleAttached(Exception): | |
"""Raised when there is no thermocouple attached to MAX6675""" | |
pass |
Would you give more information about the issue?
Hello Árpád,
First of all thanks for the idea, it was very useful for me. I am a
beginner! I think found some mistakes in the program.
If not, take my apologies.
So when I disconnect the MAX6675 panel from ESP32 WROOM, nothing happens.
Otherwise working well
if data[-3] == 1:
raise NoThermocoupleAttached()
Is this row doing nothing??
******************************************
yes, I changed pins.
#def __init__(self, so_pin=21, cs_pin=22, sck_pin=23):
def __init__(self, so_pin=19, cs_pin=5, sck_pin=18):
*************************************************
I commented out this :
#self.last_read_time = utime.ticks_ms() what is it here??
it has no influenced to program..
That's all,
Best regards,
Márton
Árpád Tamási ***@***.***> ezt írta (időpont: 2022. máj. 11.,
Sze, 17:30):
… ***@***.**** commented on this gist.
------------------------------
Would you give more information about the issue?
—
Reply to this email directly, view it on GitHub
<https://gist.github.com/67255f39e1e5465fa8f76e06394668be#gistcomment-4163781>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AOWVVRXCHS57N2R75TZULS3VJPG77ANCNFSM5VUQEJTA>
.
You are receiving this because you commented.Message ID:
***@***.***>
Disconnect detection was tricky and my solution is not bulletproof at all. Please update me if you find a better solution.
I used last read time for debugging purposes and is not needed at all. Same is true for printing values.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello,
These raise in row 38 does not works:
raise NoThermocoupleAttached()
Marton from Budapest