MAX31855 Thermocouple driver


42 posts   Page 1 of 2   1, 2
by tuckie » Sat Sep 22, 2012 6:11 pm
Just finished this up for those that are interested: https://github.com/Tuckie/max31855

Edit: version 2.0 released. More chips. Less dependencies.
Last edited by tuckie on Wed Sep 11, 2013 2:07 am, edited 1 time in total.
Posts: 11
Joined: Mon Sep 03, 2012 1:50 am
by Beantown_Brewer » Sat Dec 15, 2012 10:01 pm
So glad you made this python driver for the pi. I am an avid home brewer and I plan on using the MAX31855 to monitor and log temperature during my fermentations.

I am new to Python, but I believe that I have stumbled my way through successfully installing both the prerequisite quick2wire-python-api and bitstring libraries . When I run the quick2wire.spi and bitstring imports under python3, I am getting no errors.

I am not sure what to do next in order to use your driver. If you could help out a newbie and point me in the right direction I would very much appreciate it.

Thanks,
Beantown_Brewer
Posts: 2
Joined: Sun Dec 09, 2012 2:25 am
by thogue » Mon Dec 17, 2012 4:38 pm
Just found this, kudos to you sir!
Posts: 131
Joined: Wed Sep 19, 2012 2:16 am
by thogue » Tue Dec 18, 2012 2:22 am
@Beantown_Brewer: You need have the SPI driver installed, it comes with the most recent builds (pretty sure)
Not sure if both are required but the first one is, I know some other SPI things I have played with in the past required spidev so i am not sure.
modprobe spi_bcm2708
modprobe spidev

Then once you have satisfied the dependencies for the driver you can test it but running the script itself ./python max31855.py


as far as wiring: **edit**
Vin/3vo -> 3.3
GND -> GND
DO -> MISO (21)
CS -> Originally I put this to MOSI which I thought was incorrect but did work, I believe this is supposed to be CE1 or CE0 as I pretty sure these are the "CS pins"
CLK - >SCLK (23)

Just got it working. Thanks again.
Posts: 131
Joined: Wed Sep 19, 2012 2:16 am
by Winpup12 » Mon Dec 24, 2012 9:01 pm
Would this be good above 1000 deg c? Any chance for a tutorial?
Posts: 1
Joined: Mon Dec 24, 2012 5:12 pm
by thogue » Wed Dec 26, 2012 5:04 am
I dont know why you can't go over 1000C, It really depends on the thermocouple. K types go into the 1000C range http://en.wikipedia.org/wiki/Thermocouple
Posts: 131
Joined: Wed Sep 19, 2012 2:16 am
by Beantown_Brewer » Fri Jan 04, 2013 3:25 am
Thanks so much for this git post .....with my new RasPi, I got the MAX31855 add-on board from Adafruit found here:
http://www.adafruit.com/products/269

.....and using a great quality thermocouple from here: http://www.thermoworks.com/products/pro ... htemp.html

I am now carefully logging (and controlling) my fermentation temperature over time!!!!
Posts: 2
Joined: Sun Dec 09, 2012 2:25 am
by novonic » Thu Mar 21, 2013 10:21 am
Hi,

Thanks for the driver. It took me quite a while to get it going. It seems that quick2wire must've changed from python2 to python3 at some point after you wrote it. As I had to add ( ) to the print commands, and run under python3.

I'm trying to create a web front end, using flask, to monitor the thermocouple. The problem I have is that flask is python2.

So my question is, can you help me by advising how I can ditch the quick2wire reference and just communicate directly with the spi device? Writing drivers is a bit beyond my ability at the moment.

Thanks
Steve
Posts: 1
Joined: Thu Mar 21, 2013 10:10 am
by sheimend » Sat Apr 06, 2013 10:05 pm
Thank you so much for putting together this driver. Unfortunately, as a RPi newbie, I'm getting stuck at the following. When I run "python max31855.py", I get

"File ",ax31855.py", line3, in <module>
import quick2wire.spi as Spibus
ImportError: No module named quick2wire.spi"

I've installed the quick2wire-python-api package under /home/pi/git/quick2wire-python-api.

Any suggestions?

Thanks much,
Scott
Posts: 1
Joined: Sat Apr 06, 2013 10:00 pm
by geoncic » Sun Apr 28, 2013 5:32 am
I have been trying for a while to figure out how to get the Max31855 drivers working with the gertboard.

I was about to get it working with just the PI and breakout board. Any tips on what jumpers to use on the gertboard? And what kind of code may need to be added to max31855.py?

