Software help!

I am a total beginner to the world of micro-controllers…and C for that matter…

I purchased an Baby Orangutan 168 and i’ve powered it with 8 AA batteries so it can power 1 motor and a sharp distance sensor. I’m trying to make something very similar to this popsci.com/diy/article/2008- … car?page=1

After trying and testing everything I found out that the blinkLED program works…but i don’t even know how to make the motor turn on!

I connected two wires to the “M1” port but i don’t know how to tell the micro controller to turn on the motor.
Also, I don’t know where, and what Libraries i should download…

could someone please help me?

Hello.

There are a number of resources on our website to help you use the hardware on your Baby Orangutan:

If you have questions about any of the above documents, please ask.

- Ben

Thank you very much!
I finally got my motors to rev up to full speed!
I was looking at the code provided by Popular Science, and I was trying to edit out everything that i don’t need because I don’t have an LCD panel…but I don’t know how to make it work

Here’s the code: (btw what are the libraries that they’re using? I definately don’t have those…)

#include <OrangutanBuzzer.h>
#include <OrangutanMotors.h>
#include <OrangutanLCD.h>
#include <OrangutanAnalog.h>

/***************************
 * Arduino Muscle Car
 * PopSci.com
 * 28 July 2008
 *
 * Parts:
 * Orangutan LV-168; [www.pololu.com](https://www.pololu.com)
 * Sharp GP2D120
 * Nikko RC Car
 *
 * Power Orangutan from RC car battery pack-2 AA Ni-MH
 * Add drive motor to motor 1 output
 * Add steering motor to motor 2 output
 * Add Sharp sensor to pin PC4
 *
 * Distance formula for Sharp sensor adapted from:
 * [www.acroname.com/robotics/info/articles ... inear.html](http://www.acroname.com/robotics/info/articles/irlinear/irlinear.html)
 *
 */

OrangutanLCD lcd;
OrangutanMotors motors;
OrangutanBuzzer buzzer;
OrangutanAnalog analog;

int ledPin = 1;                // LED connected to digital pin 1

// Sharp sensor variables
int val;
int distance=0;

void setup()
{
  pinMode(ledPin, OUTPUT);      // sets the digital pin as output

// toot the horn
  buzzer.play("T240 L8 a gafaeada c+adaeafa <aa<bac#ada c#adaeaf4");
  
// Startup screen
  lcd.gotoXY(0, 0);
  lcd.print("PopSci");
  delay(500);
  lcd.gotoXY(0, 1);
  lcd.print("Robot");
  delay(1000);
  lcd.gotoXY(0, 1);
  lcd.print("Hummer");
  delay(1000);
  lcd.clear();

// set 10-bit analog-to-digital conversion
  analog.setMode(MODE_10_BIT);

  digitalWrite(ledPin, HIGH);   // sets the LED on
  delay(500);                  // waits
  digitalWrite(ledPin, LOW);    // sets the LED off
  delay(250);
  digitalWrite(ledPin, HIGH);
  delay(500);
  digitalWrite(ledPin, LOW);
}

void loop()
{
// setup motor speed
  int motorSpeed1 = 128;
  int motorSpeed2 = 0;

  lcd.gotoXY(0, 0);

// get temperature in tenths of a degree F
  unsigned int temp = analog.readTemperatureF();
  
  lcd.print(temp/10);
  lcd.print('.');
  lcd.print(temp - (temp/10)*10);
  lcd.print((char)223);
  lcd.print("F  ");
  
  delay(100);
  
  lcd.gotoXY(0, 1);

// calculate distance with Sharp sensor
  val = analogRead(4);
  distance = (2914/(val+5))-1;
  
  lcd.print(distance);
  lcd.print("cm    ");

// adjust motor speed for distance reading
  if (distance < 30) {
    motorSpeed1 = -128;
    motorSpeed2 = 255;
  }
  
  motors.setSpeeds(motorSpeed1, motorSpeed2);  // set speeds of motors 1 and 2
}

The reason it doesn’t work is because the article is programming the LV-168 using the Arduino environment rather than AVR Studio. The Arduino environment provides a number of library functions such as digitalWrite(). You have two options:

  1. Download the Arduino environment, modify it as necessary to work with your Baby Orangutan and programmer, and use it along with our Pololu Arduino libraries to run the Popsci code. You can find instructions for doing this here:

Programming Orangutans from the Arduino Environment

This document provides links to everything you need to download, instructions for configuring the environment as needed, and information about the Orangutan libraries used in the Popsci code.

  1. Download the Pololu AVR libraries and use AVR Studio to duplicate the Popsci code. In the Arduino environment, you define your own setup() and loop() functions. setup() is automatically executed once at the start of your program, and then loop() is automatically executed repeatedly for the duration of your program. You can duplicate this functionality by writing your own main() that does this same thing:
int main()
{
  setup();
  while (1)
    loop();

  return 0;
}

You will need to replace the digitalWrite() calls with your own code. Since it only seems to be used for control of the user LED on pin PD1, you can just use our LED library (part of the Pololu AVR library package), which gives you the functions red_led(0) and red_led(1) for turning the red user LED off and on respectively.

