Page 1 of 1

accessing i2c without i2c-tools

Posted: Sun May 04, 2014 4:24 pm
by sparaflesh
Hi, i'm sorry for the noob question (and for my little english too).
However, is there a way to access i2c without using i2c-tools?
I have a tmp101 sensor and I'm perfectly able to read and write on it using i2c-tools (my os on raspberry is rasbpian).

I try to explain better. I can access gpio "playing" with the folders /sys/class/gpio/, exporting pin and writing on direction and value files (for example to turn on led). Is it possible to do a similar thing with i2c? Where can I find documentation about how raspbian works with i2c?

Thanks.

Re: accessing i2c without i2c-tools

Posted: Sun May 04, 2014 5:50 pm
by joan
You can access the raw devices (/dev/i2c-0 and /dev/i2c-1) from any programming language you want. C and Python both support smbus access to the I2C bus.

Do you have a programming language in mind?

Re: accessing i2c without i2c-tools

Posted: Sun May 04, 2014 9:15 pm
by EHiggins
If you are learning to program I would suggest Python, I was trying to do something similar to you when leaning before and I controlled the i2c from Python using the 'smbus' module.

This is something similar: http://www.raspberry-projects.com/pi/pr ... nterface-2

Re: accessing i2c without i2c-tools

Posted: Sun May 04, 2014 10:33 pm
by sparaflesh
I have a little project for university, that is remote control of some device that professor will give us going on with the course. I know that there are a lot of similar project (for example webiopi), but the goal is building something from beginning and from myself with the purpose of learning something.
We started with the control of gpio to turn on led, so I build a simple library similar to this https://github.com/ronanguilloux/php-gpio and a very simple page with a form through which I can press some buttons to turn on/off leds.
Now next step is reading value from tmp101 sensor. I can use the "exec" in php to execute the i2c-tools commands via shell, but it seems to me a very poor idea. Isn't it? So how can I reach this goal? I know a little java (read a couple of book, this is the language i know better), php, javascript and some distant memory of c++ (lol). Give me an advice, I'm a little confused :)

Re: accessing i2c without i2c-tools

Posted: Mon May 05, 2014 7:57 am
by joan
When you say you know Java is it limited to reading but not writing?

If that's the case you might as well use Python and the I2C smbus module. You'll probably get more help.

If you do have an investment in Java look at http://pi4j.com/index.html

Re: accessing i2c without i2c-tools

Posted: Mon May 05, 2014 3:02 pm
by hampi
sparaflesh wrote:I know that there are a lot of similar project (for example webiopi), but the goal is building something from beginning and from myself with the purpose of learning something.
I do not want to spoil your fun, but I have a small "draft" version of a daemon reading tmp102 with i2c

https://github.com/oh7bf/Tmp102d

More features to be added later (and time permitting) to this code. Once installed it runs as a linux service like 'ntpd' or 'sshd'.

One interesting project is to modify the code and make a temperature server running on RPi. The Berkley sockets is probably a good starting point for that, but I am not expert in this field.

Re: accessing i2c without i2c-tools

Posted: Mon May 05, 2014 3:57 pm
by sparaflesh
@joan
I did an exam on programming some simple server in java that implented some of the most important functions of the studied protocols (http, smtp, ftp and pop3). I'm at that point of knowledge of the language :) However I'll give a look to pi4j, but finally have I to start a http server in java integrating in him pi4j classes to interact with user?

@hampi
Ok thanks, I'll give it a look ;)