M3pi line reading issues

Hello pololulu forum. I’ve been testing my new m3pi line follower but have run into a few issues with regard to the detected line position. When i run the pre made line following and pid programs the robot runs perfectly fine. However when i created my own program that simply prints out the line position onto the lcd i keep getting weird values in the range of 0-50000 instead of the expected value between 0-4000. I’m programming on the mbed lpc microprocessor and suspect that the sensor values aren’t being transfered propery through the serial communication. Do you have any ideas why this is happening?

Note: I created my own intline_position function which has the same exact code at the line_position function except it returns an integer and doesn’t convert the acquired data packet into floating point. Either way neither my function nor the line_position function return appropriate values. The line_position function should return values between -1 and 1 but ends up showing floating point values like 15.0 and my function ends up showing integer like 50,000 instead of values between 0 and 4000

#include "mbed.h"
#include "m3pi.h"

m3pi m3pi;

int main() {
    int intpos = 0;
    m3pi.locate(0,0);
    m3pi.printf("Wait");
    wait(5);
    m3pi.cls();
    m3pi.printf("Go!");
    m3pi.sensor_auto_calibrate();
    int i = 0;
    while(1) {
    intpos = m3pi.intline_position();
    float position_of_line = m3pi.line_position();
    if(i==1000)
    {
      m3pi.cls();
      m3pi.locate(0,0);
      m3pi.printf("%7.1f",position_of_line);
      m3pi.locate(0,1);
      m3pi.printf("%7d",intpos);
      i=0;
    }
    i++;
    }  
}

Hello.

Can you post your complete code?

- Amanda

#include "mbed.h"
#include "m3pi.h"

m3pi m3pi;

int main() {
    int intpos = 0;
    m3pi.locate(0,0);
    m3pi.printf("Wait");
    wait(5);
    m3pi.cls();
    m3pi.printf("Go!");
    m3pi.sensor_auto_calibrate();
    int i = 0;
    while(1) {
    intpos = m3pi.intline_position();
    float position_of_line = m3pi.line_position();
    if(i==1000)
    {
      m3pi.cls();
      m3pi.locate(0,0);
      m3pi.printf("%7.1f",position_of_line);
      m3pi.locate(0,1);
      m3pi.printf("%7d",intpos);
      i=0;
    }
    i++;
    }  
}

We noticed you edited your first post with more information, including your code. We generally prefer people to create new posts in response to our questions and requests (e.g. posting code). That way it makes the discussion easier to follow, especially for others who might be having a similar issue.

Your code looks fine. (I was going to remark about intline_position() but then saw the note you added in your first post, explaining that it is a function you created.) Does “Wait” and “Go!” print correctly on the LCD screen? Can you try using the print() function in the m3pi library and let us know the results?

- Amanda