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

Pololu Forum

OPT3101 distance value (overflow?)

Hello,

I am trying to get 3 channel distance values from TI OPT3101 board from Pololu
with Arduino101(Intel Curie board) and sample library source code.

The following is the distance values output to the serial monitor.
It contains negative possibly overflowed value. I used my hand to check the distance.

I’d appreciate if someone could give me an advice.
Should I do some kind of calibration operation?, or Did I damaged the sensor hardware?

----------------------------

Amplitude0, Distance0, Amplitude1, Distance1, Amplitude2, Distance2
299,5483, 226,-3159, 460,-3505, 
299,5483, 226,-3159, 460,-3505, 
299,5483, 226,-3159, 460,-3505, 

----------------------------

Below is the OPT3101 sample source code(Advanced sample)
I’ve added Serial.begin(9600) line into the setup() function.

---------------------------
#include <OPT3101.h>
#include <Wire.h>

OPT3101 sensor;

uint16_t amplitudes[3];
int16_t distances[3];

void setup()
{
  Serial.begin(9600);
  Wire.begin();

  // Wait for the serial port to be opened before printing
  // messages (only applies to boards with native USB).
  while (!Serial) {}

  sensor.init();
  if (sensor.getLastError())
  {
    Serial.print(F("Failed to initialize OPT3101: error "));
    Serial.println(sensor.getLastError());
    while (1) {}
  }

  sensor.setFrameTiming(256);
  sensor.setChannel(0);
  sensor.setBrightness(OPT3101Brightness::Adaptive);

  sensor.startSample();
}

void loop()
{
  if (sensor.isSampleDone())
  {
    sensor.readOutputRegs();

    amplitudes[sensor.channelUsed] = sensor.amplitude;
    distances[sensor.channelUsed] = sensor.distanceMillimeters;

    if (sensor.channelUsed == 2)
    {
      for (uint8_t i = 0; i < 3; i++)
      {
        Serial.print(amplitudes[i]);
        Serial.print(',');
        Serial.print(distances[i]);
        Serial.print(", ");
      }
      Serial.println();
    }
    sensor.nextChannel();
    sensor.startSample();
  }
}

---------------------------

Kind Regards,
– Tomonori Manome

Hi, Tomonori.

I’m sorry to hear you are having trouble with your OPT3101 board. Could you please run the ReadEEPROM example from the library and show us what it outputs? Also, do you have a different Arduino, such as an Uno, that you can try using the sensor with?

Kevin

Hello, Kevin

Thank you for your reply and also thank you for the samples. OK, I will try different Arduino UNO board. Sorry it takes some time because currently my colleague is using it. The following is the result of the “ReadEEPROM” example with Arduino101(3.3V intel Curie).

Sincerely,
Tomonori Manome

p.s.
Please let me say, Thank you all for releasing OPT3101 sensor board with such an affordable price. I think this device may help low vision person who need smart cane like devices.

EEPROM contents as a C string:
"\xA0\x00\xB2\xF1\xB4\x50\xF5\x33\xB4\x85\x00\x00\x0B\x09\x00\x10\x0C\x00\x00\xBF\x29\xE4\x93\x2F\x2A\x20\x49\x7C\x2B\x78\x69\x00\x2C\xA7\x0B\x00\x2D\xBB\xE4\x5E\x2E\xA0\x01\x84\x2F\x23\xFB\x4C\x30\x17\x0D\x20\x31\x27\x1E\x5F\x32\xC6\x54\xB0\x33\xC9\xEF\x4B\x34\xF1\xFD\x60\x35\x2D\xCD\x00\x36\x3F\xD2\x00\x37\xC7\xE1\x00\x38\xF1\xFA\x29\x39\xEF\x8E\xF1\x3A\x24\xB1\x4D\x3F\xC8\x08\x00\x41\x10\x80\x8C\x42\xCE\x3D\x00\x43\x83\x00\x00\x45\xDD\x85\x8C\x47\xC8\x08\x80\x48\xC8\x08\x00\x49\xC8\x08\x00\x51\xB9\x33\x00\x52\xBC\x3C\x00\x53\xAE\x33\x00\x54\x4C\x3C\x00\x55\x79\x34\x00\x5E\x00\x63\x13\x5F\xF8\x16\xBB\x60\x1D\xEA\xD8\x61\xDF\x88\x00\x72\x50\x00\x00\x85\x7A\x26\x00\x86\x82\x26\x00\xB4\xD3\xE4\xE8\xB5\x01\x00\x00\xB8\x1A\x6C\x01\xB9\xA6\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF";

No metadata.

Hi, Tomonori.

Thanks for the EEPROM contents. It looks like the EEPROM data on your board might have been slightly corrupted (it includes information like calibration values for your specific board). Before we look into trying to fix it in the EEPROM, let’s see if we can work around it at runtime. Immediately after the Advanced example calls sensor.init(), could you try adding the line sensor.writeReg(0xA0, 0x2198); and see if that improves the sensor’s behavior?

By the way, thanks for pointing out that you had to add Serial.begin() to the examples in your first post; we are fixing that and should release an updated version of the library soon.

Kevin

Hello Kevin,

I’m really sorry for being very late in replying to your advice.

  sensor.init();
  sensor.writeReg(0xA0, 0x2198); 

By adding “sensor.writeReg(…);” line, my OPT3101 sensor board displayed correct distance values with
3.3V Arduino 101 (Intel Curie) board.
If possible, Can you please let me know how to fix the EEPROM data?

Thank you for your help, I’m very impressed by the 180 degree
performance of this sensor board. It’s a great work!

Sincreley,
– Tomonori Manome

Hi, Tomonori.

I’m glad to hear the workaround helped. Running this program should fix the issue permanently in the EEPROM data of your unit:

// Fixes the first two bytes of EEPROM on a Pololu OPT3101 board.
#include <OPT3101.h>
#include <Wire.h>
OPT3101 sensor;
const uint8_t eepromAddress = 0x50;
void setup()
                    
{
  Serial.begin(9600);
  Wire.begin();
  sensor.resetAndWait();
  while (!Serial) {}
  if (sensor.getLastError())
  {
    Serial.print(F("Failed to initialize OPT3101: error "));
    Serial.println(sensor.getLastError());
    while (1) {}
  }
  // Delay to avoid accidentally writing to EEPROM thousands of times.
  delay(5000);
  // FORCE_EN_BYPASS = 1: Lets us talk to the EEPROM.
  sensor.writeReg(0x00, 0x200000);
  Wire.beginTransmission(eepromAddress);
  Wire.write(0);
  Wire.write(0xB4);
  Wire.write(0xF0);
  uint8_t lastError = Wire.endTransmission();
  if (lastError)
  {
    Serial.println(F("Failed to write EEPROM."));
    while (1) {}
  }
  Serial.println(F("Wrote EEPROM."));
}
void loop()
                    
{
}

After running that program, you should be able to run the ReadEEPROM example again and confirm that the first two bytes are \xB4\xF0. (We can also check that it looks right if you post the full output here.)

Kevin