You will also need to replace all of the C++ library methods with C library functions. You can find these in the library command reference. For example, you would replace buzzer.play() with play(), and you would replace motors.setSpeeds() with set_motors(). You would also remove from your program the lines:

OrangutanLCD lcd;
OrangutanMotors motors;
OrangutanBuzzer buzzer;
OrangutanAnalog analog;

The Pololu AVR library user’s guide should give you all the information you need to get started using the library, but if something is confusing please ask for clarification.

- Ben

Thank you very much, that was a very detailed explanation! This will really help me use the little programing knowledge that I have and expand it! Thank you once again.

Hello,

I’m quite flustered at the moment, I am unable to write a program that takes the analog input and converts it to adjust motor speed. Currently I have programed it as so:

int main(void)
{
int val;
int distance=0;
int motorSpeed = 128;

val = analog_Read(4);
  distance = (2914/(val+5))-1;
if (distance < 30) {
    motorSpeed = -128;
    
set_motors(motorSpeed);
	}
}

I don’t even know how to make it loop…but that’s beside the point…

When I tell it to compile, It gives me two errors
1…/Motors.c:2: undefined reference to `analog_Read’
2…/Motors.c:12: undefined reference to `set_motors’

First of all, just to make sure, you have a Baby Orangutan B-168, a blue-colored board, not the older, green, baby orangutan, right?

Now, Ben was suggesting using the Arduino environment. Are you trying to do that? Or are you still using AVR Studio? Did you download the Pololu AVR C/C++ library?

It looks like you are trying to use Pololu library functions from C with AVR Studio. But you did not include pololu/orangutan.h according to the instructions. The function analog_read() should all be in lower-case (it matters!) and the function set_motors() needs to take two arguments, for motor 1 and motor 2. Finally, you should never just end your program: always have a line like

while(1);

at the end of main(), to prevent unexpected behavior. If you are using the Pololu AVR library, I recommend that you start by compiling one of the many included example programs. There is even one (motors1) that uses an analog input to set the motor speed!

Thank you very much this really helps!

I downloaded the Pololu library, and I used AVR studio to do this.
I did not know how to make the program loop, so I will try the “while(1)” (I knew of “While(1)” but I didn’t know exactly where to place it.
I will try these modifications hopefully they’ll work, so I can stop bugging you guys and help more advanced people!

Thanks again!

Okay, but if you continue to have trouble, please start by telling us exactly what board you have, and make sure you understand what I was saying about while(1) - it’s not to make the main part of your program loop, just to prevent it from doing strange things at the end. We’ll be happy to help you if you tell us more clearly what you are doing.

I have the (blue) Baby orangutan B-168 board.
I bought it for a school project which entails hooking up an IR sensor to the board and then using the board to control the motors.

It seems very simple but I’m unable to program this…Here’s a current version of my program:

#include <pololu/orangutan.h>
int main(void)
{
int val;
int distance=0;
int motorSpeed = 128;

  for (;;)
  {
     val = analog_read(4);
     distance = (2914/(val+5))-1;
     
	 if (distance < 30)
	 {
        motorSpeed = 10;
     } 
     set_motors (motorSpeed, motorSpeed);
  }
return (0);	
}

When I try to compile AVR studio gives me this error:

  1. Undefined reference to “analog_read”
  2. Undefined reference to “set_motors”

what am I doing wrong?

Okay, were you able to compile any of the example programs? That’s where you should start if you haven’t used the library before. It looks like your problem is that you didn’t set up your project file to link to the pololu library. You can find information about how to do this in the section of the documentation on using the Pololu Library in you own programs, or just copy one of the example project files. Other than that, I don’t see any problem with your code.

Thank you very much, now this program works! (I had forgotten to include the library into AVR studio)

unfortunately though, I have another problem, i need to set an if condition to slow the car down before it reaches the wall i’ve tried many possiblities and I have realized that for some reason, the program never goes to the second if condition.
here is my current program:

#include <pololu/orangutan.h>

int main(void)
{
for (;;)
  {
int val;
int distance=0;
int motorSpeed = 80;
red_led(0);

  
     val = analog_read(4);
     distance = (2914/(val+5))-1;
     if(distance < 18)
	 {
	 	motorSpeed = 40;
		red_led(0);
 	 }
	 set_motors (motorSpeed, motorSpeed);

distance = 0;

	 val = analog_read(4);
     distance = (2914/(val+5))-1;
	 if (distance < 30)
	 {
        motorSpeed = 0;
	 	
    	red_led(1);
     }	
	 

     set_motors (motorSpeed, motorSpeed);
  }
return (0);	
}

What am I doing wrong?

Good, it looks like you are making progress! Every line within your for(;:wink: loop is going to be executed over and over again. In particular, the motor speed will be reset to 80 immediately after it gets set to zero, every time, so the motors will never turn off. I think you probably wanted your initial settings to be placed outside of the loop, at the beginning of main().