### You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Sensors, Actuators, and Robotics » 2 Servos, 1 Analog Joystick

 January 13, 2010 by Phrank916 So, I'm brainstorming on projects and have been scouring the "intar-webs" for things I want to tackle in the future. One thing I'd like to attempt is something similar to this project which is currently on the front news page of Sparkfun: Youtube Video - M&M Dispenser Now, I don't want to be told how to do it, I know learning means doing it myself. So, I guess I'm posting here to "think aloud" if you will, and I do indeed welcome any suggestions or minor help where needed to help me fit the pieces together. So here's my idea so far, along with information I have gathered from projects here and other things I've read and studied: I want to use the same analog joysick in the project above which I've found for cheap on Sparkfun. They also have a custom made breakout board for it, altogether about 5 bucks. The analog joystick is, if I recall, just two 10k potentiometers for each axis. I know I'll need to give power to the joystick and I'll have two leads from each axis pot going into 2 pins on the MCU. These pins will be set as inputs for the ADC. I'm unsure here on the math and the exact setting for the ADC but I'm pretty confident that with a pad of paper and the data sheets I'll be able to do the computations. I know the pots will be fed +5v and when turned back and forth that it will vary the output voltage. So, say it's a 0 to 5 range, then the middle would be 2.5, so I'm assuming when the joystick is at rest and centered that both axes will read 2.5V. From this point I will need to take the digital data I get from the ADC which I know from the thermistor project, is 0-1023 sincne it's a 10-bit ADC. From this I'm again assuming that the centered reading would be 2.5v, giving me an output from both channels of the ADC of 512 when the jotstick is centered. NEXT, I know I'm going to be driving two servos for each axis with two PWM channels (please correct me if I'm using the wrong "lingo"). I will take the data from the two ADC channels and do some fancy math to convert that to a figure that will be plugged into OCRnx to adjust the "compare value" up or down. This will also involve some fancy math to ensure the bottom end of the ADC range at zero is dropping the compare line down, while 512 is the center and 1023 is the top. Ok, so I think that's pretty much the basic theory which I've put together in my head. My next plan is to get ahold of just a single hobby servo, which I think I can get for free from a friend of mine who is WAY into RC 4X4 trucks. With that I was thinking of doing some experimentation with the pot included in the USB NerdKit and see if I can't get the servo to move back and forth when the pot is moved back and forth. My main goal of this experiment is to get real-time responsiveness with an analog input source and not simply sending a digital signal to move the servo to left or right at a constant speed. I want to be able to move the joystick slow or fast and have the servo move slow or fast. So, if after reading this it got your wheels turning, and you're aching to throw in your 2 cents, PLEASE DO SO! I welcome all feedback and advice. Ted Basic Idea is very good. Might want to check out the servo squirter tutorial here for servo programming ideas. I've used a joystick very similar to that one as an input for an avr and it centers around the halfway point but does not go to the full top and bottom (0 - 1023) I set up ranges in my application for varying degrees of movement and a "safe zone" at center. Keep us updated... looks like an interesting project !! Rick Ahh yeah, the "dead zone" in the center. I thought of that the other day but forgot to mention it in the post. Thanks for reminding me of that little bit of not-so-fun coding, LOL This is exactly what I want to do, but it's on a stupid Arduino. http://www.youtube.com/watch?v=FKj9jJgj8Pc So I guess I might get some ideas from looking at the servo.h library they reference. We'll see. I'm up way later than I should be, but I just finished this little bit of code. It's really nothing, so trivial to most of you I'm sure, but I was extremely excited when the make went through and I turned on the MCU and it did what I wanted it to do!! This is just a small part of what I want the final project to actually be, but it is a HUGE first step for me. This basically just reads a potentiometer and gives back an ADC reading between 0 and 1023. I print that to the LCD so I can turn the pot back and forth and watch the numbers go up and down :) This code was mashed together from the tempsensor project and a little of my own.. ``````#define F_CPU 14745600 #include #include #include #include #include #include #include "../libnerdkits/delay.h" #include "../libnerdkits/lcd.h" uint16_t adc_read() { // read from ADC, waiting for conversion to finish // (assumes someone else asked for a conversion.) // wait for it to be cleared while(ADCSRA & (1<