cagiva
January 13, 2017, 6:39pm
1
Will it be possible to use the OpenMV M4 board with this VL53L0X sensor?
The interface is I2C, but the OpenMV board complains when I try to do “import smbus” and “import struct”
import smbus
import struct
import time
def bswap(val):
return struct.unpack('<H', struct.pack('>H', val))[0]
def mread_word_data(adr, reg):
return bswap(bus.read_word_data(adr, reg))
def mwrite_word_data(adr, reg, data):
return bus.write_word_data(adr, reg, bswap(data))
def makeuint16(lsb, msb):
return ((msb & 0xFF) << 8) | (lsb & 0xFF)
def VL53L0X_decode_vcsel_period(vcsel_period_reg):
# Converts the encoded VCSEL period register value into the real
# period in PLL clocks
vcsel_period_pclks = (vcsel_period_reg + 1) << 1;
return vcsel_period_pclks;
This file has been truncated. show original
cagiva
January 13, 2017, 8:30pm
2
After doing some searches, I see that the “struct” module is available (in a limited form) on the openmv board as “ustruct”. Unfortunately, “smbus” module was written specially for the microbit and will not work on the openmv board. I guess will have to adapt an existing driver.
cagiva:
After doing some searches, I see that the “struct” module is available (in a limited form) on the openmv board as “ustruct”. Unfortunately, “smbus” module was written specially for the microbit and will not work on the openmv board. I guess will have to adapt an existing driver.
I think you just need I2C, see Examples->02-Board-Control->i2c_control.py.
You should be able to port this driver, although I’d just start by reading/writing a register:
// Most of the functionality of this library is based on the VL53L0X API
// provided by ST (STSW-IMG005), and some of the explanatory comments are quoted
// or paraphrased from the API source code, API user manual (UM2039), and the
// VL53L0X datasheet.
#include "VL53L0X.h"
#include <Wire.h>
// Defines /////////////////////////////////////////////////////////////////////
// The Arduino two-wire interface uses a 7-bit number for the address,
// and sets the last bit correctly based on reads and writes
#define ADDRESS_DEFAULT 0b0101001
// Record the current time to check an upcoming timeout against
#define startTimeout() (timeout_start_ms = millis())
// Check if timeout is enabled (set to nonzero value) and has expired
#define checkTimeoutExpired() (io_timeout > 0 && ((uint16_t)(millis() - timeout_start_ms) > io_timeout))
This file has been truncated. show original