generalenthu
Posts: 9
Joined: Tue Dec 13, 2011 4:43 am

Re: Do I need a gertboard to run a servo

Mon Dec 19, 2011 3:28 am

I am a complete hardware newbie - please pardon my ignorance.

I need the ability to mechanically turn a switch on or off. The switch is on an device and I am planning to install a servo motor (probably with its own power) next to this switch. I need r-pi to activate the servo.

Can I just connect the servo to the GPIO ports and program r-pi or do I need to get a gertboard / teensy in between. Obviously I am not looking for high precision from the servo.

tntexplosivesltd
Posts: 72
Joined: Fri Sep 30, 2011 8:08 am
Contact: Website

Re: Do I need a gertboard to run a servo

Mon Dec 19, 2011 4:32 am

You could wire up a relay to do the switching for you. Cut out the middle man.
If you are going to use a servo, you can directly connect the servo to the R-Pi. You won't need a gertboard

User avatar
abishur
Posts: 4477
Joined: Thu Jul 28, 2011 4:10 am
Location: USA
Contact: Website

Re: Do I need a gertboard to run a servo

Mon Dec 19, 2011 4:39 am

Yes, you can access things like this without the gertboard. The nice part of the gertboard, however, is that he took care of all the current/voltage protection so you don't have to worry about frying your board. With anything we custom make there are two issue we have to address.

1) The GPIO put out a *very* low current output, so you need something to boost that up to drive a servo or relay.

2) voltage/current protection. Since you're upping the current and possibly the voltage according to your needs you need to make sure that your device is protected against that current suddenly go back down to the board

As long as you handle those two main points, then you can make your own boards. Well I suppose you could ignore those two points and theoretically be fine, but it could end very poorly for you in the long run ;)
Dear forum: Play nice ;-)

generalenthu
Posts: 9
Joined: Tue Dec 13, 2011 4:43 am

Re: Do I need a gertboard to run a servo

Mon Dec 19, 2011 6:20 am

Very clear explanation. Thank you. My only concern is that the gertboard looks like overkill for what i am trying to accomplish (also, assembling the kit seems scary). Are there any halfway solutions / preferably off-the-shelf which would avoid frying r-pi over the long run.

@tntexplosivesltd, thanks for the relay idea. I didn't think of it, but in any case, that will be a no go. I am not going to open up the amp and void the warranty on it. Also I still need the manual control.

nelson
Posts: 38
Joined: Sat Dec 17, 2011 3:43 am

Re: Do I need a gertboard to run a servo

Mon Dec 19, 2011 8:35 am

You can use something like this http://www.coolcomponents.co.u.....cts_id=667 it was made for a microcontroler more expensive than the pi so I assume that it was made to be safe for the control board, as there seams to be a fet/transistor driving the relay, it should be safe

Edit: Sorry didn't read the last part. If you can't open the device search instead for a small solenoid and drive it with the relay board, normally you would only need a FET but if your afraid to solder its your best bet, if not FETs are pretty easy to work with and should keep your pi safe

bradburts
Posts: 341
Joined: Sun Oct 02, 2011 7:07 am

Re: Do I need a gertboard to run a servo

Mon Dec 19, 2011 9:37 am

Lets hope that Gert has time to post the final circuits and BOM. That way those who want a light weight option can copy the best of his design.
I would recommend getting a Gert board to start with though. Its a lot harder to debug unproven hardware with unproven software. Gert will have an excellent working hardware solution so that just leaves your software (not being rude but software mistakes are easy to make!)

So its best to demonstrate your software with a known working hardware design before starting your diet plan. Next you should try and understand how the protection circuit works, make and test your own protection circuit. Then you will be safe to experiment and learn with FETs etc.

EDIT:
PS The protection circuit is just a few components and should be fairly easy to understand & crib. It will be a couple of diodes which, in essence, act as a couple of 'IF' statements, IF voltage too high send it this way & IF voltage too low...
It is well worth the effort learning these electronics basics as it will open your world to lots of fun embedded projects.

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 26413
Joined: Sat Jul 30, 2011 7:41 pm

Re: Do I need a gertboard to run a servo

Mon Dec 19, 2011 9:38 am

