This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Unable to Access i2c port using wiringPI library
#1
Hi,

   we are using the Tinker board with Android os.
   we are trying to interface the I2c port using wiring PI Library.
   But, we getting error as follows: 
   Unable to select I2C device: Device or resource busy.

   how to solve the above problem, please help out me
Reply
#2
hi..all...
maybe this will help.. UART and I2C config in android

I still haven't played with serial / I2Cs devices..
looking to get ARDUINO UNO REV3
Adafruit HUZZAH32 – ESP32 Feather Board 
setup with tinker board.. ;-]..
---------------
hope it helps
k,
Reply
#3
Hi  k247tEK,

  Thank you for your Reply.
   
  it is to inform you that with the given link I am not able to config the I2C. 
  so please provide us an alternative for the same.

Thanks and Regards.
Reply
#4
Hi krishna,

as a tEK_Newbie.. I 'm sorry I can't provide an alternative link for the same..

I'm using original tinker Board.. with TinkerOS_Android 7 Nougat V14.3.2.82..
sooo.. have adb root access to mksh [MirBSD Korn Shell LINUX interactive user interface]
via USB / Serial or Network tcp/ip [LAN/Wifi]..

I've also used lobo's guide to root TinkerOS_Android 7 Nougat V14.3.2.82 & installed 
Termux 0.73 (73) with root-repo / tsu & tsudo installed.. 
this give.. Android terminal emulator with local root access to shell.. 
but once ssh is installed in termux.. 
this give.. Network access to termux Android terminal emulator shell..
then.. as part of setting up an Android Termux Development Environment..
installed.. lobo: wiringPi for Android.. ;-]..
soooo... now can.. ssh into termux Android terminal emulator shell..
& run.. sudo gpio readall
Code:
bash:5.0][u0_a60]@~:$ sudo gpio readall
+-----+-----+---------+------+---+--Tinker--+---+------+---------+-----+-----+
| CPU | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | CPU |
+-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
|     |     |    3.3v |      |   |  1 || 2  |   |      | 5v      |     |     |
| 252 |   8 |   SDA.1 |  I2C | 1 |  3 || 4  |   |      | 5v      |     |     |
| 253 |   9 |   SCL.1 |  I2C | 1 |  5 || 6  |   |      | 0v      |     |     |
|  17 |   7 | GPIO0C1 |  OUT | 0 |  7 || 8  | 0 | SERL | TxD.1   | 15  | 161 |
|     |     |      0v |      |   |  9 || 10 | 1 | SERL | RxD.1   | 16  | 160 |
| 164 |   0 |  CTSN.4 | SERL | 1 | 11 || 12 | 1 | I2S  | I2S_CLK | 1   | 184 |
| 166 |   2 | GPIO5B6 |   IN | 0 | 13 || 14 |   |      | 0v      |     |     |
| 167 |   3 | GPIO5B7 |   IN | 0 | 15 || 16 | 0 | IN   | GPIO5B2 | 4   | 162 |
|     |     |    3.3v |      |   | 17 || 18 | 0 | IN   | GPIO5B3 | 5   | 163 |
| 257 |  12 |  MOSI.2 |  SPI | 0 | 19 || 20 |   |      | 0v      |     |     |
| 256 |  13 |  MISO.2 |  SPI | 1 | 21 || 22 | 0 | IN   | GPIO5C3 | 6   | 171 |
| 254 |  14 |  SCLK.2 |  SPI | 1 | 23 || 24 | 1 | SPI  | CE0.2   | 10  | 255 |
|     |     |      0v |      |   | 25 || 26 | 1 | IN   | GPIO8A3 | 11  | 251 |
| 233 |  30 |   SDA.4 |  I2C | 1 | 27 || 28 | 1 | I2C  | SCL.4   | 31  | 234 |
| 165 |  21 |  RTSN.4 | SERL | 1 | 29 || 30 |   |      | 0v      |     |     |
| 168 |  22 | GPIO5C0 |   IN | 1 | 31 || 32 | 1 | SERL | GPIO7C7 | 26  | 239 |
| 238 |  23 | GPIO7C6 | SERL | 1 | 33 || 34 |   |      | 0v      |     |     |
| 185 |  24 |  I2S_FS |  I2S | 0 | 35 || 36 | 1 | SERL | RxD.3   | 27  | 223 |
| 224 |  25 |   TxD.3 | SERL | 1 | 37 || 38 | 1 | I2S  | I2S_SDI | 28  | 187 |
|     |     |      0v |      |   | 39 || 40 | 0 | I2S  | I2S_SDO | 29  | 188 |
+-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
| CPU | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | CPU |
+-----+-----+---------+------+---+--Tinker--+---+------+---------+-----+-----+
bash:5.0][u0_a60]@~:$
note.. with sudo gpio... use wPi Pin#...

with a pibrella connected to tinker Board.. this allows for safe play with electronics ;-]]]...
& basic functions to control gpio pins.. 

like.. compile pibrella.c from.. Template for Programming the Pimoroni Pibrella in C 
in termux Android terminal emulator shell..
Code:
gcc -Wall -o pibrella pibrella.c -I/data/data/com.termux/files/usr/include/wiringPi -lwiringPi
& to run.. use ./pibrella

