Monthly Archives: October 2014

Problem with my 1-wire found

Last week I posted about an issue with my 1-wire temperature sensors.  I believe I have found the issue.

I am using DS18B20 Waterproof Temperature Sensor assemblies that I picked up on  I looked in a datasheet for a DS18B20 from Maxim Integrated and found a note at the bottom of table 1.


“The power-on reset value of the temperature register is +85°C” means to me that when my database is reporting “85” that means at the time of the temperature reading, the sensor was in its power-on reset state.  I also note later in the document that the “Minimum Supply Voltage” is listed at “+3.0 volts.”  Since my pi is powering the DS18B20 sensors from a 3.3V supply pin, it is possible that this is being pulled too low (below 3.0V) and causing the sensor to be reset.

I was also reminded that every “Transaction Sequence” (communication) on the 1-wire system begins with an initialization step that includes the master (raspberry pi) transmitting a reset pulse on the 1-wire bus data line. This is then followed by a presence pulse from the slave(s) on the bus.  This timing is pretty specific, and if incorrect the data won’t be correct.  It is possible that there being many devices on the bus or extra long cabling between master and slave(s) on the bus could cause this timing to be incorrect.  This would be helped by a stronger pull-up resistor on the data line, meaning less resistance.  My piHouse uses a 4.7K ohm resistor for this pull-up, following the datasheet recommendations.  And with only 4 slaves and cable run of a couple-hundred feet at most, I don’t think this will be necessary to change.  Plus, since I hot glued the thing in place, it might be difficult to change the 4.7K resistor.


Since the maximum operating voltage listed for the DS18B20 is shown to be +5.5V, I will change the V+ source for the temperature sensors to one of the +5V outputs on the pi and see if this makes a difference.  If not, I will endeavor on changing the 4.7K to something smaller.

Unfortunately until then, my graphs will keep looking like this


Problem with my 1-Wire

Since I added a long run of cable and 2 new sensors, I have been noticing some strange temperature readings.  Every once in a while, the reported temperature will spike up off the graph.  I have seen this on every sensor and sometimes it seems to happen several times within a short period of time.  Here is an example of what it might look like from yesterday:


click to enlarge

I have seen this maybe a dozen times.  The first few times I assumed it was a fluke and manually deleted the values from the database.  This is obviously not the best practice but I couldn’t imagine what was happening and just decided to ignore and hope it went away.  When the problem didn’t go away, I stopped deleting them in hopes of finding a pattern.

This is the SQL query I ran to find (and eventually delete) the offending entries.  The temperatures are all saved in one table of the database and I am looking for temperatures greater than 50ºC (122ºF).
SELECT * FROM temps WHERE temperature > 50 AND reading_time > date '2014-10-15';
When I run this query right now, PSQL returns:

         reading_time      |   location   | temperature
2014-10-16 22:17:27.265155 | outside      | 85
2014-10-19 14:32:56.26111  | outside      | 85
2014-10-19 14:44:06.480761 | outside      | 85
2014-10-21 16:50:26.453891 | dining_room  | 85
2014-10-21 20:22:55.547973 | back_bedroom | 85
2014-10-21 20:23:56.437617 | back_bedroom | 85
2014-10-21 20:24:57.342779 | back_bedroom | 85
(7 rows)

What I immediately notice is that all of the out-of-range values are all the same.  85ºC.  This can’t be simply a coincidence.

I am going to do some research about this and get back to you.

New Sensors

Previously, I described the wiring for attaching my new Rinnai heater to my raspberry pi.  I also changed the graph to display these new data trends (and stop displaying the old one).  There are 2 stages to the heater and I am graphing them separately.  Previously, I did successfully add a second sensor to the raspberry pi and programmed the pi to graph the second temperature.

The graph below (click to enlarge) shows the two temperatures (blue and purple) near the top following each other.  That is because the sensors were next to each other.  It also shows that on this day, Stage 1 (red) of the Rinnai was cycling, but Stage 2 (green) never kicked on.  The other interesting thing is that around 12:00 the ROOM TEMP control was raised.  A keen eye can see that the room temp. did not quite come down as far as it had been, and then Stage 1 came on and stayed on for a longer time, raising the room temp.  This was the point the setting was raised.


