Author Topic: UART and servos  (Read 3018 times)

0 Members and 1 Guest are viewing this topic.

Offline javafiendTopic starter

  • Robot Overlord
  • ****
  • Posts: 125
  • Helpful? 0
UART and servos
« on: July 29, 2008, 11:42:11 AM »
I think it's about time that I add UART to my robot, but I was curious about the microcontroller pins that it connects to.  In the tutorial, it says to just move your servos off of the Rx and Tx pins.  Could those pins be used for both UART and servos at the same time assuming the UART connection was relocated?

Please feel free to ask for clarification if I'm getting any of the terminology wrong.

Thanks!

Offline izua

  • Supreme Robot
  • *****
  • Posts: 682
  • Helpful? 0
Re: UART and servos
« Reply #1 on: July 29, 2008, 11:45:10 AM »
you can't use servos on hardware UART pins because the signal to drive a servo is not the same signal to send a byte. Plus, one of the UART pins must be an input, so that can't drive a servo at all.

What tutorial are you talking about?
Check out my homepage for in depth tutorials on microcontrollers and electronics.

Offline javafiendTopic starter

  • Robot Overlord
  • ****
  • Posts: 125
  • Helpful? 0
Re: UART and servos
« Reply #2 on: July 29, 2008, 11:51:49 AM »

Offline rgcustodio

  • Robot Overlord
  • ****
  • Posts: 217
  • Helpful? 0
  • Use "Search" and ye might find answers!
Re: UART and servos
« Reply #3 on: July 29, 2008, 12:03:35 PM »
izua:
Depends on the MCU.

A developer can configure the ATmega's so that the UART pins can be used as I/O (actually interrupt inputs), specially if you use a low pin count variety and you don't need a UART. These are documented as "Alternate Functions".


javafiend:
No you can't use the UART pins for UART and other function at the same time. If you program a specific pin for a function (ie as UART) you can't use it as an I/O port to drive your servo. The pin function is supposed to be programmed by your code during bootup of the system.

What MCU are you using? If you're using an MCU with 2 UARTs you can dedicate one UART for UART/communications functions and you can re-program the other UART as an I/O port to do your bidding.
The best thing one can do when it's raining is to let it rain. - H. W. Longfellow

understanding is the path to enlightenment

Offline javafiendTopic starter

  • Robot Overlord
  • ****
  • Posts: 125
  • Helpful? 0
Re: UART and servos
« Reply #4 on: July 29, 2008, 12:12:26 PM »

What MCU are you using? If you're using an MCU with 2 UARTs you can dedicate one UART for UART/communications functions and you can re-program the other UART as an I/O port to do your bidding.


I'm using an ATMEGA168 and I believe it only has 1 UART.

It appears that if I use UART, I would be limited to using a maximum of 3 servos, correct?  If true, how can I get the most out of my MCU?  I'm still using the board from the $50 robot tutorial.

Offline pomprocker

  • Supreme Robot
  • *****
  • Posts: 1,430
  • Helpful? 16
  • Sorry miss, I was giving myself an oil-job.
Re: UART and servos
« Reply #5 on: July 29, 2008, 12:14:24 PM »
« Last Edit: July 29, 2008, 12:33:37 PM by pomprocker »

Offline rgcustodio

  • Robot Overlord
  • ****
  • Posts: 217
  • Helpful? 0
  • Use "Search" and ye might find answers!
Re: UART and servos
« Reply #6 on: July 29, 2008, 12:19:38 PM »
javafiend:
You can use pomprocker's suggestion of using Software UART (or bit-bangging).

If you do bit-bang verify the pins used in the code and change it appropriately to your setup.
The best thing one can do when it's raining is to let it rain. - H. W. Longfellow

understanding is the path to enlightenment

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,150
  • Helpful? 109
Re: UART and servos
« Reply #7 on: July 29, 2008, 12:27:02 PM »
When you use the UART pins you just need the signal outputs - ie the pins that are connected to the mcu. If the gadget at the other end of the UART is, for example, a serial LCD display then you need to be careful. The LCD display also needs power ie +5v and Gnd - but the power pins on the headers are connected to the motor supply. So you may need to get 'power' by using another 2 pin plug that connects to an unused TTL voltage - ie an unused Analogue 2 Digital input.