then I came across lobo's post #4 in "UART and I2C config in android" Thread..
"..there are no helper tools on Android, nothing like the i2c-tools on Linux. You need to write a program to read the i2c data..."

hmmmmm.. so.. how do I get Linux tools like.. i2c-tools to run on Android ?????
well... in termux.. you can install debian-on-termux environment.. via.. debootstrap..

then install all the Linux Apps tools you want in the debian-on-termux environment.. 
& as long as the debian-on-termux environment has root access to termux Android terminal emulator shell..
& everything in Unix/Linux is a file.. ;-].. 
it should work.. in theory...

sooo... I was about to test this.. but.. I updated termux in TinkerOS_Android 7 Nougat V14.3.2.82..
& updated Termux 0.98 (98) removes tsudo from root-repo.. which breaks my ability to start 
debian-on-termux environment... with sudo from termux Android terminal emulator shell.. [[[[[....

currently.. I'm re-installing & updating system to TinkerOS_Android 7 Nougat v14.4.0.5..
meanwhile.. found this.. I2C with Arduino and Raspberry Pi - Two Methods &

---------------------------------------------- ;-]...
hope to be back up over the weekend,
k,
----
ps.. from lobo: wiringPi for Android. wiringPiI2C.c
Code:
...
// I2C definitions

#define I2C_SLAVE 0x0703
#define I2C_SMBUS 0x0720 /* SMBus-level access */

#define I2C_SMBUS_READ 1
#define I2C_SMBUS_WRITE 0

// SMBus transaction types

#define I2C_SMBUS_QUICK    0
#define I2C_SMBUS_BYTE    1
#define I2C_SMBUS_BYTE_DATA    2
#define I2C_SMBUS_WORD_DATA    3
#define I2C_SMBUS_PROC_CALL    4
#define I2C_SMBUS_BLOCK_DATA    5
#define I2C_SMBUS_I2C_BLOCK_BROKEN  6
#define I2C_SMBUS_BLOCK_PROC_CALL   7 /* SMBus 2.0 */
#define I2C_SMBUS_I2C_BLOCK_DATA    8

// SMBus messages

#define I2C_SMBUS_BLOCK_MAX 32 /* As specified in SMBus standard */
#define I2C_SMBUS_I2C_BLOCK_MAX 32 /* Not specified but we use same structure */
...
hope this helps somehow.. ;-].. k,
Reply
#5
Hello there, sorry that I can't help so much. My only left TB is in production and I can't disassemble easy for testing something. My other TB died.

But here I compiled the i2ctools to use on Android. I tried without to have a i2c device connected, it seems to work. I tried on a different Android device and there it works.

.zip   i2ctools.zip (Size: 41.82 KB / Downloads: 4)
Simply copy the bins to /system/bin and the lib to /system/lib. Don't forget to see or change the bins to chmod 755.
Not needed to say it needs root to use, as the /dev/i2c-x are only accesible by root.

And to the OP, are you sure your app has root?
Reply
#6
hi lobo,

nice... ;-]..


your help is always greatly appreciated...


I have downloaded  i2ctools.zip -  for Android, & ordered..
ARDUINO UNO REV3.. just also looking for some I2C devives. ]]]]]...

meanwhile.. I'm updating system to TinkerOS_Android 7 Nougat v14.4.0.5...

by.. next week.. should have everything.. 
to start playing with I2C on tinker Board...

-----------------
Many thanks,
k,
Reply
#7
Hi  k247tEK,

      Thank you for your reply.
      The alternative link is very helpful.

Hi Lobo,

     Thank you for your response.
     I am following your post for WiringPI on Android OS.
    
     I downloaded the i2ctools.zip file, then extract and pushed it into the Tinkerboard using ADB shell.

     then run the following commands
             
     
Code:
ASUS_TINKERBOARD:/ # i2cdetect -l
i2c-0   i2c             rk3x-i2c                                I2C adapter
i2c-1   i2c             rk3x-i2c                                I2C adapter
i2c-2   i2c             rk3x-i2c                                I2C adapter
i2c-3   i2c             rk3x-i2c                                I2C adapter
i2c-4   i2c             rk3x-i2c                                I2C adapter
i2c-6   i2c             DesignWare HDMI                         I2C adapter
ASUS_TINKERBOARD:/ # i2cdetect -y 1
    0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:                         -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- 57 -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- UU -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
ASUS_TINKERBOARD:/ #  

 I checked the UU in the below-given link and got the answer as 
Quote: If the address result is “UU”, it is currently being used by a driver.
maker.pro/raspberry-pi/tutorial/how-to-add-an-rtc-module-to-raspberry-pi

