FabAcademy 2017
TUYIHIMBAZE Serge

FabAcademy2017 - Projects





Interface and application programming
May 17, 2017 - Week#16


For Interface and application programming, I made a simple interface that I can use to move my motors in both directions. Left, Right, Down and Up. and it be able to know when it is day time or night time.

I sketched a draft interface




My Motors's interface is programmed using different languages, I used Php to receive signals from pressed buttons, python to send data to Arduino and programmed arduino to control motors, and I also used HTML to create interface which is accessed via web.




The code and files I used are attached here at the bottom of the page. I just listed here some codes I wrote while making interface.



Below are the codes I used


                 

/*I used Php to receive signal of pressed button.*/ function writeData($data){ $fh=fopen("file.txt",'w'); fwrite($fh,$data); fclose($fh); } if(isset($_POST['top'])){ writeData(1); } else if(isset($_POST['right'])){ //open file for output writeData(180); } else if(isset($_POST['left'])){ writeData(180); } else if(isset($_POST['bottom'])){ writeData(1); }

                 

/*I used Python to send data to arduino board.*/ import serial import time print("trying......") arduino=serial.Serial("COM6",9600) arduino.flush() sleepTime=0.1 while True: fh=open("file.txt","r") data=fh.read() fh.close() arduino.write(data.encode('ascii')) print("Written data are:{}",data) time.sleep(1)

                 

/*Here are arduino codes to control motor.*/ #include Servo myservo; // create servo object to control a servo int val; void setup() { myservo.attach(9); // attaches the servo on pin 9 to the servo object Serial.begin(9600); //begins serial communication } void loop() { } void serialEvent(){ val=Serial.parseInt(); if(val!=0) { myservo.write(val); Serial.println(val); } }

Finally my application and interface I programmed is ready to control motor. here is a video that shows how it works.