峥小陈
发表于 2017-4-7 11:42
支持官方正品
fgnfxgn
发表于 2017-6-3 10:28
:L:L:L:lol:lol:lol呵呵呵
全天假日
发表于 2017-6-7 16:13
嗯,楼主的帮助很大,谢谢!
椰菜婆婆
发表于 2017-7-21 14:12
感谢大佬!seeeduino套件已入~准备学起来~哈哈
flzx
发表于 2017-9-29 22:38
新手学习
兔尾君
发表于 2017-10-7 11:29
在此马克,初学长存:loveliness:
single1
发表于 2017-10-7 16:29
#include <Wire.h>
#define VL53L0X_REG_IDENTIFICATION_MODEL_ID 0xc0
#define VL53L0X_REG_IDENTIFICATION_REVISION_ID 0xc2
#define VL53L0X_REG_PRE_RANGE_CONFIG_VCSEL_PERIOD 0x50
#define VL53L0X_REG_FINAL_RANGE_CONFIG_VCSEL_PERIOD 0x70
#define VL53L0X_REG_SYSRANGE_START 0x00
#define VL53L0X_REG_RESULT_INTERRUPT_STATUS 0x13
#define VL53L0X_REG_RESULT_RANGE_STATUS 0x14
#define address 0x29
byte gbuf;
void setup() {
// put your setup code here, to run once:
Wire.begin(0x52); // join i2c bus (address optional for master)
Serial.begin(9600);// start serial for output
Serial.println("VLX53LOX test started.");
}
void loop() {
void test();
Serial.println("----- START TEST ----");
test();
Serial.println("----- END TEST ----");
Serial.println("");
delay(1000);
}
void test() {
byte val1 = read_byte_data_at(VL53L0X_REG_IDENTIFICATION_REVISION_ID);
Serial.print("Revision ID: "); Serial.println(val1);
val1 = read_byte_data_at(VL53L0X_REG_IDENTIFICATION_MODEL_ID);
Serial.print("Device ID: "); Serial.println(val1);
val1 = read_byte_data_at(VL53L0X_REG_PRE_RANGE_CONFIG_VCSEL_PERIOD);
Serial.print("PRE_RANGE_CONFIG_VCSEL_PERIOD="); Serial.println(val1);
Serial.print(" decode: "); Serial.println(VL53L0X_decode_vcsel_period(val1));
val1 = read_byte_data_at(VL53L0X_REG_FINAL_RANGE_CONFIG_VCSEL_PERIOD);
Serial.print("FINAL_RANGE_CONFIG_VCSEL_PERIOD="); Serial.println(val1);
Serial.print(" decode: "); Serial.println(VL53L0X_decode_vcsel_period(val1));
write_byte_data_at(VL53L0X_REG_SYSRANGE_START, 0x01);
byte val = 0;
int cnt = 0;
while (cnt < 100) { // 1 second waiting time max
delay(10);
val = read_byte_data_at(VL53L0X_REG_RESULT_RANGE_STATUS);
if (val & 0x01) break;
cnt++;
}
if (val & 0x01) Serial.println("ready"); else Serial.println("not ready");
read_block_data_at(0x14, 12);
uint16_t acnt = makeuint16(gbuf, gbuf);
uint16_t scnt = makeuint16(gbuf, gbuf);
uint16_t dist = makeuint16(gbuf, gbuf);
byte DeviceRangeStatusInternal = ((gbuf & 0x78) >> 3);
Serial.print("ambient count: "); Serial.println(acnt);
Serial.print("signal count: ");Serial.println(scnt);
Serial.print("distance "); Serial.println(dist);
Serial.print("status: "); Serial.println(DeviceRangeStatusInternal);
}
uint16_t bswap(byte b[]) {
// Big Endian unsigned short to little endian unsigned short
uint16_t val = ((b << 8) & b);
return val;
}
uint16_t makeuint16(int lsb, int msb) {
return ((msb & 0xFF) << 8) | (lsb & 0xFF);
}
void write_byte_data(byte data) {
Wire.beginTransmission(address);
Wire.write(data);
Wire.endTransmission();
}
void write_byte_data_at(byte reg, byte data) {
// write data word at address and register
Wire.beginTransmission(address);
Wire.write(reg);
Wire.write(data);
Wire.endTransmission();
}
void write_word_data_at(byte reg, uint16_t data) {
// write data word at address and register
byte b0 = (data &0xFF);
byte b1 = ((data >> 8) && 0xFF);
Wire.beginTransmission(address);
Wire.write(reg);
Wire.write(b0);
Wire.write(b1);
Wire.endTransmission();
}
byte read_byte_data() {
Wire.requestFrom(address, 1);
while (Wire.available() < 1) delay(1);
byte b = Wire.read();
return b;
}
byte read_byte_data_at(byte reg) {
//write_byte_data((byte)0x00);
write_byte_data(reg);
Wire.requestFrom(address, 1);
while (Wire.available() < 1) delay(1);
byte b = Wire.read();
return b;
}
uint16_t read_word_data_at(byte reg) {
write_byte_data(reg);
Wire.requestFrom(address, 2);
while (Wire.available() < 2) delay(1);
gbuf = Wire.read();
gbuf = Wire.read();
return bswap(gbuf);
}
void read_block_data_at(byte reg, int sz) {
int i = 0;
write_byte_data(reg);
Wire.requestFrom(address, sz);
for (i=0; i<sz; i++) {
while (Wire.available() < 1) delay(1);
gbuf = Wire.read();
}
}
uint16_t VL53L0X_decode_vcsel_period(short vcsel_period_reg) {
// Converts the encoded VCSEL period register value into the real
// period in PLL clocks
uint16_t vcsel_period_pclks = (vcsel_period_reg + 1) << 1;
return vcsel_period_pclks;
}
宋天
发表于 2017-10-18 21:48
为了后续的开发省心,硬件保证是第一位的,深有体会,不然排查问题的时候会相当纠结!
lix20000
发表于 2017-12-29 10:58
小白学习:)
hjm258
发表于 2018-4-14 18:59
特来学习arduino
页:
1
2
3
4
5
6
7
[8]
9
10
11
12
13