so I was Supposed to get 68 instead of UU in the above output. 
therefore, Kindly help me to overcome this output.
Reply
#8
Maybe you can see this way, if a driver is already mapped to this address:
Code:
ls /sys/bus/platform/devices/ff650000.i2c/i2c-0/0-001b                         <
driver   name    power     rk808-clkout    rk808-rtc uevent
modalias of_node regulator rk808-regulator subsystem
Note, this is for i2c-0 where the rk808 i2c device 0x1b is, and you can see that rk808-clkout, rk808-rtc and rk808-regulator drivers are mapped to it. As this is also described in the devicetree.
For the i2c-1 device 0x68 you would list like this:
Code:
ls /sys/bus/platform/devices/ff140000.i2c/i2c-1/0-0068
I see in my devicetree that there is a DS3231 driver for that address, but I don't remember if I put this years ago, or it is there from Asus. Maybe it is there from Asus, than it would explain, that this address is used and you would need to change the devicetree.
Reply
#9
hi all,

just to check..  

i2c-4 is for Physical  PINs  [27 SDA.4] & [28 SCL.4]
i2c-1 is for Physical  PINs  [3   SDA.1] & [5   SCL.1]

on the Raspberry Pi.. Pins 27 & 28  are listed as  (EEPROM Data) & (EEPROM Clock) 
and are for re-programming HATs, so should not be used by us...

so... only i2c-1  is available for us to use.. is this the case for tinker board also ????
so... only PINs 3 & 5 can be used for I2C devices.... ????

and...  do PINs 3  & 5  have GPIO Pin Alternate Functions like the Pi.. 

I've been playing with gpio mode..
Code:
gpio mode 8 alt0
gpio mode 8 alt1
gpio mode 8 alt5

alt0 seem to set Physical PIN 3 to GPIO mode... &
alt1 and alt5 both.. set Physical PIN 3 to I2C mode..

is there a difference between alt1 & alt5 ????

also.. I copied the i2c-tools files to a clean install TinkerOS_Android 7 Nougat v14.4.0.5
with nothing connected to GPIO header of tinker board..
Code:
rk3288:/ # ls -Flah /sys/bus/platform/devices/ff140000.i2c/i2c-1/
total 0
drwxr-xr-x 5 root root    0 2020-08-18 04:23 ./
drwxr-xr-x 4 root root    0 2020-08-18 04:23 ../
drwxr-xr-x 3 root root    0 2020-08-18 04:23 1-0068/
--w------- 1 root root 4.0K 2020-08-18 04:29 delete_device
lrwxrwxrwx 1 root root    0 2020-08-18 04:29 device -> ../../ff140000.i2c@
drwxr-xr-x 3 root root    0 2020-08-18 04:23 i2c-dev/
-r--r--r-- 1 root root 4.0K 2020-08-18 04:29 name
--w------- 1 root root 4.0K 2020-08-18 04:29 new_device
lrwxrwxrwx 1 root root    0 2020-08-18 04:29 of_node -> ../../../../firmware/devicetree/base/i2c@ff140000@
drwxr-xr-x 2 root root    0 2020-08-18 04:23 power/
lrwxrwxrwx 1 root root    0 2020-08-18 04:29 subsystem -> ../../../../bus/i2c@
-rw-r--r-- 1 root root 4.0K 2020-08-18 04:23 uevent
rk3288:/ #

there is a  1-0068/  listed...
Code:
rk3288:/ # ls -Flah /sys/bus/platform/devices/ff140000.i2c/i2c-1/1-0068/
total 0
drwxr-xr-x 3 root root    0 2020-08-18 04:23 ./
drwxr-xr-x 5 root root    0 2020-08-18 04:23 ../
-r--r--r-- 1 root root 4.0K 2020-08-18 05:22 modalias
-r--r--r-- 1 root root 4.0K 2020-08-18 05:22 name
lrwxrwxrwx 1 root root    0 2020-08-18 05:22 of_node -> ../../../../../firmware/devicetree/base/i2c@ff140000/ds3231@68@
drwxr-xr-x 2 root root    0 2020-08-18 04:23 power/
lrwxrwxrwx 1 root root    0 2020-08-18 05:22 subsystem -> ../../../../../bus/i2c@
-rw-r--r-- 1 root root 4.0K 2020-08-18 04:23 uevent
rk3288:/ #

Code:
rk3288:/ # i2cdetect -l
i2c-0   i2c             rk3x-i2c                                I2C adapter
i2c-1   i2c             rk3x-i2c                                I2C adapter
i2c-2   i2c             rk3x-i2c                                I2C adapter
i2c-3   i2c             rk3x-i2c                                I2C adapter
i2c-4   i2c             rk3x-i2c                                I2C adapter
i2c-6   i2c             DesignWare HDMI                         I2C adapter
rk3288:/ #

Code:
rk3288:/ # i2cdetect -y 1
    0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:                         -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
rk3288:/ #
rk3288:/ # i2cdetect -y 4
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:                         -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
rk3288:/ #

I don't know what any of that mean ;-]..

I hope I don't kill my tinker board next week ]]]]]]]
----------------
many thanks,
k,
Reply
#10
Hi lobo,

       
Quote:I see in my devicetree that there is a DS3231 driver for that address, but I don't remember if I put this years ago, or it is there from Asus. Maybe it is there from Asus, than it would explain, that this address is used and you would need to change the devicetree.

      how to change the device tree. Is there any reference procedure.

   
Thank you.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)