B4R Question How can i convert a Arduino Libary to B4R

pucki

Active Member
Licensed User
I have a library that runs perfectly under the Aurdino IDE.

How can I convert it so that it is available under the B4R IDE and can be integrated and used.

If possible, please provide precise instructions, as I am still unable to cope with the internal things of B4R.

Many Thanks

greeting

Pucki

* text translated from German into English with google *
 

vali khandangoll

Active Member
I have a library that runs perfectly under the Aurdino IDE.

How can I convert it so that it is available under the B4R IDE and can be integrated and used.

If possible, please provide precise instructions, as I am still unable to cope with the internal things of B4R.

Many Thanks

greeting

Pucki

* text translated from German into English with google *
Hi Pucki
I had this problem before and I hardly solved it.
I have explained in detail in one of the previous \Posts.
The solution is described in the image below.
 

Attachments

  • image_2021_1_10-23_22_19_669_w9X.jpg
    image_2021_1_10-23_22_19_669_w9X.jpg
    56.3 KB · Views: 291
Upvote 0

candide

Active Member
Licensed User
can you share your library?

in fact you have to
1) to extract "public" part or xxx.h file arduino
2) to create a rxxx.cpp file to make convertion of data between arduino library and B4R interface
3) to create a rxxx.h file for interface with B4R
4) and to create rxxx.xml file for management of all functions of this class in B4R

itis not so simple.....
 
Last edited:
Upvote 0

pucki

Active Member
Licensed User
when I use the attached files with the command
java -jar B4Rh2xml.jar c: \ 4 \ MyPCF8574.h c: \ 4 \ r_my_keyboard.xml
Editing, I get the following error message.

Error parsing: MyPCF8574();
parser._parsemethod (java line: 527)
java.lang.NumberFormatException: For input string: "error"
at sun.misc.FloatingDecimal.readJavaFormatString(Unknown Source)
at sun.misc.FloatingDecimal.parseDouble(Unknown Source)
at java.lang.Double.parseDouble(Unknown Source)
at b4j.example.parser._parsemethod(parser.java:527)
at b4j.example.parser._parseline(parser.java:464)
at b4j.example.parser._parseh(parser.java:422)
at b4j.example.parser._parse(parser.java:267)
at b4j.example.main._appstart(main.java:46)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:84)
at b4j.example.main.main(main.java:29)


I once attached the 3 files.

Maybe someone else can do it. Or knows a library that a keyboard via i2c as pcf8475 can read. The keyboard is a 2 x 4 matrix.

greeting

Pucki.
 

Attachments

  • my_pcf8574.zip
    1.9 KB · Views: 235
Upvote 0

candide

Active Member
Licensed User
i don't know if it is what you want, but it is possible to create a wrapper on MyPCF8574 library:

compilations is OK on esp8266, all functions are available on B4R side, next step is to test in real configuration
 

Attachments

  • rMyPCF8574.zip
    4.9 KB · Views: 225
Upvote 0

pucki

Active Member
Licensed User
Many Thanks.

Can you "convert" the attached file.

And what are you doing differently than me. ???

Why do I get an error message with the Java command?

I don't want to bother you (or others) all the time, I want to be able to do it myself.

Many thanks in advance.

greeting

Pucki.

p.s. : Sorry for my English ist a Translat from google.
 

Attachments

  • MyKeypad_I2C.zip
    2.8 KB · Views: 206
Upvote 0

pucki

Active Member
Licensed User
Hi you can use this directly in B4R:

Thanks for the link.
But now I need the other library because the layout is a matrix. And I haven't found anything in b4r that can read out a matrix on an PCF-8574.

But I'll test your link for "normal" PCF-8574 queries.


Greetings Pucki.
 
Upvote 0

candide

Active Member
Licensed User
for MyKeypad_I2C library, please to check this version for B4R. (compilation is OK)

to answer at you question, to create a wrapper for B4R, i have to process in 4 steps:
1) extract the public part of the h file
2) create a cpp file for wrapper to make interface between arduino library and B4R constraints
3) create a h file for wrapper
4) and at last create a xml file for B4R interface

and at last creation and compilation of a projecton B4R with all functions of the new library is a way to check search issues in the wrapper.

