Menu

V53L0X

2020-05-24
2021-01-19
<< < 1 2 (Page 2 of 2)
  • Haroen

    Haroen - 2021-01-16

    Thanks, also putting #include <mega2560.h> helped.

     
    • Anobium

      Anobium - 2021-01-16

      Excellent stuff. It is cool to discover the solution!

       
  • Haroen

    Haroen - 2021-01-16

    Here I did some VL53LOX code adjustments for steady terminal readings without errors.
    It works great on my Arduino Nano but should work on a Uno too!

    #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
    dim distance as Word
    
    HI2CStart ;software restart
    HI2CSend(0x52)
    HI2CSend(0x89)
    HI2CSend(0x01)
    HI2CStop
    wait 200 ms
    
    do
      ;Sys Range Start
      HI2CStart
      HI2CSend(0x52)
      HI2CSend(0x00)
      HI2CSend(0x01)
      HI2CStop
      ;read distance
      HI2CStart
      HI2CSend(0x52)
      HI2CSend(0x1e)
      HI2CReStart
      HI2CSend(0x53) ;set the read flag
      HI2CReceive(distance_hi, ACK)
      HI2CReceive(distance_lo, NACK)
      HI2CStop
    
      'Code adjustments for steady readings without errors.
      distance=distance_hi*256+distance_lo
        Select Case distance
          Case 0
            'Skip errors
          Case 20
            'Skip errors
          Case <9
            hserprint " Distance:    "+str(distance)+" mm ";
            HSerPrintCRLF
          Case <99
            hserprint " Distance:   "+str(distance)+" mm ";
            HSerPrintCRLF
          Case <999
            hserprint " Distance:  "+str(distance)+" mm ";
            HSerPrintCRLF
          Case <2000
            hserprint " Distance: "+str(distance)+" mm ";
            HSerPrintCRLF
          Case >2000
            'Skip maximal errors
        End Select
     loop
    
     

    Last edit: Haroen 2021-01-17
  • stan cartwright

    stan cartwright - 2021-01-17

    Nice you got it working.
    ;set up v53l0x

    ;set up v53l0x
    #define HI2C_DATA PORTC.5;sda
    #define HI2C_CLOCK PORTC.4 ;scl
    

    for some reason I thought these were swapped but it's the lgt328 that has the pins swapped
    No,not swapped,your code?

    pc.5 is scl

     

    Last edit: stan cartwright 2021-01-17
  • stan cartwright

    stan cartwright - 2021-01-17

    I copied this from a robot vehicle code

    ;set up V53L0X
    #define HI2C_DATA PORTC.5 ;sda portc.4 for nano portc.5 for uno
    #define HI2C_CLOCK PORTC.4 ;scl portc.5 for nano portc.4 for uno
    #define HI2C_BAUD_RATE 400
    HI2CMode Master
    

    so I know it works but dunno where my confusion came from.

    I had no results from TOF 10120.
    tried i2c to terminal and serial to spi display. maybe broke but doubt it.
    any info on tof10120?

     
  • Haroen

    Haroen - 2021-01-17

    yes, I checked C.5 scl on the Nano leg a5.

    I will try the TOF10120 with gcb

     
  • stan cartwright

    stan cartwright - 2021-01-18

    I been working on it but will try again,
    like what is serial? distance and mm as 5 bytes so is that continuous?
    set up device as usart and terminal as usart1.. dunno.
    I checked it's id with i2c finder . brain ache

     
  • Haroen

    Haroen - 2021-01-19

    He Stan, for the TOF10120 I will post in your other topic TOF10120 conversion.

     
<< < 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.