Baby Orangutan 328P HELP!

As I said, I have no experience using that product, but the datasheet should make it clear how to use it. Have you tried looking through the datasheet?

- Ben

yes I have

Question, how do you assign an analog I/O as an input or output on the baby orangutan???

I know with the the digital it is
DDRD &= ~(1 << PD0); // make pin PD0 an input
PORTD |= (1 << PD0); // enable pull-up on pin PD0 (this means pin PD0
// will read as high unless externally driven low)
what would be the string for a analog I/O?

If you want to set a pin up as an analog input, you should configure it as a digital input with the internal pull-up disabled (or just disable the digital functionality for that pin entirely) and then perform the appropriate configuration of the ADC registers. Specifically, you should configure the ADMUX register to connect the pin to the ADC. You should also configure the ADC clock (I recommend using the CPU clock / 128) and a few other minor things. If you want a good example of how to set up the ADC registers, I suggest you take a look at the OrangutanAnalog source code that is included with the Pololu AVR library. Specifically, take a look at the read() function, which uses the startConversion() and conversionResult() functions.

- Ben

Ok I will take a look, thanks for the help.

I cannot find a clear example of how to declare an analog pin as an input or output. Can someone please clearly write out a simple C language declaration for me or direct me to a link that does. The only examples in the pololu library that are available do not illustrate how to declare a specific pin, it only has TRIMPOT…unless I am missing something, can someone please clear this up with a visual example.

The code in the Pololu AVR library lets you specify the specific pin you want to use as an analog input (it’s done using the argument to the read() function. If you don’t feel comfortable with variables, you can just go through the code and replace the channel argument with a constant (it will work with any channel from 0 to 7). Also, is there a reason why you don’t want to just use the Pololu AVR library functions for this?

- Ben

Thank you Ben! We got it to work! Our team is in a competition, but should we post our findings on the website when we’re done??

I’m glad to hear you got it working. We’d love to hear more about what you’re doing and how things turn out.

- Ben

We have programmed line following for our specific course specifications, object detection, and an analog input on the baby-o. I could explain the entire project but it’s too long for right now; need a lot of testing…LOL. I will upload some videos when I get a chance. We are, however, having issues programming the 3π to count the turns it makes. We do not want to use the maze solver programming, because it would hurt us more than help us. For some reason the programmer will not recognize numbers greater than 1. for example we set a for loop similar to this:

//In our line-following program there is an if statement for when sensors > 2850//
//this means there is a junction. So the robot will call this function to count junctions found//
//This function will count the number of junctions met; make 3 lefts on the 1st the junctions//
//and on the 4th turn make a long stop.
#include <pololu/3pi.h>
#include <avr/pgmspace.h>

motion()
{
 unsigned char junction=3;
 int i;
 for(i=0;i<junction;i++)
  {
   set_motors(0,80);
   delay_ms(200);
  }
  
  set_motors(0,0);
  set_delay(1000);
}

I have no idea what you mean by “For some reason the programmer will not recognize numbers greater than 1”, and I don’t understand what your example is trying to illustrate. You provided code and implied something is going wrong, but you don’t say what happens when you run it.

- Ben

when I run the program, the robot is not completing anything after the second increment. In the for loop i is increased from 0 to 2.
1st turn : i=0
2nd turn : i=1
3rd turn : i =2

on the fourth turn, I want the robot to stop. When I run the program, the robot comes to one turn, makes a left and then stops. We changed the program to an if, else if, else statement.

//this function counts the number of junctions.
//it will make three left turns at the first three junctions,
//and stop at the fourth junction.  

junction()
{
unsigned int junction=0; //set junction equal to 0 
 if(junction == 0)            // when junction equals 0 the first turn is made.
 {
  set_motors(0,80);         //a left is made
  delay_ms(200);
  junction=1;                 //junction is set to equal 1
 }
 else if(junction == 1)    // when junction equals 1, the second turn is made
 {
  set_motors(0,80);         //a left is made
  delay_ms(200);
  junction=2;                 //junction is set equal to 2
 }
 else if(junction ==2)    //when junction equals 2, the third turn is made 
 {
  set_motors(0,80);         //a left is made
  delay_ms(200);
  junction=3;                 //junction is set equal to 3
 }
 else                             //junction is greater than 2 so this is the fourth stop
 {
  set_motors(0,0);         //a stop is made
  delay_ms(1000);
 }
}

When I run the for loop or the if, else if, else statements the program stops following the routine after we set “junction” equal to 2. We even changed the program to have the robot stop when “junction” = 2, and the robot will not stop. We went back again and made one if statement, first we set junction = 0, and it worked. We then set it to 2, and it would not. We changed the program again and again and it will not perform any loop in which the value is greater than 1. It is only recognizing 0 and 1.

I’m still not really following you. It sounds like something in your program is not behaving as you would expect, which means you should simplify it as much as possible until the source of your program becomes evident. For example, if your program flow is not what you expect, use very simple indicators to tell you what part of the program is running (having the robot turn at intersections or stop is not simple). Program the 3pi to write to the LCD to tell you where in the program it is, or flash the user LEDs. You should be able to debug this entirely separately from the line-following/maze-solving code.

If you want help, please post the simplest complete program you can that demonstrates the problem, tell me what you expect to happen when you run the code, and tell me what actually happens.

- Ben