at last, only a check in real environment with confirm if library is OK or not.
 

Attachments

  • rMyKeypad_I2C.zip
    9 KB · Views: 224
Upvote 0

pucki

Active Member
Licensed User
nice project !
if it is working now with B4R, i am happy for you ! 🙂

At first I thought it would work. It Works any Time and then it' s crash.

But it looks like the library has a bug because the program hangs up on the Arduino-Nano (older Board).

Here is my code. It's really crap but I don't know how else I can address a matrix keyboard.

Does anyone have an idea what I can do?

Here's the code.

greeting

Pucki

B4X:
#Region Project Attributes
    #AutoFlushLogs: True
    #CheckArrayBounds: True
    #StackBufferSize: 300
#End Region
'Ctrl+Click to open the C code folder: ide://run?File=%WINDIR%\System32\explorer.exe&Args=%PROJECT%\Objects\Src

Sub Process_Globals
    Public Serial1 As Serial
    Public lcd As LiquidCrystal_I2C
    Public my_keypad As MyKeypad_I2C
   
    Public taste As Byte
    Dim timer1 As Timer

    'Dim d1pin As D1Pins
   
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
   
    Log("AppStart")
   
    lcd.Initialize(0x27, 20, 4) 'based on the example from the project.
    lcd.Backlight = True
    lcd.Write("System gestartet")
    lcd.SetCursor(0,0)
   
    timer1.Initialize("timer1_Tick",1000)
    timer1.Enabled=True
   
    my_keypad.Initialize(0x38)
   
    my_keypad.clearAllKeyCodes()
    my_keypad.setKeyCode(0xEE,1) ' Prg-1
    my_keypad.setKeyCode(0xDE,2) ' Prg-2
    my_keypad.setKeyCode(0xBE,3) ' Reset
    my_keypad.setKeyCode(0x7E,4) ' Pin
   
    my_keypad.setKeyCode(0x7D,5) ' Start
    my_keypad.setKeyCode(0xBD,6) ' +1
    my_keypad.setKeyCode(0xDD,7) ' +5
    my_keypad.setKeyCode(0xED,8) ' +10
   
End Sub

Sub timer1_Tick
        taste = my_keypad.receiveKey(1) ' nur 1 x abfragen
        lcd.SetCursor (0,1)
       
        If taste = 1 Then lcd.Write("Prg-1   ")
        If taste = 2 Then lcd.Write("Prg-2   ")
        If taste = 3 Then lcd.Write("Reset   ")
        If taste = 4 Then lcd.Write("Pin     ")
        If taste = 5 Then lcd.Write("Start   ")
        If taste = 6 Then lcd.Write("+1      ")
        If taste = 7 Then lcd.Write("+5      ")
        If taste = 8 Then lcd.Write("+10     ")
       
        lcd.SetCursor (0,2)
        lcd.Write(Millis)  ' this stop at crash
End Sub
 
Upvote 0

pucki

Active Member
Licensed User
Try to write the timer1.Initialize("timer1_Tick",1000) and timer1.Enabled=True to the end of your
AppStart Sub.

i have do it, but its the same as before. The APP run a little time then crash.

The millis counter stop , so i see the app crash.
 
Upvote 0

thetahsk

Active Member
Licensed User
Longtime User
i have do it, but its the same as before. The APP run a little time then crash.

The millis counter stop , so i see the app crash.
B4X:
       If my_keypad.isReady Then
    
        taste = my_keypad.receiveKey(1) ' nur 1 x abfragen
        lcd.SetCursor (0,1)
      
        If taste = 1 Then lcd.Write("Prg-1   ")
        If taste = 2 Then lcd.Write("Prg-2   ")
        If taste = 3 Then lcd.Write("Reset   ")
        If taste = 4 Then lcd.Write("Pin     ")
        If taste = 5 Then lcd.Write("Start   ")
        If taste = 6 Then lcd.Write("+1      ")
        If taste = 7 Then lcd.Write("+5      ")
        If taste = 8 Then lcd.Write("+10     ")
      
        lcd.SetCursor (0,2)
        lcd.Write(Millis)  ' this stop at crash
        
        End If
 
Upvote 0
Top