John R McAlpine V Mac
Created April 7, 2018

Lidar distance sensor and IOT OLED remote display

Take a distance measurement in Hong Kong. Display it in Key West.

109
Lidar distance sensor and IOT OLED remote display

Story

Read more

Code

VL53L0X publish

Arduino
// This #include statement was automatically added by the Particle IDE.
#include <Adafruit_VL53L0X.h>

// This #include statement was automatically added by the Particle IDE.
#include <Adafruit_SSD1306.h>

//SYSTEM_THREAD(ENABLED);

#define VL53L0X_LOG_ENABLE 0
uint32_t _trace_level = TRACE_LEVEL_ALL; 

#if defined(PARTICLE) && (SYSTEM_VERSION >= 0x00060000)
SerialLogHandler logHandler(LOG_LEVEL_ALL);
#endif

Adafruit_VL53L0X lox = Adafruit_VL53L0X();
char publishString[40];

double mm =0;
double inches =0;
double filterinch=0;
double filterconstant=0;
double filtermm=0;

#include "Adafruit_GFX.h"

#define OLED_RESET D4
Adafruit_SSD1306 display(OLED_RESET);


const unsigned char MACSBOOST_Flag [] = {
 // 'mini macsboost logo3', 128x64px http://javl.github.io/image2cpp/
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xe7, 0xf8, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x0f, 0x00, 0x00, 0x00, 0x00, 
0x01, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x03, 0xff, 0xff, 0xf0, 0x00, 
0x00, 0x00, 0x7f, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x03, 0xc0, 0x7f, 0xe0, 0x80, 0x1f, 0xfc, 
0x00, 0x00, 0x00, 0x00, 0x3f, 0xf0, 0xc0, 0x00, 0x00, 0x03, 0x8f, 0xf0, 0x0c, 0xc0, 0x00, 0x06, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xf8, 0x00, 0x00, 0x01, 0xfe, 0x00, 0x1d, 0x80, 0x0f, 0xf8, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xce, 0x00, 0x00, 0x03, 0xe0, 0x00, 0x1f, 0x07, 0xf8, 0x0c, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xc3, 0xc0, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x3e, 0x00, 0xc4, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x78, 0x00, 0x30, 0x00, 0x3e, 0x01, 0xe0, 0x91, 0x34, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x0e, 0x07, 0xe0, 0x03, 0xfc, 0x07, 0x00, 0x6c, 0x8c, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x03, 0x9e, 0x60, 0x0e, 0x70, 0x1c, 0x7b, 0x23, 0x80, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0x00, 0xf0, 0xc0, 0x3f, 0xe0, 0x78, 0x98, 0xe0, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0xc0, 0x79, 0xc0, 0xe3, 0xcc, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0xe0, 0xf3, 0xc1, 0xc0, 0x80, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0xe0, 0xe3, 0xe3, 0x8f, 0x87, 0x33, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x60, 0x78, 0xc1, 0xe7, 0x80, 0x79, 0x66, 0x30, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x0f, 0x78, 0x3c, 0x00, 0xe3, 0xf8, 0x00, 0x9a, 0xc8, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xfe, 0x0f, 0x86, 0x00, 0x00, 0x1f, 0x80, 0x01, 0x08, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xe0, 0x01, 0xf3, 0x83, 0x00, 0x01, 0xfe, 0x00, 0x30, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x01, 0x80, 0x00, 0x07, 0xf0, 0xe0, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x01, 0xfc, 0x00, 0x00, 0x07, 0x80, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xc0, 0x01, 0xff, 0xff, 0xff, 0xf8, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x0f, 0x80, 0xff, 0xff, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xff, 0xfc, 0x1f, 0xef, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x03, 0x00, 0x30, 0x0c, 0x03, 0xfe, 0x7f, 0xdf, 0xfc, 0x7f, 0xc3, 0xfe, 0x3f, 0xdf, 0xfc, 0x00, 
0x07, 0x00, 0x70, 0x1e, 0x07, 0xfc, 0xff, 0x9f, 0xfc, 0xff, 0xc7, 0xfe, 0x7f, 0x9f, 0xfc, 0x00, 
0x07, 0x80, 0xe0, 0x3e, 0x07, 0x81, 0xf8, 0x3c, 0x3d, 0xe3, 0xcf, 0x1e, 0xf8, 0x03, 0xc0, 0x00, 
0x07, 0x81, 0xe0, 0x7e, 0x0f, 0x01, 0xfc, 0x3c, 0x39, 0xe3, 0xcf, 0x1e, 0xfc, 0x03, 0xc0, 0x00, 
0x07, 0xc3, 0xe0, 0xdf, 0x0f, 0x00, 0xfc, 0x3c, 0x73, 0xe3, 0x9f, 0x1c, 0x7e, 0x07, 0xc0, 0x00, 
0x0f, 0xcf, 0xc1, 0x9f, 0x1f, 0x00, 0xfe, 0x7f, 0xe3, 0xc7, 0x9e, 0x3c, 0x7f, 0x07, 0x80, 0x00, 
0x0f, 0xcf, 0xc3, 0x1f, 0x9f, 0x00, 0x7e, 0x78, 0xf3, 0xc7, 0x9e, 0x3c, 0x3f, 0x07, 0x80, 0x00, 
0x09, 0xfb, 0xc6, 0x0f, 0x9e, 0x00, 0x3f, 0x78, 0xf7, 0xc7, 0xbe, 0x3c, 0x3f, 0x8f, 0x9d, 0xd1, 
0x19, 0xf3, 0x8c, 0x0f, 0x9e, 0x00, 0x3f, 0x78, 0xf7, 0x8f, 0x3c, 0x78, 0x1f, 0x8f, 0x11, 0x5b, 
0x19, 0xe7, 0x9f, 0xe7, 0xdf, 0xf9, 0xfe, 0x7f, 0xe7, 0xff, 0x3f, 0xf9, 0xff, 0x0f, 0x11, 0x55, 
0x18, 0xc7, 0xbf, 0xe7, 0xcf, 0xf3, 0xfc, 0xff, 0xc3, 0xfe, 0x1f, 0xf3, 0xfe, 0x1f, 0x5d, 0xd1, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x21, 0x22, 0x79, 0xe7, 0x82, 0x27, 0x9e, 0x78, 0x22, 0x79, 0xef, 0xbc, 0x1e, 0x79, 0xe7, 0x9e, 
0x2d, 0x22, 0x41, 0x24, 0x03, 0x24, 0x10, 0x44, 0x36, 0x41, 0x02, 0x20, 0x10, 0x49, 0x04, 0x11, 
0x2d, 0x3e, 0x71, 0xe7, 0x02, 0xa7, 0x1c, 0x44, 0x2a, 0x71, 0xc2, 0x3c, 0x1e, 0x79, 0xc7, 0x11, 
0x12, 0x22, 0x41, 0x44, 0x02, 0x64, 0x10, 0x44, 0x2a, 0x41, 0x02, 0x04, 0x02, 0x41, 0x04, 0x11, 
0x12, 0x22, 0x79, 0x27, 0x82, 0x27, 0x9e, 0x78, 0x22, 0x79, 0xe2, 0x3c, 0x1e, 0x41, 0xe7, 0x9e, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};

