Pololu Robotics & Electronics
Menu
My account Comments or questions? About Pololu Contact Ordering information Distributors

Pololu Forum

Attaching 3 sensors problem


#1

I have connected 3 Sharp Sensors to the ADC7,ADC6,and PC5 ports.Then I removed the ADC7,ADC6,and PC5 jumpers.I’ve modified the Wall Following code to work with 3 sensors.
But the sensor that is connected to ADC6 doesn’t work.
Here is the code:

#include <pololu/3pi.h>
 
// This include file allows data to be stored in program space.  The
// ATmegaxx8 has 16x more flash than RAM, so large
// pieces of static data should be stored in program space.
#include <avr/pgmspace.h>
 
// Introductory messages.  The "PROGMEM" identifier causes the data to
// go into program space.
const char welcome_line1[] PROGMEM = " Pololu";
const char welcome_line2[] PROGMEM = "3\xf7 Robot";
const char name_line1[] PROGMEM = "Sharp";
const char name_line2[] PROGMEM = "Sensors";
 
// A couple of simple tunes, stored in program space.
const char welcome[] PROGMEM = ">g32>>c32";
const char go[]      PROGMEM = "L16 cdegreg4";
 
// Refresh the LCD display every tenth of a second.
const int display_interval_ms = 100;
 
#define MS_ELAPSED_IS(n) (get_ms() % n == 0)
#define TIME_TO_DISPLAY (MS_ELAPSED_IS(display_interval_ms))
 
void initialize()
{
        // Set PC5 as an input with internal pull-up disabled
        DDRC  &= ~(1<< PORTC5);
        PORTC &= ~(1<< PORTC5);

        // Play welcome music and display a message
        print_from_program_space(welcome_line1);
        lcd_goto_xy(0,1);
        print_from_program_space(welcome_line2);
        play_from_program_space(welcome);
        delay_ms(1000);
 
        clear();
        print_from_program_space(name_line1);
        lcd_goto_xy(0,1);
        print_from_program_space(name_line2);
        delay_ms(1000);
 
        // Display battery voltage and wait for button press
        while(!button_is_pressed(BUTTON_B))
        {
                clear();
                print_long(read_battery_millivolts());
                print("mV");
                lcd_goto_xy(0,1);
                print("Press B");
                delay_ms(100);
        }
 
        // Always wait for the button to be released so that 3pi doesn't
        // start moving until your hand is away from it.
        wait_for_button_release(BUTTON_B);
        clear();
        print("Go!");
 
        // Play music and wait for it to finish before we start driving.
        play_from_program_space(go);
        while(is_playing());
}
 
void back_up()
{
        if (TIME_TO_DISPLAY)
        {
                clear();
                lcd_goto_xy(0,0);
                print("Backing");
                lcd_goto_xy(0,1);
                print("Up");
        }
 
        // Back up slightly to the left
        set_motors(-50,-75);
}
 
void turn_in_place() {
        if (TIME_TO_DISPLAY) {
                clear();
                lcd_goto_xy(0,0);
                print("Front");
                lcd_goto_xy(0,1);
                print("Obstacle");
        }
 
        // Turn to the right
        set_motors(90, 50);
}
 
int main()
{
        // set up the 3pi
        initialize();
 
        int last_proximity    = 0;
        //const int base_speed  = 75;
        //const int set_point   = 100;
 
        // This is the "main loop" - it will run forever.
        while(1)
        {
                //In case it gets stuck: for 1 second every 15 seconds back up
                if (get_ms() % 15000 > 14000) {
                        back_up();
                        continue;
                }
 
                // If something is directly in front turn to the right in place
                int front_proximity = analog_read(5);
                if (front_proximity > 150) { 
                        turn_in_place();
                        continue;
                }
				int close_proximity = analog_read(6);
				if(close_proximity < 300) {
					turn_in_place();
					continue;
				}
 
                int proximity = analog_read(7); 
                int proportional = proximity - set_point;
                int derivative = proximity - last_proximity;
 
                // Proportional-Derivative Control Signal
                int pd = proportional / 3 + derivative * 20;
 
                int left_set  = base_speed + pd;
                int right_set = base_speed - pd;
 
                set_motors(left_set, right_set);
 
                if (TIME_TO_DISPLAY) {
                        clear();
                        lcd_goto_xy(0,0);
                        print_long(proximity);
 
                        lcd_goto_xy(5,0);
                        print_long(pd);
 
                        lcd_goto_xy(0,1);
                        print_long(left_set);
                        lcd_goto_xy(4,1);
                        print_long(right_set);
                }
 
                last_proximity = proximity; // remember last proximity for derivative
        }
 
        // This part of the code is never reached.  A robot should
        // never reach the end of its program, or unpredictable behavior
        // will result as random code starts getting executed.  If you
        // really want to stop all actions at some point, set your motors
        // to 0,0 and run the following command to loop forever:
        //
        // while(1);
}

Please help.

Thanks.


#2

Hello.

Can you please clarify what you mean when you say that “the sensor doesn’t work”, and can you also provide a much simpler program that demonstrates the problem (e.g. a few lines that print the sensor output to the LCD). Also, it would be helpful if you could specify exactly what sensors you are using and how they are connected.

I think you could benefit from the general suggestions on troubleshooting found in this thread:

- Ben


#3

Ok, sorry for that. I have connected a Pololu Carrier with Sharp GP2Y0D805Z0F Digital Distance Sensor 5cm
to ADC6 by soldering the OUT port to VCC, the GRD to Ground and VIN port to ADC6.Then I removed the ADC6 jumper. When I turn on the 3pi and look into the sensor, I see a faint red light in one of the LED’s, that means it is powered on.

So, here is the short code:

#include <pololu/3pi.h>

const int display_interval_ms = 100;

#define MS_ELAPSED_IS(n) (get_ms() % n == 0)
#define TIME_TO_DISPLAY (MS_ELAPSED_IS(display_interval_ms))

int main()
{

        // This is the "main loop" - it will run forever.
        while(1)
        {
               
				int proximity = analog_read(6);

				if(TIME_TO_DISPLAY)
				{

				clear();
				lcd_goto_xy(0,0);
				print_long(proximity);
                                }
           }
}

The LCD prints out numbers between 700 - 900, but the numbers don’t change
when I put my hand in front of the sensor.

Thanks for your patience,
Boris.


#4

This is not the correct way to connect the sensor. The OUT pin is the sensor output and should be connected to an I/O (e.g. ADC6). The VIN pin is sensor power and should be connected to VCC.

- Ben


#5

Thank you so much! It worked! Before I soldered it the first time, i had a slight idea that I
was wrong.
Right now I am working on a Pololu 3pi on-table Soccer-bot, I will post out my project
and code on the projects page when I am done.

Thanks,
Boris.


#6

I’m glad to hear it’s working now. Please note that incorrect connections can very easily permanently destroy your electronics, so you should do all you can to be confident in your connections before you make them. If you have some sense they might be wrong, look over them again or ask questions first!

- Ben