Page 1 of 1

generic sysfs GPIO temperature sensor

Posted: Tuesday 31 August 2021 17:54
by Raxis777
Hello i was trying to add thermocouple sensor by using ADC MCP3008 directly to GPIO of my RPi. I used this code
echo 4 > /sys/class/gpio/export
echo in > /sys/class/gpio/gpio4/direction
and added my GPIO to domoticz hardware. The problem is that i need temperature sensor but when i added my GPIO it shows as lighting input which is now closed. Can someone please tell me is there a way to change it somehow to temperature sensor? input value is now in mV and I have a code to transform it into temp value. How can i implement this transformation that domoticz can read it for 6 GPIOs from my MCP3008 eg.
for i in range 6:
values=((values/1023)*3300*24.39))
Can i put it somehow in domoticz files? i would be very grateful for your help
I assume that connecting ADC channels directly with generic sysfs GPIO domoticz will always give me mV value. maybe you have idea or program where domoticz could read all 6 values from program

Re: generic sysfs GPIO temperature sensor

Posted: Tuesday 31 August 2021 18:07
by waltervl
GPIO input can only see open close (binary input). It cannot handle ADC. Be aware that putting a high voltage on your GPIO can damage your RPi!

Re: generic sysfs GPIO temperature sensor

Posted: Tuesday 31 August 2021 18:13
by Raxis777
waltervl wrote: Tuesday 31 August 2021 18:07 GPIO input can only see open close (binary input). It cannot handle ADC. Be aware that putting a high voltage on your GPIO can damage your RPi!
maximum input of voltage i'm gonna put to GPIOs is 100mV so RPi will be fine :D Can i ask you then how i can read signal on domoticz from my ADC adding a conversion code from mV to temp or there isn't any way to do that?

If there isn't an option to do that from MCP3008 is there an option to read temp from thermocouple using max6675 module?

Re: generic sysfs GPIO temperature sensor

Posted: Tuesday 31 August 2021 18:29
by waltervl
You could do something with python:
to read the MCP3008:
https://learn.adafruit.com/mcp3008-spi- ... cuitpython

Then make a python script and call that in dzVents to update a temperature device.
See for example below topic for a battery voltage reading.
viewtopic.php?t=34088

Re: generic sysfs GPIO temperature sensor

Posted: Tuesday 31 August 2021 18:44
by Raxis777
waltervl wrote: Tuesday 31 August 2021 18:29 You could do something with python:
to read the MCP3008:
https://learn.adafruit.com/mcp3008-spi- ... cuitpython

Then make a python script and call that in dzVents to update a temperature device.
See for example below topic for a battery voltage reading.
viewtopic.php?t=34088
i have already python code to receive temp values from my MCP connecting it to 4 GPIO pins instead of SPI software. I must admit i can't really understand part with dzVents and the rest could you explain it more specific what can i do with my values received from python code to domoticz.

Re: generic sysfs GPIO temperature sensor

Posted: Tuesday 31 August 2021 19:50
by waltervl
Dzvents is one of the internal scripting languages. You can use the internal events system to write the code and do some automation (eg switch on fan when temp is > 40 deg).
The last code in the other topic reads the voltage and puts it in a device. You can do the same but then for a temperature.

Other option is to adapt your current python script and have it update the Domoticz temperature device by a http API url. That is what they do in the first script:

Code: Select all

httpresponse = urllib.urlopen("http://127.0.0.1:8080/json.htm?type=command&param=udevice&idx=" + str(domoticz_V) + "&nvalue=0&svalue=" + str(float(VOLTAGE_BATTERY)))
But then you have to fire that python script from the OS every x minutes by a crontab. In the optimized script the dzVents script is triggering the python script. So it is more regulated from Domoticz.