My first home automation system was based on Arduino and Raspberry PI .
All the relays I wanted to control, the switches from which I received signals and temperature sensors that I used, were connected to the arduino mega with ethernet shield.
Arduino was responsible for storing the states of individual devices. I had the MQTT server installed on Raspberry PI. Arduino sent all signals to the MQTT they were downloaded by OpenHAB and made available to the user via a web GUI or a mobile application.
In addition, OpenHab could send user commands to MQTT. Arduino read messages from MQTT queue and updated the status of home appliances.
The solution had one basic advantage: it worked :)
However, there were a few problems that I mentioned in previous posts. These included:
- complicated architecture - in case of problems there were many places to verify.
The solution had one basic advantage: it worked :)
However, there were a few problems that I mentioned in previous posts. These included:
- complicated architecture - in case of problems there were many places to verify.
- problems with power failures - arduino with ethernet shield has problems with proper boot after power outage. The system could hang on startup and it was necessary to manually disconnect it from power and restart. Sometimes several times. There are descriptions of such cases on the internet. Some advise putting an additional capacitor between reset PIN and GND (if I remember correctly :)), but in my case it did not help much.
- random switching on / off of devices during voltage peaks. I could not find the reason. I tried to connect the device to additional stabilizers, but it did not help. It was not somehow troublesome, because it happened relatively rarely, but it was quite a big scratch on the stability of the whole solution
- uncomfortable connection of devices to arduino - connecting sensors and relays directly to the arduino PINs is generally a very poor solution.
- problematic introduction of changes to the system - adding new relay or sensor besides connecting the hardware required changes in the arduino code, moving the laptop to the garage where my arduino was stored, hooking the USB to arduino, programming the system, testing and in case of error repeating everything several times - unhealthy :)
After more than two years of using such a system, I began to think about how to simplify the entire architecture, so that most of the above problems could be eliminated. Subconsciously, I felt that in this situation arduino is completely unnecessary, that Raspberry PI should be enough for everything. The problem is, however, the limited number of GPIO PINs.
In the previous post RPI and additional GPIO pins on several mcp23017 circuits and a switch on the transistor I described how these problems can be solved. The only thing left was to design a suitable system that would meet all my requirements, provide flexibility and the possibility of further expansion, and a PCB with possibility of easy attach devices to Raspberry. I have defined the following requirements:
- 16 digital inputs (support for up to 16 switches)
- 16 digital outputs (support for 16 devices which I can on / off)
- support for One Wire bus
- LIRC support (infrared remote control)
- easy and durable connection with Raspberry PI
- easy and durable connection of devices and sensors
- access to other GPIO PINs
- the ability to operate devices powered by different voltage
In the previous post RPI and additional GPIO pins on several mcp23017 circuits and a switch on the transistor I described how these problems can be solved. The only thing left was to design a suitable system that would meet all my requirements, provide flexibility and the possibility of further expansion, and a PCB with possibility of easy attach devices to Raspberry. I have defined the following requirements:
- 16 digital inputs (support for up to 16 switches)
- 16 digital outputs (support for 16 devices which I can on / off)
- support for One Wire bus
- LIRC support (infrared remote control)
- easy and durable connection with Raspberry PI
- easy and durable connection of devices and sensors
- access to other GPIO PINs
- the ability to operate devices powered by different voltage
The task was quite time-consuming, but I think that I managed to achieve the required effect. I did a scheme and project at Eagle, and here are the PCB I received:
This is the first prototype, as you can see, not yet fully soldered.
The board is designed for a 40-pin GPIO connector available from Raspberry Pi 2.
In this case, the connection is very convenient and durable - via a 40-core strip to the Raspberry and the PCB.
Nothing, however, stands in the way of connecting it to the older version of RPI where the connector was 26-pin. In this case the connection must be different - for example, female-female cables:
The connection is simple because the connector on the board corresponds to the GPIO port in Raspberry.
The tile contains all the elements about which I wrote in the requirements:
This is the first prototype, as you can see, not yet fully soldered.
The board is designed for a 40-pin GPIO connector available from Raspberry Pi 2.
In this case, the connection is very convenient and durable - via a 40-core strip to the Raspberry and the PCB.
Nothing, however, stands in the way of connecting it to the older version of RPI where the connector was 26-pin. In this case the connection must be different - for example, female-female cables:
The connection is simple because the connector on the board corresponds to the GPIO port in Raspberry.
The tile contains all the elements about which I wrote in the requirements:
Now a few words of explanation.
The board should be connected to the Raspberry PI GPIO port. In addition, an external DC power source must be connected.
I decided on this solution because RPI has too little current efficiency to handle 16 external devices that may have different requirements.
As you can see on the picture we have 16 transistors.
All outputs are designed as transistor keys. MCP23017 chips activate individual transistors and supply external power to individual outputs.
So here we have a very interesting feature - depending on what voltage we supply as an external power source, such devices might be controlled on the outputs.
For example, by plugging the board to + 5V we will be able to control relays that require 5V, connecting the board to + 12V we will be able to connect 12-volt devices, for example LED strips. There is a limitation here - all outputs must operate at the same voltage.
However, another feature of the PCB allows to overcome this limitation.
As you can see on the board there is an additional GPIO output, which theoretically can be connected to the second same PCB. Then connect first PCB to + 5V and the other to + 12V. Then we have 16 outputs + 5V and 16 outputs + 12V. And so on .... To the second we can connect the third, third to the fourth :). On each board you only need to change the addressing of MCP23017 circuits using jumpers.
The limit is only the number of addresses - 3 bits, i.e. we can handle 7 MCPs - from the fourth board we would have to take out one MCP chip - they are in sockets, so there is no problem. I have not tested such a solution yet - I do not have so many PCBs :), but the theory says that this solution should work. I have yet to investigate the current limitation of all connected devices - it is still ahead of me. From the preliminary calculations it appears that up to 2A should work without the risk of overheating - this is what I will study.
Another note - only the devices that can be connected via two wires (plus and minus) can be connected to the outputs. This allows, for example, to enable relays, but only one-channel relays. They have 3 pins. We connect the minus to minus, the plus of the board at the same time to the plus and signal on the relay. For me, this solution is enough. I control single-channel relays hidden in wall boxes. Controlling multi-channel relay modules can be problematic because they share power for all channels. I'm already working on the solution.
There are 16 digital inputs on the board. They are ordinary 2-pin connectors. Shorting the pins causes the + 5V voltage to be applied to the appropriate MCP23017 channel and from there we can read the state of the button.
In addition, I placed a 3-pin LIRC connector on the board, which can be directly connected to the TSOP receiver.The connector is connected to 3.3V with RPI so only TSOP circuits that support such voltage will work. I personally checked the TSOP4836 and it works fine.
You can connect 10 OneWire devices directly to the board. Each input has 3 PINs (+ 5V, GND, SIGNAL).Devices are plugged in directly, without an additional resistor, which I have already placed on the PCB.
These are probably all the functions of the board. For me, the PCB has replaced the previous configuration about a month ago and it has been working fine so far. All the limitations of my previous home automation were removed.
And the biggest advantage - how we use the board, what language do we use - it only depends on us.. You can use python, java, c, or even write scripts in bash. Only the imagination limits us. Everything can be tested by logging in to RPI via ssh and running programs. You do not need to program arduino every time :)
I decided that I would still stay with OpenHab launched on RPI.
OpenHab 1.x has a "binging" supporting MCP23017 systems. Probably it can be used, but recently i switched to OpenHab 2.x.
Unfortunately, the binding did not work, so I had to write my own. The code is already merged to official release, so it should work with OpenHab 2.3 or above.
There was also no binding for handling temperature sensors connected to OneWire connectors. I also had to write my own. The code is also available in OpenHab 2.3 or above
Summarizing:
the whole solution took a lot of time, from the prototype on the contact board, through the diagram and project in eagle, soldering the circuit, writing the software, but it was definitely worth it. The whole system works much more stable than the previous solution, and it is much more convenient and flexible. I am able to imagine a lot more use cases of such a PCB than just home automation.
Currently I use it with:
Another note - only the devices that can be connected via two wires (plus and minus) can be connected to the outputs. This allows, for example, to enable relays, but only one-channel relays. They have 3 pins. We connect the minus to minus, the plus of the board at the same time to the plus and signal on the relay. For me, this solution is enough. I control single-channel relays hidden in wall boxes. Controlling multi-channel relay modules can be problematic because they share power for all channels. I'm already working on the solution.
There are 16 digital inputs on the board. They are ordinary 2-pin connectors. Shorting the pins causes the + 5V voltage to be applied to the appropriate MCP23017 channel and from there we can read the state of the button.
In addition, I placed a 3-pin LIRC connector on the board, which can be directly connected to the TSOP receiver.The connector is connected to 3.3V with RPI so only TSOP circuits that support such voltage will work. I personally checked the TSOP4836 and it works fine.
You can connect 10 OneWire devices directly to the board. Each input has 3 PINs (+ 5V, GND, SIGNAL).Devices are plugged in directly, without an additional resistor, which I have already placed on the PCB.
These are probably all the functions of the board. For me, the PCB has replaced the previous configuration about a month ago and it has been working fine so far. All the limitations of my previous home automation were removed.
And the biggest advantage - how we use the board, what language do we use - it only depends on us.. You can use python, java, c, or even write scripts in bash. Only the imagination limits us. Everything can be tested by logging in to RPI via ssh and running programs. You do not need to program arduino every time :)
I decided that I would still stay with OpenHab launched on RPI.
OpenHab 1.x has a "binging" supporting MCP23017 systems. Probably it can be used, but recently i switched to OpenHab 2.x.
Unfortunately, the binding did not work, so I had to write my own. The code is already merged to official release, so it should work with OpenHab 2.3 or above.
There was also no binding for handling temperature sensors connected to OneWire connectors. I also had to write my own. The code is also available in OpenHab 2.3 or above
Summarizing:
the whole solution took a lot of time, from the prototype on the contact board, through the diagram and project in eagle, soldering the circuit, writing the software, but it was definitely worth it. The whole system works much more stable than the previous solution, and it is much more convenient and flexible. I am able to imagine a lot more use cases of such a PCB than just home automation.
Currently I use it with:
- 7 relays for controlling lighting or sockets
- switches for operating relays
- 7 One Wire DS18B20 temperature sensors
- controling relays with infrared remote control
- reading a state of garage door (closed / open)
All this on one Raspberry PI and the PCB described :)
During the work I prepared three prototypes of the tile. One works productively, one I have for further testing and one left unused. If anyone is interested, I can sell it. Feel free to contact me if interested. It is fully manually soldered. Contact me if You are interested. If there will be more interested persons I'll prepare more of them.
You can also buy MCP23017 chips for example in aliexpres, from this link:
http://ali.pub/2hk68b
This is affiliate link. When you will buy from this link I will get some provision, so You will help in this blog development. Thank You!
- 7 One Wire DS18B20 temperature sensors
- controling relays with infrared remote control
- reading a state of garage door (closed / open)
All this on one Raspberry PI and the PCB described :)
During the work I prepared three prototypes of the tile. One works productively, one I have for further testing and one left unused. If anyone is interested, I can sell it. Feel free to contact me if interested. It is fully manually soldered. Contact me if You are interested. If there will be more interested persons I'll prepare more of them.
You can also buy MCP23017 chips for example in aliexpres, from this link:
http://ali.pub/2hk68b
This is affiliate link. When you will buy from this link I will get some provision, so You will help in this blog development. Thank You!
Comments
Post a Comment