I am curious to know is there a generic library for both the Arduino and Raspberry Pi (or alternative mini-computer that has GPIO pins) where the code can be EXACTLY written in the same form and it can be used for both Arduino or Raspberry Pi without having to modify the code?
Yes, kind of, this is what
embedded-hal is for. It allows writing generic drivers that talk via well-known interfaces like I²C and SPI.
Is this what both the Arduino and Raspberry Pi uses?
They both have I²C and SPI, but those were just examples of common interfaces.
embedded-hal also has abstractions for GPIO pins and UARTs, for example.
Is there any code I have to change if I want to port my code over from Arduino to Raspberry Pi?
embedded-hal in active development, like is it quickly being developed or is it slow in progression?
embedded-hal does not directly allow you to write binaries that build and run on both targets. What it does allow is writing generic drivers for external devices, as well as business logic, that works with any implementation of the
If you need to run specific applications and aren't just writing a library, you would probably end up writing 2 binaries that hook up the platform-specific parts to a shared library.
embedded-hal is somewhat slow but still active. It is an official project of the embedded working group: https://github.com/rust-embedded/embedded-hal
So what you mean by this is that I can write up the exact same code but during compilation, it would generate different binaries?
Is it close to being stable?
Yes, it has to. An Arduino doesn't run ELF files, but a Raspberry Pi with Linux does. A Pi without Linux needs yet another format. And an Arduino with an AVR chip doesn't even run the same instruction set as a Pi.
I don't think at this point that you can write literally the same Rust code for both, a device-specific entry point is likely still needed, but depending on what you want to do (which would be good to know to give you a more precise answer) you can share almost everything else.
embedded-hal sees very few breaking changes, so I'd say it is very stable already. I'd certainly call it production ready at this point.
Oh ok so for example lets say that I want an LED light bulb to turn on for 4 seconds and then turn off for a 4 seconds and the cycle repeats. Would my Rust code (not the machine code) be the exactly the same for both these two devices?
Is this cause it is very slow in development?
Hello...yes it is available.Firmata is include in the IDE File | Examples | Firmata. The host computer can read/write analog/digital pins of the Arduino board. There is probably generic c/c++ code for the host side of the protocol but you will have to some digging with google.
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.