In this tutorial I will show you how to read out an SDM630 Modbus meter with a RaspberryPi (or any other Linux computer). The tutorial is intended more as a basis for your own project. There is plenty of ready-made software, such as Smartmeter.

Hardware

  • SDM630 Meter (e.g. this one)
  • Modbus USB Adapter (e.g. this one)
  • Cables
  • 2x 150 Ohm resistor

On the upper flap of the meter there are the terminals A+ and B-. These are connected to terminals A and B on the adapter. A terminating resistor of 150 Ohm is connected to the end of the bus or to the last and first device. Since I only have 2 devices, this is the meter and the USB adapter.

Theoretically, several meters can be connected to the bus in parallel.

Software

Configuration of the meter

Various settings must be made on the meter for the Modbus. This is how it works with my meter:

  1. Press and hold the E button
  2. Enter password (default: 1000)
  3. Press and hold the E button
  4. The message “Set Addr” appears
  5. Select the setting by pressing and holding the E button and change the address with the arrows. Exit the setting by pressing and holding the E button.
  6. Use the arrows to select the settings “Set baud”, “Set Pari” and “Set Stop” and set them as well.

The address is used to identify the device on the bus. If you have only one device, you can leave the address at 1, if you have several, give the devices different addresses.

The baud rate is simply the transmission speed. With a higher baud rate, however, only a shorter cable length is possible.

I do not use parity, so I use “none”

The stop bit can be left at 1

Read out values with script

In addition to the settings you made before, you need another value: the USB port. You can be quite successful here by trial and error. With ls /dev/ttyUSB* you can display all ports. In my case, there was only one.

This is my code:

In line 1, the Modbus module is imported from Python. You may need to install this:

In the next line, the device is initialised. Here you may have to change the USB port and the Modbus address. After that, there is a very long part, through which the script later knows which value has which number and which unit. The “use” can be used to determine whether the value is to be used or not. To do this, simply set the value to True or False. Line 177 contains a for loop that is executed once for each value. Line 178 checks whether the value should be used. Everything after that (don’t forget the indentations) can now be programmed freely. In my example, all the data is simply printed. The line

returns the value (the one at which the for loop is currently). With

you get the unit.

For example, this code example writes the data to an Influx database.

Now have fun programming!