Tags

, , , ,

  1. Arduino sample servo sketch – upload from laptop to Arduino Uno
    • Connect servo power to Arduino 5V; Gnd-Gnd; signal to pin ~9
    • sweep from 180 to 0 to -180
    • Works well

    Servo connected to Arduino Uno and running using USB connected to laptop

    Servo connected to Arduino Uno and running using USB connected to laptop

  2. Servo connected directly to Raspberry Pi GPIO – using PiGPIO
    • Connect 5V from R-Pi to servo power; Gnd-Gnd; Signal to R-Pi GPIO 4 (port 7)
    • Start PiGPIO daemon by typing sudo pigpiod in the terminal. Run the program python servotest19feb.py
    • Works fine but somehow disrupt the input from keyboard and mouse after 3rd run – guess it would be better if I use external power supply.
    Servo connected to R-Pi

    Servo connected to R-Pi

    Codes used as below:

    #!/usr/bin/env python
    
    import time
    
    import pigpio
    
    servos = 4 #GPIO number
    
    pigpio.start()
    #pulsewidth can only set between 500-2500
    try:
    	while True:
    
    		pigpio.set_servo_pulsewidth(servos, 500) #0 degree
    		print("Servo {} {} micro pulses".format(servos, 1000))
    		time.sleep(1)
    		pigpio.set_servo_pulsewidth(servos, 1500) #90 degree
    		print("Servo {} {} micro pulses".format(servos, 1500))
    		time.sleep(1)
    		pigpio.set_servo_pulsewidth(servos, 2500) #180 degree
    		print("Servo {} {} micro pulses".format(servos, 2000))
    		time.sleep(1)
    		pigpio.set_servo_pulsewidth(servos, 1500)
    		print("Servo {} {} micro pulses".format(servos, 1500))
    		time.sleep(1)
    
       # switch all servos off
    except KeyboardInterrupt:
    	pigpio.set_servo_pulsewidth(servos, 0);
    
    pigpio.stop()
  3. Multi Servos connection
      • Another servo’s power is connected in parallel with the previous servo’s 5V; gnd-gnd; Signal to GPIO 7 (pin 26)

    Code as follow:

    #!/usr/bin/env python
    
    import time
    
    import pigpio
    
    servos = [4,7] #GPIO number
    
    pigpio.start()
    #pulsewidth can only set between 500-2500
    try:
    	while True:
    
    		pigpio.set_servo_pulsewidth(servos[0], 500) #servo 1 to 0 degree
    		print("Servo {} {} micro pulses".format(servos, 500))
    		time.sleep(1)
    		pigpio.set_servo_pulsewidth(servos[1], 1500) #servo 2 to 90 degree
    		print("Servo {} {} micro pulses".format(servos, 1500))
    		time.sleep(1)
    		pigpio.set_servo_pulsewidth(servos[0], 1500)
    		print("Servo {} {} micro pulses".format(servos, 1500))
    		time.sleep(1)
    		pigpio.set_servo_pulsewidth(servos[1], 500)
    		print("Servo {} {} micro pulses".format(servos, 500))
    		time.sleep(1)
    
       # switch all servos off
    except KeyboardInterrupt:
    	for s in servos:
    
    		pigpio.set_servo_pulsewidth(s, 0);
    
    pigpio.stop()

    Luckily it works well! πŸ˜€ Here’s the video!

  4. Arduino to Raspberry Pi via USB

Other Problems or Things to note:

  • 4xAA Energizer batteries gave me 6.44V which exceeds the power supply needed for micro servos (4.8V to 6V). I’m not sure what will happen if I connect them to the supply. 😦 Not sure if I can use DC power supply :s
  • Ethernet has some problem probably due to the current drawn by the servo motors?? Not too sure.
raspberry pi gpio

Raspberry Pi GPIO guide

Advertisements