+ All Categories
Home > Documents > Wireless Servo Motor

Wireless Servo Motor

Date post: 15-Oct-2014
Category:
Upload: imran-soudagar
View: 131 times
Download: 1 times
Share this document with a friend
Popular Tags:
16
Searching for a reliable wireless solution for your project can be a real pain if you're not familiar with current wireless standards, data rates and reliability. The Xbee Modules that we will use in this article are widely available, use a very reliable wireless transmission protocol and have sufficient datarates for most hobby projects. This article will show you how to build a basic wireless input and output system in the form of a single transmitter and single receiver. Communication will be one way to keep things simple with two xbee modules being used for the wireless link. In the end, a small trimpot will control the movement of a servo motor Purpose & Overview of this article The goal for this article is to build a wireless transmitter that we can send input to and a wireless receiver that can recieve, translate and implement this input data to move a servo motor to a specific location. To arrive at this goal, we will use two PIC Microcontrollers (one for the receiver and the transmitter) and two Xbee WiFi Modules (again, one for the receiever and the transmitter). The transmitter will have a standard trimpot circuit to input a variable analog voltage to the PIC's A/D converter. The receiver will be connected to a servo motor that can be driven by a PWM signal Parts List Details The parts for both the transmitter and the receiver are listed above (notice a lot of duplicate 2x parts are listed. I'll describe the more important parts in greater detail below. PICkit2 This is the programmer that I use to load the firmware (software) that I create in Microchip's MPLAB onto the PIC 18F4520 microcontroller. It's a little expensive, but only comes as a one time cost. Once you have the programmer you can use it over and over to program almost every PIC that microchip makes. PIC 18LF4520 Normally I use the PIC 18F4520 series PIC in my articles but since the Xbee Modules are not +5v compatible (Xbee Modules use +3.3v) I decided to use the 'LF' series of the PIC. The 'LF' series of the PIC can run on a +3.3v power supply, which means we can use the same power supply going to the Xbee Module and the PIC Microcontroller. Xbee WiFi Module
Transcript
Page 1: Wireless Servo Motor

  Searching for a reliable wireless solution for your project can be a real pain if you're not familiar with current wireless standards, data rates and reliability. The Xbee Modules that we will use in this article are widely available, use a very reliable wireless transmission protocol and have sufficient datarates for most hobby projects.           This article will show you how to build a basic wireless input and output system in the form of a single transmitter and single receiver. Communication will be one way to keep things simple with two xbee modules being used for the wireless link. In the end, a small trimpot will control the movement of a servo motor

Purpose & Overview of this article           The goal for this article is to build a wireless transmitter that we can send input to and a wireless receiver that can recieve, translate and implement this input data to move a servo motor to a specific location.           To arrive at this goal, we will use two PIC Microcontrollers (one for the receiver and the transmitter) and two Xbee WiFi Modules (again, one for the receiever and the transmitter). The transmitter will have a standard trimpot circuit to input a variable analog voltage to the PIC's A/D converter. The receiver will be connected to a servo motor that can be driven by a PWM signal

Parts List Details           The parts for both the transmitter and the receiver are listed above (notice a lot of duplicate 2x parts are listed. I'll describe the more important parts in greater detail below.

PICkit2           This is the programmer that I use to load the firmware (software) that I create in Microchip's MPLAB onto the PIC 18F4520 microcontroller. It's a little expensive, but only comes as a one time cost. Once you have the programmer you can use it over and over to program almost every PIC that microchip makes.

PIC 18LF4520           Normally I use the PIC 18F4520 series PIC in my articles but since the Xbee Modules are not +5v compatible (Xbee Modules use +3.3v) I decided to use the 'LF' series of the PIC. The 'LF' series of the PIC can run on a +3.3v power supply, which means we can use the same power supply going to the Xbee Module and the PIC Microcontroller.

Xbee WiFi Module           These modules use the Xbee protocol (stack) for wireless communication, making them pretty darn reliable. The default speed setting for these modules is 9600 baud, so if you want to use these modules out of the box be sure your serial communication module is set to output at 9600 bps (as I do in this article).

LM317 Voltage Regulator           This voltage regulator is a variable type which means it can output 1.25 - 37v. We use a 240&Omega resistor and a 5k trimpot circuit, then vary the trimpot value until the LM317 outputs the +3.3v that we need.

Breadboard           Two standard sized breadboards are used to build the transmitter circuit and the receiver circuit. No secrets are surprises here, just a generic $10 breadboard.

Page 2: Wireless Servo Motor

Jumper Wire           Standard breadboard jumper wire is used to connect everything together. Jumper wire kits are pretty easy to find, or you can always just go to the store and buy a few feet of wire and cut your own jumper wire with a pair of wire cutters

Schematic Overview           There are two schematics that we'll look at to see how to build this transmitter/receiver system. The first one is the transmitter, with a variable trimpot input into RA0. The trimpot value will be sent out of the Tx pin of the PIC and to the Din pin of the Xbee module to send the signal wirelessly.           The receiver circuit, will receieve the transmitted signal through the Xbee module, out of the Dout pin and to the PIC's Rx pin. The receiving PIC will then translate the data to movement coordinates for the servo motor.

" Trimpot Input Into The PIC           The input we will give to the PIC's will come from a standard trimpot's output. The trimpot is tied to power and ground, with the middle pin being a variable voltage send to the PIC's A/D converter on pin RA0.

"Xbee Module Wireless Output           The PIC will then translate this input to an integer of value 0-50 and send it via the PIC's serial communication module at 9600 BPS to the Xbee's Din pin.

Page 3: Wireless Servo Motor

"Servo Motor Output           After the serial data is receieved by the PIC, it will put the dynamic integer value into the the delay cycle that is creating a PWM output to control the servo motor. Each specific value of 0 to 50 correlates to a specific location that the motor can move to.

"Xbee Module Wireless Input           The Xbee receiver will automatically connect with the transmitter and begin receiving data. All data will be receiving and output via the Dout pin on the Xbee module. The Dout pin is conneceted directly to the PIC's Rx pin so that the PIC can catch the data

Servo Motor Theory           The signal that we need to create inorder to control the servos is called a Pulse With Modulation signal or PWM for short. The general requirements are:

Frequency: 50HzUp-time: 0.9mS ~> 2.1mSDown-time: 19.1mS ~> 17.9mS

           At first glance these definitions & numbers might make little or no sense. So lets look at a simple PWM wave at 50Hz.

Page 4: Wireless Servo Motor

           So a PWM wave is just a signal that changes between 0 volts & 5 volts (digital logic 0 and 1). We see that the wave is symmetrical; uptime is 10mS & downtime is 10mS which when added together give us the period (10mS + 10mS = 20mS).

Xbee Modules @ 9600 Baud

           In order for the PIC's serial communication module (USART) to send serial data at the correct speed, it uses a 'counter' to know when to send the next bit. A quick look at the PIC 18LF4520's datasheet shows us a table that correlates to our 20 MHz oscillator speed and shows us what value to set the 'counter' to, in our case it is: 129.           The datasheet also has the exact formula for calculating this number, but it's far easier to look it up in the tables they have if you're using a standard oscillator 

Transmitter Hardware           The normal hardware section will be split into two parts. The first part will show you how the transmitter circuit was built on a single breadboard. No tricks, we're just following the schematic here. The second part will show you how the receiver was build, again on a single breadboard, following the schematic.Xbee + SIPs

Page 5: Wireless Servo Motor

           For whatever reason, the Xbee module doesn't used standard 2.54mm (0.1") pitch pins, so it doesn't fit into a breadboard like an IC. To solve this minor issue, I attached 3 SIPs to the Power, Ground and Din pins as you can see in the picture above. After doing that, the Xbee module fits nicely into the breadboard.

Building The Wireless Xbee Servo Controller Transmitter           Below, I'll go step by step starting with all the parts laid out and then connect them together on the breadboard section by section until the transmitter is complete. In the pictures below you can see all the parts used for the transmitter:

·First the 9v connector is added to the board.

Page 6: Wireless Servo Motor

·Next we connect the +3.3v Power Circuit via the LM317.

·The basic PIC circuit comes next. PIC18LF4520 + 20 MHz Crystal.

Page 7: Wireless Servo Motor

·Here we add the input trimpot circuitry.

·Lastly, the Xbee is wired up to power, ground and the PIC.

Page 8: Wireless Servo Motor

·The transmitter is complete, it just needs some software and its ready to go. Now let's take a look at the receiver hardware.

Receiver Hardware           The second part of the hardware we need to put together is the receiver portion of the schematic. This hardware will receive the wireless transmission, decode and tell the servo motor where and how to move.

          This 'tiny' development board packs a large punch because of all the extra features it has. RAM, ROM, Accelerometer, Tons of I/O, LEDs, Push Buttons and a gigantic FPGA to go with it all.

Building The Wireless Xbee Servo Controller Receiver           Below you can see a picture of all the parts used to build the receiver portion of the circuit. So let's get started building it!

Page 9: Wireless Servo Motor

·First the 9v connector is put into the breadboard.

·Next, the power circuit is assembled to output +3.3v.

Page 10: Wireless Servo Motor

·The PIC circuit, 18LF4520 + 20 MHz Crystal, is added to the board.

·The Xbee module's 3 pins: Power, Ground, Dout are connected.

Page 11: Wireless Servo Motor

·Lastly, the servo motor is connected to Power, Ground and Signal.

·Now that both the transmitter and receiver have been assembled, let's take a look at the software for each PIC and get it uploaded to the PICs.

The Software           The full project used to create the firmware hex file in included for both the transmitter and the receiver in the downloadable archive files. Let's take a quick look at snippets of code from the two programs:    -The Data Output via Transmitter    -The Data Input via Receiver

Page 12: Wireless Servo Motor

           The main purpose of the transmitter is to take input via the A/D converter, format the data and then send it to the transmitter via USART. The forever while loop seen below does exactly that.

Snippet of Xbee Tranmistter Code:

------------« Begin Code »------------.....while(1){   Delay10TCYx( 5 ); // Delay for 50TCY   ConvertADC(); // Start conversion   while( BusyADC() ); // Wait for completion   result = (ReadADC()/20); // Read result

   Delay10KTCYx(5);   putcUSART( result );}.....

------------« End Code »------------

           The receiver's forever while loop simply inputs the data value received input the PWM generation circuit which is a series of delay statements triggering PORTD on and off. The USART data variable is updated by an interrupt that is triggered when data is received.

Two Interrupt Service Routines

------------« Begin Code »------------.....while(1){     PORTD = 0x00;     Delay100TCYx(100);     Delay100TCYx(100);     Delay100TCYx(100);     Delay100TCYx(100);     Delay100TCYx(100);     Delay100TCYx(100);     Delay100TCYx(100);     Delay100TCYx(100);     Delay100TCYx(100);     Delay100TCYx(100-(data));

     PORTD = 0xFF;     Delay100TCYx(50+(data));}.....

------------« End Code »------------

Page 13: Wireless Servo Motor

           The software for this article is not meant to be overly complex in anyway. The main purpose is to give you a skeleton core of code to start with and use for your own project. So take a look through the code and let's see how it works in the system

Data & Observations           This article has taken the simple idea of how to control a servo motor and moved past the wires to the wireless realm that xbee offers us. With a little serial interfacing using the PIC's USART, let's see how the system works in a short video.

           Things were quite successful and worked rather flawlessly. There's a tiny delay between transmission and reception but that is due to the fact that the transmitter sends commands every 5-10 miliseconds, which will cause a tiny, but noticeable delay. I also tested the system out on my animatronic eyes and it worked quite well. Seems like a cool future project, wireless control of animatronics =D

An Overview Of The DE0 Nano VGA Output           Although I've taken a previous look at a xbee interface this article takes it a step further and shows you how you can actually do something cool with such an interface to control a motor and therefore even some animatronics. The Xbee modules worked seemlessly together with the PIC making them look like a great pair for any of your wireless application needs.

What To Do Now           As I've mentioned a few times already, a good next step would be to take a look at my animatronics tutorials which pair up really nicely with this wireless xbee article given that all the animatronics use servo motors. Another direction to take this type of wireless

Page 14: Wireless Servo Motor

control would be for stepper motor or dc motor control, it would be a little trickier but definitely do-able.

Conclusion           This concludes all that I wanted to talk about for wireless servo motor control via xbee modules. They provide a low-cost easy to use solution with a lot of flexibility. I hope that you learned something from this article and that you can build something cool with the information that you got from here.           If you have any further questions, I implore you...don't be shy, take a look at theforums or ask a question there. I check them out regularly and love getting comments & questions.


Recommended