15. Interface and Application Programming¶
For a graphical user interface to interact with an embarked device, we need :¶
- to have a device and protocol of communication between the computer hosting the interface of the application and the board
- a program providing the interface
That means that we have at least 2 choices to do.
How do we send messages to the board ?¶
We first need to choose the medium of communication
- Wired connection : can require an an intermediate board as computers rarely offer other ports than USB or RJ45. Some computers (eg: Raspberry Pi) offer pins natively for wired communications. Possibilities: USB, Serial, I2C, …
- Wireless : Usually available on a Graphical User Interface computer. Wifi Bluetooth, NFC, … Some of these might require an intermediate interface to send the signals.
Programming languages and GUI libraries¶
Depending on the medium and the device chosen most programming languages offer an interface to all options.
The next question depends on the objective of the interface and the performances expected and the requirements for portability of the interface.
Regarding the user, we would have 2 criteria :
For the developper, one more criteria would be very important (on top of hundreds of other):
- Availability of libraries and associated with that, the existence of an active community
The latter is true for any developper but for beginning developpers, the readability and simplicity is important too.
Runs everywhere on any boards large enough (256kB is enough), even on microcontrollers (with CircuitPython or Micropython). Python is a language built to be easy to read (in enforces indentation) and easy to learn. Therefore is makes it a great tool to start programming.
It is also highly portable and runs on all OS. Moreover, a lot of GUI applications have been written in Python but Python has also taken over the scientific space and the data science space making it a very versatile choice for data intensive applications.
The major criticism towards python is the fact that it is not compiled but interpreted and thus is a lot slower than other languages. This is true for simple applications however in my experience, early tests do not require high performances.
For advanced applications, requiring high performances, different libraries have been written to go around the performance issues. Especially Numpy that handles most large arrays and math and more recently Numba, that precompiles the python code and provides advice to make it run faster making properly written code approach the speed of C/C++ or Fortran.
Now the key difference with Numba which makes me want to test it deeper, is the fact that you only need decorators to improve your functions performances, which means, you code basically the same way as before but some program comes after you and improves the speed and distribution of the tasks between the cores of the microprocessors.
Python is a good choice for desktop applications (a lot of opensource apps are now fully python) and can run webservers (Django, Pyramid, Flask) but only in backend. Python also runs on microcontrollers and is great at data science stuff (scikit, Jupyter, fastai, …)
Hello world example :
1 2 3 4 5
Jupyter is not a programming language but a sort of IDE (integrated development environment) but it’s much more than that.
Jupyter provides an interface that makes block of code runnable independently, provides an inline graphical interface and widgets that makes it possible to create your whole app within the code.
Jupyter provides Julia (another programming language), python or R (hence the name Ju-Pyth-R) run in a notebook a notebook is similar to a website or rather an interactive book. It runs code but also allows you to write formatted text with Markdown, without any additional difficulties.
Moreover, Jupyter makes it possible to access the documentation and code of the function you are using very easily as similarly or even more easily as standard IDE.
Runs on any browser which are available for any Operating Systems. Especially indicated for communications running through internet (It is also available in browser emulators such as ElectronJS.
Coupled with HTML and CSS, it makes it possible to create beautiful graphics.
However it is an interpreted language and therefore does not offer the best performances.
Because of that it’s great for data visualisation or web interfaces but can be used in a lot of use cases.
C is a low level programming language giving the user a lot of freedom but also requiring less abstraction. C++ provides oriented object programming making data manipulation easier while still providing the low level control of C enabling better performances.
It is perfect for small applications running on microcontrollers because it requires very limited resources or for computation intensive applications but is quite hard to learn.
Hello world example :
1 2 3 4 5 6 7
Java was invented to make applications portable as they were not compatible across different operating systems before. However since that time the landscape has changed and most languages are cross platform excepted specific languages created for Windows such as C# or Swift for iOS.
Because of that, what Java had to offer is now much less interesting. It is however a key language in mobile apps programming on Android.
If you are building an mobile app running on Android, it’s a good deal but you could look for other languages that are cross platforms (running on iOS or the web) such as ReactNative.
A lot of languages have emerged to be more portable or to provide better performances for specific problems.