#--------------------------------------- # GPIO_serial_servo.py # # Reads a file 'data.txt' that is writable from # 'on.php' or 'off.php' scripts in /var/www/ # -called from webpage /var/www/index.html # # gpio setup: Using GPIO block pin 11 which is # called GPIO 17. An LED is wired through a # 330 ohm resistor to the Ground pin. # # Also: example of sending data to the # serial port (-like to the Arduino) #--------------------------------------- import serial import time import RPi.GPIO as GPIO GPIO.setmode(GPIO.BOARD) GPIO.setup(11, GPIO.OUT) ser = serial.Serial("/dev/ttyACM0",9600) ser.flushInput() while True: read_data = open('/var/www/html/piWeb/data.txt','r') str = read_data.read() rtest = str[7:10] print(rtest) if rtest == 'on.': print("It's true!") GPIO.output(11, True) # LED: on ser.write(b'0') # -one byte char '0' is sent else: print("Stopped at: %s" % time.ctime()) GPIO.output(11, False) ser.write(b'1') # -one byte char '1' is sent read_data.close() time.sleep(1)