Adafruit's Raspberry Pi Lesson 8. Using a Servo Motor

Similar documents
Adafruit 16 Channel Servo Driver with Raspberry Pi

Adafruit 16-Channel PWM/Servo HAT for Raspberry Pi

Adafruit 16-Channel PWM/Servo HAT & Bonnet for Raspberry Pi

Fading a RGB LED on BeagleBone Black

Arduino Lesson 1. Blink. Created by Simon Monk

Adafruit 16-Channel Servo Driver with Arduino

Adafruit 16-Channel Servo Driver with Arduino

LEVEL A: SCOPE AND SEQUENCE

J. La Favre Using Arduino with Raspberry Pi February 7, 2018

CodeBug I2C Tether Documentation

Motor Driver HAT User Manual

J. La Favre Controlling Servos with Raspberry Pi November 27, 2017

가치창조기술. Motors need a lot of energy, especially cheap motors since they're less efficient.

Adafruit 16-channel PWM/Servo Shield

Adafruit 16-Channel Servo Driver with Arduino

CamJam EduKit Robotics Worksheet Six Distance Sensor camjam.me/edukit

Experiment #3: Micro-controlled Movement

So-Lo. Team 12. Department of Electrical and Computer Engineer

Programming 2 Servos. Learn to connect and write code to control two servos.

Adafruit 16-channel PWM/Servo Shield

Mechatronics Engineering and Automation Faculty of Engineering, Ain Shams University MCT-151, Spring 2015 Lab-4: Electric Actuators

Pi Servo Hat Hookup Guide

Chroma Servo Board v3 for Raspberry Pi. (Firmware 0.1 and 0.2)

EITN90 Radar and Remote Sensing Lab 2

Adafruit Ultimate GPS Breakout On the Raspberry Pi. NERP: Not Exclusively Raspberry Pi

For this exercise, you will need a partner, an Arduino kit (in the plastic tub), and a laptop with the Arduino programming environment.

Chroma. Bluetooth Servo Board

In this activity, you will program the BASIC Stamp to control the rotation of each of the Parallax pre-modified servos on the Boe-Bot.

Adafruit 8-Channel PWM or Servo FeatherWing

Gravity: 12-Bit I2C DAC Module SKU: DFR0552

Programming a Servo. Servo. Red Wire. Black Wire. White Wire

Ping Pong Trainer. Cal Poly Computer Engineering Senior Project. By Aaron Atamian. Advised by Andrew Danowitz

Adafruit Pi Box Plus. Created by Phillip Burgess. Last updated on :38:17 AM UTC

Directions for Wiring and Using The GEARS II (2) Channel Combination Controllers

UCL Micro:bit Robotics Documentation

INA169 Breakout Board Hookup Guide

Programming Arduino Getting Started With Sketches [Kindle Edition] By Simon Monk READ ONLINE

the Multifunctional DCC decoder for servo s and accessory s with Arduino for everybody (with a DCC central station)

Project Kit Project Guide

Feed-back loop. open-loop. closed-loop

Adafruit SGP30 TVOC/eCO2 Gas Sensor

Total Hours Registration through Website or for further details please visit (Refer Upcoming Events Section)

Internet of Things Student STEM Project Jackson High School. Lesson 3: Arduino Solar Tracker

Preface. The kit is suitable for the Raspberry Pi model B+, 2 model B and 3 model B.

Demon Pumpkin APPROXIMATE TIME (EXCLUDING PREPARATION WORK): 1 HOUR PREREQUISITES: PART LIST:

Module: Arduino as Signal Generator

ENGR 1110: Introduction to Engineering Lab 7 Pulse Width Modulation (PWM)

Castle Creations, INC.

Exercise 5: PWM and Control Theory

Automobile Prototype Servo Control

Marine Debris Cleaner Phase 1 Navigation

