Menu

VL53L0X Library - State of development

2020-05-13
2020-05-25
<< < 1 2 (Page 2 of 2)
  • stan cartwright

    stan cartwright - 2020-05-20

    why is line 255 the error not line 252?

     

    Last edit: stan cartwright 2020-05-20
  • stan cartwright

    stan cartwright - 2020-05-20

    why is line 255 the error not line 252?

     
  • mmotte

    mmotte - 2020-05-21

    @Stan
    Would you please hook up the terminal and dump the registers on your 53L0X so I can compare to mine and to the initialization values.

    Here is the program to dump with and my dump of the registers.

    Thanks
    Mike

     
  • stan cartwright

    stan cartwright - 2020-05-21

    I get var not defined. When I define it I get the dump shown. It says deverror 11.

     

    Last edit: stan cartwright 2020-05-21
  • mmotte

    mmotte - 2020-05-21

    @stan
    Thanks for the info!
    I don't understand the error. It is only a byte so it should have auto dimensioned. This started to crop up after the readMulti was aligned with element 1 of the array instead of element 0. Before that I had subtracted 1 from the NumOfByteData variable and it recognized it as a variable. And it is actually Dimmed in the sub declaration.

    BR
    Mike

     
    • stan cartwright

      stan cartwright - 2020-05-21

      I do not use subs with parameters.
      Is it normal basic?
      Does it make programs more readable?
      Does it actually work?
      I prefer all vars dimmed at start and use option explicit. I think they are called global variables.
      I do not know why numofbytedata not defined showed for that line and other vars not dimmed passed.
      Evan has used the passing vars to subs in his include files and it, imho, makes it difficult to follow.
      @mmotte your first code did give deverror as 0 and then printed distance.
      Changed it to glcb display and ok.
      Gone odd since then, deverrors and behaving odd.
      Still thank you again for replying.

      This is your code that gives deverror 0 and shows distance.
      for mega328 and glcd ili9341

      ;vl53l0x converted from picaxe by mmotte
      ;to ili9341 glcd
      #chip mega328p, 16
      #option Explicit
      
      #include <glcd.h>
      #include <uno_mega328p.h >
      
          #define GLCD_TYPE GLCD_TYPE_ILI9341
      
          'Pin mappings for SPI - this GLCD driver supports Hardware SPI and Software SPI
          #define GLCD_DC       DIGITAL_8         ' Data command line
          #define GLCD_CS       DIGITAL_10          ' Chip select line
          #define GLCD_RESET    DIGITAL_9         ' Reset line
      
          #define GLCD_DI       DIGITAL_12          ' Data in | MISO    - Not used therefore not really required
          #define GLCD_DO       DIGITAL_11          ' Data out | MOSI
          #define GLCD_SCK      DIGITAL_13          ' Clock Line
      
      
      
      
      'Pin mappings for SPI - this GLCD driver supports Hardware SPI and Software SPI
      '#define GLCD_DC PortB.2 ;      DIGITAL_8         ' Data command line
      '#define GLCD_CS PortD.7 ;      DIGITAL_10          ' Chip select line
      '#define GLCD_RESET PortD.4 ;   DIGITAL_9         ' Reset line
      '#define GLCD_DI PortB.4 ;      DIGITAL_12          ' Data in | MISO    - Not used therefore not really required
      '#define GLCD_DO PortB.3 ;      DIGITAL_11          ' Data out | MOSI
      '#define GLCD_SCK PortB.5 ;     DIGITAL_13          ' Clock Line
      ;
      #define ILI9341_HardwareSPI
      ;
      ;now rename colours to make it easier to set up sprite data
      #define bk ILI9341_BLACK
      #define re ILI9341_RED
      #define gr ILI9341_GREEN
      #define bl ILI9341_BLUE
      #define wh ILI9341_WHITE
      #define pu ILI9341_PURPLE
      #define ye ILI9341_YELLOW
      #define cy ILI9341_CYAN
      #define dg ILI9341_D_GRAY
      #define lg ILI9341_L_GRAY
      #define si ILI9341_SILVER
      #define ma ILI9341_MAROON
      #define ol ILI9341_OLIVE
      #define li ILI9341_LIME
      #define aq ILI9341_AQUA
      #define te ILI9341_TEAL
      #define na ILI9341_NAVY
      #define fu ILI9341_FUCHSIA
      
          'GLCD selected extension font set. ASCII characters 31-254, the extended font uses 1358 bytes of program memory
          #define GLCD_EXTENDEDFONTSET1
          GLCDfntDefaultsize = 1
      
          'GLCDCLS  supports GLCDBackground as default
          'GLCDCLS  also support passing color parameter.
          'GLCDCLS [color]
      GLCDRotate ( Landscape )
      GLCDfntDefaultsize = 3
      GLCDCLS ILI9341_BLUE
      
      #define W_ADDRESS 0xEC
      #define R_ADDRESS 0xED
      #define VL53Dev 0x52
      
      #define HI2C_BAUD_RATE 400
      #define HI2C_DATA PORTC.5
      #define HI2C_CLOCK PORTC.4
      HI2CMode Master
      
      #define USART_BAUD_RATE 9600
      #define USART_TX_BLOCKING
      #define USART_DELAY 1 ms
      
      dim VL52ByteValue as byte
      dim VL52WordValue as word
      dim DATABUFFER_POINTER as byte
      
      
      'VL53L0x Registers Write and Read
      'No.  Command Return value  Description
      '1    0XA0    BYTE1,BYTE2   Word output mode, the output distance is (BYTE1 < 8) &BYTE2;
      '                       the conversion to 10 is the actual measurement distance, the unit is mm
      '2    0XA1    BYTE1,BYTE2   VL53L0X initialization (initialization time is 500mS)
      '3    0XB0    0XB0      The module baud rate is set to 9600, and it takes effect in time (default)
      '4    0XB1    0XB1      The module baud rate is set to 19200, and it takes effect in time
      '5    0XB2    0XB2      The module baud rate is set to 115200, and it takes effect in time
      '6    0XC0    0XC0      Set up as a long distance measurement mode (default)
      '7    0XC1    0XC1      Set up as a high-speed measurement model
      '8    0XC2    0XC2      Set to high precision measurement mode (measurement interval is greater than 180mS)
      '9    0XD0    0XD0      Set XSHUT to high level, module work normally and initialize module
      '10         0XD1          0XD1      Setting XSHUT to low level, VL53L0X closes
      '11         0XF0            BYTE1--BYTE4          Current baud rate (MSB)
      '                     BYTE5  0X00 long distance mode                                                    0X01 high speed measurement mode
      '                            0X02 high precision measurement mode
      '                     BYTE6  The status of the current XSHUT
      dim da(12) as byte
      dim devError,datoVL,tmp,addr,ctr,NumOfByteData as byte
      dim Distance,Signal,SPAD,Ambient as word
      
      
      ' Soft reset
      'hi2cout $89,($01)
          wr_byte_VL52 ( VL53Dev,0x89,  0x01 )
      
          wait 200 ms
      do
      'Sys range start
      ';hi2cout $00,($01)
          wr_byte_VL52 ( VL53Dev,0x00,  0x01 )
      
      'Read 12 raw data of Sensor:
      ;hi2cin $14,(da1,da2,da3,da4,da5,da6,da7,da8,da9,da10,da11,da12)
      rd_multi_verVL53  ( VL53Dev, 0x14, 12, Da() )
      
      'Resolve sensor errors
      devError = (Da(1) and 0x78)/8 ;>> 3 ' // Check for errors
      
      
      'Resolve info of sensor VL53L0x:
        'If devError = $00 or devError = $06 update Distance
        'If devError = $00 Or devError = $06Then
      devError = (Da(1) and 0x78)/8 ;>> 3 ' // Check for errors
      GLCDfntDefaultsize = 3
      GLCDDrawString 0,0,"Error "+str(devError)+"  ",wh
      ;if devError=0 then
        Distance=Da(10)*256+Da(11)
        GLCDDrawString (0,40,"Distance: ",wh)
        GLCDfntDefaultsize = 5
        GLCDDrawString (0,120, str(Distance)+"   mm  ",wh)
      
      loop
      
        sub rd_byte_verVL53( in VL53Dev as byte, in VL53Addr as byte, out VL53ByteVal as byte )
            ;read a single byte from an address
            #ifdef HI2C_DATA
                HI2CStart
                HI2CSend(VL53Dev)
                HI2CSend(VL53Addr)
                HI2CReStart
                HI2CSend(VL53Dev or 1)                   ;set the read flag
                HI2CReceive(VL53ByteVal, NACK)           ;read one byte and conclude
                HI2CStop
            #endif
      
            #ifdef I2C_DATA
                I2CStart                              ;generate a start signal
                I2CSend(VL53Dev)                       ;inidcate a write
                I2CSend(VL53Addr)
                I2CReStart
                I2CSend(VL53Dev or 1)                   ;set the read flag
                I2CReceive(VL53ByteVal, NACK)           ;read one byte and conclude
                I2CStop
                I2CAckPoll(VL53Dev)                ;wait for buffer write
            #endif
      
          end sub
      
      
          sub rd_word_verVL53( in VL53Dev as byte, in VL53Addr as byte, out VL53WordVal as word )
            ;read a single byte from an address
            #ifdef HI2C_DATA
                HI2CStart
                HI2CSend(VL53Dev)
                HI2CSend(VL53Addr)
                HI2CReStart
                HI2CSend(VL53Dev or 1)                   ;set the read flag
                HI2CReceive(VL53WordVal_h)           ;read one byte and conclude
                HI2CReceive(VL53WordVal, NACK)           ;read one byte and conclude
                HI2CStop
            #endif
      
            #ifdef I2C_DATA
                I2CStart                              ;generate a start signal
                I2CSend(VL53Dev)                       ;inidcate a write
                I2CSend(VL53Addr)
                I2CReStart
                I2CSend(VL53Dev or 1)                   ;set the read flag
                I2CReceive(VL53WordVal_h)           ;read one byte and conclude
                I2CReceive(VL53WordVal, NACK)           ;read one byte and conclude
                I2CStop
                I2CAckPoll(VL53Dev)                ;wait for buffer write
            #endif
      
          end sub
      
          sub rd_multi_verVL53  ( in VL53Dev as byte, in VL53Addr as byte,  in  NumOfByteData as byte, out DataBuffer() )
            'NumOfByteData--
            #ifdef I2C_DATA
                I2CStart
                I2CSend(VL53Dev)                 ;Send address
                I2CSend(VL53Addr)
                I2CReStart
                I2CSend(VL53Dev+1)               ;indicate a read operation
                For DataBuffer_Pointer = 0 to (NumOfByteData -1)
                    I2CReceive DataBuffer( DataBuffer_Pointer), ACK
                next
                I2CReceive BME280_DataBuffer( NumOfByteData ) , NACK
                I2CStop
            #endif
      
            #ifdef HI2C_DATA
                HI2CStart
                HI2CSend(VL53Dev)
                HI2CSend(VL53Addr)
                HI2CReStart
                HI2CSend(VL53Dev+1)               ;indicate a read operation
      
                For DataBuffer_Pointer = 0 to (NumOfByteData -1)
                    HI2CReceive DataBuffer( DataBuffer_Pointer), ACK
                next
                HI2CReceive DataBuffer( NumOfByteData   ), NACK
                HI2CStop
            #endif
      
      end sub
      
      
      
      
      sub wr_byte_VL52 ( in VL52Dev as byte, in VL52Address as byte,  in VL52_SendByte as byte )
      
            #ifdef I2C_DATA
                I2CStart
                I2CSend(VL52Dev)                 ;Send address
                I2CSend(VL52Address)
                I2CSend(VL52_SendByte)           ;Send data
                I2CStop
            #endif
      
            #ifdef HI2C_DATA
                HI2CStart
                HI2CSend(VL52Dev)
                HI2CSend(VL52Address)
                HI2CSend(VL52_SendByte)
                HI2CStop
            #endif
      
      end sub
      
       

      Last edit: stan cartwright 2020-05-21
  • Anobium

    Anobium - 2020-05-21

    I do not use subs with parameters.

    You should try. Makes the code resusable and reduces the RAM.

    Is it normal basic?

    Yes

    Does it make programs more readable?

    Yes. As the variables are stated in the sub/function not the user define variable.

    Does it actually work?

    Yes. Extensively.

    I prefer all vars dimmed at start and use option explicit. I think they are called global variables.

    This is good also.


    To help Mike. Remove all the GCLD and use something more common. Like HSerPrint.

     
  • mkstevo

    mkstevo - 2020-05-21

    I have to say, I use Subs with parameters and Functions as much as I can.

    In my eye it makes code much easier to understand.

     
  • stan cartwright

    stan cartwright - 2020-05-21

    I have to dim numofbytedata or I get compile error?no reason yet.
    mmotte's original code gave deverror as 0...that may be false
    and gave a change for distance.Seemedto work a bit.
    I do not see the reason for 2 arrays..da() and HI2CReceive DataBuffer( DataBuffer_Pointer), ACK
    other than translation from picaxe.
    It is because of the code and subs and vars I found it did not work using 1 array...but it could.

     

    Last edit: stan cartwright 2020-05-21
  • stan cartwright

    stan cartwright - 2020-05-21

    In mmotte;s original
    delete dim da(14) as byte

    add
    dim DataBuffer(12) as byte
    change
    rd_multi_verVL53 ( VL53Dev, 0x14, 12, DataBuffer() )
    devError = (DataBuffer(1) and 0x78)/8 ;>> 3 ' // Check for errors
    Distance=DataBuffer(10)*256+DataBuffer(11)

    now just 1 array...seems to work as before with glcd.

     
  • stan cartwright

    stan cartwright - 2020-05-21

    changing
    For DataBuffer_Pointer = 0 to (NumOfByteData-1) to For DataBuffer_Pointer = 1 to (NumOfByteData)
    HI2CReceive DataBuffer( DataBuffer_Pointer), ACK
    next
    HI2CReceive DataBuffer( NumOfByteData ), NACK
    HI2CStop
    gives numofbytedata invalid,not defined

     
  • stan cartwright

    stan cartwright - 2020-05-21

    It seems rd_multi_verVL53 ( VL53Dev, 0x14, 12, DataBuffer() ) has problems..

    If it was broken down to be simpler..understandable..what would it be?
    ...please. is there a problem ..or am I not bright?
    is it I am using mega328p,16?
    the first code mmotte posted worked.
    could in NumOfByteData as byte be a constant. It is defined where???
    Thanks again...I did not start this thread but shows others are interested in this device.

     
  • stan cartwright

    stan cartwright - 2020-05-22

    I got the core code down to

     dim ptr,buffer(13) as byte
    
             HI2CStart ;software restart
              HI2CSend(0x52)
              HI2CSend(0x89)
              HI2CSend(0x01)
              HI2CStop
    wait 200 ms
    
    do
              HI2CStart ;Sys Range Start
              HI2CSend(0x52)
              HI2CSend(0x00)
              HI2CSend(0x01)
              HI2CStop
    ;read array
              HI2CStart
              HI2CSend(0x52)
              HI2CSend(0x14)
              HI2CReStart
              HI2CSend(0x53)               ;indicate a read operation
              For ptr =1 to 13
                  HI2CReceive buffer(ptr), ACK
              next
              HI2CReceive buffer(13), NACK
              HI2CStop
    
    GLCDfntDefaultsize = 3
    GLCDDrawString 0,0,"Error "+str((buffer(2) and 0x78)/8)+"  ",wh
      GLCDDrawString (0,40,"Distance: ",wh)
      GLCDfntDefaultsize = 5
      GLCDDrawString (0,120, str(buffer(11)*256+buffer(12))+"   mm  ",wh)
    
    loop
    

    It works! only ptr and buffer(13) variables.
    Much simpler for just distance.
    https://www.youtube.com/watch?v=bqeT5oR1ERI&feature=youtu.be
    I still can't convert
    Then the distance in mm will be ready in registers 0x1E, 0x1F :

    hi2cin 0x1E,(b3,b2) ;read range in mm

    To convert from the two input bytes to word value w3:

    w3 = b3
    w3 = w3 * 256
    w3 = w3 | b2

     

    Last edit: stan cartwright 2020-05-22
  • stan cartwright

    stan cartwright - 2020-05-23

    This is shortened for terminal output

    #chip mega328p, 16
    #option Explicit
    ;for terminal distance out
    #define USART_BAUD_RATE 9600
    #define USART_TX_BLOCKING
    #define USART_DELAY 1 ms
    ;set up v53l0x
    #define HI2C_DATA PORTC.5;sda
    #define HI2C_CLOCK PORTC.4 ;scl
    #define HI2C_BAUD_RATE 400
    HI2CMode Master
    ;main Get Distance-------
    dim ptr,buffer(13) as byte
    
    HI2CStart ;software restart
    HI2CSend(0x52)
    HI2CSend(0x89)
    HI2CSend(0x01)
    HI2CStop
    wait 200 ms
    do ;------------------------
      HI2CStart ;Sys Range Start
      HI2CSend(0x52)
      HI2CSend(0x00)
      HI2CSend(0x01)
      HI2CStop
      HI2CStart
      HI2CSend(0x52)
      HI2CSend(0x14)
      HI2CReStart
      HI2CSend(0x53) ;indicate a read operation
      For ptr =1 to 12
        HI2CReceive buffer(ptr), ACK
      next
      HI2CReceive buffer(13), NACK
      HI2CStop
    wait 300 ms
      hserprint " Distance: "+str(buffer(11)*256+buffer(12))+" mm ";
    loop ;----------------------
    
     
  • stan cartwright

    stan cartwright - 2020-05-23

    hi2cin 0x1E,(b3,b2) ;read range in mm seems to be this in gcb

    HI2CStart ;read distance
    HI2CSend(0x52)
    HI2CSend(0x1e)
    HI2CReStart
    HI2CSend(0x52 or 1) ;set the read flag
    HI2CReceive(distance_hi) ;read one byte and conclude
    HI2CReceive(distance_lo, NACK) ;read one byte and conclude
    HI2CStop

    It must be possible to make hi2creceive like picaxe hi2cin

     
  • stan cartwright

    stan cartwright - 2020-05-23

    This uses my cobbled together hi2cin 0x1E,(b3,b2) to read distance and it works fine but please check it for me as it was more imagination than knowing what I was doing.

    #chip mega328p, 16
    #option Explicit
    ;for terminal distance out
    #define USART_BAUD_RATE 9600
    #define USART_TX_BLOCKING
    #define USART_DELAY 1 ms
    ;set up v53l0x
    #define HI2C_DATA PORTC.5;sda
    #define HI2C_CLOCK PORTC.4 ;scl
    #define HI2C_BAUD_RATE 400
    HI2CMode Master
    
    dim distance_lo,distance_hi as byte
    
    HI2CStart ;software restart
    HI2CSend(0x52)
    HI2CSend(0x89)
    HI2CSend(0x01)
    HI2CStop
    wait 200 ms
    do ;------------------------
      HI2CStart ;Sys Range Start
      HI2CSend(0x52)
      HI2CSend(0x00)
      HI2CSend(0x01)
      HI2CStop
    
      HI2CStart ;read distance
      HI2CSend(0x52)
      HI2CSend(0x1e)
      HI2CReStart
      HI2CSend(0x53) ;set the read flag
      HI2CReceive(distance_hi, ACK)
      HI2CReceive(distance_lo, NACK)
      HI2CStop
    
      hserprint " Distance: "+str(distance_hi*256+distance_lo)+" mm ";
     loop
    
     

    Last edit: stan cartwright 2020-05-23
  • stan cartwright

    stan cartwright - 2020-05-23

    I'm starting to like this device.Could be nice on a small robot vehicle.
    Does not like flesh,maybe it's infrared laser but even black denim it sees.

     
  • mmotte

    mmotte - 2020-05-24

    @Stan
    You have "minimalized " this to the nth. Y ou might be interested in one more step. One feature of GCB is the bytes of word and long are named HUE. So when distance is read as two bytes they can be automatically combined into a "word" variable "distance". Probably doesn't save you another line of code but you don't need to do the multiply and add.

    Dim Distance as word
    Dim Distance_Hi as Byte alias Distance_H
    Dim Distance_Lo  as Byte alias Distance
    ...
    'hserprint " Distance: "+str(distance_hi*256+distance_lo)+" mm " is replaced  by
    HSerPrint distance
    
      'later these were added so it isn't all strung together
      HSerPrintCRLF
      wait 1 s
    

    ironically , in my original code , I had a subroutine

    sub rd_word_verVL53( in VL53Dev as byte, in VL53Addr as byte, out VL53WordVal as word )
    

    That for Hardware I2C looks exactly like your broken out code BUT it don't read the two bytes from reg 0x1E and 0x1F as the word. it only reads the register 0x1F. returns 0 from 0x1E. Yours works and mine don't!

    Worse than that. I can not read the 0x14 register which is the status, by itself. If I Read Multiple reggisters like we were doing before it reads all the 12 regs from 0x14 to 0x1F and they read correctly. Reading just the one ox14 register would allow us to pick out the valid "range" reads . There is some strange going on.

    I had wanted to make a more general library that could be hooked up as both HI2C andI2C. Also the 53L0X has ability to send an interrupt on the GPIO1 pin to read the valid distance. Besides that it has settings for better distance or better accuracy. Lots to learn, what are SPADS and TCC. Why is the measurement not accurate? Mine is off by ~75mm.

    Just saying, i wouldn't consider this done.

    BR
    Mike

     
  • stan cartwright

    stan cartwright - 2020-05-25

    Nice Mike and thanks again...for the nth time.
    If you want to read the error code then

    HI2CStart ;software restart
    HI2CSend(0x52)
    HI2CSend(0x89)
    HI2CSend(0x01)
    HI2CStop
    wait 200 ms ;you need all this before reading anything-once at start of program. Don't need to run it again.
    
     HI2CStart ;this reads read error code
      HI2CSend(0x52)
      HI2CSend(0x15) ;register to read-this is error code change to 0x14 if you want
      HI2CReStart
      HI2CSend(0x53) ;set the read flag
      HI2CReceive errcode, NACK ;read one byte and conclude
      HI2CStop
    

    You read 12 bytes from 0x14 to array and 2nd element was error code which is usually 0.
    I gave credit to Buzby on picaxe forum but looking lately and Pongo needs some credit.
    It seems it was the proton basic program I posted that was altered to picaxe and that was half changed to gcb.
    The latest method is just read 0x14 hi byte and 0x15 hi byte for range.

    I did try dim distance as word then store 0x14 byte to distance_H and 0x15 byte to distance
    but distance was only the lo byte ie 0x15 so distance only went to 255 then back to 0.
    I used

    dim distance_lo,distance_hi,errcode as byte
    #define distance distance_hi*256 + distance_lo
    

    You don't dim distance as word or gives compile error.

    I don't consider this finished but we have ways to read and write registers now.
    You can change the i2c address and use multiple devices.
    It reads quite fast. It was the glcd slowing display rate.
    It probably does several samples/second. Add 5 then divide by 5.
    You used
    sub rd_word_verVL53( in VL53Dev as byte, in VL53Addr as byte, out VL53WordVal as word )
    Which seemed like Anobiums answer to David Briscoe.
    I lost track of the variables being passed so used the constants for the device as the code is no use for anything else it makes sense and is easier IMHO to follow what's going on.
    I have given you credit and didn't want the code to get lost over time as it might be as useful to someone else as it was for me. These devices have been in my box of bits too long. All I got was finding the i2c address from a gcb program in demos.

    The actual board has what looks like a regulator and DOES work off 5V...not 2.2-3.3V.
    As you said, no i2c pull ups needed...I was using 2.2K and 3.3V supply but they must be on the board.

    Only moan is short range which might not be a problem for a robot. It drops to 20 mm on over range as you said.
    cheers stan

    you could make a sub to return any reg value
    reg=0x14:getreg
    if regval=xx then....

    sub getreg
    HI2CStart
    HI2CSend(0x52)
    HI2CSend(reg) ;register to read
    HI2CReStart
    HI2CSend(0x53) ;set the read flag
    HI2CReceive regval, NACK ;read one byte and conclude
    HI2CStop
    end sub

    Way to read all 12 regs to array that doesn't give compile errors
    ~~~
    dim ptr,buffer(13) as byte
    ' HI2CStart
    ' HI2CSend(0x52)
    ' HI2CSend(0x14)
    ' HI2CReStart
    ' HI2CSend(0x53) ;indicate a read operation
    ' For ptr =1 to 12
    ' HI2CReceive buffer(ptr), ACK
    ' next
    ' HI2CReceive buffer(13), NACK
    ' HI2CStop
    ~~~
    error code is buffer(2)
    distance is str(buffer(11)*256+buffer(12))+" mm "
    I think the problem you had was using 2 arrays and getting the elements not corresponding to registers. The error with numofbytedata not defined...and couldn't be! got to me....that's why I simplified it...but I never got an answer to the compile error which referred to a line the variable was not on...all very confusing...that's is why I don't pass vars and keep it simple ie global vars dimmed at start...old style,need for speed,if you use a sub only once-put it in line.

    which is faster distance_hi256 +distance_lo..... or ... distance_hi256 or distance_lo...or even distance=fnLSL (distance _hi , 8 ) or distance_lo :)

     

    Last edit: stan cartwright 2020-05-25
  • stan cartwright

    stan cartwright - 2020-05-25

    Looking back to the first post...all the info is there

        sub rd_byte_verVL53( in VL53Dev as byte, in VL53Addr as byte, out VL53ByteVal as byte )
          ;read a single byte from an address
          #ifdef HI2C_DATA
              do
                HI2CReStart                              ;generate a start signal
                HI2CSend(VL53Dev)                       ;inidcate a write
              loop While HI2CAckPollState
              HI2CSend(VL53Addr)
              HI2CReStart
              HI2CSend(VL53Dev or 1)                   ;set the read flag
              HI2CReceive(VL53ByteVal, NACK)           ;read one byte and conclude
              HI2CStop
          #endif
    
          #ifdef I2C_DATA
              I2CStart                              ;generate a start signal
              I2CSend(VL53Dev)                       ;inidcate a write
              I2CSend(VL53Addr)
              I2CReStart
              I2CSend(VL53Dev or 1)                   ;set the read flag
              I2CReceive(VL53ByteVal, NACK)           ;read one byte and conclude
              I2CStop
              I2CAckPoll(VL53Dev)                ;wait for buffer write
          #endif
    
        end sub
    
    
        sub rd_word_verVL53( in VL53Dev as byte, in VL53Addr as byte, out VL53WordVal as word )
          ;read a single byte from an address
          #ifdef HI2C_DATA
              do
                HI2CReStart                              ;generate a start signal
                HI2CSend(VL53Dev)                       ;inidcate a write
              loop While HI2CAckPollState
              HI2CSend(VL53Addr)
              HI2CReStart
              HI2CSend(VL53Dev or 1)                   ;set the read flag
              HI2CReceive(VL53WordVal_h)           ;read one byte and conclude
              HI2CReceive(VL53WordVal, NACK)           ;read one byte and conclude
              HI2CStop
          #endif
    
          #ifdef I2C_DATA
              I2CStart                              ;generate a start signal
              I2CSend(VL53Dev)                       ;inidcate a write
              I2CSend(VL53Addr)
              I2CReStart
              I2CSend(VL53Dev or 1)                   ;set the read flag
              I2CReceive(VL53WordVal_h)           ;read one byte and conclude
              I2CReceive(VL53WordVal, NACK)           ;read one byte and conclude
              I2CStop
              I2CAckPoll(VL53Dev)                ;wait for buffer write
          #endif
    
        end sub
    
     
  • stan cartwright

    stan cartwright - 2020-05-25

    why the v53l0x is a pain
    this https://github.com/GrimbiXcode/VL53L0X-Register-Map
    and this may help you, got from arduino website

    register addresses from API vl53l0x_device.h (ordered as listed there)

    enum

    regAddr
    {

    SYSRANGE_START =

    0x00

    ,
    SYSTEM_THRESH_HIGH =

    0x0C

    ,
    SYSTEM_THRESH_LOW =

    0x0E

    ,
    SYSTEM_SEQUENCE_CONFIG =

    0x01

    ,
    SYSTEM_RANGE_CONFIG =

    0x09

    ,
    SYSTEM_INTERMEASUREMENT_PERIOD =

    0x04

    ,
    SYSTEM_INTERRUPT_CONFIG_GPIO =

    0x0A

    ,
    GPIO_HV_MUX_ACTIVE_HIGH =

    0x84

    ,
    SYSTEM_INTERRUPT_CLEAR =

    0x0B

    ,
    RESULT_INTERRUPT_STATUS =

    0x13

    ,
    RESULT_RANGE_STATUS =

    0x14

    ,
    RESULT_CORE_AMBIENT_WINDOW_EVENTS_RTN =

    0xBC

    ,
    RESULT_CORE_RANGING_TOTAL_EVENTS_RTN =

    0xC0

    ,
    RESULT_CORE_AMBIENT_WINDOW_EVENTS_REF =

    0xD0

    ,
    RESULT_CORE_RANGING_TOTAL_EVENTS_REF =

    0xD4

    ,
    RESULT_PEAK_SIGNAL_RATE_REF =

    0xB6

    ,
    ALGO_PART_TO_PART_RANGE_OFFSET_MM =

    0x28

    ,
    I2C_SLAVE_DEVICE_ADDRESS =

    0x8A

    ,
    MSRC_CONFIG_CONTROL =

    0x60

    ,
    PRE_RANGE_CONFIG_MIN_SNR =

    0x27

    ,
    PRE_RANGE_CONFIG_VALID_PHASE_LOW =

    0x56

    ,
    PRE_RANGE_CONFIG_VALID_PHASE_HIGH =

    0x57

    ,
    PRE_RANGE_MIN_COUNT_RATE_RTN_LIMIT =

    0x64

    ,
    FINAL_RANGE_CONFIG_MIN_SNR =

    0x67

    ,
    FINAL_RANGE_CONFIG_VALID_PHASE_LOW =

    0x47

    ,
    FINAL_RANGE_CONFIG_VALID_PHASE_HIGH =

    0x48

    ,
    FINAL_RANGE_CONFIG_MIN_COUNT_RATE_RTN_LIMIT =

    0x44

    ,
    PRE_RANGE_CONFIG_SIGMA_THRESH_HI =

    0x61

    ,
    PRE_RANGE_CONFIG_SIGMA_THRESH_LO =

    0x62

    ,
    PRE_RANGE_CONFIG_VCSEL_PERIOD =

    0x50

    ,
    PRE_RANGE_CONFIG_TIMEOUT_MACROP_HI =

    0x51

    ,
    PRE_RANGE_CONFIG_TIMEOUT_MACROP_LO =

    0x52

    ,
    SYSTEM_HISTOGRAM_BIN =

    0x81

    ,
    HISTOGRAM_CONFIG_INITIAL_PHASE_SELECT =

    0x33

    ,
    HISTOGRAM_CONFIG_READOUT_CTRL =

    0x55

    ,
    FINAL_RANGE_CONFIG_VCSEL_PERIOD =

    0x70

    ,
    FINAL_RANGE_CONFIG_TIMEOUT_MACROP_HI =

    0x71

    ,
    FINAL_RANGE_CONFIG_TIMEOUT_MACROP_LO =

    0x72

    ,
    CROSSTALK_COMPENSATION_PEAK_RATE_MCPS =

    0x20

    ,
    MSRC_CONFIG_TIMEOUT_MACROP =

    0x46

    ,
    SOFT_RESET_GO2_SOFT_RESET_N =

    0xBF

    ,
    IDENTIFICATION_MODEL_ID =

    0xC0

    ,
    IDENTIFICATION_REVISION_ID =

    0xC2

    ,
    OSC_CALIBRATE_VAL =

    0xF8

    ,
    GLOBAL_CONFIG_VCSEL_WIDTH =

    0x32

    ,
    GLOBAL_CONFIG_SPAD_ENABLES_REF_0 =

    0xB0

    ,
    GLOBAL_CONFIG_SPAD_ENABLES_REF_1 =

    0xB1

    ,
    GLOBAL_CONFIG_SPAD_ENABLES_REF_2 =

    0xB2

    ,
    GLOBAL_CONFIG_SPAD_ENABLES_REF_3 =

    0xB3

    ,
    GLOBAL_CONFIG_SPAD_ENABLES_REF_4 =

    0xB4

    ,
    GLOBAL_CONFIG_SPAD_ENABLES_REF_5 =

    0xB5

    ,
    GLOBAL_CONFIG_REF_EN_START_SELECT =

    0xB6

    ,
    DYNAMIC_SPAD_NUM_REQUESTED_REF_SPAD =

    0x4E

    ,
    DYNAMIC_SPAD_REF_EN_START_OFFSET =

    0x4F

    ,
    POWER_MANAGEMENT_GO1_POWER_FORCE =

    0x80

    ,
    VHV_CONFIG_PAD_SCL_SDA__EXTSUP_HV =

    0x89

    ,
    ALGO_PHASECAL_LIM =

    0x30

    ,
    ALGO_PHASECAL_CONFIG_TIMEOUT =

    0x30

     

    Last edit: stan cartwright 2020-05-26
<< < 1 2 (Page 2 of 2)

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.