Design of embedded system

Today, I would like to ponder on a subject of creating some measurement systems, or in more general, embedded systems. There are multiple approaches to make such a system. Let’s consider a few of them — the most popular approaches.

Embedded systems are gaining popularity by the day. Those systems are used in Internet of Things (IoT) but also in more advanced control systems. However, sometimes a need of more sophisticated system is emerging which requires more computational power. I would like to present some architectures of such systems and highlight some features of those approaches.

When one considers an embedded system following aspects should be taken into consideration:

  1. Feasibility — can the system be created using chosen tools.
  2. Extendability — can the system be easily extended with new features.
  3. Maintainability — maintenance of the whole system should not be time consuming and should not require a lot of effort.
  4. Longevity — the system should work for foreseeable feature without major downtime.
  5. Repairable — each system can be damaged and you should be able to fix it in terms of available technology or spare parts, which themselves, have limited period of availability.
  6. Modularity — system is divided into independent components which can be swapped.

Above are not limited there can be more aspects or conditions that have to be met.

Below there is an example with a few proposed solutions that consider different aspects and sometimes over emphasize to just make you aware of some problems.

Example

Let’s take as an example a system responsible for measuring temperature in a room and visualizing the data using some web server.
As you can see it is not a trivial example. There are at least two objectives:
1. measuring the temperature.
2. visualizing the data.

Solution I — Arduino

The most popular embedded platform is Arduino there are plenty of project which consider different aspects of life including the example presented above. However, is it always the best solution? It is said that you should choose right tools to the task not the other way!

Let’s take the Arduino platform. You could use a DS18B20 temperature sensor or some DHT sensor. The first task of measuring temperature is completed. To launch a web server you would probably take an Ethernet shield and use it to serve a web site with measurements.

The huge advantage of this approach is that all of the libraries for the sensors and the shield are ready to use. However, is it the best solution? Consider extending the system wit a new feature. You would also like to measure the humidity. You change the DS18b20 to DHT sensor and add a few lines of code to make it work. Done! Do you see it yet? Consider a something easier. Suddenly you have decided that you do not like the data to be presented as a table. You would like it to be a plot, nothing fancy just a plot… You have found a project which draw a plot or you even have it written it by yourself. Everything is ready to flash the microcontroller. Done!

I am sure that you see it now. Of course, every time you add something or change something you have to: change the code, do some hardware adjustments and flash the new firmware. You won’t be able to miss changing the code, you just need to do this. Also, when you add some extra hardware you have to add it to the current system but do you need to flash it?

Let’s consider above more deeply. Adding a new feature involves changing the code. However, each code is more or less platform dependant. Using Arduino platform you are limited to the tools you have chosen. Sometimes, there is an existing solution but sometimes there’s not. The existing solution also can be addressing different platform, hence needing some modifications. Still, Arduino platform is quite good because the community support is huge plus there are many solutions/project which can be altered to your specific task. Finally, flashing a microcontroller is not resource demanding but you have to take the unit, plug it to a PC and flash it. It consumes time and it is not always required as you will see further with different solutions.

Please keep in mind that the same goes to other bare-metal platforms like STM32 and their Nucleo or Discovery boards. Consider this solution as a general one describing a certain group of platforms like Arduino, mentioned ST platforms or any other.

Solution II — ESP8266

ESP8266. Boy Oh Boy, this is a real treat!

The popularity of this module has increased significantly over the years. The community is growing fast and there are many project using this chip. The biggest advantage of this system is that it has a rich ecosystem build in! All what you need to do is to attach a sensor of you choice to the device and voila!

You can easily set up a simple web server for you measurements. What is more, the best part of this system is its key feature. It has WiFi on the board which means that you can set up it for wireless data transfer. This is really convenient. Also if you configure it right you can even deliver firmware updates without any cable! Moreover, for those who are familiar with Arduino platform and its ecosystem, the ESP can be programmed using the Arduino IDE. As you can see this solution is one of the best but it also have some downsides. The basic ESP8266 has limited number of pinouts which means that you won’t be able to easily extend it with new devices. Of course, it is possible but to some point and after that you will need to attach expanders, modules which deliver extra capabilities to the hardware, that will make the system overcomplicated.

Solution III — Raspberry Pi