Make: Sensors. Tero Karvinen, Kimmo Karvinen, and Ville Valtokari. (Hi MAKER MEDIA SEBASTOPOL. CA

ZX Distance and Gesture Sensor Hookup Guide

Cardboard Circuit Playground Express Inchworm Robot

Moto1. 28BYJ-48 Stepper Motor. Ausgabe Copyright by Joy-IT 1

Pi-Cars Factory Tool Kit

Preface. About SunFounder. About the PiCar-S. Free Support

Adafruit DC and Stepper Motor HAT for Raspberry Pi

Lab Exercise 9: Stepper and Servo Motors

Stereo 3.7W Class D Audio Amplifier

Web Site: Forums: forums.parallax.com Sales: Technical:

Pulse-Width-Modulation Motor Speed Control with a PIC (modified from lab text by Alciatore)

ECE 511: FINAL PROJECT REPORT GROUP 7 MSP430 TANK

Eclipse Ballooning Project

Introduction: Components used:

100UF CAPACITOR POTENTIOMETER SERVO MOTOR MOTOR ARM. MALE HEADER PIN (3 pins) INGREDIENTS

Rochester Institute of Technology Real Time and Embedded Systems: Project 2a

433MHz LRS Adjustable TX/RX Set 100mW-2000mW

ESE 350 HEXAWall v 2.0 Michelle Adjangba Omari Maxwell

- Introduction - Minecraft Pi Edition. - Introduction - What you will need. - Introduction - Running Minecraft

the Board of Education

High Speed Continuous Rotation Servo (# )

Digital Guitar Effects Box

Objective of the lesson

HB-25 Motor Controller (#29144)

meped v2 Assembly Manual

EE 314 Spring 2003 Microprocessor Systems

NORTHERN ILLINOIS UNIVERSITY. A Thesis Submitted to the. University Honors Program. In Partial Fulfillment of the

Ocean Controls KT-5198 Dual Bidirectional DC Motor Speed Controller

FABO ACADEMY X ELECTRONIC DESIGN

Pololu Dual G2 High-Power Motor Driver for Raspberry Pi

University of Texas at El Paso Electrical and Computer Engineering Department

The Torxis Linear Servo meets the following environmental conditions:

A servo is an electric motor that takes in a pulse width modulated signal that controls direction and speed. A servo has three leads:

Introduction to programming with Fable

Hobby Servo Tutorial. Introduction. Sparkfun:

CMSC838. Tangible Interactive Assistant Professor Computer Science. Week 11 Lecture 20 April 9, 2015 Motors

Brushed DC Motor Control. Module with CAN (MDL-BDC24)

EE 308 Spring S12 SUBSYSTEMS: PULSE WIDTH MODULATION, A/D CONVERTER, AND SYNCHRONOUS SERIAN INTERFACE

Linear vs. PWM/ Digital Drives

Electronic Components

Name & SID 1 : Name & SID 2:

Content Components... 1 i. Acrylic Plates... 1 ii. Mechanical Fasteners... 3 iii. Electrical Components... 4 Introduction... 5 Getting Started... 6 Ar

LED + Servo 2 devices, 1 Arduino

Hardware Platforms and Sensors

Built-in soft-start feature. Up-Slope and Down-Slope. Power-Up safe start feature. Motor will only start if pulse of 1.5ms is detected.

RC Servo Interface. Figure Bipolar amplifier connected to a large DC motor

Pibrella Fairground Ride. This lesson follows on from the Pelican Crossing lesson

Circuit Playground Quick Draw

Servos A Brief Guide

Transcription:

Adafruit's Raspberry Pi Lesson 8. Using a Servo Motor Created by Simon Monk Last updated on 2016-11-03 06:17:53 AM UTC

Guide Contents Guide Contents Overview Parts Part Qty Servo Motors Hardware Software Python Example! Test & Configure 2 3 4 4 4 5 6 8 9 12 Page 2 of 12

Overview This lesson describes how to control a single servo motor using Python. Servo motors are controlled by pulses of varying lengths. This requires fairly accurate timing. The Raspberry Pi has one pin that generates pulses in hardware, without having to rely on the operating system. Page 3 of 12

Parts To build this project, you will need the following parts. Part Qty Raspberry Pi 1 Cobbler Breakout Board and IDC cable 1 Set of male to male jumper leads 1 Half-size breadboard 1 Servo 1 4 x AA or AAA battery holder and batteries. 1 Page 4 of 12

Servo Motors The position of the servo motor is set by the length of a pulse. The servo expects to receive a pulse roughly every 20 milliseconds. If that pulse is high for 1 millisecond, then the servo angle will be zero, if it is 1.5 milliseconds, then it will be at its centre position and if it is 2 milliseconds it will be at 180 degrees. The end points of the servo can vary and many servos only turn through about 170 degrees. You can also buy 'continuous' servos that can rotate through the full 360 degrees. Page 5 of 12

Hardware There is only one pin on the Pi that is capable of producing pulses in this way (GPIO pin 18). This will be connected to the control pin of the servo. The power to the servo is provided by an external battery as powering the servo from the Pi itself is likely to cause it to crash as the Servo draws too much current as it starts to move. Servos require 4.8-6V DC power to the motor, but the signal level (pulse output) can be 3.3V, which is how its OK to just connect the signal line directly to the GPIO output of the Pi. The Pi Cobbler is used to link the Raspberry Pi to the breadboard. If you have not used the Cobbler before take a look at Lesson 4 (http://adafru.it/ath) in this series. Servo motors generally come with three pin sockets attached. The red and brown sockets supply power (positive to red) and the third yellow or orange socket is for the control signal. To link the socket to the breadboard, use the male-to-male jumper wires. Page 6 of 12

Page 7 of 12

Software We'll be using the great wiringpi tool gpio to control the servo. Begin by installing gpio with sudo apt-get install -y wiringpi Set pin #18 to be a PWM output gpio -g mode 18 pwm Pin #18 has PWM output, but you have to set it to be the right frequency output. Servo's want 50 Hz frequency output For the Raspberry Pi PWM module, the PWM Frequency in Hz = 19,200,000 Hz / pwmclock / pwmrange If pwmclock is 192 and pwmrange is 2000 we'll get the PWM frequency = 50 Hz (thx to kev for the numbers! (http://adafru.it/sdj)) Now you can tell gpio to set the PWM clock to those numbers: gpio pwm-ms gpio pwmc 192 gpio pwmr 2000 Now you can set the servo to all the way to the left (1.0 milliseconds) with Page 8 of 12

gpio -g pwm 18 100 Set the servo to the middle (1.5 ms) with gpio -g pwm 18 150 And all the way to the right (2.0ms) with gpio -g pwm 18 200 Servos often 'respond' to a wider range than 1.0-2.0 milliseconds so try it with ranges of 50 (0.5ms) to 250 (2.5ms) Of course you can try any number between 50 and 250! so you get a range of about 200 positions Note that the Raspberry Pi PWM is not necessarily a 'stable' output, and there might be some jitter! For a steady PWM signal, you'll want to check out a dedicated Servo HAT. (http://adafru.it/2327) Python Example! You can also use wiringpi in python! Run sudo apt-get install -y python-pip sudo pip install wiringpi The Python program to make the servo sweep back and forth is listed below: # Servo Control import time import wiringpi # use 'GPIO naming' wiringpi.wiringpisetupgpio() # set #18 to be a PWM output wiringpi.pinmode(18, wiringpi.gpio.pwm_output) # set the PWM mode to milliseconds stype wiringpi.pwmsetmode(wiringpi.gpio.pwm_mode_ms) # divide down clock wiringpi.pwmsetclock(192) wiringpi.pwmsetrange(2000) delay_period = 0.01 Page 9 of 12

while True: for pulse in range(50, 250, 1): wiringpi.pwmwrite(18, pulse) time.sleep(delay_period) for pulse in range(250, 50, -1): wiringpi.pwmwrite(18, pulse) time.sleep(delay_period) We're basically using the wiringpi functions but within python, so its easy to practice with the gpio utility and then use the matching commands in python A variable (delay_period) is used to contain the time in seconds between each step of the servo. The while loop will just continue forever or until the program is interrupted by pressing CTRL-C. Within the loop there are two near identical 'for' loops. The first counts the pulse width up from 5.0ms to 2.5ms and the second sets the pulse with starting with 2.5m and counts down to 0.5ms, moving the servo arm back and forth. To install the software, connect to your Pi using SSH and then type the command: $ nano servo.py Paste the code above into the editor and then do CTRL-X and Y to save the file. Page 10 of 12

To run the servo program just type the following command into your SSH window: $ sudo python servo.py The servo should start to move straight away. Page 11 of 12

Test & Configure If you want to make the servo move faster, try changing delay_period to a smaller value, say 0.001. Then to slow it down try increasing it to 0.1. If you want to control more than one servo, then the easiest way to do this is to use something like the Adafruit I2C 16 channel servo / pwm controller (http://adafru.it/815). This tutorial (http://adafru.it/apn) explains how to use it. Last Updated: 2016-11-03 06:17:52 AM UTC Page 12 of 12