Tuesday, 10 May 2016

Pi Communication - Part Deux

Team : ESD
Name: Ian Murphy
Section: Pi Communication

Introduction

The last sprint saw the communication being done using Wi-Fi, however there was a major issue with the speed at which this communication occurred. To combat this a new method of getting the pis to talk to each other had to be found. First was by using Bluetooth, again there was issues with this as the Pis couldn't detect that the dongle was even attached. In the end the built-in serial communication port was chosen.


Connection

The connection is established with two ports on the Pi, an Rx pin and a Tx pin. For both pis a wire was connected from the Rx pin to the Tx pin, a common ground is also needed.

Configuring The Pi

To use the serial port as for data comms it is necessary to disable the ability to use the serial port as a terminal. For this enter 'sudo raspi-config' into the terminal, scroll down and select 'advanced options' -> 'serial' -> select 'no' and then reboot. You can now use the GPIO ports on the raspberry pi to communicate.

Setup


The above shows the code used to set up on the pi, it is the same on both pis.

Sending Data

Above shows the code used to send the data from the pi. It goes through a list of the objects in memory that are to be sent, packages the data along with its tag and then sends them over the serial port. A small delay is needed to allow the receiving end to unpack the data and place it into the other pis memory. The delay here is 100ms, which seems to be enough of a delay to allow the pis remain in sync but not so much that the application on the receiving end appeared to be lagging behind.

Receiving Data

Above is the code inside the main loop of the module that receives data. 

In Operation

Without Delay after sending data

The above image shows what happens when the delay isn't used. The window on the left shows the sender of data and the right panel shows the receiver. The image was captured a few seconds after the sender was stopped but the receiver still hadn't caught up with it at that stage. 
With Delay after sending data

The image above was captured as data was being sent with the delay implemented. The window on the right shows a slight delay on the message it is at but this is due to the window on the left being active and the terminal seems to update quicker when it's active than when it isn't. Showing that messages are being sent and received real-time.

Place in the System



Conclusion

The communication between multiple pis had to be as near to real-time as possible, the switch from using sockets over Wi-Fi to the serial port achieved this. The first run of implementing the modules together was where the problem of the receiver being behind the sender module was highlighted, the addition of a delay on sending the data proved successful in solving the problem. The servo and voice operations that were carried out on one pi in the system reacted quickly to the change in what the face detection on the other pi saw as shown in the demo made. 


No comments:

Post a Comment