Home › Forums › Forums › General discussion › How to Open I2C Bus
- This topic has 22 replies, 4 voices, and was last updated 4 years, 11 months ago by PeterP.
- AuthorPosts
- May 27, 2015 at 1:13 am #4047PatrickParticipant
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 ๐
May 27, 2015 at 3:54 am #4051Mark WilliamsKeymasterHi Patrick, did you follow the instructions on the page below?
https://ozzmaker.com/i2c/Mark --OzzMaker.com --
May 27, 2015 at 4:50 am #4053PatrickParticipantYes, 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.
Attachments:
May 27, 2015 at 5:56 am #4055Mark WilliamsKeymasterThe 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 --
May 28, 2015 at 12:04 am #4063PatrickParticipantPlease 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.
Attachments:
May 28, 2015 at 12:49 am #4065Mark WilliamsKeymasterdo
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 --
May 28, 2015 at 5:07 am #4068PatrickParticipantThanks, 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!
May 28, 2015 at 5:57 am #4073Mark WilliamsKeymasterWhen you are within the correct directory, compile with;
gcc -o gyro_accelerometer_tutorial02 -lm gyro_accelerometer_tutorial02.csdl-config --cflags
sdl-config --libs
-lSDL_image -lSDL_gfxMark --OzzMaker.com --
May 28, 2015 at 6:00 am #4077Mark WilliamsKeymasterActually, go to the correct directory and view the README file. It will show the command to compile
Mark --OzzMaker.com --
May 29, 2015 at 7:08 pm #4087PatrickParticipantHi!
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.
Attachments:
May 29, 2015 at 11:21 pm #4090Mark WilliamsKeymasterThose are not errors.. they are warnings. You can disregard them. The program should compile successfully
Mark --OzzMaker.com --
June 20, 2015 at 9:45 pm #4149PatrickParticipantHi!
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.Attachments:
June 21, 2015 at 8:43 pm #4151Mark WilliamsKeymasterDid you run the program with?;
sudo ./compass_tutorial02
Mark --OzzMaker.com --
June 22, 2015 at 1:22 am #4152PatrickParticipantYes, 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 runsudo ./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 tellingcommand not found
. (see image)Attachments:
June 22, 2015 at 2:09 pm #4155Mark WilliamsKeymasterThe 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 --
- AuthorPosts
- You must be logged in to reply to this topic.