Zumo 32u4 and two Sharp GP2Y0A41SK0F sensors

Hi,

I’m working on MiniSumo robot based on Zumo 32u4.
I removed jumpers from front sensor array as well as front diodes to use external proximity sensors.
I’ve connected Sonar (HC-SR04) and two reflective distance sensors. Ports are defined as follows:

> #define PORT_SONAR_TRIG 14
> #define PORT_SONAR_ECHO 5
> #define PORT_SHARP_LEFT 2
> #define PORT_SHARP_RIGHT 6

In addition I have HC-06 bluetooth module connected for remote communication.
During tests I spotted strange behaviour of robot - mst probably connected to inaccurate distance measurements.

I simplified code to following:

    #include <Wire.h>
    #include <Zumo32U4.h>

    #define PORT_SHARP_LEFT 2
    #define PORT_SHARP_RIGHT 6

    Zumo32U4ButtonC buttonC;

    char report[120];

    void setup()
    {
    	Serial1.begin(9600);

    	buttonC.waitForButton();

    	delay(1000);
    	snprintf_P(report, sizeof(report),
    		PSTR("counter leftDistance rightDistance")
    		);

    	Serial1.println(report);
    }

    int counter = 0;

    void loop()
    {

    	counter++;

    	int leftDistance = SharpDistance(PORT_SHARP_LEFT);
    	int rightDistance = SharpDistance(PORT_SHARP_RIGHT);


    	snprintf_P(report, sizeof(report),
    		PSTR("%d %d %d"),
    		counter, leftDistance, rightDistance);

    	Serial1.println(report);
    }

    int SharpDistance(int port)
    {
    	int filtered = analogRead(port);
    	delay(25);

    	return filtered;
    }

Test: place robot directly facing wall (~15cm/~6inch distance)
Then created charts basing on received data. Please find in attached file for 2 different delays after analogRead.
VedderSharpIssueAnalysis.xlsx (333.3 KB)

Seems left and right sensor have inaccuracies occuring in regular phases. In addition - considering shift between readings (25 or 50ms), faults they seem to be of the same value, but with negative sign.

I’m out of options and have no clue on how to move forward - would appreciate any support.
Eager to provide more data.

Cheers,
Slomek

Hello, Slomek.

I looked at your code and did not see anything obviously wrong. From your graphs, it sounds like you are concerned about the spiked readings you are getting from both sensors when you expect to get steady readings of 160. Is that correct? Can you post pictures of your setup that clearly show how you have everything connected to the Zumo 32U4? Also, can you post a video showing how you are testing the sensors?

- Amanda