Displaying 2 heating stages and 2 temp. sensors

This past weekend, I finally put the second temperature sensor outside!  This is something I never accomplished at my previous apartment.  The graph below (click to enlarge) shows two things.  Firstly, at around 11:00 the ROOM TEMP control was lowered.  This caused the heater not to run the rest of the day.  Secondly, at around 18:45 I turned off the raspberry pi and put the sensor outside.  By the time I got everything wired back up and turned the pi back on, it was just before 20:00.  This is when the plot for the outside temp (purple) takes a steep dive.

ROOM TEMP lowered during day, OUT temp. sensor moved outside

ROOM TEMP lowered during day, OUT temp. sensor moved outside

Of interest is what happened the next morning.  In the graph below (click to enlarge), at just after 08:00 there is a sharp spike in the outside temp plot (purple).  This settles back down a bit, but then spikes again.  This then finally settles back down and regains a more steady slope upward as the air warmed up.


Sun hits outside sensor

With this proof-of-concept and some motivation, on Monday I took on the task of putting a sensor in my bedroom.  Both of the additional sensors are attached to the raspberry pi downstairs via a run of old Cat5 Ethernet cable I had lying around.  Since the 1-wire protocol the temperature sensors use is a bus, I simply wired a few of the conductors of the Cat5 in parallel into the screw terminals for the temperature sensor.  I decided to double-up each conductor (I used the twisted pairs in the wire) in order to reduce voltage drop over the length of the cable.

Photo Oct 11, 19 02 04

As can be seen in the photo above, I wired it as follows:

Gnd 1-Wire +5V
Cat5 Br-Br/W Bl-Bl/W Or-Or/W
Temp. Sensor Black Yellow Red

Three-way splice for room temp.

Three-way splice for room temp.


For the sensor in my bedroom, I cut the Cat5 cable and striped the wires on either side of the cut.  I then soldered both of these wires and the temperature sensor wires together, essentially making a 3-way splice in the wire (pi/bedroom/outside).  This was all covered with heat-shrink tubing.  I did this with the pi powered down to reduce the risk of damage to the pi.

With the soldering complete, I powered it back up and first made sure that the old sensors still worked with the new wiring.  This was simple because the graph started running immediately and I just had to wait a few minutes then check the graph.



To test the 3rd sensor that I just added, I went through a couple steps.

  1. Check if raspberry pi sees three sensors
  2. Identify which sensor is the new one
  3. Ask raspberry pi for a reading from the sensor
  4. Artificially change sensor temp and ask raspberry pi again, to confirm correct sensor

Step 1: To find out if the pi sees the sensor, I ran this command to see what devices were listed on the 1-wire bus:

house@raspberrypi ~ $ ls /sys/bus/w1/devices

this returned 3 items that I was interested in:

Step 2: These are the addresses used by the 1-wire bus for the temperature sensors.  Since I already had 2 of these working, I checked my notes to see which were accounted for and which was the new one (28-00000512f401).

Step 3: Then I could run the following command to ask the pi to take a reading and then display the result to the command line:

house@raspberrypi ~ $ cat /sys/bus/w1/devices/28-00000512f401/w1_slave 2>&1

this returns the following block of data:
5f 01 4b 46 7f ff 01 10 9b : crc=9b YES
5f 01 4b 46 7f ff 01 10 9b t=21937

This is the format in which the temperature info. comes out of the temp. sensors.  The info afer the “t=” is a temperatre in milliCelsius (thousandths of a degree celsius).  In this example, the reading is 21.937 C.  My pi runs this command then strips out that value and saves it into the database once per minute for every sensor.

Step 4: The easiest way to accomplish this is to continually ask for a new reading, and then grab onto the sensor and warm it in your hand.  The reported temperature should rise.  So I wrote a quick loop function to run the above command over and over, with a 1 second delay between each:

house@raspberrypi ~ $ while true; do cat /sys/bus/w1/devices/28-00000512f401/w1_slave 2>&1; sleep 1; done