Thanks.
Posts: 1
Joined: Sun Apr 28, 2013 5:30 am
by joelwehr » Sun May 19, 2013 10:50 pm
I'm using this driver with the Adafruit breakout board and a Pi. Measuring the temperature of my BBQ grill and dumping the data to a Windows Azure web database. I'd like to connect a second thermocouple. I'm not sure if I can connect a second breakout board to the Pi. Can anyone help me out with this?
Posts: 1
Joined: Sun May 19, 2013 10:32 pm
by tuckie » Mon May 20, 2013 3:01 am
http://en.wikipedia.org/wiki/Serial_Per ... figuration

The Raspberry Pi has support for two spi devices via CE0 and CE1. In the wiki article, it is SS1 and SS2

Code: Select all
one_probe = MAX31855(0, "f")
another_probe = MAX31855(1, "f")


Note, I haven't actually tested this, but it should work.
Posts: 11
Joined: Mon Sep 03, 2012 1:50 am
by jeffremer » Thu Jul 04, 2013 11:36 pm
Thanks for the driver! It took a lot of work to actually get the SPI interfaces going, but now I'm having a lot of trouble getting a reading. With no GPIO cable attached to the Raspberry Pi I get promising output from the max31855.py script itself:

Code: Select all
pi@raspberrypi ~/max31855 $ python3 max31855.py
Test conversions from MAX31855 datasheet
External Thermocouple:
"0110 0100 0000 00" should equal 1600.0: True
"0011 1110 1000 00" should equal 1000.0: True
"0000 0110 0100 11" should equal 100.75: True
"0000 0001 1001 00" should equal 25.0: True
"0000 0000 0000 00" should equal 0.0: True
"1111 1111 1111 11" should equal -0.25: True
"1111 1111 1111 00" should equal -1.0: True
"1111 0000 0110 00" should equal -250.0: True
Internal Reference Junction:
"0111 1111 0000" should equal 127.0: True (127.0)
"0110 0100 1001" should equal 100.5625: True (100.5625)
"0001 1001 0000" should equal 25.0: True (25.0)
"0000 0000 0000" should equal 0.0: True (0.0)
"1111 1111 1111" should equal -0.0625: True (-0.0625)
"1111 1111 0000" should equal -1.0: True (-1.0)
"1110 1100 0000" should equal -20.0: True (-20.0)
"1100 1001 0000" should equal -55.0: True (-55.0)
tc: 32.0 and rj: 32.0
tc: 32.0 and rj: 32.0
tc: 32.0 and rj: 32.0
tc: 32.0 and rj: 32.0
#...and so on.


Now with a GPI cable attached and the Adafruit MAX31855 breakout breadboarded with the following wiring (MAX31855 > RPi) I just get the following output:

Wiring: VIN > 3V3, GND>GND, DO > MISO, CS > CE1||CE0||MOSI (tried all 3 and modified the code accordingly), CLK>CLK.

Output:

Code: Select all
Test conversions from MAX31855 datasheet
External Thermocouple:
"0110 0100 0000 00" should equal 1600.0: True
"0011 1110 1000 00" should equal 1000.0: True
"0000 0110 0100 11" should equal 100.75: True
"0000 0001 1001 00" should equal 25.0: True
"0000 0000 0000 00" should equal 0.0: True
"1111 1111 1111 11" should equal -0.25: True
"1111 1111 1111 00" should equal -1.0: True
"1111 0000 0110 00" should equal -250.0: True
Internal Reference Junction:
"0111 1111 0000" should equal 127.0: True (127.0)
"0110 0100 1001" should equal 100.5625: True (100.5625)
"0001 1001 0000" should equal 25.0: True (25.0)
"0000 0000 0000" should equal 0.0: True (0.0)
"1111 1111 1111" should equal -0.0625: True (-0.0625)
"1111 1111 0000" should equal -1.0: True (-1.0)
"1110 1100 0000" should equal -20.0: True (-20.0)
"1100 1001 0000" should equal -55.0: True (-55.0)
Traceback (most recent call last):
  File "max31855.py", line 138, in <module>
    print("tc: {} and rj: {}".format(thermocouple.get(), thermocouple.get_rj()))
  File "max31855.py", line 31, in get
    self.read()
  File "max31855.py", line 43, in read
    self.checkErrors()
  File "max31855.py", line 55, in checkErrors
    raise MAX31855Error("No Connection")
__main__.MAX31855Error: 'No Connection'


