This is an example for Arduino IDE how to create an own MBUS consumption meter (MBUS Slave) for Arduino MKR boards, Raspberry Pi Pico and Feather Boards (including ESP32, RP2040, nRF52840, Cortex M0 ....).
I've used our MBUS Slave boards:
MBUS Slave Raspberry Pi Pico HAT: https://www.hwhardsoft.de/english/projects/m-bus-pico-hat/
MBUS Slave Feather Wing: https://www.hwhardsoft.de/english/projects/m-bus-featherwing/
MBUS Slave Arduino MKR Shield: https://www.hwhardsoft.de/english/projects/m-bus-mkr-shield/
The code was tested with the following boards:
- Arduino MKR Wifi 1010
- Adafruit Feather Huzzah32
- Adafruit Feather nRF52840
- Adafruit Feather M0 Express
- Sparkfun ESP32 Thing Plus
- Sparkfun Thing Plus RP2040
- Raspberry Pi Pico
Furthermore, an MBUS master is required to supply the MBUS and to be able to exchange data with the slave. For example, you can use a Raspberry Pi with libmbus and our MBUS Master HAT....
The default baud rate, default bus address and id of the device can be adjusted in mbusslave.h.
Consumption values can be added or edited in the Encode_Payload() function. Be careful with MBUS codes of the "Device" domain. This code does not work or is already contained in the header of the protocol.
You can view the structure of the header in mbusslave.cpp and change parameters, e.g. the manufacturer ID, if necessary.
Install the following library through Arduino Library Manager
MBUSPayload Library MBUSPayload Library
Based on the awesome work of OpenEnergyMonitor code by Trystan Lea, Glyn Hudson, and others
https://github.com/openenergymonitor/HeatpumpMonitor
and Bryan McLellan btm@loftninjas.org
https://github.com/btm/emonMbus
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU