Printout PSoC6 data or logs via BLE on PC/Windows

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

cross mob
lock attach
Attachments are accessible only for community members.
Kenshow
Level 8
Level 8
Distributor - Marubun (Japan)
50 solutions authored 25 solutions authored 10 solutions authored

Hello,

I was approached by someone who required to use the PC's BLE instead of Uart serial to output PSoC logs and data. And since there was no sample, I made one.

The environment used is as follows:

・PSoC Creator 4.2

・CY8CKIT-062-BLE

In the case of Bluetooth, we were able to use SPP to represent it, but BLE does not have this profile, so we need to create a custom one. The communication between the PSoC6 kits was created by Yugandhar, so I used this Peripheral side program as a base and combined it with a simple printf sample. When the SW2 on the kit is pressed, a message is counted up and displayed on PC’s DOS window.

The program using BLE on the PC side has been created in C#/VisualStudio2019 and can be used as a basic program for PC BLE. It runs on the DOS of the PC and can pair with BLE devices and read/write, but in this case, we have chosen to run read directly after pairing. The menu is not shown in the comment out, but you can select Read or Write as well.

After the PSoC side program is executed, the PC side program is executed on Dos. The procedure is:

  • Scanning for BLE Devices
  • Connect to the PSoC 6 BLE kit
  • Press SW2 on the PSoC 6 BLE Kit and verify that the message on the DOS updates.

The PC I am using is Win10 with BLE4.2. The result is displayed as follows:

 

C:\Users\134546\source\repos\BLE_Dice\bin\Debug>BLE_Dice.exe

BLE Gatt Client(.Net Framework) by Marubun

 

Menu:

1:Scan

2:Connect

Q:Exit

?

1

 

Scan Start

---Received---

MAC:00A050AABBFF <- PSoC6's

NAME:BLE_Serial

---Received---

MAC:12AA042E349B

NAME:

--------------

Scan Stop

 

Menu:

1:Scan

2:Connect

Q:Exit

?

2

 

0:00A050AABBFF <- PSoC6's

1:12AA042E349B

?

0

 

Connect to 00A050AABBFF

UART Service {0x0003cdd0,0x0000,0x1000,{0x80,0x00,0x00,0x80,0x5f,0x9b,0x01,0x31}} found

RXD Char. {0x0003cdd2,0x0000,0x1000,{0x80,0x00,0x00,0x80,0x5f,0x9b,0x01,0x31}} found

TXD Char. {0x0003cdd1,0x0000,0x1000,{0x80,0x00,0x00,0x80,0x5f,0x9b,0x01,0x31}} found

Notification Enabled

Connect success

 

Menu:

1:Scan

2:Connect

Q:Exit

?

Please start PSoC. <-  Push SW2 on 062 kit

 Hello Count 1

  Hello Count 2

  Hello Count 3

  Hello Count 4

  Hello Count 5

  Hello Count 7

  Hello Count 8

  :

 

Known issue:

As mentioned above, the first column is missing for some reason. So I put a blank in the first column of the message, but I hope someone will fix this bug and post it.

 

Thanks,
Kenshow

1 Solution

Kenshow-san,

I believe I have some answers.   

Using debugging on the BLE_Dice shows the PSoC6 ASCII string IS INTACT as expected.

The issues appear to be how certain ASCII codes are processed in the BLE_Dice console window using the Console.Write().

First issue (Missing 'H' on the first Count report).

The BLE_Dice console uses LF ('\n') to advance the line AND places the cursor to column 1.   Using CR ('\r') only returns the cursor to column WITHOUT advancing the line.

Your original string "Hello Count %d \r \n" would print "Hello Count <with the new count>".  Next the CR would NOT line advance but place the cursor at column 1 (right on top of the 'H').  The next character is a SPACE which overwrites the 'H' (the reason for the missing 'H') and then the LF would advance the line and place the cursor back at column 1.

Change the code at line 138 to fix the missing first Count report:

sprintf((char *)notify, "Hello Count %d\n", count);

Second issue (New Count reports start in Column 2).

The PSoC6 program has the following code at line 139. 

buffer = strlen((char *)notify)+1;

The "+1" causes the NULL (\0) to be passed to BLE_Dice console.   The Console.Write() takes this ASCII code and convert it to SPACE character.   This is why the following Count reports start in column instead column 1.

There are two ways to solve this.

1) Eliminate the transfer of NULL in the BLE ASCII data.   Change line 139 to:

buffer = strlen((char *)notify);

OR

2) Ignore NULLs in BLE_Dice.

I chose 1) above.  Below is a "fixed" Count report with no missing 'H' and text starting in column 1.

Len_CONSULTRON_1-1617194773889.png

 

Len
"Engineering is an Art. The Art of Compromise."

View solution in original post

11 Replies
Vasanth
Moderator
Moderator
Moderator
250 sign-ins 500 solutions authored First question asked

Hi Kenshow san,

Thanks for sharing the solution with the community.

Best Regards,
Vasanth

0 Likes
Len_CONSULTRON
Level 9
Level 9
Beta tester 500 solutions authored 1000 replies posted

Kenshow,

I downloaded your files.

