Android Question [things] I2C

@tigrot see this tutorial: https://www.b4x.com/android/forum/threads/74821/#content

You can access the I2C API with JavaObject:
Code:
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
Hi Erel,

I get this error:
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Error occurred on line: 31 (Main)
java.lang.RuntimeException: Object should first be initialized (PeripheralManager).
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:50)
at b4a.example.main._activity_create(main.java:382)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:708)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:337)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:247)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
at b4a.example.main.afterFirstLayout(main.java:102)
at b4a.example.main.access$000(main.java:17)
at b4a.example.main$WaitForLayout.run(main.java:80)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
** Activity (main) Resume **
get the same error with the PWM example.

if i use b4j with Linux Image on the Pi, i2c works well.
 
Upvote 0
Pls find an I2C example attached.
The BH1750 Digital Light Intensity Sensor is directly connected to the Raspberry Pi. Read the source for details. incl. pin mapping.

upload_2017-1-24_16-14-4.png
 

Attachments

Upvote 0
Great to see working.

Would it be possible to share the code for your solution?
 
Upvote 0
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

Upvote 0
Back
Top