this returns a bunch of readings in a row, such as:
79 01 4b 46 7f ff 07 10 0a t=23562
78 01 4b 46 7f ff 08 10 51 : crc=51 YES
78 01 4b 46 7f ff 08 10 51 t=23500
78 01 4b 46 7f ff 08 10 51 : crc=51 YES
78 01 4b 46 7f ff 08 10 51 t=23500
79 01 4b 46 7f ff 07 10 0a : crc=0a YES
79 01 4b 46 7f ff 07 10 0a t=23562
79 01 4b 46 7f ff 07 10 0a : crc=0a YES
79 01 4b 46 7f ff 07 10 0a t=23562

The result proved that I had the correct sensor and it seemed to work well, so I made a new script to take readings from this sensor and save the data to the database.  I then modified my graph to display the new sensor as well.

The graph below (click to enlarge) shows a couple interesting things.  The first and most obvious thing is at just after 08:00, when the sun came around a tree and shone directly onto the outside sensor.  This is obviously a problem and I will need to move the outside sensor.  Then, at 19:30 I powered down the pi to work on wiring the bedroom sensor.  You can see the green Stage 2 plot break, showing that there was no data there.  Then, at 20:20 the new sensor script starts running.  There is a third temperature plot (light blue) near the top just under the legend.


Added bedroom plot, outside sensor in sun

piHouse Monitor part 2

I moved over the summer and the new apartment does not have the same type of heating that the last apartment did. So this is a perfect opportunity to revamp my existing project with my raspberry pi.

Quick re-cap, previously I had a forced hot water system where a furnace heated water and circulated it through radiators in each room.  This was controlled by one central thermostat located in the dining room (center room in the apartment).  By sensing if the thermostat was “ON” I was able to see if the furnace was heating the radiators.

This new apartment has 2 sources of heat.  Each room has electric heat baseboards with a thermostat to control that room.  Additionally, there is a single natural gas wall vent furnace in the living room. The furnace is intended to heat all the rooms and replace the electric heat.  The apartment is a two-floor town-house, so this may be a tall order.

The electric heat is not expected to be used much if at all.  This is mostly because it would be expensive, but luckily, this means I don’t need to monitor 6 different thermostats.  Unfortunately, the furnace is an all-enclosed unit with no external thermostat and it has a single temperature control for both stages.  So a new approach needs to be devised.

Here is what we are dealing with: A Rinnai Energy Saver-551F

Photo Sep 21, 18 17 30


This unit, which has 2 stages so it can make LOW or HIGH heat.  Whether it is making LOW or HIGH heat is determined by the heater, the idea being that if the room is very cold it makes more heat, then to maintain the temperature it runs lower and more efficiently.



Controls from different unit, but are the same as mine

Under the little door near the top-right of the front are the controls.  There are only two settings available: ON/OFF and ROOM TEMP.  This is a little disappointing and distinctly different from the last apartment, so I had to find out if I could use it.

After opening it up, I found the schematic and block diagram on the inside (THANK YOU Rinnai).



(click to enlarge)


(click to enlarge)

It seems like there is a lot going on here.  What I’m looking for is the equivalent of a thermostat in order to tell if the furnace is making heat and if so, LOW or HIGH.

After studying the Block Diagram for a while I was focused on the solenoid valves.  These valves are controlled by an electric switch and control the amount of gas delivered to the burners, so it seemed like if I could check if these are turned ON (open valve), I could monitor if the fuel is on.  Following the diagram, it looked like SV1 & SV3 are controlled by a single relay (R1) and SV2 is controlled by a different relay (R2).  These relays also control the Blower fan, which is also used when the heat is on.  A relay is simply a switch, as was the thermostat in the previous apartment, so if I could find the relays on the circuit board (marked MICRO COMPUTER) in the diagrams, I might be able to monitor them the same way.  Let’s take a look!

Photo Sep 21, 17 55 50

(click to enlarge)

Photo Sep 21, 17 56 40(edit)

Photo of “MICRO COMPUTER PCB” with relays circled

Above, I circled the locations of what appear to be relays on the PCB.  The diagram lists Relays 0-4 but I don’t have anyway of knowing which is which.  There is also no obvious way to sense what is happening.  So I looked around for what else might be easily accessible, focusing on the solenoids.