I can build and run the VS9 program OK.   The PSoC6 project is missing the host_main.c file at a minimum to rebuild.

Len
"Engineering is an Art. The Art of Compromise."
0 Likes
lock attach
Attachments are accessible only for community members.
Kenshow
Level 8
Level 8
Distributor - Marubun (Japan)
50 solutions authored 25 solutions authored 10 solutions authored

Hi Len,

Thank you very much for pointing this out. Only this file was in another project and was not included in this project. I will attach the file you pointed out to this thread. Please add host_main.c file under the "Shared Files" folder of the project.

1.png

 

Thanks,
Kenshow

0 Likes

Kenshow-san,

Thank you.  The host_main.c solved the build issue.

I'm trying to debug the PSoC6 code but having some difficulty.   I'm trying to locate the ISR that is connected to SW2 to trace the issue you post.

I need some help.  I'm more familiar with PSoC5 coding methods.   

I see the GlobalSignal connected to the SysInt.   The SysInt PDL method is a bit convoluted.   I'm trying to locate the ISR for this interrupt.

Len
"Engineering is an Art. The Art of Compromise."
0 Likes

Kenshow-san,

I can reproduce the dialog you detail in the BLE_Dice console window.  However, I cannot locate the code being executed on the PSoC6-side when the SW2 is pressed.

I've looked for text "Hello Count" in the source files to no success.  I've tried to code analyze the IRQ path to no success.

Len
"Engineering is an Art. The Art of Compromise."
0 Likes
lock attach
Attachments are accessible only for community members.
Kenshow
Level 8
Level 8
Distributor - Marubun (Japan)
50 solutions authored 25 solutions authored 10 solutions authored

Hi Len-san,

I'm sorry. I accidentally deleted the file, so it took a long time to recreate the project. As you pointed out, it is added to the interrupt ISR settings in host_main.c. And, attach a new project. I hope you enjoy it.

Thanks,
Kenshow

 

0 Likes

Kenshow-san,

The new code now has the " Hello Count" string.  I changed your string to "Hello Count"

When I run the PSoC and BLE_Dice code I get your missing 'H' for the first count only.  The remaining counts from SW2 presses, the initial 'H' is present.

I noticed that the output to the BLE_Dice console for the "Hello Count" starts in Column 2.  Other string output to the console window starts at Column 1.

I've begun the debugging task.  My first impression is that the missing 'H' on the first count is due to the BLE_Dice console output processing.

Len_CONSULTRON_0-1617192857952.png

I'm trying to find a PC program (other than BLE_Dice) to display text on a BLE channel.  If not available, I'm trying to find a BLE 'raw' data program to determine if the missing 'H' is occurring on the PSoC6-side or not.

Len
"Engineering is an Art. The Art of Compromise."
0 Likes

Kenshow-san,

I believe I have some answers.   

Using debugging on the BLE_Dice shows the PSoC6 ASCII string IS INTACT as expected.

The issues appear to be how certain ASCII codes are processed in the BLE_Dice console window using the Console.Write().

First issue (Missing 'H' on the first Count report).

The BLE_Dice console uses LF ('\n') to advance the line AND places the cursor to column 1.   Using CR ('\r') only returns the cursor to column WITHOUT advancing the line.

Your original string "Hello Count %d \r \n" would print "Hello Count <with the new count>".  Next the CR would NOT line advance but place the cursor at column 1 (right on top of the 'H').  The next character is a SPACE which overwrites the 'H' (the reason for the missing 'H') and then the LF would advance the line and place the cursor back at column 1.

Change the code at line 138 to fix the missing first Count report:

sprintf((char *)notify, "Hello Count %d\n", count);

Second issue (New Count reports start in Column 2).

The PSoC6 program has the following code at line 139. 

buffer = strlen((char *)notify)+1;

The "+1" causes the NULL (\0) to be passed to BLE_Dice console.   The Console.Write() takes this ASCII code and convert it to SPACE character.   This is why the following Count reports start in column instead column 1.

There are two ways to solve this.

1) Eliminate the transfer of NULL in the BLE ASCII data.   Change line 139 to:

buffer = strlen((char *)notify);

OR

2) Ignore NULLs in BLE_Dice.

I chose 1) above.  Below is a "fixed" Count report with no missing 'H' and text starting in column 1.

Len_CONSULTRON_1-1617194773889.png

 

Len
"Engineering is an Art. The Art of Compromise."

Kenshow-san,

Did my recommendations help?

Len
"Engineering is an Art. The Art of Compromise."
0 Likes
lock attach
Attachments are accessible only for community members.
Kenshow
Level 8
Level 8
Distributor - Marubun (Japan)
50 solutions authored 25 solutions authored 10 solutions authored

Len-san,

Sorry for my late reply. I couldn't participate in the CDC because I was busy with other projects.
Thank you for your advice. It worked well in my PC as well. I was doing it with UART first, so it was because the program was remained. Thank you for making it a perfect CE.

10.png

I attached the PSoC 6 project that I changed with your advice.

Best Regards,
Kenshow

 

Kenshow-san,

You're welcome.  Glad I could help.

Len
"Engineering is an Art. The Art of Compromise."