View on GitHub

Knxdevice

Allow to turn your Arduino into a self-made KNX device using the hardware TPUART interface

Download this project as a .zip file Download this project as a tar.gz file

KNX Bus Device library for Arduino

Links :

Realization examples :

NB : The source code is available in the "examples" folder.

Presentation :

KNX is an open communication protocol standard for intelligent buildings.

This library allows you to create your "self-made" KNX bus device. For that, you need an arduino hardware and a Siemens TPUART chipset for the physical coupling to the KNX bus (see hardware section below)... and of course a home KNX installation (or at least a prototyped one like I have while my real one -and the attached house- is being delivered)! To avoid spending energy on electronic stuff, the easiest way (I chose) is to use an electronic board with the TPUART already integrated : I used a "TPUART2 test Board BTM2-PCB" that I bought from http://www.opternus.com. Or a Siemens bus coupler should also be OK even if I have not tested it. Or why not create a new PCB with both Arduino and TPUART integrated (any motivated person?).

You also need to know a few things about the KNX system, in particular about KNX communication. There are plenty of information on the web, or you can also read the "KNX Basic Course Documentation" book, available on the knx online shop (www.knx.org), which offers a complete technical overview of the KNX system.

Why to create its own KNX devices ? First this library is intended for hobbyists only. It allows you to create something funny and fully customized. The main drawback is that your self-made device can not be configured using ETS, the KNX software allowing KNX installation commissionning. I hope to make this library as reliable as possible (you can help me in this task!) even if its use remains at your own risks. I'm still confident enough and plan to use self-made bus devices in my future own KNX home installation.

Hardware :

For hardware part, I considered the following points :

The ideal arduino board seems to be Arduino Mini for its tight dimensions and low power consumption, around 10mA with power optimization. But its drawback is the presense of one serial only, meaning you cannot debug while the bus device is running.

That's why, for the development of the software library, I have used the Arduino Mega offering several serials : Serial0 is used for programming & debug, while Serial1 is connected to the TPUART. Since the Arduino Mega is connected and powered by the USB port, I isolated the RX/TX lines between Arduino and TPUART using opto-couplers.

Roadmap :

This library is still under developpement. The next actions in the pipe are :

API

1/ Define the communication objects

First of all, define the KNX communication objects of your bus device. For each object, define its group address its gets linked to, its datapoint type, and its flags. Theoritically, you can define up to 256 objects, even if in practical you are limited by the quantity of RAM (it would be worth measuring the max allowed number of objects depending on the memory available).

KnxComObject KnxDevice::_comObjectsList[];

// Definition of the Communication Objects attached to the device
KnxComObject KnxDevice::_comObjectsList[] =
{
//              adress,                                  DataPoint ID,                                      flags           } ,
/* Index 0  */ { G_ADDR(0,0,1) /* addr 0.0.1 */,          KNX_DPT_1_001 /* 1.001 B1 DPT_Switch */ ,           COM_OBJ_LOGIC_IN_INIT } ,
/* Index 1  */ { G_ADDR(0,0,2) /* addr 0.0.2 */,          KNX_DPT_5_010 /* 5.010 U8 DPT_Value_1_Ucount */ ,   COM_OBJ_SENSOR        } ,
/* Index 2  */ { G_ADDR(0,0,0xA) /* addr 0.0.A */,        KNX_DPT_1_003 /* 1.003 B1 DPT_Enable*/ ,            0x30 /* C+R */        } ,
};

const byte KnxDevice::_comObjectsNb = sizeof(_comObjectsList) / sizeof(KnxComObject);

2/ Start/Stop/Run the KNX device


byte begin(HardwareSerial& serial, word physicalAddr);

Knx.begin(Serial, P_ADDR(1,1,0xAA)); // start a KnxDevice session with physical address "1.1.AA" on "Serial" UART

void task(void);

Knx.task();

void end(void);

Knx.end();

3/ Interact with the communication objects

The API allows you to interact with objects that you have defined : you can read and modify their values, force their value to be updated with the value on the bus. You are also notified each time objects get their value changed following a bus access :


void knxEvents(byte objectIndex);

// Callback function to treat object updates
void knxEvents(byte index) {
  switch (index)
  {
    case 0 : // object index 0 has been updated
      // code to treat index 0 object update
      break;

    case 1 : // object index 0 has been updaed
      // code to treat index 1 object update
      break;

//  ...

    default:
      // code to treat remaining objects updates
      break;
  }
};

byte Knx.read(byte objectIndex);


void Knx.write(byte objectIndex, byte byteValue);


void Knx.update(byte objectIndex);