-
Notifications
You must be signed in to change notification settings - Fork 19
Temperature Sensors
Temperature sensor support in REM can be accomplished using the I2c or SPI bus. The choice for which one to use typically depends on your understanding of the bus topologies. For those of you who do not yet have an Analog to Digital converter I would suggest using I2c to get the job done and we will focus on using this to create and read the sensors.
REM has built in support for 10k thermistors. The algorithms to convert the resistance from the thermistor are built in and REM will calculate the temperature from the resistance for you. There is also support for Atlas EZO-RTD and EZO-HUM which may be the right choice for you and really only involves adding the appropriate EZO devices to your Raspberry pi stack.
This parts list will give you the ability to connect up to 4 temperature probes to your pi. These parts are readily available and very inexpensive.
1 - ADC: You can use any I2c controller for this but the easiest ones to implement are based upon the Texas Instruments ADS11x5 chip. There are also a number of pi hats that make the job as simple as plugging it into the pi. You may also use one of the several automation cards out there that have a 0-10v inputs to read the probe. As of this writing only the ADS1115 and ADS1105 hats are supported. We have not written the driver for the ADS1256 chip yet.
Some Suggested Hats:
- Seeed Studios 4-Channel 16-bit ADC - ADC Hat
- Pimoroni Automation Hat - Automation Hat
- Sequent Microsystems MEGA-IND - Mega IND
While a hat only requires plugging it into the 40 pin connector of the pi, you may also use any of circuits based upon the ADS1115 or ADS1015. These standalone circuits require simply connecting to the I2c bus through the SDA and SCL pins on the pi.
Some Suggested Standalone Circuits:
- Adafruit ADS1115 16-bit
- Adafruit ADS1015 12-bit
- Sparkfun 12 Bit ADC
- Seeed Studio 4 Channel 16-bit ADC
- One of the myriad of off-brand circuits based upon the ADS1115 or ADS1015
2 - Thermistor: If you desire to read the water temperature on your pool with REM we suggest you get a 10k thermistor that is either encased in plastic or uses a stainless steel thermowell. In any case both of these are installed by drilling a small hole into your plumbing somewhere then the probe is simply clamped to the pipe. The ones designed for pool water temperature are the easiest to install. Some Suggested Thermistors (Anything that is a 10k thermistor)
- Pentair 520272
- Hayward GLX-PC-12-KIT
3 - Resistor: We will be using a voltage divider circuit to connect the sensor to the ADC. For this you will need a 10kOhm 1/4 watt or 1/2 watt resistor.
In order to read a temperature probe you will need something that converts the resistance of the probe into digital values. These are analog to digital converters (ADCs). If you are reading this and think wow that is some really complicated stuff ignore the name and simply know that it is just something that you will be connecting the probe to.
But hold on a minute. We will not be connecting the thermistor directly to the ADC. In order to read the resistance of the thermistor we need something called a voltage divider circuit. It is really easy so do not fret. If you have done a web search you may have come across lengthy discussions regarding bridge dividers and crazy schematics but I have boiled it down to a simple schematic for you.
So what you are looking at is the basic wiring hookup. The terminal block terminals shown have some abbreviations so I will describe where these come from if your hat does not have an easy setup like the one shown.
- 3v3 - This is the 3 volt connection on the Raspberry pi. On the Raspberry Pi 40-pin connector they are pin #s 1 or 17. For convenience many of the hats have a terminal to connect to this. If it has one use that.
- AIN[0-3] - These are the Analog Inputs for the ADC. For the ADS11x5 series ADCs there are 4 of them labeled 0-3.
- GND - This is the ground from the Raspberry Pi. On the 40-pin Raspberry Pi connector they are pin #s 6, 14, 20, 25, 30, 34, or 39. If your ADC hat has a ground use that.
Now that you are familiar with the connection points, connect a 10kOhm resistor to the 3v3 connection. Then connect the other end of this to one of the AIN[0-3] connections for the ADC. Finally, connect one wire from the thermistor to this same AIN[0-3] connection and the other wire to GND. While it typically doesn't matter which thermistor wire goes where, if you have a black wire connect it to the GND and if you have a red or white wire connect it to the AINx. There you have it you have divided the voltage and conquered. In simple terms what we have done is to "pull-down" the 3v3 voltage to 0 using the 10kOhm resistor so that we are measuring only the remaining voltage after the thermistor has had its way with it.
If you made it to here your hardware should all be configured meaning the thermistors that you want the temperature from have been wired to the ADC and the Raspberry Pi has been turned back on. If you are using an I2c or SPI hat make sure you enable the interface on your Raspberry Pi. There are a ton of step by steps out there so I won't write another but here is one that uses pictures. You can ignore all the programming python/c++ crap at the end of it because we have made it so you don't need to do any of that. Enable I2c
At this point you should have your hardware set up, REM Installed, and I2c enabled on the Pi. What follows is a Step by Step to start reading the Thermistor(s)
REM will not let you configure I2c devices until you identify the bus so from the general tab click the + sign on the I2c Buses list and a dialog will appear. If you don't know what an I2c Bus number is then leave this as 1 but if you do know then REM will support multiple I2c buses on a single pi. Then click the Create Bus button.
Once you do this another tab should appear and the bus will be listed in the I2c Buses list.
Now that REM knows all about your I2c bus. You need to tell it that there is an ADC at the address you set up for the hat. If you have done everything correctly the address should automatically appear in the I2c - Bus #1 tab. If you have a lot of other devices it may not be the only one. Refer to the documentation for the hat if you have any questions as to which address is selected for it. Sometimes there is a jumper block on the board that will tell you which address is selected. NOTE: You may need to click the + on the Devices List then Re-scan if your device does not show up right away.
Once you figure this out click on the address in the Devices list, check the Is Active checkbox and select ADS1x15 ADC from the Device dropdown. Then click Save Device
Select the proper ADS chip from the converter dropdown. This is the chip series used to make your ADC board. The 16 or 12 bit chips are supported. Choose the correct one or your results will be incorrect.
The ADC now needs to know how to read the analog input channels where the thermistors are connected. So if you connected the Thermistor to AIN0 then you will configure Channel #1 if you connected to AIN3 then you will configure Channel #4. Click the gears icon next to the channel. A dialog will appear allowing you to name the input. Check the Enabled checkbox and give it a meaningful name. For the Power Gain dropdown we are using 3v3 for the VCC (Voltage Collector to Collector) so select 2.048v there. If you are drawing outside the lines of this guide a bit and are using 5v VCC then select 4.096 for the Power Gain. If you want to know more about this setting you can burn a couple of hours on your favorite search engine.
After you have made your changes to the Edit Channel dialog click the save button to dismiss it. This does not save the channel settings back to REM at this point it only saves them locally on the browser until you configure all the channels. When you are done setting up all your channels press the Save Device button. The channels that you have configured should start reading the voltage from the divider we created earlier.
As you can tell from the last step we now have an ADC that is reading voltage. Well that isn't very useful for telling temperature. What we want to know is what that voltage means in regard to temperature. So to do that we need to create a 10k Temperature probe on REM so from the Generic Devices Tab, click the + in the Devices List. Select 10k Temperature Probe, Give it a name and select the units. On the Input Value section select Voltage and set 3.3 in the Vcc Ref field. If you are familiar with ADCs you will know what to do if you want to use the raw ADC value. For our purposes the voltage will work a treat. Once you are done doing that press the save button.
Now that you have set all this up you need to start feeding the voltage readings from the ADC into your new temperature probe. So go back to the I2c Bus #1 tab and click on the ADC device we created earlier. The device definition should appear next to the Devices list. Click the Feeds tab and press the + sign on the list of feeds.
In the Connection dropdown select Internal Devices. Set the Send Value to the channel voltage and select the to Device to be the probe we set up earlier. The input on that will always be adcValue. Once you have all of this set up click the Save button to save the feed. You can leave the other options alone for now. However, these can be used to smooth out the readings if you are seeing too many temperature changes for your liking. At this point the Temperature Probe(s) you set up on the Generic Devices tab are now translating the voltage into temperature.
Now that all the components have gotten to know each other we can now send the temperature off to whatever needs it including nodejs-PoolController. If you haven't set up a connection to njsPC yet. Click the + on the Connections list from the General tab then fill out the connection information for nodejs-Pool Controller. If you have ssdp enabled on njsPC you may also search for the server. When you are done press the Save button then the cancel button.
Now lets feed the temperature to njsPC. Click on the Generic Devices tab then press the edit icon in the Devices list next to the probe we want to feed to njsPC. At this point it should be reading temperature from the ADC.
From the Feeds tab click the + sign on the Device Value Feeds list and an Add Feed to Generic device dialog will appear. Choose the connection you set up for nodejs-PoolController select Temperature as the send value then select temps as the socket event for njsPC.
The choice for the Property dropdown will be dependent upon your pool setup in njsPC. If you are set up as a shared pool/spa or a single body and this represents your water temperature select waterSensor1. If you are a dual body setup then select waterSensor2 for the second body temperature and waterSensor1 for the first body. If this is the solar temperature select the solarSensor that corresponds to the heater number. In most cases you are selecting solarSensor1 but up to 4 separate solar arrays are supported. Finally, if this is an air sensor then select that. Once you made your selection click the save button and njsPC will now be getting the temperatures from your new probes.
You can use this same functionality to send the temperature values over MQTT, Sockets, or internal devices that will use it by setting up a connection of that type then setting up a feed.
Now that the temp hardware and feeds have been set and you added the sensors you needed, you can calibrate the sensors in njsPC by telling it what the temperature should be.