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

1 Like

Hello Kevin,

Thank you for posting the patch program to fix the EEPROM. The patch fixed my board successfully.
I’m very glad to use this OPT3101 sensor board with good distance precision.

I am really sorry for being very late for reporting the final result. Thanks again to you and the Pololu members.

Sincerely.

Tomonori Manome

1 Like

I am glad to hear that the fix worked for you! Thanks for letting us know.

Kevin

Hello Kevin.
I’m having a similar issue to Tom. My distance readings from the sensor are all over the place.
I’m using an arduino uno and the the advanced example included with the library (although the problem is also present when I use the Basic example)

Here’s an sample of the sensor output

> 663, 516, 87, 
> 620, 589, -53, 
> 657, 515, 260, 
> 638, 561, 181, 
> 657, 541, 154, 
> 613, 534, 86, 
> 667, 525, 353, 
> 631, 545, 167, 
> 663, 475, 272, 
> 615, 588, 100, 
> 646, 530, 213, 
> 618, 550, 45, 
> 637, 493, 158, 
> 596, 532, -7, 
> 639, 511, 319, 
> 609, 587, -83, 
> 637, 511, 130, 
> 617, 556, 182, 
> 639, 506, 218, 
> 632, 564, 116, 
> 641, 529, 329, 
> 601, 546, 82, 
> 627, 521, 217, 
> 603, 548, 231, 
> 639, 524, 195, 
> 601, 543, 146, 
> 634, 524, 105

And here’s the output of the ReadEEPROM example included with the library

EEPROM contents as a C string:
"\xB4\xF0\xB2\xF1\xB4\x94\x69\xD5\xB4\x08\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\x86\xF3\x4C\x30\x10\x0E\x20\x31\x62\x07\x5F\x32\x87\x59\xB0\x33\x5E\xEF\x4B\x34\xA8\xFD\x60\x35\x6A\xD4\x00\x36\x08\xDC\x00\x37\xF5\xDE\x00\x41\x2B\xFD\x29\x39\xD7\x8C\xF1\x3A\xDF\xC4\x4D\x3F\xC8\x08\x00\x41\x10\x80\x8C\x42\xB0\x3E\x00\x43\x83\x00\x00\x45\xDD\x85\x8C\x47\xC8\x08\x80\x48\xC8\x08\x00\x49\xC8\x08\x00\x51\x5E\x35\x00\x52\x5B\x3F\x00\x53\x71\x35\x00\x54\x47\x3D\x00\x55\x24\x35\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";

Serial number: 94-69-D5-08

Regards,
Nahuel

Hi, Nahuel.

It looks like your board’s EEPROM data might have been similarly corrupted. Could you try adding the line sensor.writeReg(0x38, 0x29FD2B); after sensor.init(); to see if that makes it better?

Kevin

A post was split to a new topic: OPT3101 troubleshooting help

A post was split to a new topic: OPT3101 with ESP32-WROOM troubleshooting help

Hi Kevin - I’ve also had problems with reading correct distances. I’ve ported the code to C, running on an NXP ARM microprocessor, and was getting bad values. Then, as a shot in the dark, applied the fix listed above - reg A0 = 0x2198 and now am getting values that make sense.

Is the eprom data specific for each board, or generic for the design? Can you send me a copy please so I can check the other values? Not sure if I can read the data directly from the eprom, but can compare with registers once the eprom load has completed.

Thanks, Andy H