void setup() {
 Particle.variable("mmsseen",mm);
 Particle.variable("filtermm",filtermm);
 Particle.variable("inchesseen",inches);
 Particle.variable("filterinch",filterinch);
 Serial.begin(230400);
 
 if (!lox.begin()) {
    Serial.println(F("Failed to boot VL53L0X"));
    Particle.publish("vl53l0x/booterror","");
 }   

 
 delay(2500);
 Serial.print("Hello World Distance Test Photon ");
 Serial.print("a demo for MEGR3171, Example VL53L0X lidar sensor");
 
  Wire.setSpeed(100000);  //may need to set speed slower if your I2C wires are long, have many devices
  
  // by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
  //display.begin(SSD1306_SWITCHCAPVCC, 0x3D);  // initialize with the I2C addr 0x3D (for the 128x64)
  //display.begin(SSD1306_SWITCHCAPVCC, 0x3c);  // initialize with the I2C addr 0x3D (for the 128x64)
  display.begin(SSD1306_SWITCHCAPVCC, 0x3D);  // initialize with the I2C addr 0x3D (for the 128x64)
  // init done

  delay(2000);
  display.clearDisplay();   // clears the screen and buffer
  
  display.drawBitmap(0,0,MACSBOOST_Flag, 128, 64, WHITE);
  display.display();

  delay(2000);
  display.invertDisplay(false);
 display.clearDisplay();   // clears the screen and buffer
  display.display();
  
}

void loop() {

 VL53L0X_RangingMeasurementData_t measure;

  Serial1.print("Reading a measurement... ");
  lox.rangingTest(&measure, true); // pass in 'true' to get debug data printout!
  //Particle.publish("vl53l0x/readerror","");
      
  if (measure.RangeStatus != 4) {  // phase failures have incorrect data
    Serial1.print("Distance (mm): "); 
    Serial1.println(measure.RangeMilliMeter);
    sprintf(publishString,"%d",measure.RangeMilliMeter);  //format distance to string for publishing
    Particle.publish("vl53l0x/mm",publishString);
    delay(2000);
  } else {
    Serial1.println(" out of range ");
    Particle.publish("vl53l0x/outofrange","");
    delay(2000);
  
  }
 //delay(100);
 mm = measure.RangeMilliMeter;
 inches = mm/25.4;
 filterinch = ((filterinch*filterconstant)+inches)/(filterconstant+1);
 filtermm = ((filtermm*filterconstant)+mm)/(filterconstant+1);
 Serial.print("mm ");
 Serial.print(mm);
 Serial.print(" inches ");
 Serial.println(inches);
 
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0,0);
  display.println("Inches");
  display.setCursor(0,20);
  //display.setTextColor(BLACK, WHITE); // 'inverted' text
  display.setTextColor(WHITE, BLACK); // 'standard text'
  display.setTextSize(4);
  display.println(filterinch);
  display.display();
 //delay(50);

}

