Connecting an Arduino to EIB/KNX

Update 14.07.2015: We are currently thinking about producing an Arduino KNX shield. Please let us know if you are interested. Thanks!

After having heard about it a couple of times already, I recently rediscovered the Arduino for myself and quickly came up with an idea for a first project – connecting it to KNX (formerly known as EIB). This was actually quite easy and I’d like to share my experience (and code) here in case somebody wants to do a similar thing.

To interface with KNX an interface IC is required (at least if you’re not able to build one on your own). I used a Siemens TP-UART for the job (obtained from Opternus Components). The TP-UART converts the signal from KNX to a UART signal (compatible with Arduino’s serial ports) and cares for a lot of the low-level details, e.g. line access control and telegram repetition. The serial protocol is described in depth in the TP-UART datasheet.

To connect the TP-UART to KNX you need some rather standard parts (resistors, capacitors, diodes, a crystal, …). To a large extend I used a schematic designed by the TU of Vienna for their TP-UART PC Interface Board. On the Arduino side I added optocouplers to isolate from KNX. The full schematic is as follows (you can find the Eagle files in the Bitbucket repository):

b4165158c9

I built it up on a breadboard for now using an Arduino Mega 2560. Using the Mega is the simplest solution as it has multiple UARTs so that you can connect the usual USB for programming and the TP-UART at the same time. This makes debugging using the serial “console” easy.

IMG_5613

Next, I needed some software. After fiddling around with the Arduino IDE for a short time, I noticed it’s pretty limited (at least if you’re used to full-fledged environments like Eclipse). So I quickly started building a library in Eclipse. The library has a comparably simple interface to the user such that he/she doesn’t have to care about the details of the KNX / TP-UART protocol. While implementing the library I needed some time to figure out the details of the protocol (e.g. when I need to send the ACK / NACK confirmation on an incoming telegram). Overall however it was not too difficult.

The whole source code of the library can be found on my Bitbucket repository for this project. There are also some examples in there that show the use of the library. The first “real” example is the use of a Dallas temperature sensor and sending its values to KNX in regular intervals and also answering to read requests on a certain group address – in the repository the “TemperatureReadoutOneWire” example.

Feel free to use the library for anything you want (of course without any warranty). If you have any improvements, suggestions or found a bug please let me know e.g. by using the issue tracker.

37 Gedanken zu „Connecting an Arduino to EIB/KNX

  1. viknet

    very interesting stuff, probably lead to much cheaper KNX stuff :-), I will probably use this to create cheap PIR KNX detector

    one question though, why are you using the tp-uart alone instead of using the evaluation board:
    http://www.opternus.com/en/siemens/development-tools/tp-uart2-evaluation-board.html

    another question, is why all knx tpuart use optoisolator, why do we need them ? isn’t it easier to directly connect the rx/tx to the arduino ?

    best regards, and keep going, knx is a marvelous stuff, but too expensive

    Antworten
    1. dka Beitragsautor

      Hi Viknet,

      this was basically out of interest and price concerns. The eval board seems to be great stuff though!

      The Optocouplers are just a safety measure. While the Arduino is powered from the USB port of my PC I wanted to make absolutely sure that it is never hit by any voltage originated in the KNX bus. Once you’re running the Arduino of KNX (which is easily possible with the TP-UART) you can safely remove them.

      Best regards
      Daniel

      Antworten
    1. dka Beitragsautor

      Hi Dennis,

      you can have a look at the Bitbucket repository. There’s already a PCB layout in there. I’m currently getting a few of them produced for my own use. I’ll report if everything works well such that anyone could safely have them produced for themselves. Note that I don’t plan to sell any of these at any time.

      Best regards
      Daniel

      Antworten
    1. dka Beitragsautor

      Sure, just determine which pin to switch depending on the received address. In the „ReceiveKNXTelegrams“ example everything is prepared for this. First you set on the TPUart objects which group addresses shall be listened on. Then, just use the appropriate methods on the KNXTelegram to determine the addressed object.

      Note that the address you need to pass to the constructure of KnxTpUart is the physical address to use. Each device on KNX only has one such address which is also mainly used for programming and as sender address in the telegrams. Normal communication is always done through group addresses. It can be confusing as both addresses look very similar.

      Antworten
    1. dka Beitragsautor

      Hi Luar,

      yes, some friends and myself are still working on this project. In fact we are trying to design a full room controller based on an ATXMega processor (using the great XMegaDuino environment). However, we will only publish the source once it has reached a certain level of stability which might take us another 6 months or so. Updates to the Arduino KNX library are in the repository as soon as we do them, though.

      Cheers
      Daniel

      Antworten
    1. dka Beitragsautor

      Hi Yvonne,

      I have a Raspberry Pi as well but am not using it for KNX at the moment (also not planning to do so). If you like to have an easy-to-use ready-made module I suggest looking at the BAOS modules of Weinzierl Engineering, see http://weinzierl.de/de/development/820.html – we have also used one of these modules in the past and they work great.

      On the other hand, you can use the Raspberry Pi to connect to your KNX/IP gateway via Ethernet, which would save you from any additional Hardware costs.

      Best regards
      Daniel

      Antworten
  2. PsP

    Hi Daniel

    great lib! Thanks for sharing.
    I was wondering if you had any plans to include KnxNet/IP? It would be great to be able to add stuff (as in arduino based I/O) to an existing network. It would also allow me to experiment with some home automation projects out there (openremote, LMCE, mister house, …) without the need for a KNX network: Add some I/O to e.g. a mega to create a device cable of button input, switch a relay, convert KNX (KNXnet/IP) to DMX
    Second question: would it make senst to add dpt types to the KnxTelegram lib? Do I understand correctly that you currently implemented reading/writing 6 bits of data of byte[7] or 2 bytes (8&9) with a 2 byte floating nr)

    thanks again for all your effort

    Antworten
    1. dka Beitragsautor

      Hi,

      I currently do not have plans to include KnxNet/IP. However, there are KNX-IP-Routers that can convert from/to KNX and can also be used for programming the KNX devices via IP.

      Yes, you understand correctly – these are currently the only two functions. Adding DPT types would make sense and also an abstraction such that you have some kind of „datapoint objects“ to interact with.

      Best regards
      Daniel

      Antworten
  3. RSM47

    Dear Daniel,

    First of all – great work!

    I have just one question:
    Did you ever try to use Serial0 for communication with the TPUART? We have tried this but it was not possible to establish a communication between TPUART and the Arduino Mega. If we use Serial1, Serial2, … it works great.
    Maybe you have an answer for this? Can this be caused by the USB To RS232 converter connected to the Serial0 port.
    The reason why we have tried Serial0 is to use this also on an UNO which only has Serial0.

    It would be great if you could give us a short answer!

    Best Regards,
    RSM47

    Antworten
      1. Roland

        Daniel,
        Thanks for your answer!
        I have tried it.
        I have disabled all the debug messages and I also have the USB connection removed to be sure that there is no influence on serial interface via the USB interface. But there is still no communication possible. With the serial interface 1,2 and 3 it works without problems. I still think that the USB to serial converter will cause the problem in this situation.

        Maybe anyone has found a solution for this. It would be fine to get an answer on this.

        Best regards
        Roland

        Antworten
  4. Edmund

    Background: We are currently using your code with a TPUART 2.0 evaluation board connected to Arduino Mega 2560 and a existing up and running KNX system.

    So the problem we are is as such:
    TP-UART Test
    Incoming Byte : 0 – 0
    Event UNKNOWN
    Frame Error
    Incoming Byte : 3 – 11
    EVENT TPUART_RESET_INDICATION

    Also, we are facing trouble establishing a physical address for the evaluation board. When we upload the program to the Arduino, and tried to check the physical address on the ETS 4.0. We are unable to find the physical address 15.15.20.

    What are the potential steps to solve the above question?

    Antworten
    1. dka Beitragsautor

      Hi Edmund,

      the most easy thing to test is actually to let the Arduino send out any telegram (e.g. a group write boolean). Put this in a loop to send it out e.g. every 2 seconds or so. Then, use the ETS bus monitor and you should see the telegrams. I have never used ETS 4, so I can’t tell how it would look there, but I guess this procedure should also work here just to see if the Arduino is connected to KNX correctly.

      Best regards
      Daniel

      Antworten
  5. Gert-Jan

    Hello,

    Very nice project….

    I added this board to a Jeenode (arduino clone from http://www.jeelabs.org). It works great, but some times i miss a read request. My code is:
    // all knx events are written to the serialEvent routine
    void serialEvent() {
    KnxTpUartSerialEventType eType = knx.serialEvent();
    if (eType == KNX_TELEGRAM) {
    KnxTelegram* telegram = knx.getReceivedTelegram();

    delay(10); // getCommand() == KNX_COMMAND_READ)
    {
    #if DEBUG
    uart.println(„knx packet read“);
    #endif
    }
    }
    }

    As you can see i use a delay(10);, else no right read request is received, maybe you know why?

    Is this also the problem that if i do 50 reads in a very short time, i miss 2 or 3 read requests?

    Antworten
    1. dka Beitragsautor

      Hi Gert-Jan,

      it’s possible that you miss the requests because of the delay (the serial buffer is limited in Arduino and the serialEvent() function is only called once per loop). It might also be influenced by whatever you do in your loop()-function.

      It’s also strange that you need the delay for receiving the request correctly. This should not be neccesarry.

      Best regards
      Daniel

      Antworten
  6. Hans petter

    Hi,
    I was thinking to make a KNX server with an android unit (JXD MiniPad 36USD on aliexpress.com).

    I downloaded the BAOS democlient since i was planning to do some testing with their BAOS card. In the DEMO software you can switch from RS232 to IP/UDP and IP/TCP suggesting the port 120004 (TCP/IP). Has anyone here made a TCP/IP or IP/UDP server for KNX? Does it use the same protocol as twisted wire?

    My goal is to be able to bridge a RS485(modbus) system to KNX, and since Android supports the FTDI chip’s (RS232R) making it possible to get a serialport on android it should be only a matter dataexcange of protocol differences. I already can see the data on the RS485 on my android terminal window already 🙂
    ( i made a small card ralaying data from a ttlserial to rs485modbus in both directions)

    Antworten
  7. Pasi

    Hi,
    good work!

    I was wondering if the tpuart could be used with BatiBUS? I have Siemens Albatross and that uses BatiBUS to communicate. I’d like to log mainly temperatures but also other measuremets and statuses from there.

    I already have few Arduinos and am planning to use Mega as interface between BatiBUS and LAMP (MySQL) server…

    vg,
    Pasi

    Antworten
  8. Guido

    hello.
    finally i have developed a similar project based on pic microprocessor PIC18F26K80.
    i have developed two different firmware project:
    First project (EIBscout) have the goal to study and understand communications on a „Vimar by-me“ domotic bus similar to EIB/KNX. First presentation of this project is at page http://guidopic.altervista.org/alter/EIBscout.html

    Second project is an effective interface between a domotic network Vimar and a self-builded CAN network. Now from my web server connected on CAN net i can interact with the official domotic system. this second project differ from first only for different firmware, same hardware.

    thanks for your useful material
    Guido

    Antworten
  9. Pingback: Do you like to have an Arduino KNX shield? | Daniel's Blog

  10. Will

    Hi,
    This is excellent – I was planning on doing something very similar myself, so to find most of it here is great.

    I’ve been having some difficulty in sourcing the tpuart parts – Opternus seem fine if you’re a company, but seem a bit difficult if you’re not, so I was thinking that there has to be a market to sell these shields (or even make an Arduino + TPUart board that comfortably fits in a wall recess). I have found however that there are other similar parts that are easier to get hold of (Elmos‘ E981.03 is available from mouser), so this is currently the route that I’m looking at, so I guess I may make a port of your code.

    For me the critical part is price – I would like to be able to make an 8 button wall switch and temperature sensor for <£20. My target break down as £11 for electronics components, £2 for PCB and £5 for enclosure (3d printed front panel and buttons), £1 for assorted mechanical bits and pieces.

    However, I'm just getting started at the moment, so this is all a little far away.

    Antworten
    1. dka Beitragsautor

      Hi Will,

      for another project we were also looking at this pricing, but found that it’s almost impossible especially if you like to create a great looking and feeling enclosure with high quality materials (like aluminium) and also need some parts manufactured directly to the PCB (which you probably need if you like to have such a miniaturized solution).

      Thanks for the hint to the Elmos!

      Best regards
      Daniel

      Antworten

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.