Quote from generalenthu on December 19, 2011, 06:20
Very clear explanation. Thank you. My only concern is that the gertboard looks like overkill for what i am trying to accomplish (also, assembling the kit seems scary). Are there any halfway solutions / preferably off-the-shelf which would avoid frying r-pi over the long run.

@tntexplosivesltd, thanks for the relay idea. I didn't think of it, but in any case, that will be a no go. I am not going to open up the amp and void the warranty on it. Also I still need the manual control.

The Gertboad is designed so you just add the components you need for the particular task in hand, so you don't need everything soldered on.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed.
I've been saying "Mucho" to my Spanish friend a lot more lately. It means a lot to him.

tumblebomb
Posts: 50
Joined: Sun Nov 27, 2011 4:56 pm

Re: Do I need a gertboard to run a servo

Mon Dec 19, 2011 9:51 am

not to detract from @jamessh comments, looking for small or simple circuits to drive servos try the robotics comuunity/websites/books. I know I have quite a lot of information at home and practice but still a Gert board is perfect for beginning/prototyping, even if you know what you're dong. Once you have the software and hardware set then making your own board is easier.

bradburts
Posts: 341
Joined: Sun Oct 02, 2011 7:07 am

Re: Do I need a gertboard to run a servo

Mon Dec 19, 2011 10:23 am

Yes.
Get a good reference design like the Gert board and then learn from that.
After all:
"...premature optimization is the root of all evil"

User avatar
mmiller
Posts: 22
Joined: Wed Nov 16, 2011 8:38 pm
Contact: Website

Re: Do I need a gertboard to run a servo

Mon Dec 19, 2011 11:12 am

Even as I total noob myself, I think a Gert is the right way to go! I only learn by making mistakes and I'd like the Gert to protect my RasPi as much as possible.

However, I've also been looking at using some of the more readily available alternatives.
Some of which are moderately priced. In particular 'Phidgets'.
Many of their components are distributed in the UK via
http://www.active-robots.com/s.....d/phidgets
search "Phidgets" or "active-robots" on the forum as there are several related posts.
  • Slowly spreading the joy the RaspberryPi way!
    http://raspberrytorte.com/ http://wiki.raspberrytorte.com https://github.com/raspberrytorte

bradburts
Posts: 341
Joined: Sun Oct 02, 2011 7:07 am

Re: Do I need a gertboard to run a servo

Mon Dec 19, 2011 11:59 am

Quite expensive but ready made.

I think that the Gert board will be a lot cheaper.
Don't worry too much about assembly. The Gert board has been designed with idiots like me in mind, which is quite an achievement.
You can practice soldering, before trying it out on the board. Its easy enough.
The board has sockets so there is little risk of killing anything.
Once you have soldered you just need to check that you have not shorted one track to another.
Use a multimeter and 'buzz' between physically close tracks to your solder site which should not be connected.
Its kind off like playing minesweeper on a PC. The circuit diagram will be no worse than an underground map, if you can follow that then you will understand the circuit sufficient to understand that track A does not touch track B and so your probe should not buzz.

joep
Posts: 17
Joined: Sat Nov 26, 2011 4:27 pm

Re: Do I need a gertboard to run a servo

Mon Dec 19, 2011 12:03 pm

I wouldn't think it would be a problem to control the servo directly from one of the Pi's PWM GPIOs. Most servos require about 100ma or so but I'm not entirely sure if the 3.3 volts would need to be shifted up to 5V. Haven't tried it myself.

The servo motor requires its own power source of course.

A simpler solution might be:
http://www.robotshop.com/sfe-o.....ard-1.html

But this requires the I2C driver for the RPi, which at best I would consider as being available at some point after the Pi is released.

User avatar
Gert van Loo
Posts: 2487
Joined: Tue Aug 02, 2011 7:27 am
Contact: Website

Re: Do I need a gertboard to run a servo

Mon Dec 19, 2011 12:45 pm

Beware that controlling a real servo requires you to generate a 50Hz square wave with variable duty cycle. It is not a simple GPIO on/off circuit.

(It may be easier to add the PIC and let that generate your square waves)

joep
Posts: 17
Joined: Sat Nov 26, 2011 4:27 pm