OLED Subscribe

Arduino
// This #include statement was automatically added by the Particle IDE.
#include <Adafruit_SSD1306.h>

#include "Adafruit_GFX.h"

SYSTEM_THREAD(ENABLED);  //allows photon to boot without wifi connection

#define OLED_RESET D4
Adafruit_SSD1306 display(OLED_RESET);
Adafruit_SSD1306 displayb(OLED_RESET);

const unsigned char MACSBOOST_Flag [] = {
 // 'mini macsboost logo3', 128x64px http://javl.github.io/image2cpp/
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xe7, 0xf8, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x0f, 0x00, 0x00, 0x00, 0x00, 
0x01, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x03, 0xff, 0xff, 0xf0, 0x00, 
0x00, 0x00, 0x7f, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x03, 0xc0, 0x7f, 0xe0, 0x80, 0x1f, 0xfc, 
0x00, 0x00, 0x00, 0x00, 0x3f, 0xf0, 0xc0, 0x00, 0x00, 0x03, 0x8f, 0xf0, 0x0c, 0xc0, 0x00, 0x06, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xf8, 0x00, 0x00, 0x01, 0xfe, 0x00, 0x1d, 0x80, 0x0f, 0xf8, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xce, 0x00, 0x00, 0x03, 0xe0, 0x00, 0x1f, 0x07, 0xf8, 0x0c, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xc3, 0xc0, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x3e, 0x00, 0xc4, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x78, 0x00, 0x30, 0x00, 0x3e, 0x01, 0xe0, 0x91, 0x34, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x0e, 0x07, 0xe0, 0x03, 0xfc, 0x07, 0x00, 0x6c, 0x8c, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x03, 0x9e, 0x60, 0x0e, 0x70, 0x1c, 0x7b, 0x23, 0x80, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0x00, 0xf0, 0xc0, 0x3f, 0xe0, 0x78, 0x98, 0xe0, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0xc0, 0x79, 0xc0, 0xe3, 0xcc, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0xe0, 0xf3, 0xc1, 0xc0, 0x80, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0xe0, 0xe3, 0xe3, 0x8f, 0x87, 0x33, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x60, 0x78, 0xc1, 0xe7, 0x80, 0x79, 0x66, 0x30, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x0f, 0x78, 0x3c, 0x00, 0xe3, 0xf8, 0x00, 0x9a, 0xc8, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xfe, 0x0f, 0x86, 0x00, 0x00, 0x1f, 0x80, 0x01, 0x08, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xe0, 0x01, 0xf3, 0x83, 0x00, 0x01, 0xfe, 0x00, 0x30, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x01, 0x80, 0x00, 0x07, 0xf0, 0xe0, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x01, 0xfc, 0x00, 0x00, 0x07, 0x80, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xc0, 0x01, 0xff, 0xff, 0xff, 0xf8, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x0f, 0x80, 0xff, 0xff, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xff, 0xfc, 0x1f, 0xef, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x03, 0x00, 0x30, 0x0c, 0x03, 0xfe, 0x7f, 0xdf, 0xfc, 0x7f, 0xc3, 0xfe, 0x3f, 0xdf, 0xfc, 0x00, 
0x07, 0x00, 0x70, 0x1e, 0x07, 0xfc, 0xff, 0x9f, 0xfc, 0xff, 0xc7, 0xfe, 0x7f, 0x9f, 0xfc, 0x00, 
0x07, 0x80, 0xe0, 0x3e, 0x07, 0x81, 0xf8, 0x3c, 0x3d, 0xe3, 0xcf, 0x1e, 0xf8, 0x03, 0xc0, 0x00, 
0x07, 0x81, 0xe0, 0x7e, 0x0f, 0x01, 0xfc, 0x3c, 0x39, 0xe3, 0xcf, 0x1e, 0xfc, 0x03, 0xc0, 0x00, 
0x07, 0xc3, 0xe0, 0xdf, 0x0f, 0x00, 0xfc, 0x3c, 0x73, 0xe3, 0x9f, 0x1c, 0x7e, 0x07, 0xc0, 0x00, 
0x0f, 0xcf, 0xc1, 0x9f, 0x1f, 0x00, 0xfe, 0x7f, 0xe3, 0xc7, 0x9e, 0x3c, 0x7f, 0x07, 0x80, 0x00, 
0x0f, 0xcf, 0xc3, 0x1f, 0x9f, 0x00, 0x7e, 0x78, 0xf3, 0xc7, 0x9e, 0x3c, 0x3f, 0x07, 0x80, 0x00, 
0x09, 0xfb, 0xc6, 0x0f, 0x9e, 0x00, 0x3f, 0x78, 0xf7, 0xc7, 0xbe, 0x3c, 0x3f, 0x8f, 0x9d, 0xd1, 
0x19, 0xf3, 0x8c, 0x0f, 0x9e, 0x00, 0x3f, 0x78, 0xf7, 0x8f, 0x3c, 0x78, 0x1f, 0x8f, 0x11, 0x5b, 
0x19, 0xe7, 0x9f, 0xe7, 0xdf, 0xf9, 0xfe, 0x7f, 0xe7, 0xff, 0x3f, 0xf9, 0xff, 0x0f, 0x11, 0x55, 
0x18, 0xc7, 0xbf, 0xe7, 0xcf, 0xf3, 0xfc, 0xff, 0xc3, 0xfe, 0x1f, 0xf3, 0xfe, 0x1f, 0x5d, 0xd1, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x21, 0x22, 0x79, 0xe7, 0x82, 0x27, 0x9e, 0x78, 0x22, 0x79, 0xef, 0xbc, 0x1e, 0x79, 0xe7, 0x9e, 
0x2d, 0x22, 0x41, 0x24, 0x03, 0x24, 0x10, 0x44, 0x36, 0x41, 0x02, 0x20, 0x10, 0x49, 0x04, 0x11, 
0x2d, 0x3e, 0x71, 0xe7, 0x02, 0xa7, 0x1c, 0x44, 0x2a, 0x71, 0xc2, 0x3c, 0x1e, 0x79, 0xc7, 0x11, 
0x12, 0x22, 0x41, 0x44, 0x02, 0x64, 0x10, 0x44, 0x2a, 0x41, 0x02, 0x04, 0x02, 0x41, 0x04, 0x11, 
0x12, 0x22, 0x79, 0x27, 0x82, 0x27, 0x9e, 0x78, 0x22, 0x79, 0xe2, 0x3c, 0x1e, 0x41, 0xe7, 0x9e, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};

