This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[FAQ] OPT3001: Is there example raspberry pi code for the OPT3001?

Part Number: OPT3001
  • I attached the daughter card of an OPT3001 EVM to the I2C bus of the raspberry pi and wrote some experimental code to operate it, with success!  Here are my notes and the code I used as I did this:

    Code: opt3001_c.txt

    Example Output File: opt3001_c_output.txt

    Some of my notes:

    Used raspibian image on SD Card

    Expanded filesystem

    $Raspi-config and turned on spi and i2c

     

    Edit the modules file

    sudo nano /etc/modules

    Add these lines:

    i2c-bcm2708
    i2c-dev

    Exit and save the file

     

    This step wasn’t needed, it wasn’t blacklisted:

    Now edit the modules blacklist file:

    sudo nano /etc/modprobe.d/raspi-blacklist.conf

    Add a '#' character to this line so it commented out:

    #blacklist i2c-bcm2708

    Exit and save the file

     

    ​Finally install the I2C utilities

    sudo apt-get install python-smbus i2c-tools

    Enter "sudo reboot" to restart the pi and now the I2C pins will be available to use

     

     

    This step I never checked if I had to do, and didn’t do it:

    If you are running a recent Raspberry Pi (3.18 kernel or higher) you will also need to update the /boot/config.txt file. Edit it with sudo nano /boot/config.txt and add the text

    dtparam=i2c1=on
    dtparam=i2c_arm=on

    at the bottom. note that the "1" in "i2c1" is a one not an L!

     

    Checking For Connected Devices

    At the command prompt type one of these depending on whether you are using the I2C0 or I2C1 port:

    sudo i2cdetect -y 0
    //or
    sudo i2cdetect -y 1

    The 7 bit I2C address of all found devices will be shown (ignoring the R/W bit, so I2C address 0000 0110 is displayed as hex 03).

    pi@raspberrypi ~ $ sudo i2cdetect -y 1

         0 1 2 3 4 5 6 7 8 9 a b c d e f

    00:         -- -- -- -- -- -- -- -- -- -- -- -- --

    10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

    20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

    30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

    40: -- -- -- -- 44 -- -- -- -- -- -- -- -- -- -- --

    50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

    60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

    70: -- -- -- -- -- -- -- --

    pi@raspberrypi ~ $

     

    Then I tried working with i2cset and i2cget:

    pi@raspberrypi ~ $ i2cset -y 1 0x44 0x01

    pi@raspberrypi ~ $ i2cget -y 1 0x44

    0xc8

    But I could only get bytes at a time.