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):
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.
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.
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
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
This is exactly what I’m looking for!
I would be really glad if someone with better knowledge of electronics could make a Arduino Shield or some easy-to-use breakout board. 😀
Keep up the good work.
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
Hi,
Is it possible to use the target address so if you push a button with target address 0/0/1 that the arduino know that his pin 5 is that address for example?
I cant get the int of the Main,Middle,Sub into a variable that i can use in arduino.
Could you help mee?
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.
Hi,
Are you working in this project? What it is the actual situation? I´m working in a KNX network with a WAGO 750-849 and CoDeSys, but I want try this. I already ordered a arduino. I´ll let you know as soon as I get it.
Cheers,
Luar
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
Hi Daniel,
While ago, in this post you mentioned design works related to Room controller. What is the status of this project? Are you willing to publish results?
Thanks
Matulo
Guten Tag!
I would like to ask if you use Raspberry Pi? I would like to find out more on how Raspberry Pi can work with Arduino to function as a simple yet useful home automation 🙂 Also, i’m not too sure which Arduino i should choose as there are a lot of them out there. I ordered an Arduino Uno though.
Thank you!
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
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
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
hello.
i’m trying to develop a similar project based on pic microprocessors.
i have just tryed to buy the TPUART device from „opternus component“ but the answer was that they can’t deliver/sell to a private hobbyst.
do you have some suggestion for it?
thanks
Guido
Hi Guido,
unfortunately this is the downside of the TPUART. However there might be resellers that sell it to private persons without problems. In fact if you have a company it’s not a problem to also order very small quantities (1-2).
Best regards
Daniel
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
Hi Roland,
this should actually work without any problems, however note that you need to disable all DEBUG output and also – probably – disconnect the USB will communicating through this port.
Best regards
Daniel
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
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?
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
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?
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
Hello,
Thanks for your answer and its solved now. In the lib are some hardcoded Serial usages. And i use Serial to connect the KNX tpuart. I added it all after a debug parameter and now it works without delay and i receive all commands.
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)
Hi,
AFAIK the protocol is basically the same, but of course headers are different. Maybe you want to have a look at the Calimero project (http://sourceforge.net/p/calimero/wiki/Home/) – they have a Java lib for KNX communication. I only tried it once and found it working well.
Best regards
Daniel
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
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
Hello,
is it possible to connect the TPUART 2.0 evaluation board with a arduino uno ?
When i will upload the sketch, there are many failure, before I connect RX TX…
Best regards
Jens
Hi Jens,
this should be possible, but I’m not sure if you can use my TPUART code for it (as it was written for the version 1).
Best regards
Daniel
I downloaded the source code and placed the KnxTpUart forlder in C:\Program Files\Arduino\libraries\.
When I compile the Examples\GroupWrite skect i get the following error. Am I missing something ?
Error Image : http://i1265.photobucket.com/albums/jj520/cyberinsystems/Error_zpsb2d8d515.png
Thanks
Hello
Now i am able to interface KNX without TPUART,
i use internal comparator of PIC and relative interrupts for decode KNX signals.
here is my project ; „http://guidopic.altervista.org/alter/knxgate.html“
galvanic isolation is not my objective for now, i will add later.
best regards
Guido
Very usefull page thank you!
Do you think it is possible to get the knx-tp wireless with a xbee module? So that you have multiple setup’s(arduino/tpuart/xbee) as nodes to make some kind of mesh network?
Regards,
R
Pingback: Do you like to have an Arduino KNX shield? | Daniel's Blog
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.
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
Hello,
Is it also possible to use a KNX wall switch and decode this with the Arduino and your code? I would like to (mis)use the multiple button KNX wall switch from Jung to switch on/on my Philips Hue lamps. Also increase and decrease light intesity and maybe put some pre-defined light schedules behind the buttons.
Hello Daniel,
Is it possbile to use fze1066 module instead of siemens tpuart. If we use fze1066, is it pin compatible with siemens module? Should we change pcb for this changing? Because i didnt find siemens tpuart.
Hello Daniel.
I am currently doing my final year project and this project is similar to mine. I would love to have the PCB layout for the breadboard.
Please and thank you.
Hello Daniel,
I am interested in using an Arduino to interface to my KNX system. What we miss in KNX is some easy and economical time of day controllers. Most switches are ON OFF with delays. In Europe to control lights and shutters based on day light need a bit of programing not available in KNX devices.
I tried to download your code (Bitbucket repository, https://bitbucket.org/dka/arduino-tpuart) but getting an error 404. Can you please send the link where I can get the code also do you have anything new in KX and Arduino