Page 1 of 1

Raspberry pi and Arduino communication

Posted: Fri Nov 18, 2016 5:47 am
by kaskas
Hello,

(I am new to forum and i hope to be in the right section)

I wanna make a two wheeled self balancing robot with object tracking following using arduino for the balancing part and raspberry pi for the object tracking.

I want from the arduino to maintain balance when the robot lean (using the motors to move forward or backward to stay in 90 degrees) and at the same time the raspbery pi to move the robot back,forth,left,or right wherever the object is. (every microcontroller will have its own code)

Can I achieve that using the arduino as slave of the raspberry pi with serial or i2c communication? And if yes will the motors be controlled by arduino and raspberry pi simultaneously so it can be balanced and move wherever the object is at the same time?

Please tell me if that way is right. If anyone has an other way to suggest would be helpfull.(sorry for bad english) Thank u!!!

Re: Raspberry pi and Arduino communication

Posted: Sat Nov 19, 2016 4:54 pm
by michaela
I haven't done this yet myself, but I found a guide that is very helpful explaining how to use Raspberry Pi & Arduino via I2C where the Arduino listens for instructions from the Pi:

https://oscarliang.com/raspberry-pi-ard ... ected-i2c/

It sounds like it would work to:
  • Have the Arduino contain all logic for keeping balanced
  • Have the Arduino accept simple commands to: move_forward(distance), rotate_left(duration), rotate_right(duration)
  • Have the Arduino store the I2C commands in a queue. The Arduino focuses on staying balanced as a top priority, and dequeues one command at a time that it implements while keeping balanced
  • Have the Raspberry Pi handle localization, navigation, & planning, etc.
Good luck!

Re: Raspberry pi and Arduino communication

Posted: Sun Nov 20, 2016 8:56 am
by kaskas
thx michaela

Any idea about the code for the RPi to send the right commands to the Arduino?

Re: Raspberry pi and Arduino communication

Posted: Sun Nov 20, 2016 9:01 am
by kaskas
Also the code in the Arduino for the balance will be in C and in the RPi for the image processing probably in Python.

Re: Raspberry pi and Arduino communication

Posted: Sun Nov 20, 2016 12:36 pm
by michaela
As I said earlier, I haven't done anything with I2C myself yet, but I found the artist above that looked helpful with example code on both the Arduino and the Pi. The above article also references two earlier posts by the same person introducing I2C specifically. You can probably see several examples of what the code might look like. Good luck.