Let's Make Robots!

3pi robot from Pololu

Hi, I just bought a 3pi robot from pololu.  So, the first thing I did was load up a program from the arduino enviorment to see how it worked.  Unfortunately, I could not understand how the sensors worked.  So I tried downloading the Libraries for it and hated them.  They were so complicated that they took up too much time to run on the 3pi.  So, Does anyone know of a sample code for the 3pi, preferably using the anologRead function, that does not use the 3pi libraries?

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.


The 3pi's reflectance sensors are digital sensors so it does not make sense to use analogRead with them. The Arduino's analogRead is also a blocking function and isn't significantly faster (once you've called it 5 times) than the Pololu3pi::read.

The timeout on Pololu3pi::read is configurable with the Pololu3pi::init function. With the default and the AVR's clock configured correctly, you should be able to read the line sensors more than 1000 times a second. How slow was it going for you and how did you measure it?

You can find more details about the library functions in the Pololu AVR Library Command Reference: http://www.pololu.com/docs/0J18/17

Here is more information about how the 3pi sensors work: http://www.pololu.com/docs/0J21/5.d 

- Ryan 


It wasn't the sensing that took up too much time - It was the conversion of forms.  The library saves the number reported as an int[1], int[2], int[3], ect    function depending on how many sensors you include when you set the program up.  The way i converted it took several seconds and could only be displayed on the LCD and could not be used in mathmatical functions.  What I need is a way to convert that to an normal int function that way i can use the number in an equation.  I looked on the arduino website and it said i could use the int(variable) function to change that variable to a number, but it automatically resets to 0 when i do.

Basically, i need some way to convert the int[5] into five different usable variables or find another code that will detect the line and return a normal int variable.

Thanks for helping,



Can you please post your code? I don't understand why you want to change an array into 5 different variables, but here is how you might do that: 

int a = array[0]; int b = array[1]; int c = array[2]; int d = array[3]; int e = array[4];

Normally, if you needed to read individual sensors, you could just access the array positions at the point where you needed the variable.

What kind of conversion were you doing, and how did you measure that it was taking too long?

- Ryan 

Ok, Thanks.  I only needed to change the array because I'm new to this and don't quite understand how to use them.  I converted the array to something i could use before by singling out each sensor and named it an array[1], but the problem was that the 3pi would take about two seconds before it reported the variable to the lcd screen. 

I measured this the old fasion way(one mississippi...)  which might not be accurate, but gave me a fair guess to how long it took. 

Not only that, but since the variable was an array i could not call it in a "if" statement, so i needed to convert it.  Or can you call that variable in an "if" satement if you name the array as array[1]?  something like this? ---->

if (array[2] = 30) {

      Do this


previously I had it where the variable was declared as variable[1] in a code similar too--->

if (variable[1] = 30) {

        do this


then it would come back and say error.  I'm guessing now that was because i didn't call the variable as variable[1]?

Unfortunately i can't post the original code because it was deleted. 

Thanks for your help.  I'll try converting the variable that way.


Your code will not work as espected. A single "equals" sign is used for assigning a value to a variable. You need a double "equals" sign (==) to check if the variable actually equals a value.

From what you say, it seems to me that your problem with it being slow was due to your code and not the library.

I can't exactly tell because you haven't posted any code showing initialization, but I think you might be confusing array initialization with array access. In both array initialization and access the [] characters are used. During initialization, the number between the []'s is the size of the array, and during access it is the location in the array.

Please post your code here, if you manage to reconstruct it and it is still giving you the problem you describe. I would be happy to look at it, and show you how to make it faster.


ok thanks.  AS far as the equal sign.  I did put the double.  the code above was just a reconstruction of the original and i forgot it above.  Ill try writing  a new code and post it soon.  Thanks