Beispiel #1
0
class THERM_BUZZER:
    def __init__(self, baudrate):
        self.baudrate = baudrate
        self.setup()
        self.run()
        self.exit()

    def setup(self):
        self.obj_arduino = Arduino()
        self.port = self.obj_arduino.locateport()
        self.obj_arduino.open_serial(1, self.port, self.baudrate)

    def run(self):
        self.therm = 4
        self.buzzer = 3

        for i in range(20):
            val = self.obj_arduino.cmd_analog_in(1, self.therm)
            print val

            if (int(val) > 550):
                self.obj_arduino.cmd_digital_out(1, self.buzzer, 1)

            else:
                self.obj_arduino.cmd_digital_out(1, self.buzzer, 0)
                sleep(2)

    def exit(self):
        self.obj_arduino.close_serial()
Beispiel #2
0
class SERVO_POT:
    def __init__(self, baudrate):
        self.baudrate = baudrate
        self.setup()
        self.run()
        self.exit()

    def setup(self):
        self.obj_arduino = Arduino()
        self.port = self.obj_arduino.locateport()
        self.obj_arduino.open_serial(1, self.port, self.baudrate)

    def run(self):
        self.pin1 = 9
        self.pot = 2
        self.pos = 0
        self.obj_arduino.cmd_servo_attach(1, 1)
        sleep(1)
        self.angle = 18
        for i in range(100):
            val = self.obj_arduino.cmd_analog_in(1, self.pot)
            print val
            val = int(val * 180 / 1023)
            print val
            self.obj_arduino.cmd_servo_move(1, 1, val)
            sleep(0.5)
        self.obj_arduino.cmd_servo_detach(1, 1)

    def exit(self):
        self.obj_arduino.close_serial()
class THERM_BUZZER:
	def __init__(self,baudrate):
		self.baudrate=baudrate
		self.setup()
		self.run()
		self.exit()

	def setup(self):
		self.obj_arduino=Arduino()
		self.port=self.obj_arduino.locateport()
		self.obj_arduino.open_serial(1,self.port,self.baudrate)

	def run(self):
		self.therm=4
		self.buzzer=3
	    
		for i in range(20):
			val=self.obj_arduino.cmd_analog_in(1,self.therm)
			print val

			if (int(val) > 550):
				self.obj_arduino.cmd_digital_out(1,self.buzzer,1)
				
							
			else:
				self.obj_arduino.cmd_digital_out(1,self.buzzer,0)
				sleep(2)

	def exit(self):
		self.obj_arduino.close_serial()
class SERVO_POT:
	def __init__(self,baudrate):
		self.baudrate=baudrate
		self.setup()
		self.run()
		self.exit()

	def setup(self):
		self.obj_arduino=Arduino()
		self.port=self.obj_arduino.locateport()
		self.obj_arduino.open_serial(1,self.port,self.baudrate)

	def run(self):
		self.pin1=9
		self.pot=2
		self.pos=0
		self.obj_arduino.cmd_servo_attach(1,1)
		sleep(1)
		self.angle=18
		for i in range(100):
			val=self.obj_arduino.cmd_analog_in(1,self.pot)
			print val
			val = int(val*180/1023)
			print val
			self.obj_arduino.cmd_servo_move(1,1,val)
			sleep(0.5)
		self.obj_arduino.cmd_servo_detach(1,1)
		
	def exit(self):
		self.obj_arduino.close_serial()
Beispiel #5
0
class LDR:
	def __init__(self,baudrate):
		self.baudrate=baudrate
		self.setup()
		self.run()
		self.exit()

	def setup(self):
		self.obj_arduino=Arduino()
		self.port=self.obj_arduino.locateport()
		self.obj_arduino.open_serial(1,self.port,self.baudrate)

	def run(self):
		self.ldr=5
		self.blue=9
		self.green=10
		self.red=11
		for i in range(100):
			val=self.obj_arduino.cmd_analog_in(1,self.ldr)
			print val
			if int(val) < 300:
				self.obj_arduino.cmd_digital_out(1,self.blue,1)
			else:
				self.obj_arduino.cmd_digital_out(1,self.blue,0)
			sleep(0.5) 	

	def exit(self):
		self.obj_arduino.close_serial()
