Android Question Android THINGS

Adie

Member
Licensed User
Ok, our Remote display is working 100%, now the customer need multiple scales to transmit to one display. We can not source more of the same TTL radio's. We now need to go SPI.

I can not find any reference on how or if possible to use SPI on Pi3 with B4A.

Please clever people :D

Adie
 

Adie

Member
Licensed User
Hi
I get this error when I insert the code snippet.
B4X:
Dim jPM As JavaObject = PeripheralManager
Log(jPM.RunMethod("getSpiBusList", Null))

PeripheralManager stay RED error state. I do have other lines that use PeripheralManager without an issue but they are like this:
Private pm As PeripheralManager and is used for the serial port.

I have Tings, JavaObject and Core as Libraries.

Adie
 
Upvote 0

Adie

Member
Licensed User
OK, sorted.
the confusion was the 'PeripheralManager' is actually a variable that I had to create.
Code now
B4X:
Dim jPM As JavaObject = pm
Msgbox( jPM.RunMethod("getSpiBusList", Null), "SPI")

pm is the PeripheralManager variable as created in globals and used for GPIO etc.
 
Upvote 0

Erel

Administrator
Staff member
Licensed User
Upvote 0

Adie

Member
Licensed User
Thanks,
now I need the B4A commands that match the Things methods.

Like
close the port with oSPI.RunMethod("close", Null) --> working
oSPI.RunMethod("getName", Null) --> working

will it always be the same as Things?

Adie
 
Upvote 0

Adie

Member
Licensed User
Thanks for the assistance.

No that part is working 100% now (no crashes). I did not connect the slave yet so can not vouch that it is 'actually' working. I will post final TRAINING code on the forum with explanation for other entry level B4A/Things programmers in a few weeks. I found the biggest issue for us beginners is we actually only need the necessary code to get functionality. From then on we can tailor it and learn more.

Like this post of yours.

You can open a SPiDevice with:
B4X:
Dim spi As JavaObject = jPM.RunMethod("openSpiDevice", Array("SPI0.0")) 'or SPI0.1

'writing:
Dim data() As Byte = Array As Byte(0x0, 0x1, 0x2)
spi.RunMethod("write", Array(data, data.Length))
'reading:
Dim buffer(10) As Byte
spi.RunMethod("read", Array(buffer, buffer.Length))

Native methods documentation: https://developer.android.com/things/reference/com/google/android/things/pio/SpiDevice.html
This link 'exposed' the commands in .RunMethod("xxx" ..... so it became easier. :p

The scary part was before I got this read/write code the reference to this
B4X:
 https://developer.android.com/things/sdk/pio/spi.html
was daunting to say the least. BUT it seems as if "SPI0.0" is MODE 0 and .1 is mode 1 ??

My next hurdle is the keyboard input. None of the libs on the forum solve my problem. Note: the application is for industrial use and must thus not allow the operator to 'fool around'. The code will be shared between different apps and should thus be a class or code module. This module must be called from the main 'thread' and just return the result for validation.

Similar to the NumPad example. BUT the value (and the label) must be on the numpad (probably in the FloatLabeledEditText) as it might cover the main screen. At this stage I dont know how the buttons are processed. Lastly, I would prefer if only one instance of the class (Numpad/QWERTYPad) be created as there might be up to 25 numeric inputs during the system setup phase. These popup keyboards will be fixed position and size as the system is developed for 7" Pi screen. (Other screens do not integrate nice with Things)

OK, I noticed that my thread title [Android THINGS] is a bit vague. The idea was to put all my THINGS questions here.

I LOVE THIS PLATFORM. :)

Adie
 
Upvote 0
Top