Photo Sep 21, 17 57 04

View from side (cover off) showing Gas regulator and solenoids

I found the solenoids all clustered together.  From the block diagram I knew that I can find if the relay is on at the solenoid.  And luckily, there are some big connectors at the solenoids that might provide access to the contacts I want.  Following the flow of gas, I saw that the top solenoid with purple and yellow wires is SV3.  The bottom left solenoid is SV1, and the bottom right solenoid is SV2.  Let’s try it!

With the unit OFF, I pushed some probes connected to my voltmeter into the back of the connector on SV1.  I then turned the unit ON with the temperature control set at the coldest.  The voltmeter measured 0Vac and 0Vdc.  I then moved the temperature control all the way up and heard the unit click on (the sound of relays).  Now the voltmeter measured 47Vac and 100Vdc.  That is a strange reading and indicated that there is an odd waveform coming from the relays, but I might be able to sense it anyway.  Before I turned the unit back off, I confirmed that SV2 measured the same.

I decided to try the same circuit that I used previously.  The voltages are higher and the waveform may be more erratic, but I was ready for a “guess and check” session with some wires jammed into the connectors and clipped with jumpers.  I decided to modify my existing circuit on the raspberryPi by changing the resistor and checking if the GPIO pin was HIGH or LOW by running a small script command.  This command below will continuously take a reading from gpio23 and display the result to screen, then wait 1 second.

while true; do cat /sys/class/gpio/gpio23/value; sleep 1; done

Remember, in the circuit the GPIO is Normally HIGH, so a 1 is OFF and a 0 is ON.

furnaceThis is the circuit I used with the thermostat in the last apartment.  In order to retrofit it for use with the Rinnai, I increased the resistance of the bias resistor before the voltage rectifier (all the way left).  To determine what resistance to use, I got some general numbers from the datasheet for the 4N35 opto-coupler I was using.  The emitter in this will bias between 4mA and 60mA.

In order to stay at the “safe” end of lower current, I started with a 14.9Kohm resistor.  With my ammeter in series with the resistor, I measured about 6.12mAdc when the unit was on, and the raspberryPi GPIO pin was returning 0 and 1 randomly, so it seemed like I was on the edge of the optocoupler biasing fully.  In order to bring down the resistance, I put a 22Kohm resistor in parallel with the 14.9Kohm.  This time I measured about 10.2mAdc, and the pi was returning steady 0s.  I turned the ROOM TEMP slider back down and the pi started return 1s.  So I believed the circuit worked, guess and check successful.

With this “breadboard” circuit working, I decided to continue with this by adding wires more permanently to the solenoid connectors.  Note that the Block Diagram states “…if wire replacement is required 105ºC wire must be used.”  So I got some 105ºC wire from VTC, as well as some pins that seemed approximately the correct size, and made up these beauties.

Photo Sep 21, 17 59 16

These are 4 wires to bring out the 4 pins I needed to sense from the solenoid valves.  Then I installed them so that they came out the bottom of the unit and could be put away until I made new circuits to sense them at the pi.

Photo Sep 21, 18 06 04

Photo Sep 21, 18 06 37

Photo Sep 21, 18 06 53

Now that the heater was ready, I went off to solder together some new sense circuits.  I wanted 1 for each solenoid (SV1 and SV2), and I copied the circuit I made before, changing the the resistor value to that that I tested for.  I also fit both circuits onto a single board.  I ended up connecting up the SV1 sense circuit to the GPIO 22 pin, and the SV2 sense circuit to GPIO 21.  Here is a photo of me attaching (hot-gluing) the circuit board to the raspberryPi mounting plate during the wiring process.  Next I was going to solder those red and black wires to the pi for biasing of the GPIO pull-up resistor and smoothing capacitor.

Photo Sep 21, 20 05 14

Once that was done, I mounted the pi on the wall near the heater.  I wanted to keep the wires from the heater as short as they can be because the voltages coming from it seemed a little high.

Photo Oct 03, 21 04 01

Photo Oct 03, 21 04 20

Closeup of raspberryPi with new sensing for Rinnai Heater, mounted to wall.