7

I am not that familiar with the Arduino boards. For christmas, I got a sensor kit from my aunt. The source code is all for the arduino and I don't have an arduino. Is there a way I could re-compile the code into something the RasPi could use?

7

There is an Open Source project underway at: https://github.com/me-no-dev/RasPiArduino

This basically allows one to use the Arduino IDE in conjunction with a cross compiler that generates executable code that will compile arbitrary Arduino sketches and allow them to fully run on the Pi. This project is still in a very early phase but so far I have been able to take arbitrarily sophisticated Sketches and have them run on the Pi.

See also:

3

It's unlikely that any Arduino code will work on the Raspberry Pi. While Arduinos are programmed in C, their source code contains a lot of functions that are specific to their boards. The RPi won't have these libraries. In addition to some software headaches, the hardware of the RPi is very different than that of any of the Arduinos.

You could learn a lot about how the sensors work from the example code, but you'll have to manually convert it to something more usable with the RPi.

  • 1
    It may be worth looking at the book make sensors amazon.com/Make-Sensors-Hands--Monitoring-Raspberry/dp/… it covers both arduino and the Pi with back to back examples for several types of sensors. I would also suggest getting a arduino you can learn a lot from them - because they have been around longer than the Pi there is lots of code examples for almost anything you can think of. – Steve Robillard Dec 30 '15 at 23:16
  • 1
    One thing to be careful of with devices connected to the Pi but designed for the arduino is that most arduinos are designed for 5 volts and the Pi is NOT. this may require a few extra resistors or a level shifter. – Steve Robillard Dec 30 '15 at 23:16
3

No, Arduinos use a special code environment built up around the properties of the underlying hardware.

They tend to have an initialisation section followed by an infinite loop.

That said most sensors can be used on the Pi. You should Google the sensor followed by Raspberry Pi and Python and you will probably find examples.

Things to watch out for are that the Pi has 3V3 GPIO whereas Arduinos have 5V. Sensors which output 5V should not have their data output line directly connected to a Pi GPIO.

Also the Pi does not have any analog inputs so you will need to add an ADC to use analog sensors.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.