BH1750FVI sample code available?



THE BOOK of DT's INTERRUPTS is an organization of interrupt service routines and other works written by Darrel Taylor, RIP.

Interrupt routines are arranged per Darrel's original list. Darrel Taylor's Instant Interrupts are an extension of the work of Tim Box whom in October of 2002 wrote INT_CTRL.pbp

Many of the forum members felt this is a long overdue project.

THE BOOK of DT's INTERRUPTS
will be a valuable resource and a tribute to Darrel Taylor the "Fanatical Contributor".

THE BOOK of DT's INTERRUPTS is located at http://dt.picbasic.co.uk/

+ Reply to Thread
Results 1 to 15 of 15

Hybrid View

  1. #1
    Join Date
    Feb 2013
    Posts
    875

    Default BH1750FVI sample code available?

    Hello.

    I want to use this module with picbasic pro to read light intensity. Datasheet lists ideas how should this IC should be treated, however, it is quite hard to understand, since I never used I2C devices before. And reference manual lists only simple I2C code, without showing how to use these square and figure data. Nor samples included with compiler provide any useful I2C usage clues.

    As I understand from datasheet, I need to write some value into device, then wait some time, and then read measured light amount. But how exactly - remains unclear. There's picaxe tread on this, but their syntax appears to be completely different:

    http://www.picaxeforum.co.uk/showthr...-with-a-Picaxe

  2. #2
    Join Date
    Feb 2013
    Posts
    875


    Did you find this post helpful? Yes | No

    Default Re: criteria percussionist ugg boots shop

    For example, i2cmast.pbp exempt:

    Code:
    mainloop:
       I2CWrite SDA,SCL,$02,[127], bogus    ' Write offset to slave
       Pause 500               
    
       I2CRead SDA,SCL,$02,[STR a\8], bogus ' Read string from slave
          
       LCDOut $fe, 1, STR a\5,SDEC a[5]     ' Display result, preceded by 5 character
                                            ' string received from slave.
       Pause 500
       GoTo mainloop                        ' Do it forever
    
    bogus:
       LCDOut $fe,1, "timed out"            ' I2C command timed out
       Pause 1000
       GoTo mainloop
    
       End
    what is "bogus" here and what it does?

  3. #3
    Join Date
    Feb 2013
    Posts
    875


    Did you find this post helpful? Yes | No

    Default Re: criteria percussionist ugg boots shop

    OK, got clear with "bogus" but still no idea how to interpret datasheet to I2CWRITE/READ .

  4. #4
    Join Date
    Feb 2013
    Posts
    875


    Did you find this post helpful? Yes | No

    Default Re: BH1750FVI sample code available?

    8 years passed and now I'm giving it 2nd try, but it still does not works (returns 58317 constantly). Here's code:

    Code:
    ldta  var porta.6 
    lclk  var porta.3        
    
    
    x var word
    adr var byte
    adr=23
    
    
    i2cwrite ldta, lclk, adr, %0100011
    pause 200
    i2cwrite ldta, lclk, adr, %00010001
    pause 200
    maik:
    i2cread ldta, lclk, adr, %0100011, x 
    pause 200
    lcdout $fe, $1, dec x
    pause 200
    goto maik
    Here's the module https://www.addicore.com/BH1750FVI-p/ad290.htm
    With arduino it works fine, tested.

    Here's screenshot from datasheet, based on which I wrote the above code.

    Name:  datasheet.jpg
Views: 63
Size:  240.3 KB

  5. #5
    Join Date
    May 2013
    Location
    australia
    Posts
    2,118


    Did you find this post helpful? Yes | No

    Default Re: BH1750FVI sample code available?

    each and every i2c command has incorrect syntax
    Warning I'm not a teacher

  6. #6
    Join Date
    Feb 2013
    Posts
    875


    Did you find this post helpful? Yes | No

    Default Re: BH1750FVI sample code available?

    Well, I tried to use what I already have working for DS3231
    Manual is not very clear about I2C....

  7. #7
    Join Date
    Feb 2013
    Posts
    875


    Did you find this post helpful? Yes | No

    Default Re: BH1750FVI sample code available?

    Changed syntax, still getting zeroes, what I'm doing wrong?

    Code:
    ldta  var porta.6 
    lclk  var porta.3        
    
    x var word
    y var byte
    z var byte
    cnt var byte 'control word
    adr var byte
    sda var portc.0
    scl var portc.1
    lcdout $fe, $01, " "
    adr=$23
    x=0
    
    cnt=%0100011
    i2cwrite ldta, lclk, cnt, adr
    pause 200
    cnt=%00010001
    i2cwrite ldta, lclk, cnt, adr 
    pause 200
    maik:
    cnt=%0100011
    i2cread ldta, lclk, cnt, adr, x 
    pause 200
    lcdout $fe, $1, dec x
    pause 200
    goto maik

  8. #8
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    910


    Did you find this post helpful? Yes | No

    Default Re: BH1750FVI sample code available?

    1 - use the appropriate I2C address for the device based on the hardware pin state
    2) Slave Address
    Slave Address is 2 types, it is determined by ADDR Terminal
    ADDR = H ( ADDR ≧ 0.7VCC ) → 1011100
    ADDR = 'L' ( ADDR ≦ 0.3VCC ) → 0100011


    2 - the device address for case 1 is $B8 and case 2 is $46 (use one of these values in cnt)
    When you put the address as shown in your code, the leading bit is 0 and the address will be $5c or $23. This is definitely wrong.

    3 - cnt remains the same for I2CWrite and I2CRead. the least significant bit is changed internally by the compiler depending on whether the command is a read or write

  9. #9
    Join Date
    Feb 2013
    Posts
    875


    Did you find this post helpful? Yes | No

    Default Re: BH1750FVI sample code available?

    Thanks!
    Tried both, none works, so I guess, I'm missing something else too...

Similar Threads

  1. please who can help me for sample code
    By jasem700 in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 22nd February 2009, 20:41
  2. USBJADEM sample code
    By SterlingY in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 14th March 2007, 00:57
  3. sample code for M25P32
    By Pedro Santos in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 9th January 2007, 02:37
  4. Sample code for pwm
    By Md.Shah in forum mel PIC BASIC
    Replies: 1
    Last Post: - 10th October 2006, 16:59
  5. 12F675 code sample
    By marad73 in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 23rd May 2006, 13:53

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts