
Well, finally, this (publishing) project is getting close to its completion! It is now time for the SOFTWARE! Hopefully it will be clearer than my code illustration above! đ
I do know that some of you (most?) just want to get the code, upload it to your Arduino’s and get going with the reflow work! For you I recommend jumping to the end of this post where you will find the download link! đ
Do you want to get some insights into the code just keep on reading! There will also be comments on the solutions taken and explanations in some cases! Might help you if things does not work as you intended!
For me, with the oven (Clatronic MB 3463) I happened to chose and this software, this Arduino Reflow Oven works even better than I ever could have hoped for! đ If you pick another brand or model you might have to do some testing and adjustments yourself! Hopefully you will find some info here to help you with that! You are always welcome to ask question – and I will see if I can help in any way! I will see if I have enough material to write up a short article on what different paths you can take to make this reflow oven software work for you!
In the future I might update the software and release bugfixes and extensions. I am mostly interested in re-releasing it with the reflow profile editor included! That would make it much easier to make small adjustments to the profiles! I am also keen on adding “recording” of the power applied during a reflow and so be able to “replay” it and fine tune it to create a “perfect” reflow – if used under the same conditions!
My way of coding
First I would like to say that my way of coding is to write small pieces of code and test them separately. That way I handle most errors while still coding in small scale – easier both to write, test and debug the code! My advice is to: TEST A LOT! You can not do too much testing! Even if it, sometimes, is tedious and you have to write test code as well – it pays off generously in the end!
A drawback with my style of writing in small pieces – is that you can get some unexpected bugs creep up on you when you put the pieces together! Especially if you try to squeeze in a complex project like a graphically intense software like the Ar2uino Reflow Oven and is close to the limit for a small microcontroller like the ATmega328 and its very limited memory – both FLASH and RAM! But I still love the ATmega328 – so cheap and still so powerful! Absolutely perfect for IoT-projects – but that is another story to read about here …!
Writing for embedded memory restricted systems makes the use of global variables a good thing! Especially big arrays! That way the dynamic use of variables can be limited to small numbers of simple local variables and by doing this you will have much better control over how the RAM memory is used – avoiding or at least limiting the cases in which you will have (NOT!) “funny” memory related errors! Normally you would try to limit the use of global variables!
Another thing to be aware of is that there are Serial.print… statements sprinkled all over the code! This is NOT DEBUG printouts and they should be left in the code! They print out status information to the serial port while running the software. Connect your computer to the Arduino serial port if you want extra information on for example how well the reflow is going! Use this info with your favourite spread sheet software (Excel) to create information diagrams like the one on the side here! This information is critical if you want to verify adjustments you have made to the profiles!
Moreover I do like to code and often recode to get what I want! I try to comment the code so I myself will understand what I have done and what my reasons were! I do guess that most of you have that same problem when going back to your code a year or two later! BUT no matter how many comments I make I seem to sit there and stare at the code and wonder what the %¤#&? I was thinking of when I wrote that code! đ That very same thing also happens when reading someone else’s code – but even more so! That will naturally happen when you will try to understand MY code! đ Therefore I write these lines in hope of smoothing your experience a little … But with close to 2500 lines of code and code comments it will probably not be enough anyhow … so … well … good luck! đ
Comments of the Code
I start every new function with a block of comments that describes the function call and parameters used. I also comment most parts of the code and include insights about changes to make in the future – should it become necessary! Still it is usually not enough to fully understand the code – but long whiles of reading the code is still necessary!
I will now describe the code in general and I will refer to line numbers in the v1.1 of the code! This description will probably NOT be updated if I update the code! So in case you are looking at another version of the code then, please consider the line numbers to be approximate! The descriptions will vary considerably from one liners to longer blocks! Usually the comments included in the sketch code will have to be enough but if there are special reasons I will post more elaborate comments here!
I hope this will give you some understanding of the code and help you on your way to your own Reflow Oven! đ
1-102
Here you will find a brief circuit description. Also an explanation of some defines that you can make to change the software behaviour. Also a description of changes made. A description of how information is stored in EEPROM.
103-106
The library includes.
108-123
All the pin definitions. These you can change if not suitable for your solution – but be aware of what effects a change will have concerning port abilities and circuit requirements!
126
Here you can change the “Interrupts Per Second” (IPS) value. This value controls how often the power for the heating can be changed! In Sweden and in most parts of Europe with a mains frequency of 50 Hz – giving 100 half cycles – it is handy to have it set for just that to give maximum control! As the power is controlled by a zero sensing TRIAC this can not be set any higher than for the halfcycles! 60 Hz would have a max setting of 120. We ONLY switch on and off power at zero crossings thereby reducing radio interference and also makes for a more “gentle” load on the mains when switching around 1000 W (1 kW) on and off repeatedly! This is also a the same time the smallest variation the software can make on the applied power! (See also the PPD and intervalMillis settings below!)
132-136
More definitions. Not many that you have any use for changing!
137
Here you can set the Average Count (AVGC) value for the thermocouple readings. It is set for 1 at the moment. That means that there is no averaged temperature measurements. This has the advantage that the reaction to a temperature change is as fast as possible – but that also means that it could more easily overreact to sudden changes in temperature and small measurement fluctuations! A properly shielded thermocouple wire is needed as readings otherwise will fluctuate too much – even if the real temperature does not! With the reading fluctuating as little within a degree as can be seen in the diagram it is not necessary to take any averages! Increasing the AVGC over the value of 3 is not at all recommended as this cause too much delay – at least for the reflow part of the oven! Might be good for the manual part of the oven – but I have not tested that yet!
138
Percent (Power) Per Degree (PPD) can be set! This is how much increase or decrease in percent power 1 degree change will make. This value will have to be changed depending on the particular oven that you are using! For my oven a little experimentation (trial runs) gave that 20% per degree was the perfect setting! It then reacted fast enough to follow the reflow temperature profile that I had selected (Lee’s reflow) but still not too much to give any overshoots! Initially I started (chanced) with a setting of just 5 and that was not too bad! I was almost satisfied with that – it followed the profile but was “late” and I did not want that in the end and increased the value till it was perfect! This depends a lot on how well your oven and the heaters work together! To avoid initial overshoot I added a 10 second preheat at full power “to get the oven going”. My initial measurements in the end of the 1st part showed that the ovens thermal inertia (or delay) was around 20 seconds. That is very hard for any algorithm to compensate for as the measurements of the temperature happens now and the reaction to any change will come 20 seconds later! My advice is to experiment with different settings and then maybe add some code of your own to compensate for the delay! As I have said earlier I did not need a full blown PID controller because the oven performed so well! Why complicate matters if you don’t need to?! There is now plenty of FLASH space for code but the RAM is very scarce so test thoroughly (as usual!) any additions you make to the code! Also the position in the oven influences the temperature! High or low! An adjustment of just a centimeter (less than half an inch) up or down for the PCB’s might be all that is needed!
144-154
Global variable definitions. The only one of any interest to maybe change is the “intervalMillis” as it controls how often the temperature will be measured & the power changed. It is set for 1000 (milliseconds) so measurements & changes will happen every second. This is related to IPS value described above as an increase in this value also will affect the power control! But with a delay of 20 seconds from any change in power to any reactions in temperature my estimate is that an interval of 1 second is good enough!
156-161
The setup of the main menue. Text and colours! Change these to your hearts content – if you are not satisfied with my carefully selected colours! đ
164-168
Here the thermocouple and the display library setup is done. Be careful that the pin definitions correspond to your circuit!
171-178
The array declarations for the temperature profiles. These are used both to hold the current temperature profile and also helper data to that profile! Two(2) profiles have been predefined! But you can change these profiles in the function resetEEPROM() starting at line 1773. (See that function below for more information!)
182-252
Here is the program setup() function that is executed once as the program starts! Most of the code is commented and I have not much to add except to point out (again) that at line 217 the resetEEPROM() function that writes initial values to EEPROM is called. After the first execution this call can be commented out and the compiler/linker will no longer include that code in the uploaded program. Doing this saves you 856 bytes of FLASH memory and 28 bytes of RAM memory. Might be all you need for your customization?
The “Ar2uino Greetings Display” is shown for a few seconds at startup. See lines 228-246. In line 230 the display rotation is set. If your display does not show it properly – as you would like to mount the display – try changing the parameter to 0,1,2 or 3. There are (naturally) four ways to rotate the display! đ All writing to the TFT display has to be with calls to special TFT-functions!
Finally there is an initial setup so that the main menu will start at a specific point!
258-307
Here is the main loop! It deals entirely with selections in the main menu! In line 270 a call is made to the menue() function that actually draws the menu and makes it possible to make the selection with the quad encoder. Depending on the selections made different functions will be called!
317-379
The admin() function. This is the first of the different menu functions. The others are very similar so I will only go through this first one. I starts out by clearing the screen and printing out the top and bottom lines. The different alternative lines ar shown to the left! It uses the last line as a sort of a “minimenu” to show selectable alternatives. After a selection is made the information wanted is shown on the screen or the action selected is carried out. This goes on in a local loop until the “>Exit!” alternative is selected and then the main menu is shown.
382-429
The adminMenue() function. This is the function that actually shows and handles the “minimenu” on the last line. It uses function showMiniMenueItem() and readEncoder() functions to do the presentation and the selection.
432-450
The saveDefault() function writes the current profile number to EEPROM.
453-500
The selectProfile() function uses minimenue on the last line to select profile.
503-527
The showMiniMenueItem() function shows text on the last line in the specified colours.
530-595
The showProfileInfo() function shows current profile on the display.
598-606
The displayWithTab() function shows a text followed by a “tab” and then a value. Used by the above function. The TFT functions does not support the tab to “jump a bit sideways” to a specified point on the line so this function supplies that functionality!
614-717
The manualBasic() function is the simplified function of the manual oven information display. It uses just two rectangular boxes to show the set temperature (narrow box) and the current temperature (broader box). Naturally the temperatures are also shown as ordinary numbers on the display. This is the basic display – the cool circular display had to go to save FLASH and RAM memory. đŚ It reads the encoder and as soon as the encoder value changes the function applies the correct reaction! If the set temperature is lower than the current the power is switched off! If the set temperature is lower the power is switched on! There is no special action needed – just turn the encoder! Just like an ordinary oven! đ When you leave the manual oven function a short animation is shown where the set temperature is counted down to 0.
I feel stupid for saying this but: NOTE that like any ordinary oven this oven will also be HOT for a while after switching it off! Open the door and it cools down in just a few minutes!
720-786
The  displayManualBasic() function displays all the textual information on the simplified manual oven and calls the bandScale() function to display the graphics!
788-797
The bandScale() function draws the rectangular graphics areas to show the set temperature and the current temperature.
799-826
The  displayTopBottom() function draws the top and bottom lines on the display in predefined colours.
834-872
The menue() function draws the main menu and allows selection to be made. Colours can be changed in lines 156-161. (See above!)
874-914
The  selectItem() functions name pretty well describes what it does! Almost! đ It actually draws a triangle in front of currently selected item and also draws a white edge along the currently selected item. You move the triangle by rotating the encoder and you decide on the currently select the item by clicking the rotary encoder button!
922-1164
The reflow() function draws the reflow display and adjust the power to follow current profile! But first it prints out information about the currently selected reflow profile! If you accept the selection then you just press the selector button and the reflow process will start! This function prints a LOT of information to the serial line! Measurements and timing information is printed out throughout the reflow process. A 10 second preheat at full power will be applied. Testing has shown this to be good in avoiding initial over- and under-shoots. You can change this to get better results from your oven!
During the reflow process all information is shown on the display – both as numbers but also as a scrolling graphical display showing the difference between the profile temperature and the current oven temperature.
After the reflow has finished some information about the process is shown.
1166-1184
Two helper functions for displaying info. These functions have been implemented to save memory.
1187-1250
The  drawTempScale() function draws the scrolling graph showing profile and current oven temperature. It uses i circular buffer to handle the temperature. There is (as far as I know!) no other way of creating this scrolling display but to redraw it again and again … (Anyone with any suggestion?)
1252 – 2432
From here on there is a number of smaller functions. I will only point out a few that I find extra interesting. For the others you will have to read the comments embedded in the code!
1256-1291
The initializeInterrupts() function sets up the timer interrupt that we want! As the electronic construction I have makes do without being synchronized with the mains frequency the interrupts can occur whenever during the AC mains voltage cycle. Because of this a variation of 1 half cycle can always – or maybe I should say will always occur! Either one more half cycle than wanted or one less than wanted. This is such a small error that the simplified construction it offered was well worth it! It does NOT affect the reflow temperature in any degree! The heating algorithm automatically compensates for it!
1505-1586
The adjustTemp() function adjusts the temperature by controlling the POWER to the heaters. It does this by following the algorithm used. In my case it is just a proportional algorithm (That is the first “P” in PID-controller!) which is the simplest way of controlling anything! The PPD is used to control how much power should be changed depending on the difference in temperature between the profile and the current oven temperature.
It is in this function that you can add your own changes to the algorithm or change it altogether!Â
NOTE that cooling is not handled in any other way than switching off the heaters! I.e. there is no active cooling! At the end of the reflow profile a LED will light – indicating that you should open the oven door a little to help speed up cooling!
In this function you could put code to handle cooling by a fan that blows cool air into the oven or opens the door by a servo to cool the oven that way.
Note that this function is not DIRECTLY handling the power to the heaters but it modifies the volatile variable “pwr” that the interrupt service routine, ISR(TIMER1_OVF_vect), uses to change to power duty cycle to the heaters by switching on and off the TRIAC. It is declared “volatile” because it can be and is changed outside of the interrupt!
1729-1825
The function resetEEPROM() initially writes the reflow temperature profile to EEPROM. 2 profiles have been predefined! Lee’s and standard Kester profiles. But you can change these profiles in this function resetEEPROM()!
NOTE: Testing has shown that my oven is not powerful enough to follow the Kester reflow profile all the way!
An example:
char profile0Name[] = “Lee’s”;
byte profile0Temp[] =    { 25, 179, 185, 215, 30 };      <– The temperature for the END of each interval except for 1st!
byte profile0StepTime[] = {  0, 220, 35, 30, 60 };      <– The length in secs for interval
The Lee’s profile0Temp[]Â starts with 25. That should give the temperature at the beginning of the first interval! All other temperatures should give the temperature at end of each interval! Also for the first temperature; if you set it to 0 degrees the CURRENT temperature will be used instead! That is handy if your start temperature varies a lot!
Here it is set to slightly over room temperature at 25 degrees (Celsius naturally!) so that it works well in most cases!
StepTime is set to the beginning of the profile at 0 seconds
Then a linear ramp is wanted up to 179 degrees taking 220 seconds
After that a short ramp up to 185 degrees should take 35 seconds
Finally a short ramp up to 215 degrees taking 30 seconds
Last step is cooling to 30 degrees during 60 seconds
NOTE that no forced cooling is used! YOU will have to CAREFULLY open the oven door to cool it!
2216-2307
The readEncoder() function handles the reading of the encoder – with the help of an interrupt routine called doEncoder(). Reading of a quad encoder like this would require lots of speed if it was read by polling (repeatedly reading) the switches to see if they opened or closed! Therefore I am using an interrupt based approach instead!
The readEncoder() function handles the addition and subtraction of “clicks” and also “acceleration” if the encoder is turned quickly. This makes it work well both for small changes like in a menu and for changing the temperature faster from 25 to 200 degrees! It also handles part of the de-bounce filtering! NOTE that 0.1 uF ceramic capacitors MUST be connected between ALL contacts and GND!
2239-2245
The doEncoder() interrupt function reacts on one of the decoder switches being closed. At that moment an interrupt is generated and the dEncoder() function is called. It then reads the other switch and depending on if tht is high or low t can decide in which direction the encoder was turned! It returns the result in the global variables called eDiff and eChange.
This ends the code presentation! I do hope it will give you some help in understanding the code!
The Arduino Reflow Oven Software Download
First of all you will need to download the two libraries that I have not written myself:
To simplify the reading of the thermocouple I have used a library for the Thermocouple MAX6675 – from Adafruit. Here is even more info from Adafruit about thermocouples!
Please note that the MAX6675 IC has been superceded by newer IC’s but it is still in very good supply on eBay (Price just around 2 EUR/2 $ and only slightly more with a K-type thermocouple!) and the MAX6675 is still more than good enough for this projects requirements! I might update the software to use the newer versions of IC’s if there is a substantial interest in me doing so! đ
Download the eminent TFT Display library from âSUMOTOYâ! You will find it here (ILI9163C) or here (ST7735) â depending on what display chip controller you have. It is a very fast executing library and easy to use. Really recommended for other project also! It is usually NOT obvious what support chips you have on your display board. On the “SUMOTOY” sites there is information on how to see what display chip you have. You might have to set certain #define statements in his library code to select the specific board you have! But it is all explained on his sites! There might be newer libraries on his site when you get there but I have used versions 1.0r7 and 1.0p1. The libraries are using the same API’s so they can be interchanged! I say it again: Be sure to test the display out before continuing! See how to do it it at the end of posting number 9!
A bit of friendly đ advice: Hopefully you have already downloaded these and tested both the thermocouple and the display already by following previous posts in this series! đ If you have not – save yourself loads of headache by going back and do that before continuing! Small bugs have a nasty way of creeping into any construction project and it is much easier to fix them one after the other instead of being faced with all at the same time!
Also there is the question of having enough FLASH memory and RAM memory for this software! The software now uses 25368 bytes FLASH memory when compiled with Arduino IDE 1.6.12. There is 752 bytes of RAM left. Most Arduino Pro Minis (if that is what you are going to use) comes with the “old”, non-optimized boot loader so only 30720 bytes are available instead of 32256 bytes with the OptiBoot boot loader. I needed those extra bytes during development but have since managed to optimize the code and also removed some unnecessary but cool visual displays! đŚ I have updated my boot loader as can be read here and have not run the software with the standard boot loader so I can not verify if any problem will occur with that! There should be an ample margin after the optimizations to run it in an Arduino Pro Mini with the old boot loader – but as I said I have NOT verified this! It is more difficult to find out if there is enough RAM left for local variables as they vary as the code executes … You might like to do the update just to get extra space for any future updates that might occur … I might put back the “cool visuals” code again or the “profile editor” … or you might even want to add some code of your own!
DISCLAIMER!
You are sole responsible if this reflow oven does not work as expected and also for any damages incurred! Therefore make sure you test it out thoroughly before doing any real reflow work with it! Always be very careful with electrical work!
Download Ar2uino Reflow Oven software v1.1
As usual, clicking the button on the left will bring up a new window with a text only PDF.
Copy all of the code and then switch to your Arduino IDE and paste it in a new empty window.
Compile and upload to the Arduino! Ready!
(This roundabout way via a PDF is because WordPress will not allow text- or ino-files!)
Well, that is all ⌠except a short thing about experiences gained and some hints on how you can adopt this software to your oven! But that will be in the next instalment!
Good luck and cheers till next time..! đ
/Sfenn