How to Open I2C Bus

Forums General discussion How to Open I2C Bus

This topic contains 22 replies, has 4 voices, and was last updated by  PeterP 1 year, 5 months ago.

Viewing 15 posts - 1 through 15 (of 23 total)
  • Author
    Posts
  • #4047

    Patrick
    Participant

    Hi!

    I'm a beginner working with the BerryIMU & Raspberry Pi for a university project. I am currently following the "Guide to interfacing a Gyro & Accelerometer with a Raspberry Pi" tutorial.

    So far, I have successfully detected the berryIMU using 'i2cdetect y -1'. My question is for the "Open I2C Bus" part.. how do i necessarily do that?

    Do i have to install something first? and how do i open the I2C Bus?

    Thanks 🙂

    #4051

    Mark Williams
    Keymaster

    Hi Patrick, did you follow the instructions on the page below?
    http://ozzmaker.com/i2c/

    Mark --OzzMaker.com --

    #4053

    Patrick
    Participant

    Yes, i did. I was able to get the addresses 🙂

    My concern now is the next step which says:

    -- First, you need to open the I2C bus device file, as follows;

    char filename[20];
    sprintf(filename, "/dev/i2c-%d", 1);
    file = open(filename, O_RDWR);
    if (file<0) {
    printf("Unable to open I2C bus!");
    exit(1);
    }

    How do I exactly do this? shall i type it on lxterminal? or make file. and the codes are "C".. so is there a need to install cmake? Please help me understand, thank you.

    #4055

    Mark Williams
    Keymaster

    The page explains the code that is linked at the top of the page. See the attached image

    A summary of the steps to get working code;

    Download the code;

    git clone http://github.com/ozzmaker/BerryIMU.git

    Enter the directory for this tutorial;

    cd BerryIMU/gyro_accelerometer_tutorial01

    Compile;

    gcc -o gyro_accelerometer_tutorial01 -l rt gyro_accelerometer_tutorial01.c -lm

    Run;

    sudo ./gyro_accelerometer_tutorial01

    Attachments:

    Mark --OzzMaker.com --

    #4063

    Patrick
    Participant

    Please bear with me.

    When i type "cd BerryIMU/gyro_accelerometer_tutorial01" it gives me an error that says

    "bash: cd: BerryIMU/gyro_accelerometer_tutorial01: No such file or directory"

    what could be the cause of this problem? Note: all of the codes are located in home/pi

    Although I've noticed that the tutorial codes are in ".c" format.. is the error connected to this?

    Thanks.

    #4065

    Mark Williams
    Keymaster

    do
    cd BerryIMU
    Then list the contents
    ls -l

    look for a directory similar to gyro_accelerometer_tutorial01. and then CD into the directory.

    I think it is gyro_accelerometer_tutorial01_angles

    Then compile

    Mark --OzzMaker.com --

    #4068

    Patrick
    Participant

    Thanks, I have succesfully interfaced the gyro with accelero.. complete with readings 🙂

    I have now moved to the Inclinometer tutorial and have experienced an error again.

    I have successfully installed SDL by typing --> [pi@raspberrypi ~ $ sudo apt-get install libsdl1.2-dev libsdl-image1.2-dev libsdl-gfx1.2-dev libi2c-dev]

    Then, I tried to complile by typing --> [pi@raspberrypi ~ $ gcc -o test test.c sdl-config –cflags sdl-config –libs] Its giving me multiple errors. Please see image attached.

    Am i right to assume that this is because i should type gyro_acclerometer_tutorial02.c instead of test.c?
    Because when i checked the codes, i didn't find any "test.c" file in any of the folders. What should I do?

    Thanks!

    #4073

    Mark Williams
    Keymaster

    When you are within the correct directory, compile with;
    gcc -o gyro_accelerometer_tutorial02 -lm gyro_accelerometer_tutorial02.csdl-config --cflagssdl-config --libs-lSDL_image -lSDL_gfx

    Mark --OzzMaker.com --

    #4077

    Mark Williams
    Keymaster

    Actually, go to the correct directory and view the README file. It will show the command to compile

    Mark --OzzMaker.com --

    #4087

    Patrick
    Participant

    Hi!

    I've already entered the correct directory, and when i tried to compile (referencing from the README file), I'm getting multiple errors regarding the file gyro_acclerometer_tutorial02_inclinometer.c. Please see image attached.

    Thanks.

    #4090

    Mark Williams
    Keymaster

    Those are not errors.. they are warnings. You can disregard them. The program should compile successfully

    Mark --OzzMaker.com --

    #4149

    Patrick
    Participant

    Hi!

    I'm trying the new codes for "compass with tilt compensation" and was able to compile.. but after that no output was being shown?

    What do i type next to run it? thanks.
    Please see image attached.

    #4151

    Mark Williams
    Keymaster

    Did you run the program with?;
    sudo ./compass_tutorial02

    Mark --OzzMaker.com --

    #4152

    Patrick
    Participant

    Yes, i did and it worked. Sorry for the stupid mistake 🙂

    Altho i have another question regarding the Plotting of Uncalibrated Output using Mathematica.

    In the guide it said "You will want to pipe the output to a file, which we will use for Mathematica."
    From what I understand, i should run sudo ./compass_tutorial01(uncalibrated compass) - copy the outputand save it as "rawdatauncalibrated.txt"

    I have done that and saved the txt file in home/pi folder. But when i type: pi@raspberrypi ~ $ sudo compass_tutorial01 > rawdatauncalibrated.txt it is telling command not found. (see image)

    #4155

    Mark Williams
    Keymaster

    The screenshot shows 'command not found'
    CD into the first tutorial directoy again;
    CD BerryIMU/compass_tutorial01_basics
    Then run the code
    sudo ./compass_tutorial01 > rawdatauncalibrated.txt
    BTW: You need to place './' in front of the executable. The guide was missing this.
    This tells Linux to look for the executable in the current directory.

    Mark --OzzMaker.com --

Viewing 15 posts - 1 through 15 (of 23 total)

You must be logged in to reply to this topic.

Blip, blop, bloop...