#---------------------------------------- # arduino_servo.py # Reads a file: 'data.txt' that is writable from # '0n.php' or 'off.php' scripts in /var/www/html/piWeb # called from webpage /var/www/html/index.html # # gpio LED setup: Using GPIO block pin 11 -which is # called GPIO 17: an LED is wired through a 330 ohm # resistor to Gnd pin. # # An example of send serial data to the USB port # (the attached 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, timeout=1) ser.reset_input_buffer() 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') #-- send one byte else: print("Stopped -False-") GPIO.output(11, False) #-- LED off ser.write(b'1') # send different byte read_data.close() time.sleep(1)