PSoC 6.3 BLE app question

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
user_3678521
Level 3
Level 3
5 likes given First like given

Hello,

So I've setup a small BLE program, with a read and write. I can find it with the cypress app "CySmart" on my Android phone. Now my question is, how can I make this connection with a selfmade android app? I need to be able to, lets say turn on a led, and maybe recive somthing from the PSoC to display on the app to start with, but i cant find any good guide on how to get startet. I've made some android apps, but never used BLE.

Here is my PSoC creator project: Project File
For the android studio app, I've startet a project, but I think i need some help: Android studio project

Regards Mads

0 Likes
1 Solution
DheerajK_81
Moderator
Moderator
Moderator
First comment on KBA First comment on blog 5 questions asked

Additionally, you can find a video tutorial and source code for a simple BLE app in the links mentioned below:

Although this series makes use of PSoC4, the Android App side of it still remains the same and can be reused for PSoC6.

Regards,

Dheeraj

View solution in original post

11 Replies
VenkataD_41
Moderator
Moderator
Moderator
750 replies posted 500 replies posted 250 solutions authored

Hi Mads,

The source code for CySmart Android application is available for free. You can find the source files and corresponding documents here. You can use them as a starting point to analyze/reuse and understand the firmware flow.

https://www.cypress.com/documentation/software-and-drivers/cysmart-mobile-app

You can also use other company Android applications for BLE if they share the source code. Since the BLE is a universal standard protocol the vendor is independant.

Please use the above documentation and start writing the application. If you are stuck or if you need any information in particular please post in the same thread.

Hope this helps !

Thanks

Ganesh

So I've made this app, where I find all BLE Devices with a name. But how can I make one of the specific fields, clickable and automatic connect to the device, so I can start writing/reading from it?

Download android studio app project

0 Likes
lock attach
Attachments are accessible only for community members.

In your MainActivity.java, you have the function OnItemClick that needs to be implemented to identify which device was clicked in the list. You can implement it something like this:

public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

   // Used in future BLE tutorials
   if(parent == listView){

  BTLE_Device bleDevice = (BTLE_Device) parent.getItemAtPosition(position);

  Utils.toast(getApplicationContext(), "Selected Device: " + bleDevice.getName());

  Utils.toast(getApplicationContext(), "Device RSSI: " + bleDevice.getRSSI());

  Utils.toast(getApplicationContext(), "Address: " + bleDevice.getAddress());

   mBTLeScanner.connectDevice(getApplicationContext(), bleDevice.getAddress());

  }

}

You need to then add the connectDevice function. I have added it to the file Scanner_BTLE.java for now. And to understand when the connection is successful you will need to implement GattCallbacks to track the various events. I have implemented the basic structure for these in the files attached. You can build on top of this.

Hope this helps

Regards,
Dheeraj

Thanks for the input, I took some inspiration and did it like this Link to project

What I did is like you said, make a onItemClick, and this I made an intent with the mac adress, so I know what device i clicked. Then in the new activity I GettCallback, that i use in the onCreat.

First I get the device by It's MAC-addr: BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(DeviceAddress);
Then I use the GattCallback to conect: device.connectGatt(this, false, mGattCallback);mBTLeScanner.stop();

I think this might work, or should i impliment the gattCallback in Scanner_BTLE.java?

Another bug I found is when I click "Start scan" then it scans for devices 7,5sec but if i click my device after 2sec then it connects to the device, but then when the 7,5sec is done it dissconnect the device. It's because it's running stopScan(); --> mBTLeScanner.stop();

so i have to cancel this call somehow

0 Likes

Can you try increasing the connection interval (probably ~20ms)? Change the slave latency to 10. Check if it works with this change.

This issue was seen sometime back and this solution seemed to work for the user: Re: BLE disconnects immediately after connection

Regards,
Dheeraj

I dont think thats the issue here, i think it might be because the code is not all done yet.

0 Likes

Use the CySmart app and verify if all the functionality is working correctly and if you can observe the same issue. If not, we can debug the custom Android app code. Since I don't see the PSoC Creator project attached, I just want to make sure that everything is working from the PSoC side.

Regards,
Dheeraj

Here is my PSoC program: Link to project
It works fine with the CySmart app

0 Likes

So I'm creating a BLE connection between my PSoC 6 BLE and a Android App, the connection is etablished and works. But I dont get the read value from the PSoC.

If i use the app CySmart and read, it works perfectly.  So I think i might do somthing wrong in my app part.

Here is the app: app Link

PSoC project:  psoc Link

0 Likes

Discussion moved to duplicate thread: Can't read from BLE Device Android App

Regards,

Dheeraj

DheerajK_81
Moderator
Moderator
Moderator
First comment on KBA First comment on blog 5 questions asked

Additionally, you can find a video tutorial and source code for a simple BLE app in the links mentioned below:

Although this series makes use of PSoC4, the Android App side of it still remains the same and can be reused for PSoC6.

Regards,

Dheeraj