Quote
I would be limited to using a maximum of 3 servos
Not necessarily: the $50 robot doesn't use several of the pins at the bottom left of the chip. Ok - so you need to add some extra header pins to the board. But the only thing you need to decide is: are they driving servos/motors in which case they need to use the motor supply, or will they be used for digital i/o in which case they need to be connected to the +5v from the voltage regulator. The board assumes that all your inputs are 'analogue' which is not always the case with things like a Sonar which switches between being an input and an output but must be connected to the TTL supply line.

I find this to be the major headache when making a board. You have 2 supply rails: TTL and Servo/Motor - so you need to decide which pins will be used for what. IMHO - it would be great if the $50 robot could have one 'nicely smoothed' supply that could be used both as a TTL input or as a Servo or TTL output.
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline pomprocker

  • Supreme Robot
  • *****
  • Posts: 1,430
  • Helpful? 16
  • Sorry miss, I was giving myself an oil-job.
Re: UART and servos
« Reply #8 on: July 29, 2008, 12:36:47 PM »
Not necessarily: the $50 robot doesn't use several of the pins at the bottom left of the chip. Ok - so you need to add some extra header pins to the board. But the only thing you need to decide is: are they driving servos/motors in which case they need to use the motor supply, or will they be used for digital i/o in which case they need to be connected to the +5v from the voltage regulator. The board assumes that all your inputs are 'analogue' which is not always the case with things like a Sonar which switches between being an input and an output but must be connected to the TTL supply line.

I find this to be the major headache when making a board. You have 2 supply rails: TTL and Servo/Motor - so you need to decide which pins will be used for what. IMHO - it would be great if the $50 robot could have one 'nicely smoothed' supply that could be used both as a TTL input or as a Servo or TTL output.

Would there be a way to add a jumper on each port to handle this?

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,150
  • Helpful? 109
Re: UART and servos
« Reply #9 on: July 29, 2008, 12:55:48 PM »
Yeah you could do this ie:-
Gnd
Motor Supply
Signal
TTL/+5V Supply
Gnd

So that you connect your 3 way wire from your motor to the top 3 pins if its using the motor supply, or to the bottom 3 pins if needs a TTL/+5V supply. But that means you have 5 pins for each I/O port - which seems like an awful lot. Given that the Signal pin is in the middle and needs connecting to the mcu then it also means some 'rather challenging' soldering.

Could you do it with jumpers to configure what +ve is applied:- well I guess so - but the extra header pins for the jumpers would mean that, in order to connect a 3 pin servo/sensor, would require a lot of additional physical space on the board.

Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,150
  • Helpful? 109
Re: UART and servos
« Reply #10 on: July 29, 2008, 12:59:36 PM »
If you look at the CAD diagram of the Axon then it appears that Admin has got over this. Thats whay there are 3pin headers all around the outside of the board. So they MUST(?) be using a common +ve supply voltage irrespective of whether they are driving motors or acting as digital I/O lines. Maybe that's why that great big capacitor is there? Admin?
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,659
  • Helpful? 169
    • Society of Robots
Re: UART and servos
« Reply #11 on: July 29, 2008, 09:01:12 PM »
Quote
Thats whay there are 3pin headers all around the outside of the board. So they MUST(?) be using a common +ve supply voltage irrespective of whether they are driving motors or acting as digital I/O lines. Maybe that's why that great big capacitor is there? Admin?
The $50 Robot board has a *very* similar design to the Axon, in terms of the power bus.

The outside header row all around the board is ground. For the ADC pins, its a regulated 5V, while the other power pins (such as for servos) is unregulated. And the inner header rows are signal pins.

And yeap, thats why there is a big cap.


Confirming what was said above, you can add more headers to the unused pins on the $50 Robot for more servos. At one point I ran 7 servos on my $50 robot, plus used the UART for data transmission.

Offline javafiendTopic starter

  • Robot Overlord
  • ****
  • Posts: 125
  • Helpful? 0
Re: UART and servos
« Reply #12 on: July 30, 2008, 09:02:19 AM »
If I added headers to the unused pins, they could be used the same way as the pins for the servos?  That would be fantastic.  Makes me wish I had more time to actually find more ways to use them than to send a signal to servos.

That brings me to another question.  Does anyone have any examples of how they have utilized their $50 robot board beyond the SoR tutorials?

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,659
  • Helpful? 169
    • Society of Robots
Re: UART and servos
« Reply #13 on: July 30, 2008, 09:15:59 AM »
Quote
If I added headers to the unused pins, they could be used the same way as the pins for the servos?
Yeap - I actually added them on mine for my ERP, but never actually added it to the $50 Robot tutorial. I guess at some point I'll take some pictures and include it.

Quote
Does anyone have any examples of how they have utilized their $50 robot board beyond the SoR tutorials?
Just tell us what you want to do, and we'll show you how. If you can output a signal for servos, and input a signal for sensors, and can do UART, you've learned 90% the concepts already.

Offline javafiendTopic starter

  • Robot Overlord
  • ****
  • Posts: 125
  • Helpful? 0
Re: UART and servos
« Reply #14 on: July 30, 2008, 10:03:53 AM »
Just tell us what you want to do, and we'll show you how. If you can output a signal for servos, and input a signal for sensors, and can do UART, you've learned 90% the concepts already.

I'm not really the creative sort, and don't really know what I want to do.  I just want to do something.  Low cost and instant gratification is always a bonus.

Offline pomprocker

  • Supreme Robot
  • *****
  • Posts: 1,430
  • Helpful? 16
  • Sorry miss, I was giving myself an oil-job.
Re: UART and servos
« Reply #15 on: July 30, 2008, 10:05:47 AM »
the $50 robot is your friend. start from there (i did), and keep customizing/modifying/tricking it out, until you can't any more.

and you'll have learned it all.


the robot in my avatar is my not so "$50" robot  ;)
« Last Edit: July 30, 2008, 10:06:27 AM by pomprocker »

Offline krich

  • Robot Overlord
  • ****
  • Posts: 165
  • Helpful? 0
Re: UART and servos
« Reply #16 on: July 30, 2008, 12:40:43 PM »
MHO - it would be great if the $50 robot could have one 'nicely smoothed' supply that could be used both as a TTL input or as a Servo or TTL output.

I agree with you on this, however I found out that practically it didn't work out for me.  I decided to run both the MCU and the motors off a 7.2V battery pack.  I found that the drain from the motors as they start up or change direction caused the MCU to brown out.  So, I hooked up some big capacitors to take the hit, but they ended up being larger physically than the circuitry and physical size if I just ran the MCU off a separate 9V battery.  Plus, there's much less "protection" needed for my analog sensors, etc.  The obvious downside is that you have two batteries you have to make sure are charged.

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,150
  • Helpful? 109
Re: UART and servos
« Reply #17 on: July 30, 2008, 06:33:20 PM »
Sorry if this is going slightly off topic, and maybe more Axon biased, but:
The outside header row all around the board is ground. For the ADC pins, its a regulated 5V, while the other power pins (such as for servos) is unregulated. And the inner header rows are signal pins.

So that means you've 'hard wired' the power supply for each of the pins? ADC obviously needs to be regulated +5v - but is everything else on the unregulated power supply? In which case:- if you are using a 'digital' sensor, like a Ping or Devantech Sonar, or a digital infrared sensor, or a bumper micro-switch then you need to connect it to an ADC port so that the power supply is correct and hence waste an ADC pin? Just trying to understand....

Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,659
  • Helpful? 169
    • Society of Robots
Re: UART and servos
« Reply #18 on: July 30, 2008, 06:56:27 PM »
Quote
but is everything else on the unregulated power supply? In which case:- if you are using a 'digital' sensor, like a Ping or Devantech Sonar, or a digital infrared sensor, or a bumper micro-switch then you need to connect it to an ADC port so that the power supply is correct and hence waste an ADC pin? Just trying to understand....
All it means is that if you want regulated power to some external component, you need to take it from the ADC power bus. You aren't required to use the signal line on the ADC bus, however. So basically, if you fill up all 16 ADC pins and still need more, you'd have to use a Y-harness and/or create an additional power bus.

I was a bit torn between having more regulated pins (for sensors) vs unregulated pins (for actuators). I probably should have made A0-A2 regulated, but too late now . . . And then there is the 3.3V regulated line, too . . .

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,150
  • Helpful? 109
Re: UART and servos
« Reply #19 on: July 30, 2008, 07:20:21 PM »
Ok - thanks for that - it clears things up for me. It seems we all have the same board design kind of issue - ie you may take 'signal' from one header, but you may need to get 'power' from another. My prototyping carcass has several 2 pin 'power only' headers on both supply rails for just this purpose. I was just trying to see if someone else had a more elegant solution.

Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

 


Get Your Ad Here

data_list