Tinker Board Forum

Full Version: UART and I2C config in android
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello All

I want to use the UART and I2C on tinkerboard with android. However I am not able to get that running. I tried with wiringpi but I guess both are disabled.

Is there any way to check which UART is enabled for general use and whether I2C is enabled or not? If not, how do I enable them?

Thanks
(06-19-2019, 08:48 AM)vivekb Wrote: [ -> ]Hello All

I want to use the UART and I2C on tinkerboard with android. However I am not able to get that running. I tried with wiringpi but I guess both are disabled.

Is there any way to check which UART is enabled for general use and whether I2C is enabled or not? If not, how do I enable them?

Thanks

Hello vivekb,
can you please open an adb terminal and show the output off these commands here?
Code:
ls -la /dev/i2c*
There should be this output:
Code:
crw------- root     root      89,   0 2013-01-21 09:50 i2c-0
crw-rw---- system   system    89,   1 2013-01-21 09:50 i2c-1
crw-rw---- system   system    89,   2 2013-01-21 09:50 i2c-2
crw-rw---- system   system    89,   3 2013-01-21 09:50 i2c-3
crw-rw---- system   system    89,   4 2013-01-21 09:50 i2c-4
You would use usually i2c-1 with the pins 3 and 5.
I connected a DS3231 with address 0x68 to it and started the device as this:
Code:
echo "ds3231 0x68" > /sys/class/i2c-adapter/i2c-1/new_device
And I can see date and time as this:
Code:
cat /sys/class/i2c-adapter/i2c-1/1-0068-1/rtc/rtc0/date            

2019-06-20

cat /sys/class/i2c-adapter/i2c-1/1-0068-1/rtc/rtc0/time             

09:23:40

It is also possible to read and write using wiringPi:
Code:
#include <wiringPi.h>


/*setup a PCF8574 address 0x20*/
int dev = wiringPiI2CSetup(0x20);

/*to read*/
int rd = wiringPiI2CRead (dev) ;
printf ("digitalRead I2C 0x20: %d\n", rd);
To access these functions from an app code you would need to add native code to your project and extend the code off wpi_android.c you find on github:
https://github.com/joerg65/wiringTinker_..._android.c
Hi Lobo

Thanks for the response.

I executed the command
Code:
ls -la /dev/i2c*

and got the following output


Code:
crw------- root     root      89,   0 2013-01-21 08:50 i2c-0
crw-rw---- system   system    89,   1 2013-01-21 08:50 i2c-1
crw-rw---- system   system    89,   2 2013-01-21 08:50 i2c-2
crw-rw---- system   system    89,   3 2013-01-21 08:50 i2c-3
crw-rw---- system   system    89,   4 2013-01-21 08:50 i2c-4
crw------- root     root      10,  51 2013-01-21 08:50 i2c_detect

I then connected the I2C pins from an arduino to pins 3 and 5 of TB. The code running on arduino is sending a string with address "8" every 1 second

I then went to the following location on TB

Code:
root@rk3288:/sys/class/i2c-adapter/i2c-1

and "ls" there gives me 

Code:
1-0008
1-0008-1
1-000d
1-0010
1-001d
1-0051
1-0068
delete_device
device
i2c-dev
name
new_device
power
subsystem
uevent

An "ls" in the directory "1-0008-1" gives me:

Code:
modalias
name
power
subsystem
uevent

From here how do I see what data is being transmitted?
Hello vivekb,
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. Look on my github how to cross compile and install wiringPi on the TB. Then you need NDK or better the whole SDK of AndroidStudio to write some code for Android.

You can connect your Arduino only to the TB i2c if your Arduino is slave. The TB acts as master. So check if your Arduino acts as slave. If so, your Arduino waits the request from the TB. Then you can use the function int wiringPiI2CReadReg8 (int fd, int reg)  to read the registers of the Arduino until your string ends.
(06-21-2019, 06:12 PM)lobo Wrote: [ -> ]Hello vivekb,
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. Look on my github how to cross compile and install wiringPi on the TB. Then you need NDK or better the whole SDK of AndroidStudio to write some code for Android.

You can connect your Arduino only to the TB i2c if your Arduino is slave. The TB acts as master. So check if your Arduino acts as slave. If so, your Arduino waits the request from the TB. Then you can use the function int wiringPiI2CReadReg8 (int fd, int reg)  to read the registers of the Arduino until your string ends.

That was really helpful. Thank you so much.  Smile

Could you please also help me sort out UART? I did

Code:
 ls -la /dev/tty*
I get the following response

Code:
crw-rw-rw- root     root       5,   0 2013-01-21 08:50 tty
crw------- root     root     254,   0 2019-06-23 12:31 ttyFIQ0
crw------- root     root     244,   0 2013-01-21 08:50 ttyGS0
crw------- root     root     244,   1 2013-01-21 08:50 ttyGS1
crw------- root[font=Arial]     root     244,   2 2013-01-21 08:50 ttyGS2[/font]
[font=Arial]crw------- root     root     244,   3 2013-01-21 08:50 ttyGS3[/font]
[font=Arial]crw-rw---- bluetooth net_bt_stack   4,  64 2019-06-23 12:46 ttyS0[/font]
[font=Arial][size=small]crw-rw-rw- bluetooth net_bt_stack   4,  66 2013-01-21 08:50 ttyS2[/size]
[/font]

I am not sure why it shows ttyS2 as a bluetooth net_bt_stack

I pulled the init.connectivity.rc file and there ttyS2 is not configured as bluetooth. (file attached)

I am not able to send or receive any data via UART. I tried the following to read data
Code:
cat -v /dev/ttyS0
[/size][/font]
[font=Arial]cat -v /dev/ttyS2[/font]
[font=Arial][size=small]


and the following to send data

Code:
[size=small]echo h > /dev/ttyS2[/size][/font]
[font=Arial][size=small]echo h > /dev/ttyS0[/size][/font]
[font=Arial][size=small]echo 'h' > /dev/ttyS2[/size][/font]
[font=Arial][size=small][size=small]echo 'h' > /[/size][size=small]dev/tt[/size][size=small]yS0[/size][/size]


I also did a chmod 666 /dev/ttyS0 and chmod 666 /dev/ttyS2 but still nothing.