Raspberry Pi is widely know platform which in truth is a mini computer equipped with an ARM CPU. That means you can install on it normal operating system like i.e. Raspbian (Linux distribution based on Debian). Therefore, adding additional features to the system, software features, can be done on demand by installing some packages from the repositories. Let’s focus now on the problem. We will start from behind which means visualization of the data. Web server can be easily installed using Apache. More advanced visualization methods, like animation, can be used. Another big advantage is connected with storing historical data. Using SD card on which Raspbian is running lots of data can be stored for further analysis. Also adding additional algorithms to forecast weather can be done easily using vast number of available software, or even writing it by hand using for example HMM (Hidden Markov Model) to predict tomorrow’s weather.

On the other hand, there is a matter of hardware and connecting sensors. What is great about the Raspberry Pi is that it offers 40 pins, there were less pins in the first RPi version, and among them there are:

  • GPIOs (General Purpose Input Outputs),
  • I2C (Inter-Integrated Circuit),
  • SPI (Serial Peripheral Interface),
  • UART (Universal Asynchronous Receiver-Transmitter).

Using above you can easily connect a majority of devices.

Are there any downsides? Yes there are! The biggest disadvantage is extending the Raspberry Pi with other devices. But wait, didn’t I just said you can connect almost everything to RPi? That’s true, but it is also important how do you connect them to the mini computer. If you connect them directly you have to keep in mind that the voltage levels have to be always in 0-3V3 any deviation, like connecting 5V device, may damage the RPi’s ports.

Also there is one other drawback to this solution. If you would consider communication with a DS18b20 you should keep in mind that the RPi should run in real-time. This is imported during the communication with devices that use asynchronous and time–dependant protocol of communication. Consider this, you communicate with the thermometer and during the communication there is hardware interruption from a connected device to the RPi. Those hardware interruptions have to be handled right away. This means that the RPi switches from user–space, like programs and applications, and goes to kernel–space where interrupts or other low–level routines are handled. If such break occurs during the communication with external device then the protocol will be broken and you will have to retransmit, in the best case scenario.

Like in the first solution this one considers wide range of mini computers. You can substitute Raspberry Pi with Orange Pi, Banana Pi, etc.

Solution IV — mini computer + bare–metal

and

This solution is actually a hybrid one! It merges bare–metal platform with the power and software versatility of a mini computer.

Let’s focus our considerations on an union of the Raspberry Pi and a STM32 solution. This introduces a very important feature of the system! Those two modules are separated. If something happens to the first one then the other one should be fine. I only consider some faulty work of the devices not the malicious and intentional action. There are only two scenarios from which you can recover if a part of the system is damaged:

  • Raspberry Pi is down, you do not store measured data but the sensor part is still fine and well,
  • STM32 solution was damaged or the sensor is broken, the upper layer (RPi) can detect and signalize the current situation.

How the measurement system should be established? It should be divided into two layers, like mentioned above:

  • High layer — Raspberry Pi,
  • Low layer — STM32 solution.

Like in previous solution (III) you set up web server on the Raspberry Pi. You might also set up some data base to collect historical data. There is one more thing required. You should prepare an end node which would be responsible for communication with low layer. Just to focus on some protocol I2C will be used. On low layer you have to handle physical measurements like temperature or humidity. Also communication over I2C has to be implemented for data exchange with upper layer.

This solution has advantages of the two systems used separately and overcomes their disadvantages. If you want to extend the web servers with fancy animation or weather prediction you can do it as swiftly as previously described. What is important you can do this remotely, using an Ethernet cable or wireless connection. If you want add another sensor like barometer for measuring pressure you have to connect it two the lower layer and implement there a driver. This is the same as for bare–metal solution I. But there is small overhead. You need to transmit the data to the upper layer. If you invest a few moments to implement a communication protocol this will be as quick as a blink of an eye.

Well, each solutions has its pros and cons. It would be perfect if the presented one would have only pros but unfortunately there is at least one disadvantage. The cost of the system, you need not only to invest into Raspberry Pi, or any other similar platform, which is not cheap itself, but also into STM32 platform. This solution is the most expensive one but for a more complicated system it will quickly stop being such a barrier.

Summary

For proposed example I have presented a few solutions describing strong and weak sides of each one. The decision about choosing the right architecture for the task is always on the side of the maker but I hope this will allow you to widen the spectrum of available solutions. What is important, that those solutions are not the only ones. You can consider a PLC (Programmable Logic Controller) used in industrial environments or a PC with data acquisition card like Sensoray for fast control and collection of data (I also have written a hard real-time driver for this solution). However, only embedded systems were the object of this post.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.