Welcome! Log In Create A New Profile


thermocouple w/ gen2 electronics

Posted by ErikDeBruijn 
thermocouple w/ gen2 electronics
July 16, 2008 07:19AM

I just finished soldering up all boards for my switch from PIC to generation 2 electronics. I also added a thermocouple to my extruder and it measures correctly with the example code. The firmware of the single Arduino setup doesn't mention thermocouples, only thermistors. I prefer to use the thermocouple since it is much more reliable. How can I get it working with the thermistor? If there's no easy way, I'll figure it out myself (and document it), but I can imagine I'm not the first that tries it...

If someone has an answer, I'd gladly update the wiki documentation.


Erik de Bruijn
[Ultimaker.com] - [blog.erikdebruijn.nl]
Anonymous User
Re: thermocouple w/ gen2 electronics
July 16, 2008 09:41AM
I assume you meant "how do I get it working with the thermocouple".

I think this is the intended path with the Arduino stuff:


I'm not sure which firmware has the interface logic though...
Re: thermocouple w/ gen2 electronics
July 16, 2008 12:05PM
I had the thermocouple working already (with the demo code on the thermocouple page from the wiki).

I tried changing the firmware code but didn't succeed yet... now I'm just using a thermistor again, which now works better than it ever has... so I don't need the thermocouple imminently)


Erik de Bruijn
[Ultimaker.com] - [blog.erikdebruijn.nl]
Re: thermocouple w/ gen2 electronics
July 16, 2008 12:19PM
I suppose this should go on the wiki somewhere. I asked Zach about it, and after many hints I figured out a cheap and dirty way to make it work:

I've only been able to get the Snap code working so far, so I just edited the Snap firmware library and cut and pasted Zach's thermocouple code from the Gcode firmware. When I get my other computer going I'll attach the edit, hang on...

It was really simple to do, but it took me several days to figure out where exactly to make the simple change. smiling smiley

Re: thermocouple w/ gen2 electronics
July 16, 2008 02:29PM
Here's the code.

I'm more of a hack than a real programmer, so instead of doing this the right way with defines and whatnot, I just changed the temperature code in the library file.

For the single arduino snap firmware ver 1.3, change this library file in your arduino dir:

This is the function I changed - I just commented out the original code, and slapped in the thermocouple code from Zach's Gcode firmware. Ugly, but it works for me. The new code is just one line at the end, it's a lot simpler, no lookup tables.

Also, make sure you delete the .o object files before you recompile; otherwise it won't recompile the library, and it won't work.


* Samples the temperature and converts it to degrees celsius.
* Returns degrees celsius.
int ThermoplastExtruder::calculateTemperatureFromRaw(int raw)
/* int celsius = 0;
byte i;

for (i=1; i raw)
celsius = temptable[i-1][1] +
(raw - temptable[i-1][0]) *
(temptable[1] - temptable[i-1][1]) /
(temptable[0] - temptable[i-1][0]);

if (celsius > 255)
celsius = 255;


// Overflow: We just clamp to 0 degrees celsius
if (i == NUMTEMPS)
celsius = 0;

return celsius;
// Added Thermocouple code wbortz at gmail dot com 2008.07.09
return ( 5.0 * raw * 100.0) / 1024.0;
// return 120;

Edited 1 time(s). Last edit at 07/16/2008 02:30PM by Wade.
Re: thermocouple w/ gen2 electronics
July 16, 2008 06:31PM
Hi Wade,

This is really good news! You really made my day. Today I'm afraid I deformed my PTFE heat barrier because I didn't measure the temperature correctly. I think it was too high a temperature and too much pressure (this is the first time I use ABS).

With the thermocouple I have a measurement I can trust. Besides, if I can use it I haven't taken apart my extruder all for nothing to put the thermocouple under the insulation smiling smiley

I'll try this code first thing in the morning!


Erik de Bruijn
[Ultimaker.com] - [blog.erikdebruijn.nl]
Sorry, only registered users may post in this forum.

Click here to login