Additionally, wired that way the MAX31855 chip itself gets extremely hot (talk about irony, if I had the thermocouple I working I could have read the chip temp before burning the crap out my finger tips). I have duplicates of the breakout board and chip, and I have tried both.

The fact that the chip gets super hot and the reading shows "No Connection" are worrying. Any thoughts? Thanks.
Last edited by jeffremer on Fri Jul 05, 2013 12:19 am, edited 1 time in total.
Posts: 3
Joined: Thu Jul 04, 2013 11:24 pm
by jeffremer » Fri Jul 05, 2013 12:06 am
Quick followup: I've tried wiring up both the boards to an RPi with this driver/wiring suggestion then wiring them up to an Arduino, now they just seem dead - they both worked fine on the Arduino before. Given the blister I've got on my fingertip it seems likely that the chip is dead and this will be a total of 3 Adafruit MAX31855 boards that this approach has fried. I'd really just like to get this working and it's virtually impossible to find any resources online from anyone who has actually gone end to end. I'd kill (well, not really) for a straight-foward tutorial on getting a reading from the Adafruit MAX31855 breakout board on a Rasperry Pi. Anyone have any ideas?
Posts: 3
Joined: Thu Jul 04, 2013 11:24 pm
by jeffremer » Fri Jul 05, 2013 6:50 am
And one more follow-up - biggest face-palm ever: I had the GPIO cable reversed. Still seems like I fried my MAX31855 chips, but now I get readings of 0 through the RPi with it attached instead of an error at least. Once I get my hands on a new breakout board I'm a little more confident that I'll be in business. I'll follow-up once I've got it going, hopefully with a little tutorial+photos of the whole thing for anyone else who stumbles across this.
Posts: 3
Joined: Thu Jul 04, 2013 11:24 pm
by dowlf » Sun Jul 07, 2013 10:45 pm
I just got this driver to work with my adafruit max31855 after trying several other approaches unsuccessfully (not surprising since I am a total electronics newb!)

Thanks to all for the info that helped me get it going.
Posts: 9
Joined: Thu Jun 13, 2013 12:13 am
by dowlf » Sun Jul 14, 2013 9:07 pm
I didn't have a chance before, but I wanted to outline the steps I took to get this driver working with the Adafruit breakout board:

These steps were done with Raspian Wheezy:

Wiring:

clk -> sclk
cs -> ce1
do -> miso
gnd -> gnd
vin -> 3v3

Image

Kernel:

sudo modprobe spi-bcm2708
sudo modprobe spidev

I added spi-bcm2708 and spidev to /etc/modules so they would be loaded with every reboot

Software (keep in mind this is a python3 driver, so it requires python3 for all the dependencies):