Re: Do I need a gertboard to run a servo

Mon Dec 19, 2011 12:59 pm

Beware that controlling a real servo requires you to generate a 50Hz square wave with variable duty cycle. It is not a simple GPIO on/off circuit.

I thought the RPi had PWM available on some of the pins? I guess the software to control it won't be available through the generic GPIO driver?

problemchild
Posts: 22
Joined: Thu Oct 06, 2011 8:08 am
Contact: Website

Re: Do I need a gertboard to run a servo

Mon Dec 19, 2011 1:37 pm

I'm certainly no Arduino Fan boy but I think that for this kind of task you would be much better getting an Arduino or even an Arduino nano and use that to do your servo control.
Everything has already been done for you and there is an IDE in which you can develop your code on most platforms, including the 'PI since it's in Java.
Big benefit is that you can access the HW from everywhere not when 'PI get round to releasing it and you can access a much larger group of people interested in the device with 100's of examples already done. Arduinos abount from about £12 on EBAY and would drive several servos without problems, buy one now and you could have it in your hand for January and be a bit of an expert running it on your existing PC well before the 'PI or Gert board get released. You could just stick a Arduino programmed Chip down on a prototyping board like this with a similar effect as well.

http://www.raspberrypi.org/for.....038;t=1483

Wooloomooloo
Posts: 92
Joined: Fri Nov 25, 2011 10:52 am

Re: Do I need a gertboard to run a servo

Mon Dec 19, 2011 2:27 pm

...On the other hand, one could always simply take a dedicated part (SPI or I2C controllable PWM generator - going mostly under the name "LED driver" these days) with half a gazillion outputs like PCA9685 or similar, which seems to go for like 2-3 bucks. Then again, the Arduino is famous for being used as an expensive flip-flop replacement, so sure, one can go that route too.

hamjudo
Posts: 59
Joined: Thu Nov 03, 2011 3:25 pm

Re: Do I need a gertboard to run a servo

Mon Dec 19, 2011 2:31 pm

Quote from Gert van Loo on December 19, 2011, 12:45
Beware that controlling a real servo requires you to generate a 50Hz square wave with variable duty cycle. It is not a simple GPIO on/off circuit.

(It may be easier to add the PIC and let that generate your square waves)

The length of each pulse controls the position of the servo. It doesn't matter much how often the pulse is repeated.10Hz will work, so will 300Hz.

It is rude, crude, and socially unacceptable, to write a device driver which disables interrupts, pulls a GPIO pin high, busy waits for 1000 to 2000 microseconds as set by the desired servo position, pulls the GPIO pin low, schedules itself to be called 10 to 300ms later, then enables interrupts. Such a device driver would interfere with other timing sensitive applications running on the system. In particular, audio would probably sound horrible. However, the servo would work.

Hobby servos need 4 to 7 volts for power. Depending on the motor in the servo, and the usage, they can draw hundreds of milliamps to several amps of power. They need a robust power supply. They should not feed off of the R-Pi's wimpy USB powersupply, unless a suitably wimpy servo has been chosen.

The control line of the servo is a digital input, that is 3.3volt tolerant, and requires virtually no drive current. It can be directly connected to a GPIO pin on the R-Pi, with one provision. The grounds for the R-Pi and the servo must always be connected. Bad things will happen, if the servo has a power supply which is floating relative to the R-Pi.

joep
Posts: 17
Joined: Sat Nov 26, 2011 4:27 pm

Re: Do I need a gertboard to run a servo

Mon Dec 19, 2011 3:00 pm

Although this is a bit beyond the scope of the OP's question, my favorite approach has always been to use a USB connected AVR (like the teensy: http://www.pjrc.com/teensy/index.html). It is flashed to appear as a serial device to any connected computer with software like txtzyme (http://github.com/WardCunningham/Txtzyme). I've expanded on the txtzyme software with the ability to use the I2C, SPI, and uart connections on the device as well, but it works pretty well in general.

The nice thing is that it should work right out of the box with the RPi plugging into the USB port. No need to wait on drivers and the control software ports to any UNIX type host.

generalenthu
Posts: 9
Joined: Tue Dec 13, 2011 4:43 am

