#!/usr/bin/env python # -*- coding: utf-8 -*- import serial import sys from time import sleep port = '/dev/ttyAMA0' baud = 9600 serial_connection = serial.Serial(port=port, baudrate=baud) sleep(0.2) while True: try: serial_connection.write('a--A00READ--') sleep(0.2) rawdata = serial_connection.read(12) value = rawdata[7:] value = value.strip('-') print value with open("values.txt", "a") as f: f.write(value +"\n") sleep (3) except KeyboardInterrupt: sys.exit(0)