Android Question [things] I2C

Erel

B4X founder
Staff member
Licensed User
Longtime User
@tigrot see this tutorial: https://www.b4x.com/android/forum/threads/74821/#content

You can access the I2C API with JavaObject:
B4X:
Dim jo As JavaObject = Manager
Log(jo.RunMethod("getI2cBusList", Null))
Dim Name As String = "..."
Dim Address As Int = ...
Dim device As JavaObject = jo.RunMethod("openI2cDevice", Array(Name, Address))

'Now call I2cDevice methods:
Dim buffer(100) As Byte
device.RunMethod("read", Array(Buffer, Buffer.Length))
Dim data As Byte = ...
Dim reg As Int = ...
device.RunMethod("writeRegByte", Array(reg, data))
 
Upvote 0

Michael1968

Active Member
Licensed User
Longtime User
Hi Erel,

I get this error: get the same error with the PWM example.

if i use b4j with Linux Image on the Pi, i2c works well.
 
Upvote 0

rwblinn

Well-Known Member
Licensed User
Longtime User
Great to see working.

Would it be possible to share the code for your solution?
 
Upvote 0

Michael1968

Active Member
Licensed User
Longtime User
the working I2C example attached.
The SHT Sensor is directly connected to the Raspberry Pi.
Thanks to Robert ,he wrote most of the Code, to help me to get it work

best regards

Michael
 

Attachments

  • sht30.zip
    13.1 KB · Views: 567
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…