View Single Post
Old 11-16-15, 01:04 PM   #5
Acuario
Apprentice EcoRenovator
 
Join Date: May 2011
Location: Tortosa, Spain
Posts: 221
Thanks: 2
Thanked 81 Times in 46 Posts
Default

The benefit of having each part of the program running in its own thread is that it becomes somewhat easier to debug the program as you can disable individual threads and concentrate on the bit you are writing.

A couple of the oddities I found that didn't occur with a single threaded program is that many of the Arduino string class functions failed to work.
Sorry if this gets technical.. the reason appears to be that calls to malloc do not allocate memory as they should do, the return is a null pointer and so any function that relies on the dynamically allocated memory fails. Sadly this means allocating fixed length strings to hold, for example, http requests.

The other oddity was that I started getting odd results when reading analogue peripherals. Initially I was using a 4 button keypad using a single analogue input and a resistor divider to give 4 distinct values (a neat way to use a single pin for a simple keyboard). I was also reading NTC thermistors in a separate thread. Individually the peripherals worked fine but when running in threads they failed. Finally I realised that it was because the threads would clash and both try to read analogue voltages at the same time. It turns out that although the Arduino has multiple analogue pins it only has a single adc (analogue to digital converter) so can only do a single conversion at a time. A flag to indicate an analogue read is in progress that stops any other analogue read taking place sorted that problem out.

Initially I was going to use a keyboard to program the various parameters for such things as defrost temperature (start/stop), defrost cycle time, maximum temperature etc. but it started to become very complex and with 4 buttons and a small display it was getting over complex.

As the controller has an inbuilt web server for displaying status information it seemed the easiest option to use the same server to set up all the settings. A 'few' lines of code, a bit of html and response processing and now programming the controller is dead easy.


The status page looks like this:


The web pages aren't pretty but they are functional. You could 'beautify' them with some css but the Arduino itself isn't really up to serving up complex web pages, css files etc.

The status page auto updates every 15 seconds using a technique called ajax whereby it only receives the values and then fills in all the spaces on the page with the current values - this saves sending the whole web page each time a refresh is requested.
Attached Images
  
Acuario is offline   Reply With Quote
The Following User Says Thank You to Acuario For This Useful Post:
TechShop (11-16-15)