Im building this at the moment and want to add a temp sensor (DS18B20). I get get the sensor to output the temp in Celsius but dont know how to convert it to work with the moonlight protocol, there is also the temp coefficient again what do I do with this?
Any help would be great!
In the library for the LM335 (lm335-cpp), which is used here as sensor, the following formula is applied (to the end of the lib), maybe you can leverage:
Me again! Turns out I did not 'figure it out' - the hex number for the temperature needs to be a signed hex number - I have no idea how to convert a standard number say 20.5 celsius into a signed hex number! Has anybody got any idea?
Be careful with the formula. I remarked that the temperature is not quite right. I think the factor 500 come from some try and error process. It is something in my list of things to improve. (I am the author of the library)
The conversion from Celsius to Hex is not very difficult. You can find it in the github repository in the Moonlite.cpp file. At the end. For the temperature the function "convertLongToChar" is what you are looking for probably.
What happened with negative value... I am not sure of that... Check the function before using it. I have to verify that. I don't remember well.
For your question about how to code 20.5 in signed hex. There is a trick. In the protocol such values are not transfered as they are but they are multiplied by 2. Then you don't have to transfer a floating point value. That explain why the display is always with round or .5 values and nothing in between. (See the file Focuser.ino line 106)
The compensation is not used to calculate the temperature. This value is used to readjust the focus when the temperature changes. You focus, note the temperature and the number of steps of the focuser. You wait some times until the temperature is not the same. You refocus and note again the temperature and the number of steps. You know the differences for the temperature and the position between the two measures and you can calculate a step/degree value. This is the compensation value.