Microwave_Ab's Blog

Where I always sometimes document what I've been doing

RS-485 and Modbus

A post about creating a heat pump controller app from scratch by using the power of RTFM Ben Eater style.

Update 21.1.2022

Automating our house's heating

This summer we installed a heat pump to our house. (I'm 19 and still live with my parents.) This pump's indoor unit was naturally placed to the technical room of our house that contains all the heating related equipments. The only problem is that it's literally the furthest place away from living room. Remote control would be a welcome feature especially in the winter, when the heating must be constantly adjusted. So after I finished my last project, my father consulted me on this problem. My father had already dug up the docs for the controlling protocol, which was pretty epic. After taking a quick look I decided that this would be the perfect chance to learn some low-level communication.

The first thing I decided is that I want this to be an independent system. I don't want everything breaking in my house after I move out with my PC and server, so I decided to sacrifice a raspberry for this application. Now I have to figure out a way for my raspi to communicate with the heat pump. Turns out the controlling interface is RS-485 based, so I ordered a RS-485 CAN HAT for raspi. This would convert raspi's serial interface into a RS-485 one.

After I received the adapter it was time to do the cooding. Turns out I don't have to do low-level stuff because there is already a python library for modbus protocol called python3-pymodbus, which provided all the stuff I needed.

But projects are never so easy. Apparently the whole documentation provided for the memory addresses is poopoo, so I needed to reverse engineer them. All of the values were unsigned integers, which meant that value of 65530 actually means -5 because of overflow stuff. Not only that, but you need to process some values as well. For example 301 might mean 30.1 on certain values and so on.

When the reverse engineering is complete the next step is to make web-interface for reading and setting the values, which I will document in my next update.