Android Question Bluetooth, Arduino, and HTC One

nukekiller

New Member
Licensed User
Longtime User
Hello,

I'm working on an B4A app to send and receive data between a HTC One Android phone and an Arduino board. The Arduino board is equipped with a Bluefruit EZ-Link Bluetooth chip.

When I run the B4A app, I get through serial1.connect() without any error messages. The light on my Bluetooth chip begins flashing quickly, indicating a connection. However, Serial1_Connected() never gets called back.

I've gone through all of the discussion boards and Bluetooth examples, and am stumped.

Here's the relevant code:

B4X:
Sub Process_Globals
    Dim serial1 As Serial
    Dim admin As BluetoothAdmin
    Dim AStreams As AsyncStreams
End Sub

Sub initBT    
     admin.Initialize("admin")
     serial1.Initialize("serial1")
     serial1.Connect("98:76:B6:00:42:34") ' mac address from serial1.GetPairedDevices()
End Sub

Sub serial1_NewConnection (Successful As Boolean)
  log("!!!!!!!!! called !!!!!!!!!")
End Sub

I've also tried connecting using this instead:

B4X:
      serial1.ConnectInsecure(admin, "98:76:B6:00:42:34", 1)

...but it also doesn't work -- same result.

If I try to call AStreams.Initialize after any of the above, I get a Java NullPointer error, so it looks like something's not being initialized properly.

I've also tried unpairing and re-pairing my phone to the Bluetooth chip.

I can pair, connect, and send/receive data from my OS X Mac, so I know the Arduino + Bluetooth chip are working OK physically.

What else would you suggest?

Thanks for your help!
 

nukekiller

New Member
Licensed User
Longtime User
Ah, got it. My problem was that I wasn't running the code in a service. The event fires fine now. Thanks!
 
Upvote 0

howard bassen

Member
Licensed User
Longtime User
Is the code you already posted working when you put it in a Service Module? If the code needed some modifications to work, could you post the new code?

Also, How do you read the mac address from serial1.GetPairedDevices() without manually entering it into your code?
 
Upvote 0
Top