I now have the BLE library running perfectly with the Microchip RN4020 BTLE module. It implements a read characteristic, write characteristic, and notify characteristic. Each of the characteristics are private characteristics. Everything is working great! The App performs real time graphing from the data received and also control LED's on the target board. I will be putting together a presentation to describe the entire project, including the C code that is on a Microchip PIC24 that communicates with the RN4020. I am using a Microchip Explorer16 board with a RN4020 PicTail for the target.
I am working on a converter box, which shall translate commands received via BLE from an Android smartphone to other communication protocols. The converter box will use a Microchip RN4020 module. When I first read Denny Hopp's post, I was thinking ... done deal, I just have to sit and wait … But unfortunately the clients were pressing and I had to use my own brains. With the help of this forum and thanks to my predecessors in this thread, I finally figured out how to set up the RN4020 and how to connect to it via my smartphone. Now I want to share my experiences so far, perhaps paying back some of the debts I owe to others here.
I use a Microchip RN4020 PICTAIL (photo attached). It consists of a RN4020 module which can be accessed via an USB connection. I have connected it to my PC (Win7, 32 bit) and it installed as COM Port, without any problems. As terminal software I use Termite 2.9 by CompuPhase. With this I can send and receive data to and from the module, in particular commands to configure the module as needed, via USB.
The other part of my development setup forms a Samsung Galaxy S 3 neo, with a terminal app I have written, using mkh42's blueSenddata_V2 example as a template (many thanks to him). With this I write and read strings of bytes to and from the RN4020, via BLE.
At first I wanted to use the MLDP feature of the RN4020, which is said to allow a kind of direct data connection. But due to the almost total lack of information from Microchip on this subject, I could not figure out, how to use it. So I did it the classic way using a private service. The maximum length of one transmission is therefore limited to 20 bytes. Longer strings are not supported by the RN4020. In my project this does not matter.
The details can be learned from the attachments to this post:
- Description how to set up the RN4020 module
- Screenshot of the terminal app
- The B4A project of the terminal app. The app can send and receive raw byte and hex data. I have tried to comment the source code as much as feasible.
- Screenshot of the B4A log after a successful connection
Best regards, CHK
After working a while with the BLE Terminal, I realized, that my conversion of bytes to string is not correct. It works fine for byte values below 128, but for values between 128 - 255 the conversion is false. The reason is, that I have used the function StringToBytes from the ByteConverter library. This conversion is done using a certain encoding, and the encoding I have chosen translates byte values above 127 into 2 byte strings. Unfortunately I could not find another encoding, which does the translation in the desired way. So I changed the BLE Terminal at this point. I do no longer use the SetStringValue function, but the SetIntValue function, writing consecutive int values instead of a single string. The conversion of read bytes above 127 back into characters for displaying still remains a bit arbitrary, depending on the encoding used.
I post here a second version BLE_Term_2 with the corrected conversion routines.
Regards, CHK