#!/usr/bin/python3
# ===================================================================
# read/display potentiometer values
# ===================================================================
# From: www.youtube.com/watch?v=iKGYbMD3NT8
#       Arduino and Python Serial Communication with PySerial Part 1
# ===================================================================
# An arduino you can use baud rates 300, 600, 1200, 2400, 4800, 9600,
# 14400, 19200, 28800, 38400, 57600, or 115200. However 9600 is the
# standard baud rate usually used.
# ===================================================================
# ---- Establish a specific port and the connect
# ---- ser = serial.Serial('COM7',19200)
# ---- ser = serial.Serial('COM7', 115200, timeout=.1)
#ser = serial.Serial()          # create port
#ser.port     = 'COM7'
#ser.baudrate = 9600
#ser.timeout  = 0.1
#ser.open()                     # open connection
# ===================================================================

from time import sleep

import serial

import sys


# --------------------------------------------------------------------
# functions
# --------------------------------------------------------------------


# -------------------------------------------------------------------
# main
# -------------------------------------------------------------------

# ---- automatically connect to port

ser = serial.Serial('COM7',9600,timeout=1)

print('Start Test')

while True:

    arduinoData= ser.readline().decode('ascii').strip()

    print('data: {}'.format(arduinoData))
    ##print('type: {}'.format(type(arduinoData)))
    ##print('Len : {}'.format(len(arduinoData)))

print('End Test')

ser.close()