Setup Raspberry Pi to Collect and Log Data from Arduino

Capture Data

Raspberry Pi runs on Linux and Python 2 and 3 are installed by default. You only need to install a Python library called pyserial to collect data print out from the serial line.

Install serial library:

  • for Linux machine:
  • sudo apt-get install python3-serial
  • on Windows, presumed you have python3 installed
  • pip.exe install pyserial

    Download the code from the GitHub and save the script with a name, mine is recordSerial.py

    Transfer the Python script, using VNCViewer tool. There is a banner on the near the top of the VNCViewer, look for two arrows button. To transfer data from the RPi to Windows, use the File Transfer in VNC symbol on the top-right (near the Wifi symbol) on the RPi's desktop.

    Powershell
    On PowerShell/Windows 10

    Alternatively, using sftp to transfer the data, first open the folder contain the Python script, and put the script to Raspberry Pi. Open command line (on Linux) or other GUI SFTP such with PuTTY, FileZilla:

    $ sftp pi@ip_of_your_RPi:/home/pi/Desktop 
    $ put recordSerial.py

    Make the script executable on Rapsberry Pi (or double click on Windows if you plan to use your Windows to collect data directly)

    sudo chown u+x recordSerial.py

    Plug the USB cable to your Raspberry Pi and other end to Arduino Nano, check port:

  • On Linux, type this to the terminal: ls /dev/ttyUSB*
  • On Windows: go to Device Manager, check COM #
  • Transfer the script
    On PowerShell/Windows 10

    If the script is modified on Windows, you may need to run the Python script to dos2unix first to remove a weird line ending character by Windows. Install it by:

    sudo apt-get install dos2unix

    and remove the ending character of each line by:

    dos2unix recordSerial.py

    Modified the actual port in the script by a text editor:

    sudo nano recordSerial.py

    and run by:

    python3 recordSerial.py
    ./recordSerial.py yourfilename.txt

    The Python script will save the data from the RAM to the disk/SD card for every 10 lines which can be adjusted.

    To stop recording, press Ctrl + C,

    The script can be run on Windows (double click), the name of log data is the default which includes a timestamp.

    If use PowerShell, you could enter your customized filename like this:

    python.exe recordSerial.py awesome.txt 

    Hopefully, now you can see some readouts

    Readout on Windows
    On PowerShell/Windows 10
    Readout by Putty
    Readouts from PuTTY is not aligned

    Additional:

    To run the script on the background add & to end of command line.

    To put the script run on the background and not report the terminal, add nohup such as:

    nohup ./recordSerial.py yourfilename.txt &

    To kill (stop) process, first check the pid then kill it.

    ls aux| grep python;
    sudo kill -9 pid