I2C pins on Expansion Dock
-
I'm trying to hook up a pressure sensor that communicates via I2C to the expansion dock. Not sure how to do that. The sensor (MS5803-12BA from Sparkfun) has pins labelled: SDA/SDI and SCL/SCLK.
Some forum posts suggest using RX and TX lines for I2C. Not sure how to use those either. There are two sets of lines TX+/TX-.I can see that I2C pins are marked on the omega's diagram, but aren't on the expansion dock.
Any help is greatly appreciated.
-
It seems by checking the datasheet that the sensor actually has the ability to be controlled via SPI or I2C. Here's the link for the datasheet http://www.meas-spec.com/downloads/MS5803-14BA.pdf.
To use I2C you have to drive PS high, and use SCLK and SDA pins, which will connect to the respective SCL and SDA on the expansion board. Gpio 20 is SCL and Gpio 21 is SDA.
I this https://www.sparkfun.com/products/12909 is your board, i believe that you do not need to drive PS high, since there's a 0R resistor soldered on the board which actually does that for you.
-
@Andrei-Railean Once you have connected the pins correctly, you can use the
i2c-tools
to read data from the sensor.
-
Thanks @Pedro-Baco and @Boken-Lin I'll have a dig around. This sensor has a convoluted way of reading data. Arduino library is useful. I'm trying to figure out how to use i2c-tools to talk to the device. I'll dig through the code in i2c-tools to piece together a functioning program to get data from this sensor.
Are there any other tools for working with i2c in the linux/openWrt land?
I suspect I'll need to clone sparkfun's lib for this sensor and clone arduino's WIRE library to make it work with the omega.
-
@Andrei-Railean
i2c-tools
is just a commandline program. We have a library here: https://github.com/OnionIoT/i2c-exp-driver/blob/master/src/lib/onion-i2c.c. It's can do most of what Arduino's Wire library can do.
-
I don't see
i2c-tools
, as a program, it looks like it's a package that installs a few binaries, namelyi2cdetect i2cdump i2cget i2cset
https://github.com/OnionIoT/OpenWRT-Packages/blob/master/i2c-tools
I'll have a look at how you guys talk to the expansion boards via i2c as an example.
Arduino's interface is documented here: https://www.arduino.cc/en/Reference/Wire
Adafruit's i2c library is called TinyWireM - it's got a similar API to Aduino's https://github.com/adafruit/TinyWireM
-
@Andrei-Railea I think that maybe @Boken-Lin meant that i2c-tools consist of a set of commandline programs for testing/exercising i2c.
I have had a little bit of experience working with i2c on Arduino related systems. I am intending to spent some time getting to grips with the Omega i2c code as in https://github.com/OnionIoT/i2c-exp-driver - mainly because my long term goal is to be able to program the Omega in Java and will need some Java class wrappers. However, that is still in the future as yet.
However, a couple of fruitful sources from the Arduino world, in addition to those mentioned in an earlier post, include:
- i2c library for the Teensy processors - https://forum.pjrc.com/threads/21680-New-I2C-library-for-Teensy3
- software based i2c library for Arduino - http://playground.arduino.cc/Main/SoftwareI2CLibrary
-
I've developed a few basic python routines for i2c you can find them in the file pythoni2c.py
-
@Andrei-Railean yep those are the i2c-tools binaries.
Here is a quick run-down of their usage
- i2cdetect
- Scans the I2C bus to find any connected slaves and their device address
- Typical usage:
i2cdetect -y 0
- i2cget
- Issues a read command from a specific address on a specific device
- Typical usage:
i2cget -y 0 <device addr> <register addr>
- Example: To read from address 0x04 from a device with a slave address of 0x3a:
i2cget -y 0 0x3a 0x04
- i2cset
- Issues a write command to a specific address on a specific device
- Typical usage:
i2cset -y 0 <device addr> <register addr> <value to write
- Example: To write 0xfa to address 0x1c on a device with a slave address of 0x51:
i2cset -y 0 0x51 0x1c 0xfa
- i2cdump
- Issues a read command to dump data from all addresses from a specific device
- Typical usage:
i2cdump -y <device addr>
You can run them with no arguments on the command line to get more usage details.
Also make sure to stay tuned, we will have some I2C related news this week!
- i2cdetect
-
Thanks @Lazar-Demin I did play with these tools. Will need to put them together into a script of sorts to communicate with my sensor and get results that make sense. I may end up writing it in python from examples by @Pedro-Baco and in the LED script.
Here's a man page for linux i2c-tools package http://dev.man-online.org/package/main/i2c-tools/
It has good explanations of all features of each binary.Another potentially useful reference for working with i2c in C is http://elinux.org/Interfacing_with_I2C_Devices
Writing Linux i2c clients
https://www.kernel.org/doc/Documentation/i2c/writing-clients