void setup() {
 Particle.variable("countsseen",counts);
 Particle.variable("filtercount",filtercount);
 Particle.variable("inchesseen",inches);
 Particle.variable("filterinch",filterinch);
 
 Particle.subscribe("vl53l0x/mm",doitnow,MY_DEVICES);
 
 
 Serial.begin(230400);
 delay(2500);
 Serial.print("Hello World Distance Test Photon ");
 
  Wire.setSpeed(400000);
  // by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
  //display.begin(SSD1306_SWITCHCAPVCC, 0x3D);  // initialize with the I2C addr 0x3D (for the 128x64)
  display.begin(SSD1306_SWITCHCAPVCC, 0x3c);  // initialize with the I2C addr 0x3D (for the 128x64)
    // init done
    
  displayb.begin(SSD1306_SWITCHCAPVCC, 0x3d);  // initialize with the I2C addr 0x3D (for the 128x64)
    // init don
  
  delay(2000);
  display.clearDisplay();   // clears the screen and buffer
  
  display.drawBitmap(0,0,MACSBOOST_Flag, 128, 64, WHITE);
  display.display();
  
  displayb.clearDisplay();   // clears the screen and buffer
  
  displayb.drawBitmap(0,0,MACSBOOST_Flag, 128, 64, WHITE);
  displayb.display();
  
  delay(2000);
 display.clearDisplay();   // clears the screen and buffer
  display.display(); //tell the display to show the buffer data
  
}

void loop() {
}

void doitnow(const char *event, String data){
  display.clearDisplay();   // clears the screen and buffer
  pinMode(D7, OUTPUT);
  digitalWrite(D7, HIGH);
  display.setTextSize(4);
  display.setTextColor(WHITE, BLACK); // 'normal text'
  //display.setTextColor(WHITE);
  display.setCursor(0,0);
  display.println(data);  // write data to display
  display.display();  //tell display to show the buffer data
  //display.setCursor(0,20);  //move cursor if desired
  delay(2000);
  digitalWrite(D7, LOW);
  
    
}

Credits

John R McAlpine V Mac
17 projects • 87 followers
www.MACSBOOST.com Assistant Teaching Professor at UNC Charlotte MEGR3171 Instrumentation, Motorsports Research
Contact

Comments

Please log in or sign up to comment.