class LDR:
    def __init__(self,baudrate):
        self.baudrate=baudrate
        self.setup()
        self.run()
        self.exit()

    def setup(self):
        self.obj_arduino=Arduino()
        self.port=self.obj_arduino.locateport()
        self.obj_arduino.open_serial(1,self.port,self.baudrate)

    def run(self):
        self.ldr=5
        self.blue=9
        self.green=10
        self.red=11

        l = 100  # length
        x = range(l)  # x axis
        T = [420 for i in range(l)]  # initial value

        for i in range(20):
            val=self.obj_arduino.cmd_analog_in(1,self.ldr)
            print val
            if int(val) < 300:
                self.obj_arduino.cmd_digital_out(1,self.blue,1)
            else:
                self.obj_arduino.cmd_digital_out(1,self.blue,0)
            sleep(0.5)

            plt.ion()
            #plt.show()

            t = int(val)
            T.pop(0)  # pop first value
            T.append(t)  # push at the end keeping list of same size
            plt.title("Reading LDR Data from Arduino...!")
            plt.grid(True)
            plt.ylabel('LDR Readings')
            plt.legend(loc='upper left')
            plt.axis([0, l, 0.55 * min(T), 2 * max(T)])
            plt.plot(x, T ,linewidth=1)
            plt.draw()
            plt.pause(.0001)
            plt.clf()
        plt.close('all')


    def exit(self):
        self.obj_arduino.close_serial()
Beispiel #7
0
class LDR:
	def __init__(self,baudrate):
		self.baudrate=baudrate
		self.setup()
		self.run()
		self.exit()

	def setup(self):
		self.obj_arduino=Arduino()
		self.port=self.obj_arduino.locateport()
		self.obj_arduino.open_serial(1,self.port,self.baudrate)

	def run(self):
		self.ldr=5
		for i in range(100):
			val=self.obj_arduino.cmd_analog_in(1,self.ldr)
			print val
			sleep(0.5) 	

	def exit(self):
		self.obj_arduino.close_serial()
Beispiel #8
0
class LDR:
	def __init__(self,baudrate):
		self.baudrate=baudrate
		self.setup()
		self.run()
		self.exit()

	def setup(self):
		self.obj_arduino=Arduino()
		self.port=self.obj_arduino.locateport()
		self.obj_arduino.open_serial(1,self.port,self.baudrate)

	def run(self):
		self.ldr=5
		for i in range(100):
			val=self.obj_arduino.cmd_analog_in(1,self.ldr)
			print (val)
			sleep(0.5) 	

	def exit(self):
		self.obj_arduino.close_serial()
class SOLAR_TRACKER:
	def __init__(self,baudrate):
		self.baudrate=baudrate         
		self.setup()
		self.run()
		self.exit()

	def setup(self):
		self.obj_arduino=Arduino()
		self.port=self.obj_arduino.locateport()          #Locates the port 
		self.obj_arduino.open_serial(1,self.port,self.baudrate)

	def run(self):
		self.ldr1=0                      #LDR1 connected at port 0
		self.ldr2=1                      #LDR2 connected at port 1
		s=0
		self.angle=5                   # Step angle
		self.initial=90
		self.obj_arduino.cmd_servo_attach(1,1)     # Attach the servo at pin 9
		sleep(1)
		self.obj_arduino.cmd_servo_move(1,1,self.initial)     #Rotate servo by 90 deg
		sleep(1)
		for i in range(20):
			p=self.obj_arduino.cmd_analog_in(1,self.ldr1)      #Read analog input from LDR1
			q=self.obj_arduino.cmd_analog_in(1,self.ldr2)      # Read analog input from LDR2  
			print p
			print q
			sleep(1)
			if int(p) < int(q):             
				s=s+1
				self.obj_arduino.cmd_servo_move(1,1,90-self.angle*s)   # Clockwise rotation
				sleep(1)
			else:
				s=s-1
				self.obj_arduino.cmd_servo_move(1,1,90-self.angle*s)  # Anti-clockwise rotation
				sleep(1)
		self.obj_arduino.cmd_servo_detach(1,1)		# Detach the motor

	def exit(self):
		self.obj_arduino.close_serial()           # Close the serial port 
