Conecting 3pi to a at89c2051 help

Hello everyone, I am working on a project to add a ping sensor and a MMA7341L 3-axis accelerometer for class and find that my pololu 3pi does not have enough pins. I have some at89c2051-24pu chips here and was wondering if they are compatible with the chip on the 3pi. I know they would have to connect through the serial port, would I be able to program both chips this way? If not, how can I program it, or is there a better chip to use? I am assuming I can attach the clock from the 3pi and use the second chip to control all the sensors. Am I wrong in my thinking? Is there anything anybody knows that could help? What we are trying to achieve is to have the bot avoid hitting an obstacle and return to its original path.

Thank you all for you time and advice in advance.

Hello, Grixlee.

Your questions make it sound like you are pretty new to working with microcontrollers, or at least not very familiar with the at89c2051 MCUs you have, which makes it seem like a bad idea to try to use them the way you are describing (e.g. accessing the clock on the 3pi is possible but not necessarily easy). Is it an option for you to use a more complete MCU module to read the sensors and control the 3pi, such as an Arduino, Baby Orangutan, or mbed?

By the way, you should be able to free up enough I/O on your 3pi to attach the sensors you mentioned directly. If you remove the PC5, ADC6, and ADC7 shorting blocks, you can use those three analog inputs for the accelerometer, and you can connect the Ping sensor to PD0.

- Ben

First, thank you Ben for a detailed and speedy reply. Very informative.

Is it an option for you to use a more complete MCU module to read the sensors and control the 3pi, such as an Arduino, Baby Orangutan, or mbed?

Possibly, the baby orangutan looks possible, I was trying to save $ and use what I had on hand. Would I need to get the programmer or can I use the one that came with the 3pi? Or can it be programed in series?

not very familiar with the at89c2051 MCUs

Not in the least, ordered parts for a project years ago, these showed up with them, don’t know why, did fry a few when I found a project on line for them, but that’s another story.

accessing the clock on the 3pi is possible but not necessarily easy

would it be easier to put its own crystal on? I did look up some of the info on these guys, they don’t look too complicated, but then again, neither did calculus…

PC5, ADC6, and ADC7 shorting blocks

ok, I was hoping to keep PC5 for edge detection on our table top adventure
ADC6 too, that’s the battery monitor right? I guess I can dump that if I need to
and ADC7 that’s just to set the brightness on the lcd

do you think that’s a good accelerometer? I noticed it’s 3.3v, if I do order the b org should I look at a better one like the LSM303DLM? It’s voltage regulated and it has a compass (would that help?)


Our USB AVR programmer is a general AVRISP programmer and can be used with both the 3pi and the Baby Orangutan.

Using a separate crystal is an option. I don’t know if that would be easier for you, though, since that depends on whether you have access to a crystal and whether you know how to hook it up. It’s not necessarily complicated, but if you don’t know what you’re doing, you can break things (as it seems you already discovered by frying a few of your AVRs), so I was suggesting you consider using higher-level components.

[quote]ok, I was hoping to keep PC5 for edge detection on our table top adventure
ADC6 too, that’s the battery monitor right? I guess I can dump that if I need to
and ADC7 that’s just to set the brightness on the lcd
It sounds like you might not fully understand what those shorting blocks are doing on the 3pi. The PC5 shorting block just gives you control of the emitters on the 3pi’s reflectance sensors. When the shorting block is removed, you can still use all the reflectance sensors (the emitters are just on all the time). You are correct about ADC6, but ADC7 has nothing to do with the LCD. ADC7 is tied to the user trimpot through the shorting block; this is separate from the trimpot that controls the LCD contrast.

Do you actually need all three axes of your accelerometer? If, for example, you don’t need Z, you could connect X and Y to PC5 and ADC7 (with their shorting blocks removed) and leave ADC6 as the battery monitor.

I am not sure what you are doing with the accelerometer, but the one you have could be fine. Do you have the version with a regulator? If not, powering it could be an issue. The LSM303DLM has an I2C interface, and the I2C pins on the 3pi are not available, so it might be somewhat tricky to use (you would basically need to use software I2C). If you feel like you could find or write a good software I2C routine for an AVR, then I think it would be a good sensor for you. Otherwise, I suggest you go with one of our analog accelerometers with a voltage regulator, selecting the one that has the appropriate sensitivity range for your project:

