BluetoothLE, string is getting cut off or something causing issues with array in Arduino?

I'm making a project in which a BLE HM-10 is sending a string of text to an Arduino. All is working fine when sending the string via serial monitor or the DSD Tech app for Android to the Arduino.

The string sent from app is: "01,10,01,10,01,10,01,10,01,10,01,10,"
When received at Arduino it becomes: "01,10,01,10,01,10,01,2277,2277,2277,2277,2277,"

I have tried to input "values" with both "text" and "join". Same issue.

I'm using BLE extension "Build 20181124" and "Call BLE WriteStrings".

Thanks in advance. Regards, Kasper.

A piece of the code (sorry for it being in danish, but you get the point :slight_smile:)

if (Serial.available()) {
for (int dispenser = 0; dispenser < antalDispenser; dispenser++){
for (int parameter = 0; parameter < parameterDispenser; parameter++){
for (int parameterTal = 0; parameterTal < parameterLaengde; parameterTal++){
if (Serial.available()) {
serielTal = Serial.read();
serielTal = serielTal - 48;
samletTal = samletTal * 10 + serielTal;
} else {
delay(500);
serielTal = Serial.read();
serielTal = serielTal - 48;
samletTal = samletTal * 10 + serielTal;
}
}
mixerArray[dispenser][parameter] = samletTal;
samletTal = 0; // Ryd til næste tal
serielTal = Serial.read();
}

    }

Well, I don’t get the point, no :grin:

You are sending comma delimited values as a single string, yet:

serielTal = serielTal - 48;
samletTal = samletTal * 10 + serielTal

That surely does not work?

You probably need to send an end-of-data flag too.

Thanks for replying this fast.

Total noob here :+1:

I’ve used the code from DIYmechanics on YouTube. Probably not the best source!?!?

May I ask? What would be a good format for this and which of type variable would be best in this case?

Thanks. Regards, Kasper.

I do not know what it is you are trying to do Kasper. Perhaps if you can tell us that, we can help a bit :wink:

Of course.:+1:

I want to control a stepper motor and a servo sequence via Bluetooth. Ex. with a pair like “01,10”. If the first value in the segment is higher than 0, the stepper stops at a predefined location for set “xx,xx” and another for ““yy,yy” and so forth. The second value in the segment defines the amount of time the servo is active. If “02,10”, the servo is activated twice at the location, each time the amount of time given in the second value. If 00,00” the stepper skips and goes to the next place on the linear rail.

Your help is highly appreciated. Thanks.

… so it sounds as though you don’t want to send more than one pair of instructions at a time? If you actually do, then we need more than one delimiter, like this:

so for example the App would send: 1,10|2,10|1,8|00,00|E,E| (five pairs plus the ‘E’ flag to tell Arduino “end of data”).

… but sending several instructions in one go means you require an efficient way to extract the pairs from the string. C has an efficient method, but it’s not for the faint heart.

on the other hand, using a clock timer in the App, you could send each individual value one-at-a-time , or each pair one-at-a-time.

I do need to send more than one pair at a time. During a run, the stepper could stop in a series og maybe six or eight different locations, so I need to send all instructions in one go.

An idea! Given that an instruction is always two characters. Could I send a string like "0123456789\n" and look for the end flag? And do one pass for each read character?

Maybe something like:

char EOL = '\n';
char stringIn;
while (Serial.available() > 0 && EOL == false) {
........some "for" to count the passes.......
stringIn = Serial.read();
if (stringIn != EOL) {
mixerArray[arrayCount][parameter] = stringIn;
arrayCount++;
........some end to the while loop.....

Yes - you can read the string char-by-char. End the While Loop with break.

Is there a limit to how many characters you can send in one ble transmission?

I’ve seen several threads that dealt with receiving BLE fragments and reassembling them.

I have done some changes, but now I keep getting this result:

The string sent from app is: “01,10|01,10|01,10|01,10|01,10|01,10”
When received at Arduino it becomes: “01,10|01,10|01,10|01,10|00,00|00,00”

I’ve got some clues now. From what I can read in other posts, the link MTU (maximum transmission unit) is set to 23 by default(only 20 of them can be used to set a value). The BLE specification doesn’t allow write operations to exceed 20 bytes.

That seems to be the case. Only fix seems to be the implementation of a fragmetation mechanis…

The Spec does allow write ops greater than 20 bytes, but the MTU must be increased on the BLE device to allow this. We have a Beta Version of the BLE Extension that understands MTU.

How slowly can your machine accept each instruction? Perhaps you can get away with sending pairs, timed, say 200 to 300 milliseconds apart?

I’ll have to look into that later. For now I have quick-fixed it and gone down to 2 bytes pr. instruction, then multiplying the latter byte in code to compensate for the “compression”. Everything works perfect now.

Thanks for all the input!

/Kasper

That sounds like a practical way round :grin:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.