Difficulty sending more than one variable from a Microchip microcontroller using BLE (HM-10) and MIT APP inventor

I've been doing my homework, reviewing the BLE extension docs at

(The link to newer info seems only to point to a microbit course.)

There is no mention of message delimiter byte values, other than an option to use NULL as a message delimiter for strings being sent from AI2. (NULL is hex 0, which I have yet to find a meta character for, like \n or \r.)

Using \n at the end of an incoming message seems to be folklore, until I can find a reference.

I was also unable to find any mention of commas as having any significance to the BLE data stream.

Any good links to the docs for the BLE substrate?

"\0" = Null

It is in the pop-up hint of the Strings Received Block.

Commas are used to separate values in an App Inventor List.

That is done deliberately by your App Inventor code, current message replaces previous message. To append instead of overwrite:

Snap6

I always advise against trying to test BLE via the companion - APK test is best.

We need to see your most recent code, both sides.

Thanks for the NULL meta character \0.

Unfortunately, I have yet to see a sample sketch where it is used to trigger any data stream side effects.

If I had BLE hardware, I would test to see if the inclusion of commas in an incoming string data stream affect the length of the incoming stringValues list as measured by the AI2 Length of List block.

That's perfectly fine but it is good practice to request them via the App so that nothing gets overlooked and it is helpful for the people trying to help too, as we need to see everything that could have an effect on the data transmission. Speaking of which, is your microchip hardware hooked up to a monitor for debugging? Does it have exactly the right power supply?
https://www.professorcad.co.uk/appinventortips#BluetoothFailure

Well the Block is making an App Inventor List, and App Inventor Lists use a comma as the value delimiter...... it could not be a List without a delimiter. The pop-up hint refers to "Make A List" as an example, so I think that really confirms it.

Edit: It could be a List of one value without a delimiter.

Long shot: There may be something odd being introduced into the 2nd value - an unseen character or corruption.

Try this:

printf("123,456\0");

If the above test works, then try:

char sVals[16];

sprintf(sVals,"%d,%d\0",PanTempSetpoint,ProbeTempSetpoint);
 printf(sVals);

If the above fails, next step is to have more detail about your hardware - the exact PIC model for example.

Are you using the Microchip IDE MPLAB X?

Chris and ABG... thanks for your help.... it is appreciated.
The sprintf approach worked. Hopefully this forum stream will help others as they work with BLE and a "non-arduino" microcontroller. I will be working on a slider and passing data from the APP back to the Microchip micro next.

1 Like

Would you mind posting the code that worked, both sending and receiving?
We need good samples.

1 Like

Well that's good news Patrick. On the App Inventor side, are you using my "or better" Strings Received Block?

.... and tidy up your components with a proper naming convention so that your code will always be easy to understand in the future. Also delete the redundant components and Blocks.
https://www.professorcad.co.uk/appinventortips#TipsGui

Chris, ABG,
See software for the PIC
main fixed.txt (15.2 KB)

See project
Swirlworks.aia (198.5 KB)

Early this morning, I went back to the base project that ABG provided... changed the data separator from"|" to "'," ... so I didn't use the "or better"

I then implemented the sprintf and the data ended up in the labels... I have since expanded the APP to accept more values from the PIC and placed them into the new labels.

I did my homework before jumping on this forum... there is nothing else out there to deal with this combination of issues, and it should prove helpful to others...
Thanks again ...

Hi Patrick

Well, I think you should use my "or better" example because even your latest version is vulnerable to glitches and faults. You should always test the length of a List before trying to access it's content, not after. Also 'stringValues' is already a comma separated App Inventor List, so there is no need to split it into another comma separated List.

Try this:
Swirlworks_edit.aia (198.5 KB)

I'm dying to see how this works out.
Please try it!

1 Like

Chris,
I loaded Sirlworks_edit.aia --- .apk

1.) After I scan for/connect to the HM-10
2.) The BLE Status label shows "Data Fail"
3.) PAN and TIME labels show PAN and TIME and no values

1 Like

That's not great news :thinking:

Would you mind testing this one? I have added a debug label (yellow) . It should show us what has been received.

Swirlworks_edit2.aia (198.6 KB)

.....and can you tell me the model of the PIC you are using?

ABG, Chris...
loaded Swirlworks_edit2.aia ... as .apk
The PIC is PIC16f18855

The yellow label shows ["153,150"]
These are the correct values coming now from the Microcontroller.
The PAN, TIME labels are not updating