MMA7361L 3-Axis Accelerometer ±1.5/6g with Voltage Regulator
MMA7341L 3-Axis Accelerometer ±3/11g with Voltage Regulator

- Ben

Ah, yes very wise sensi

makes life easier, like the quote button

not really, isn’t learning fun (oh, and thank you for your time by the way sensi)

does this pull a lot of amps? will this drain the batteries alot faster?

well, we want it to go from point A to point B (like maybe a meter or two) and back again, with no line to follow, maybe a mark at point A and B. Then we put an object in its way and see if it can go around it and get back on course. Ok, it won’t let me paste from msword, but I have a simple flow chart of the idea

well I wasn’t planing to fly this time out, so I guess I don’t need z

what is this for?

Again, thank you for your time, you have been very helpful to our project

I just measured the IR emitter current draw on a 3pi and got 65 mA. If this additional current draw is too high for your application, one way around it would be to use a different pin for IR emitter control, such as PD1, which you could connect to the appropriate shorting block pin with a jumper wire. You could then drive PD1 high in your code before each sensor reading and drive it low again after to turn off the emitters.

I suspect achieving this kind of navigation from accelerometer feedback alone is going to be really tricky, especially because you are not going to be able to track rotations.

It’s just another optional user-interface element, like the user pushbuttons. For example, you could write a line-following program that gets its maximum speed from the position of the trimpot. For your first competition run, you could dial the speed down to something conservative and see how it handles the course. If it does well, you could make it faster for the next run. Or you could build a menu interface in and use the user pushbuttons for this kind of thing.

- Ben

Ok, I’ve been under the impression it could measure the angle it turns and measure the speed it moves over a given point time from witch I could calculate distance. I get the feeling from your last post I have misinformed myself. What would your recommendation be?

That sensor just measures linear acceleration. You can integrate that to get speed, and you can integrate again to get position, but you are going to get large errors that build up over time, and you have no information about rotation. To measure rotational, you probably want a gyro and/or a compass, so you might consider something like our MinIMU. With the MinIMU, you should be able to track orientation well, but tracking position is still going to be tricky and error-prone. Usually, you would want to use encoders for something like this, but, unfortunately, it is not easy to add encoders to the 3pi due to limited space and available I/O. Some people have done it, but it’s not something we could really help you much with.

One thing you could try to make use of is the fact that the motors are powered off a regulated (unchanging) voltage, so you get very repeatable performance. If you use the MinIMU to make sure you are driving in a straight line and to get your turns right, you might be able to achieve consistent straight-line distance just using timing.

- Ben

would this work do you think? LSM303DLM
the 3-axis accelerometer and 3-axis magnetometer - the magnetometer should show me relative angle in the x / y direction from start postition & the accelerometer should show me relative speed in any particular direction it moves. Is this correct?
the baby orangatang looks pretty good to me to power the sensors, any advice on how to wire them up? your wisdom has been very helpful sensi.

Again thank you for your time

You might be able to make it work, but I am still skeptical of using an accelerometer to keep track of speed/position. I am not sure how much the motors and batteries on the 3pi will affect the compass; you might need to mount it on a mast. You would probably get better rotational performance with a MinIMU, as the gyro is a more accurate sensor for tracking rotations in the short-term (the compass keeps it accurate over longer time scales). My suggestion is that you first try it without sensors and instead use hard-coded delays that you initially calibrate by trial and error (e.g. make a function that turns you right by 90 degrees, another one for turning left 90 degrees, and another for driving straight a fixed distance; you might need to drive your motors at slightly different set speeds so in order for the 3pi to go straight).

As far as how to wire everything up, you should spend some time looking into that yourself and ask if you have questions. We have quite a bit of documentation available online.

- Ben

Hi, me again, we were having trouble programming the adc7 pin.
While ((7) == high)
Will that work? We keep getting errors when we use ( adc7) but no errors when we use (pc5). How should we address the adc7 pin?

No. You are just comparing the number 7 to your variable “high”. To get the reading from adc7 you need to use the analog_read functions in the Pololu AVR Library Command Reference.

- Ryan

Ben and Ryan, I want to thank you for your help. If you want you can veiw the project here … F02F87!118
again thanks for your help.