Another language for arduino library

hello,

can i write some parts of library in another language? In python for example. It will be only some parts (reading, writing to files, web actions). For the main part will be used c++. Is there some way how to do it?

Thanks,
Tom

How would you expect the C++ compiler to deal with some parts of the program being in another language ?

It will be only some parts (reading, writing to files, web actions). For the main part will be used c++.

This 'new' question seems related to your earlier question on using 'C++ read from file' ?

The question you have not responded to in the earlier thread, is where is the file ?

Path name is argument when function is called.

TomasRoj:
Path name is argument when function is called.

Ok, so dont tell the forum where the file is.

C and C++ works on the Arduino like on a big computer. You can link libraries compiled in any language so long as they follow the convention.

The key word is "compiled". You need to compile Python or whatever into an Arduino binary.

Most people don't bother to do this. The Arduino IDE is just so much simpler if everything is C or C++. There will not be many tutorials online.

TomasRoj:
can i write some parts of library in another language? In python for example. It will be only some parts (reading, writing to files, web actions). For the main part will be used c++. Is there some way how to do it?

No and yes.

The basic approach to libraries adopted by Arduino IDE is actually kinda “fake”. What is usually called “libraries” in Arduino IDE world are not libraries at all. Arduino IDE pseudo-libraries are just collection of source files, which are implicitly compiled and then linked together with your own modules. The source files from the “library” are fed to the same compiler that handles your modules. And that compiler is normally set up to handle only C and C++. So, when working with creating pseudo-libraries, you are basically restricted to C and C++.(1

In real world we use the term “library” to refer to a precompiled archive of object files. The key word here is precompiled. The code stored in these archives is supposed to adhere to some implementation-specific conventions, like ABI (Application Binary Interface, e.g. function calling conventions), object file format and archive format. If these requirements are met, it does not matter what language and what compiler was used to generate these libraries. You can use any language and any compiler. Just keep in mind that to use these libraries in C or C++ code you will need header files written in C or C++.

Arduino IDE allegedly supports these real, precompiled libraries starting from Arduino IDE 1.8.6. I haven’t tried to use this feature myself though.


1) GCC executable by itself is not a compiler proper, but rather “compiler dispatcher”. It can handle many different languages, making the dispatching decision based on the source file extension (or a command-line option), provided that support for the extra languages is installed along with GCC. I wonder if it’s possible to simply extend avr-gcc package supplied with Arduino IDE to make it support GNU Fortran, for example, right there in the IDE…

In addition to C++ and C, you can use assembly language code in your libraries. Use the .S file extension.

If you're really into Python, you could consider ditching Arduino altogether and using MicroPython or CircuitPython. In that case you can use Python as well as add modules written in C when you need performance from your code.

You will need to use one of the more capable chips though, such as the SAMD (ie M0) or MKR series, if you want to use Python. It doesn't run well on ATMega328p (Arduino Uno, et. al.)

Thanks everyone for answering this question. Perts answer works best for me I will try it.

Have a nice day,
Tom