Re: Do I need a gertboard to run a servo

Tue Dec 20, 2011 6:05 am

After reading through the thread thrice and clicking through almost all the links, I think Abhishur's response makes the most sense - build a logic circuit on the gertboard to protect the r-pi while letting it drive the servo.

Gert's reply on the other hand makes me think that the GPIO can't easily do a PWM and it is preferable to use the PIC to do PWM.

Alternatively Arduino uno is less than $25 shipped and I can safely pop in the servo there and get it to work with may be 6 lines of code. Certainly the easiest if not the cheapest way out.

User avatar
Gert van Loo
Posts: 2487
Joined: Tue Aug 02, 2011 7:27 am
Contact: Website

Re: Do I need a gertboard to run a servo

Tue Dec 20, 2011 5:02 pm

We have two PWM channels and they are currently used for audio. So to use them for a servo you have to disable the audio and you need PWM drivers. Alternative (or for more outputs) you can drive the GPIOs from the timer interrupt routine. That gives you ~1KHZ update. That should be enough if servos can indeed run from a lower frequency e.g. 20 Hz.

Bakul Shah
Posts: 322
Joined: Sun Sep 25, 2011 1:25 am

Re: Do I need a gertboard to run a servo

Wed Dec 21, 2011 8:20 am

Another idea is to use an Atmel Tiny85 ($2). A versatile 8pin micro with lots of functions multiplexed onto 6 pins! Four 10-bit ADC, 2 PWM, counter/timer, watchdog timer, all 6 are GPIO, I2C, SPI and more. 20Mhz, upto 512B RAM, 8KB Flash, 512B EEROM, on chip osc. etc. Use drivers if you need more than 40mA. You can find plenty of ATtiny85 projects online.

User avatar
riffraff
Posts: 307
Joined: Tue Sep 27, 2011 3:17 am
Location: Newnan, Georgia, US

Re: Do I need a gertboard to run a servo

Thu Dec 22, 2011 1:06 am

@Bakul Shah
Was checking out data sheets for that series after I saw your post last night. Left me scratching my head how you go about de-muxing all that. Saw a "hack-a-day" site I need to check out. I think if I saw a couple of application sheets and schematics i might understand. Sound's really cool, though, having mem, eeprom, uart all onboard w/cpu in a package you can breadboard or easily etch a single layer pcb for.

bradburts
Posts: 341
Joined: Sun Oct 02, 2011 7:07 am

Re: Do I need a gertboard to run a servo

Thu Dec 22, 2011 12:41 pm

Quote from Gert van Loo on December 20, 2011, 17:02
We have two PWM channels and they are cur.rently used for audio. So to use them for a servo you have to disable the audio and you need PWM drivers.

I like that idea. It may be easier for many (esp. 'pure' HW types) to put protection & current amplifier after the Pi PWM than to involve another micro. Not sure what circuits you would need around the other micro just to alllow the micro to breath, to program it etc.

@Gert
Do you know if a PWM software driver will be available or if there will be details on the PWM hardware such that we can hack a PWM driver?
Any nice and cheap solution to motor control would add another cool string to the Pi bow.
The motor controller modules that I have seen so far are very expensive, much more than a Pi.

bradburts
Posts: 341
Joined: Sun Oct 02, 2011 7:07 am

Re: Do I need a gertboard to run a servo

Thu Dec 22, 2011 12:44 pm

Adding myself to email notifications

User avatar
Gert van Loo
Posts: 2487
Joined: Tue Aug 02, 2011 7:27 am
Contact: Website

Re: Do I need a gertboard to run a servo

Thu Dec 22, 2011 1:41 pm

Any nice and cheap solution to motor control would add another cool string to the Pi bow.
I can think of four different motor controllers which each require different drivers:
AC motors.
DC motors.
Stepper motors.
Servo motors.

Of those I would say AC are the most difficult to drive, not something I would recommend a beginner.
DC can be done using the L6203 on the Gertboard.
Stepper motors: I have to read up on those. If I recall it requires three outputs which you have to pulse high/low in a specific order to step forwards/backwards.
Servo motors: read this thread.
Welcome to the world of electronic engineering where we manage to make a problem for every solution. :-)

Return to “Other projects”