This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

1-wire DS18B20 change resolution
#8
something like this?

resident script every 60 seconds:
Code:
-- better to save the last 5 readings and avg them and then write to bus require('ow') require('user.nit_measurements') -- second argument temperature10 (10-bit value) -- third argument will force a new conversion readValue = ow.readfile('28.690E0A070000', 'temperature', true) -- measure last 5 readings mValue = measValue (5, readValue) log (round(mValue,1))

user_library nit_measurement:
Code:
avgMax = 5 function measValue (iMax,iValue)   -- init value array   if not measCount then     if iMax then       avgMax = iMax     end       measCount = 0     measValues = {}       for i=1,avgMax do         measValues[i] = iValue       end   end   measCount = measCount + 1   -- set values   for i=avgMax,2,-1 do     measValues[i] = measValues[i-1]   end   measValues[1] = iValue   --log(measValues)      -- reset counter   if (measCount == avgMax) then     measCount = 0   end      rValue = 0   for i=1,avgMax do     rValue = rValue + measValues[i]   end   rValue = rValue / avgMax   return rValue end
Reply


Messages In This Thread
RE: 1-wire DS18B20 change resolution - by gjniewenhuijse - 17.05.2016, 11:43

Forum Jump: