Baby O, newbie and how to get started?

Hi All,
I’m new here and hope someone can point me in the right direction. I’ve got the Baby o 168 , USB programmer and all is hooked up and ready to go…but I need soemthing to help me get started. I want to drive a dc motor, bi-directionally, basically. I’m familar with C and have programmed other MCu’s, but I’m not familar with the architecture of the Baby O…yet.
I’ve used the Basic stamp and have had no problems with it, mostly because it came with a very complete project book with many examples on the use of the Basic Stamp.
Can anyone tell me where I can get started with the Baby O in a similar manner? Is there a book available that will take you thru examples that illustrate the capabilities of this device? I know that once I see some basics, I’ll be able to move right on and get what I need done.
The Baby O looks like the perfect solution for me and this project. The Basic Stamp worked, but was slow, too expensive and required additional circuitry for the motor control.

Any help would be greatly appreciated, and I hope that this request is not too bothersome to all of you pro’s out there…if so, I apologize in advance. I didn’t know where else to turn.

thanks…

David

Hello.

Have you seen the documents linked from the Baby Orangutan page’s resources tab?

pololu.com/catalog/product/1216/resources

There is a user’s guide that will help you get started and show you how to load a simple blinking LED program onto your Baby Orangutan. There is also an application note on using the Baby Orangutan’s motor drivers and a tutorial on programming the Baby Orangutan from the Arduino environment (along with a series of libraries that make it easier to use the Baby Orangutan’s onboard hardware).

Hopefully these documents will be enough to get you started. If you still have any questions, don’t hesitate to ask.

- Ben

Hey David, welcome to the world of AVR microcontrollers.

I agree with Ben, the Arduino environment is a great way to get started with AVRs. It uses a modified C language to give you easy access to the AVR hardware and features, and is probably the best way for you to dive in and get things moving.

Since you said you were familiar with C already, if you’re looking for more of an instructional book to read cover to cover, I really enjoyed “C Programming for Microcontrollers” when I was migrating to AVRs from PICs. It references the AVR Butterfly demonstration board for all the projects, and you can buy it with or without various combinations of the project hardware. Since you’re already familiar with this sort of thing you might consider getting just the book alone, or as a PDF download, and working through it using your Baby-O instead. I didn’t have too much trouble adapting the sample projects to the original Orangutan. The first two chapters (up to blinking an LED) are available online here.

Assuming you’re using Windows (like me, but there are other options if you’re not), you would then also want to download:

  1. AVR Studio, Atmel’s (the manufacturer of the AVR microcontrollers used in the Orangutans) free development environment, which lets you write and compile code, ‘run’ it on a simulated microcontroller for debugging, and download it through a programmer like yours. By itself it will only compile assembly code, which is why you should also get…

  2. WinAVR, an open-source port of the GCC C compiler that lets you write and compile programs in C for within AVR Studio. It’s an amazing instance of cooperation between a big company and an open-source group for everyone’s benefit.

Just to check, do you have one of the new (i.e. blue) Baby Orangutan B-168s:

Or one of the original (green) mega168 ones:

The motor controllers are wired up a little differently on each, and (correct me if I’m wrong) the Arduino motor control library will only work with the ‘B’ (i.e. blue) baby boards (though they’re both quite nice).

Good luck with your Baby O!

-Adam

Ben…Adam…Many thanks!

Yes, I’ve got the AVRStudio and WINavr installed and all looks good. I really liked the looks of AVRStudio as it looked so much like MS Visual C++ 6.0 that I have used for years.

I did checkout the user’s guide on your site, but I danced all around the Arduino link thinking it was for another unreleated product. In checking this out, so far, I think this is what I was looking for. I’ve installed the software and followed the very helpful and detailed setup from the link and it all seems to work flawlessly!

Thanks to you guys I believe I can get a good start here.

Now…does anyone know where I can obtain some examples of connecting a brushed motor to the Baby O and some sample code to drive it bi-directionally? (forgive me if it’s somewhere in what you have already directed me to…if it is, I’m slowly working my way there.)

Btw, I’ve got the ‘Blue’ Baby O and I’m running Windows.

Thanks again…now my weekend and nights are completely full… :mrgreen: gotta find a way to explain to the wife… :unamused:

David

Glad to hear you’re off to a good start.

The Module Pinout and Component Identification page of the Baby Orangutan B user’s guide says where to hook up your motors, and lists the power specs.

If you want to continue working with AVR Studio take a look at the application note: Using the Motor Driver on the Orangutan LV-168 and Baby Orangutan B. It covers exactly what you want to do, starting with simple forward/stop/reverse, then progressing to true PWM speed control, and even some advanced bits like dealing with motor noise. Plus it’s a good primer for how to use the registers that control all the hardware on an AVR microcontroller, which will make the ~300 page datasheet much more readable! Let us know if the whole bit-shifting logic makes sense to you or not.

If you just want to get your motor up and running ASAP you could look into using the the motor control functions from the Pololu Arduino Libraries for the Orangutan. Most of the libraries will work on either the LV-Orangutans or the Baby Orangutan B’s (except where the Baby is lacking the necessary hardware, like an LCD screen for example). They’re written in C++ so actually you should be able to use them in AVR Studio (note: I haven’t tried this myself, but I can’t see why it wouldn’t work) as well as in the Arduino environment.

The Arduino language is an interesting reworking of C for beginners. There are extra simple statements you can use that are specific to ATMega168 hardware, but for the most part any C code should compile as well. The main thing to understand when looking at Arduino examples and translating them to normal C is that there is no ‘main’ function. Instead there are two functions called ''setup" and “loop.” As you can probably guess, the setup function runs first, and only once, then the loop function loops forever, which is the structure of most microcontroller programs anyway. Aside from that, Arduino programs are called ‘sketches’, and generally use the file extension ‘.pde’. It’s just text, so open it in notepad or AVR Studio or whatever (winavr comes with a nice code editor called Programmer’s Notepad too).

I hope this helps you along, but make sure you don’t ignore your wife all weekend.

-Adam

Adam, this is absolutely perfect! You are nothing less than a human ‘Wiki’-pedia…and thank you for taking the time to share this info. It would probably have taken me hours and hours to dig this up on my own.

With this information blast, I’ll easily blow away several weekends…not to mention every night… :wink:

Now that I’ll be getting my feet wet with my new Baby O, I know it will lead me into driving stepper motors too…does the ‘wiki’ have any leads on this?

I’ve got several projects to do and it looks like the Baby O will easily handle them all. One will be an annenometer and wind direction indicator. My idea is to create a train of pulses from a spinning set of cups, the frequency of which, would be dependant upon the speed of the wind. Has anyone used the Baby O to measure frequency of a pulse train? Is it possible with the Baby O? I guess I could rectify the pulse train into a varying DC voltage and simply measure that with the ADC…still working this all out. Haven’t really figured out the electronics for detecting the wind direction yet, but…this project is down the road and a ways off at this point.

Much to do and all of you have helped tremendously! Thanks again

David

You can definitely control one stepper motor from a Baby Orangutan, and there are a bunch of threads on these forums discussing how it can be done (a forum search for Stepper Motor turns up 60+ hits), most recently here. Be warned, the sample code in that thread is written for the mega168 Orangutan and Baby Orangutans, but can be easily adapted to the Baby B.

As for other things like measuring the frequency of a pulse train, it’s totally doable in a bunch of ways (directly I mean, without having to convert it to an analog voltage). You could use pin interrupts or an external counter input to count the pulses over a set period of time (better for fast pulse trains) or external interrupts again or a timer input capture pin to measure the time between pulses (better for slow pulse trains). Anyway, the short answer is yes, yes you can.

If you haven’t already, you should download and take a look through the complete ATMega168 datasheet. AVR’s have a lot of built-in hardware for you to use, and the datasheet is the complete guide to all of it. It’s pretty dense and unfriendly, but it’s also pretty well organized, and has nice things like C code examples.

-Adam

If you’re using the Baby Orangutan B under the Arduino environment, you can use the Arduino’s stepper motor library to control a stepper motor. To use the Arduino stepper library with the Baby Orangutan B you would do something like:

#include <Stepper.h>
#define STEPS 200 // the number of steps your stepper motor has in a full rotation

Stepper stepper(STEPS, 5, 6, 3, 11); // these are the pins connected to the motor driver inputs

Then you can use the stepper object’s various methods to control the stepper motor connected to your Baby Orangutan B’s motor driver outputs.

If you’re programming outside the Arduino environment, it’s not hard to write your own stepper motor control code.

- Ben

Wow…you guys are simply awesome!

This is really great help. Less than a day ago I was digging and tonight I’m sure I’ll be spinning a motor shaft.

thanks again…& will be back :slight_smile:

Dave