1. wget https://github.com/Tuckie/max31855/archive/master.zip
2. unzip master.zip
3. rm master.zip (the quick2wire download is also named master.zip
4. wget https://github.com/quick2wire/quick2wir ... master.zip
5. unzip master.zip
6. sudo apt-get install python3-setuptools
7. cd quick2wire-python-api-master
8. sudo python3 setup.py install
9. cd ..
10. wget http://python-bitstring.googlecode.com/ ... -3.1.2.zip
11. unzip bitstring-3.1.2.zip
12. cd bitstring-3.1.2
13. sudo python3 setup.py install
14. cd ../max31855-master/
15. sudo python3 max31855.py

The final step will begin to print the output, it was set to Fahrenheit by default, to change it to Celcius:

line 134 is changed from:

thermocouple = MAX31855(1, "f")

to:

thermocouple = MAX31855(1, "c")

The 1 in that line refers to which ce pin is used, for ce1 -> 1or for ce0 -> 0.

Hopefully others will be able to get this going easier than I did.

I plan to use this sensor to monitor the temperature of meats in my smoker on my back porch. The wifi connection to my pi is very flaky, so I decided to use an arduino with a bluetooth module for the sensor that will send the data to the raspberry pi with a bluetooth dongle and a ethernet cable inside the house. The pi will then serve the data to a web page that I can check from any browser (even on my phone.) The bluetooth connection between the arduino and pi is rock solid, and I don't have to worry about running a wire outside to get a solid connection to a pi. The pi sitting inside the house is going to be doing some other tasks, so it all works out perfectly. I will post a link to the project once I am finished, but it is already usefull in its early state.

This sensor will work perfectly with the pi with the driver posted here. Good luck!
Posts: 9
Joined: Thu Jun 13, 2013 12:13 am
by JCanada » Tue Jul 16, 2013 11:51 pm
Thanks to dowlf's post, I managed to get everything installed correctly and "working". However, no matter how I connect the pins from the GPIO on the Pi to the pins on the MAX31855, the output produced by max31855.py is still the same:

Code: Select all
Test  conversions from MAX31855 datasheet
External Thermocouple:
...
Everything passes
...
tc: 32.0 and rj: 32.0
tc: 32.0 and rj: 32.0
tc: 32.0 and rj: 32.0
...and so on.


How can I make sure that the python driver is actually detecting my board?
Posts: 3
Joined: Tue Jul 16, 2013 11:46 pm
by dowlf » Wed Jul 17, 2013 5:11 pm
You might have a look at the following thread over at the adafruit forum about a similar issue:

http://forums.adafruit.com/viewtopic.php?f=19&t=35656

Do you happen to have an arduino to test to make sure it works?
Posts: 9
Joined: Thu Jun 13, 2013 12:13 am
by JCanada » Sun Jul 21, 2013 2:29 am
Thanks for the reply, but it turns out that in my prototyping, I have many connections that are not totally solid. With a bit of wiggling, I can get the sensors to read temperatures quite nicely. Once I get it soldered in the right spot it should be good to go. Kudos to you!
Posts: 3
Joined: Tue Jul 16, 2013 11:46 pm
by tuckie » Wed Sep 11, 2013 2:10 am
Heads up to anyone using this, or looking to use this. I've released a version 2.0 that has removed all dependencies but the GPIO lib. I've converted to SPI bitbanging so no fancy SPI config is needed and you can use whatever pins you want. This came a result of me wanting to use more than two MAX31855s with my raspbery pi. There's a slightly different init function as no pins can be assumed anymore. More details can be found at the github repo.

Hope you all enjoy 8-)
Posts: 11
Joined: Mon Sep 03, 2012 1:50 am
by awootton » Tue Sep 17, 2013 12:00 am
Apologies for my rudimentary python knowledge. I'm trying to work out whether I have a hardware or software problem.

test_max31855.py completes with "Ran 2 tests in 0.011s OK" message
max31855.py gives "tc: Error: No Connection and rj: 31.8875" (x4)

I don't get the messages with all the 0s and 1s as in http://www.skpang.co.uk/blog/archives/886

1) is the OK message in test_max31855/py indication that hardware is all fine?
2) Does max31855 call test_max31855.py as part of the program (I can't see that it does)?
3) Do I need to specify the GPIO pins to use for max31855.py or does it automatically assign these?

Thanks in advance for your input. Andrew
Posts: 5
Joined: Mon Sep 16, 2013 11:32 pm
by tuckie » Tue Sep 17, 2013 1:46 am
awootton wrote:Apologies for my rudimentary python knowledge. I'm trying to work out whether I have a hardware or software problem.
No problem.

awootton wrote:1) is the OK message in test_max31855/py indication that hardware is all fine?

That's just for testing the conversion function for converting the bits to the proper temperature, nothing more (it doesn't even attempt to make a read of the thermocouple). This was originally part of max31855.py, but I separated it out as the conversion tests don't need to be running by default (mainly for development purposes).

awootton wrote:2) Does max31855 call test_max31855.py as part of the program (I can't see that it does)?

It does not. In fact, you could go without it, should you choose.

awootton wrote:3) Do I need to specify the GPIO pins to use for max31855.py or does it automatically assign these?

My example (just running max31855.py) just picked some arbitrary pins, showing off use of 4 thermocouple chips connected at once.

For a single chip example, just throw the "basic use" code from the readme https://github.com/Tuckie/max31855/blob/master/README.md into a .py file next to max31855.py, with the pins properly assigned.
Posts: 11
Joined: Mon Sep 03, 2012 1:50 am
by awootton » Tue Sep 17, 2013 2:47 am
thanks heaps for the prompt response - I've made progress, nearly there(!) - I have run the "basic use" program which I see calls the max31855 module and passes the pins.
With the pins suggested in the readme (24,23,22) I still get "No Connection"
Changing to pins (12,11,10) I get a response of 32 (or 0 using c) - which doesn't change with heating/cooling the thermocouple, so this implies I may have a hardware problem????
cheers, Andrew
Posts: 5
Joined: Mon Sep 16, 2013 11:32 pm
by tuckie » Tue Sep 17, 2013 2:55 am
Which breakout board are you using? I want to make sure that you don't have any wires/pins crossed.
Posts: 11
Joined: Mon Sep 03, 2012 1:50 am