Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

Adafruit Libraray for VL53L0x multiple objects Not Enough me
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Adafruit Libraray for VL53L0x multiple objects Not Enough me

by utsav2413 on Mon Jun 22, 2020 8:18 am

Hi,
I have Arduino Uno as a microcontroller board , and I am working with 3 VL53L0x sensors at a time.
Using your guidance given on https://learn.adafruit.com/adafruit-vl5 ... duino-code, I successfully write code for 2 VL53L0x sensors at a time and generated output also.
But when I am initializing 3 Objects for 3 different sensors My Arduino board run out of memory error.
My code is: -

Code: Select all | TOGGLE FULL SIZE
/*
 * Code For 3 sensors 22nd june 2020
*/

#include "Adafruit_VL53L0X.h"

Adafruit_VL53L0X sensor1 , sensor2 , sensor3  = Adafruit_VL53L0X();

void setup() {
  Serial.begin(115200);
  while (! Serial) {
    delay(1);
  }
 
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);

  digitalWrite(2,LOW);
  digitalWrite(3,LOW);
  digitalWrite(4,LOW);
 
  delay(10);
 
  digitalWrite(2,HIGH);
 
  Serial.println("Adafruit VL53L0X test sensor 1");
  if (!sensor1.begin(0x28)) {
    Serial.println(F("Failed to boot VL53L0X sensor 1"));
    while(1);
  }
 
  digitalWrite(3,HIGH);
  Serial.println("Adafruit VL53L0X test sensor 2");
  if (!sensor2.begin(0x29)) {
    Serial.println(F("Failed to boot VL53L0X sensor 2"));
    while(1);
  }

  digitalWrite(4,HIGH);
  Serial.println("Adafruit VL53L0X test sensor 3");
  if (!sensor3.begin(0x30)) {
    Serial.println(F("Failed to boot VL53L0X sensor 3"));
    while(1);
  }
  // power
  Serial.println(F("VL53L0X API Simple Ranging example\n\n"));
}


void loop() {
  VL53L0X_RangingMeasurementData_t measure ;
   
//  Serial.print("Reading a measurement... ");
  sensor1.rangingTest(&measure, false); // pass in 'true' to get debug data printout!

  Serial.print("Sensor 1 = ");
  if (measure.RangeStatus != 4) {  // phase failures have incorrect data
    Serial.print("Distance (mm): "); Serial.print(measure.RangeMilliMeter);
  } else {
    Serial.print("Infinity ");
  }
 
  sensor2.rangingTest(&measure, false); // pass in 'true' to get debug data printout!
  Serial.print("\t Sensor 2 =  ");
  if (measure.RangeStatus != 4) {  // phase failures have incorrect data
    Serial.print("Distance (mm): "); Serial.print(measure.RangeMilliMeter);
  } else {
    Serial.print("Infinity");
  }

  sensor3.rangingTest(&measure, false); // pass in 'true' to get debug data printout!
  Serial.print("\t Sensor 3 =  ");
  if (measure.RangeStatus != 4) {  // phase failures have incorrect data
    Serial.print("Distance (mm): "); Serial.println(measure.RangeMilliMeter);
  } else {
    Serial.println("Infinity ");
  }
  delay(100);
}


Generated Error:- ]

Code: Select all | TOGGLE FULL SIZE
Sketch uses 17230 bytes (53%) of program storage space. Maximum is 32256 bytes.
Global variables use 2200 bytes (107%) of dynamic memory, leaving -152 bytes for local variables. Maximum is 2048 bytes.data section exceeds available space in board


So Is this Error generated due to heavy library objects?
If yes then How can I solve this issue If I want to use the same library?
Or if I have to go with other libraries can you give me any kind of suggestions.

Thank You !!!

utsav2413
 
Posts: 1
Joined: Mon Jun 22, 2020 8:04 am

Re: Adafruit Libraray for VL53L0x multiple objects Not Enoug

by adafruit_support_bill on Mon Jun 22, 2020 8:37 am

The VL53L0x library is quite complex and requires a lot of dynamic memory. Most of the code is from the source provided by the manufacturer of the chip: STMicroelectronics. All of the other VL53L0x I have seen are also based on the manufacturer supplied code, so I would expect their memory requirements to be similar. Supporting 3 of these sensors is probably too much to ask from an Arduino UNO.

There are many more modern boards out with a lot more memory than the UNO. For example, the Metro M0 has 32K of RAM. That is 16 times as much as the UNO: https://www.adafruit.com/product/3505

adafruit_support_bill
 
Posts: 78759
Joined: Sat Feb 07, 2009 10:11 am

Please be positive and constructive with your questions and comments.