Arduino UNO: Serial Outputs to Raspberry Pi

Our Submersible is not only going to have "eyes" (which would be our camera setup); it is going to have an array of sensors to test its physical surroundings. We want sensors to test such things as water temperature, salinity, and depth. We know that Raspberry Pi's are not designed for this type of work and therefore purchased an Arduino UNO. We chose the UNO for a couple of reasons.

  1. There is extensive documentation on the Arduino webpage as well as all over the internet.
  2. Arduino is great micro-controller that is known for its numerous sensor capabilities. 
  3. The UNO is one of the more basic, but still powerful boards
  4. We have experience using the UNO from smaller projects. 
Arduino UNO with USB

Knowing that we wanted to use the UNO for a data collection device, we also know that we need to find a way of transferring this data off of the submersible and to the user. Naturally we decided to channel this data through the Raspberry Pi. To do this we can use a simple serial port command on the Arduino which can then be received by the Pi through a USB connection. To do this follow the steps below:

    1. Download Pyserial-2.6 and unzip it on your laptop. Then forward it using this ssh command (make sure you cd into the correct file-path for "pyserial-2.6" on your laptop; i.e. Desktop) :

Similar to sshing into the Raspberry Pi
    2. Next cd into the new folder on your Raspberry Pi and compile pyserial-2.6.

Navigate to pyserial-2.6 

    3. Open up the Arduino Software and plug in the Arduino. Choose the correct board under
        Tools ----> Board and the correct serial port by going to Tools ----> Serial Port.

    4. Next use code similar to the following and upload it to the Arduino.
Arduino sketch
      5. Now attach the Arduino to your Raspberry Pi using the same USB cable used to attached it to one's computer. Try to locate which device name is given the to Arduino. Look for the device under /dev/tty. Do this by typing in ls /dev/tty*:

no /dev/ttyACM0

and then unplug the Arduino and again type in ls /dev/tty*. Device which device has disappeared. Whichever device disappeared is the Arduino UNO. Our Arduino was located under the name: /dev/ttyAMC0.

/dev/ttyACM0 appears

    6. Make sure that the Arduino is plugged in to the RPi. Now the Raspberry Pi has to "read" the serial data streaming from the Arduino. To do this use a simple Python command. Open up Idle and type in the following commands, making sure that both the baud rate and file path for the Arduino are correct.


Serial output

Done! Now one can write your own code to transfer readings such as temperature using the serial output on the Arduino! One can customize the Arduino code to output salinity, temperature, and depth readings easily!

No comments:

Post a Comment