Beispiel #10
0
class THERM_BUZZER:
    def __init__(self, baudrate):
        self.baudrate = baudrate
        self.setup()
        self.run()
        self.exit()

    def setup(self):
        self.obj_arduino = Arduino()
        self.port = self.obj_arduino.locateport()
        self.obj_arduino.open_serial(1, self.port, self.baudrate)

    def run(self):
        self.therm = 4

        for i in range(20):
            val = self.obj_arduino.cmd_analog_in(1, self.therm)
            print val
            sleep(0.5)

    def exit(self):
        self.obj_arduino.close_serial()
Beispiel #11
0
class POT:
    def __init__(self, baudrate):
        self.baudrate = baudrate
        self.setup()
        self.run()
        self.exit()

    def setup(self):
        self.obj_arduino = Arduino()
        self.port = self.obj_arduino.locateport()
        self.obj_arduino.open_serial(1, self.port, self.baudrate)

    def run(self):
        self.pot = 2
        self.blue = 9
        self.green = 10
        self.red = 11
        for i in range(20):
            val = self.obj_arduino.cmd_analog_in(1, self.pot)
            print(val)

            if (int(val) >= 0 and int(val) < 320):
                self.obj_arduino.cmd_digital_out(1, self.blue, 1)
                sleep(2)
                self.obj_arduino.cmd_digital_out(1, self.blue, 0)
            elif (int(val) >= 320 and int(val) < 900):
                self.obj_arduino.cmd_digital_out(1, self.green, 1)
                sleep(2)
                self.obj_arduino.cmd_digital_out(1, self.green, 0)
            else:
                self.obj_arduino.cmd_digital_out(1, self.red, 1)
                sleep(2)
                self.obj_arduino.cmd_digital_out(1, self.red, 0)

    def exit(self):
        self.obj_arduino.close_serial()
class POT:
    def __init__(self,baudrate):
        self.baudrate=baudrate
        self.setup()
        self.run()
        self.exit()

    def setup(self):
        self.obj_arduino=Arduino()
        self.port=self.obj_arduino.locateport()
        self.obj_arduino.open_serial(1,self.port,self.baudrate)

    def run(self):
        self.pot=2
        self.blue=9
        self.green=10
        self.red=11


        l = 100  # length
        x = range(l)  # x axis
        T = [420 for i in range(l)]  # initial value


        for i in range(35):
            val=self.obj_arduino.cmd_analog_in(1,self.pot)
            print val

            if (int(val) >= 0 and int(val)< 320):
                self.obj_arduino.cmd_digital_out(1,self.blue,1)
                sleep(.25)
                self.obj_arduino.cmd_digital_out(1,self.blue,0)
            elif (int(val) >= 320 and int(val) < 900):
                self.obj_arduino.cmd_digital_out(1,self.green,1)
                sleep(.25)
                self.obj_arduino.cmd_digital_out(1,self.green,0)
            else:
                self.obj_arduino.cmd_digital_out(1,self.red,1)
                sleep(.25)
                self.obj_arduino.cmd_digital_out(1,self.red,0)


            plt.ion()
            plt.show()

            t = int(val)
            T.pop(0)  # pop first value
            T.append(t)  # push at the end keeping list of same size
            plt.title("Reading Potentiometer from Arduino...!")
            plt.grid(True)
            plt.yticks([0,100,200,300,400,500,600,700,800,900,1000,1100])
            plt.xticks([0,5,10,15,20,25,30,35,40,45,50,55,60,65,70,75,80,85,90,95,100])
            plt.ylabel('Potentiometer Readings')
            plt.legend(loc='upper left')
            plt.axis([0, l, 0.55 * min(T), 1.2 * max(T)])
            plt.plot(x, T, linewidth=1)
            plt.draw()
            plt.pause(.0001)
            plt.clf()
        


    def exit(self):
        self.obj_arduino.close_serial()