I have some problems connecting my Raspberry Pi with my Arduino, and making them exchanging messages through a serial connection.
With four other people, we are building a robot to take part in a French competition. It has several actuators (such as servomotors or pumps) and sensors (sonars, bumpers) that we use to complete the different tasks offered by the competition rules. The robot has to be entirely autonomous and able to complete a 90s match.
We are using both cards:
- The Arduino controls all the different actuators and receives the sensors information
- The Raspberry Pi runs the program that dictates the actions the robot will perform during the match
We need to be able to receive informations from the sensors, as well as to be able to send orders to the different actuators which are controlled by the Arduino. To do so, the Arduino and the Raspberry Pi have to exchange messages which contain, on one side, the information, and on the other side, the orders.
We created a serial connection between the Arduino and the Raspberry Pi by a USB wire.
The Raspberry Pi program opens the serial connection (baud rate 9600), and then both cards start exchanging messages. Messages consist in series of 20 unsigned chars. Both cards have "emission" and "reception" methods. While the "reception" method is called every 300 miliseconds, the "emission" method is called every 1500 miliseconds. In order to avoid overflow, we also have a method which "flushes" the connection if more than 60 characters are available on the serial.
1) Arduino -> Pi works perfectly.
2) Pi -> Arduino does not work very well...
We want to make sure the connection can work continuously for 90 seconds at least, but it appears it cannot maintain itself stable for that long. It sometimes work - our test program asks the Arduino to move up and down a servomotor evey X miliseconds, which it sometimes does, but not always. Sometimes, the Arduino crashes and reboots. We thought it could be because the connection was lost and recreated (which causes Arduinos to reboot), or maybe because of an overflow. It does not seem to be a software issue, so I am asking if some of you tried to connect a Raspberry Pi and an Arduino via a serial USB connection and had similar issues?
- I read the "Pi -> Arduino" problem could come from a power difference. The Pi should be provided with 3 V while the Arduino received 5 V.
- Which libraries should be used to create and use the serial connection? We are using C++, and <wiringSerial> on the Pi, and the default serial library on the Arduino.
- Does the Raspberry Pi support 115200 baud rate serial connection?
Thank you for any information you could give me, any help would be greatly appreciated.