Help with unwanted ASCII characters in my Status area

You are doing really well.

I would say your ASCII char issue is due to the illegitimate use of sprintf, but the .ino you have posted does not seem to send anything to the App?

The Bluetooth data is sent in 'packets'. Each packet is approx 23 bytes and it's payload (your data) is 20 bytes. Ideally you want to send messages to the App as a single packet, so they have to be concise.

"Blue Hawaii in the making" is 25 bytes whereas "Blue Hawaii" is just 11 bytes. Even then, some cocktails have very long names - since those names are already known by the App and the App has sent a code to the board, there is no need for the board to send a message of this nature back to the App - just the "Drink is Ready!" message is enough, "Making Blue Hawaii" can be displayed directly by the App on send.

@Michael_s_Toybox Looking at your INO file, at the top of your loop is:

if(Serial.available() > 0){ // Checks whether data is comming from the serial port
    state = Serial.read(); // Reads the data from the serial port
    sprintf(state);
}

If you comment out that sprintf you should get the desired effect I would think.

Also, I'm generally confused about the use of sprintf here and that this even works at all. The general form of sprintf in the standard C library populates the memory of the first argument (taken as char *) with the format string at the second argument formatted with any remaining arguments. It seems like printf would be more appropriate.

There is a huge list of 'if' too, I have made an example using switch.

As Evan said, sprintf will generate error, with this arrangement.

So, here is an updated Project and a matching updated Sketch. Using these methods makes it much easier to edit them. The Sketch now compiles but I have had to trust the pin-outs etc.

Cocktails2.aia (4.1 KB)

Cocktail_16_pump_v2.ino (12.1 KB)

yes, I realized after reading that was a messed up version....where the (sprintf) it should have been Serial.println

Chris, I like your code better, the only issue is anything after case 9, doesn't work., like case 11 just runs case 1 twice, and case 12 runs case 1 then 2

Can you debug that by printing the state variable to the Serial Monitor?

           if(Serial.available() > 0)
           {         //Checks for App data (serial port)
                     state = Serial.read(); //Reads data
                     Serial.println(state);
           }

Ah no, cancel that - the code is good, but not the right code!

Try this:

           if(Serial.available() > 0)
           {         //Checks for App data (serial port)
                     state = Serial.parseInt(); //Reads data
                     Serial.println(state);
           }

The above should work given that it accepted 'text' sent by the App as a number. If it fails, then we can send an actual integer thus:

EDIT:

Use this Block Michael, Send1ByteNumber, as per Evan's Post.

.... and this Sketch:

Cocktail_16_pump_v3.ino (12.1 KB)

@ChrisWard I think the issue with your code is that Serial.read() will read a byte (as an int) off of the stream, whereas your switch statement compares the read value against individual characters. However, '10', '11', etc. are not "characters" and so the test against the state variable can never succeed. Instead, loop() will execute twice where state is 1 then 0 or 1 then 1, etc. for each character in the string you send because you are calling BluetoothClient1.SendText.

Instead, it might make more sense to call BluetoothClient1.Send1ByteNumber where the selection index will be interpreted as an integer between -128 and 127. Under this scenario, the switch can test cases 1, 2, 3, ...

Thanks Evan, re my previous post the .read mistake had already been discovered.

So the v3.ino worked, except I had to change :

if(Serial.available() > 0)
{ //Checks for App data (serial port)
state = Serial.parseInt(); //Reads data
Serial.println(state);
}

Back to:

if(Serial.available() > 0)
{ //Checks for App data (serial port)
state = Serial.read(); //Reads data
Serial.println(state);
}

Because the "println" code wouldn't turn on any relays for the pumps. So with the ver 3, and the Send1ByteNumber as per Evans Post...every thing seems to be working correctly.

I'll be honest....I'm lost on what command it is actually sending to the arduino now....so I'm kinda confused how it is working. I'm assuming if I want to add more drinks or create setup buttons for each alcohol I just keep the correct order on the arduino code, and the app?

OK -

  1. The cocktail names are stored in a Blocks List. The cocktail ingredients are also stored in a Blocks List, in sequence with the cocktail names. Each Item of a List has an index number, starting at 1 (Item 1) and currently ending at 21 (Item 21).

cocktail Index 1: AMF; Ingredients Index 1: Sour mix, gin, vodka, tequila, rum
cocktail Index 2: BGM; Ingredients Index 2: Creme de violette, gin, lemon juice

  1. The procedure 'PopulateListView' combines the two Block Lists into one List View component that displays the info to the App User. The List View also has Index numbers (currently 1 to 21), same as the Block Lists.

  2. When the App User selects a cocktail from the List View, the code 'knows' the Index number of the selection. For example, if the User selects "Double Strike", that's index number 8 - the code sends that number, the 'Selection Index', to the Arduino. The code also uses the Main Text of the List View selection (Main Text = Cocktail Name) to inform the User that the system is making the cocktail (Status) .

  3. When the Arduino receives the selection index number as the variable 'state', the switch code runs the Mix procedure, sending it the ingredients required to make the cocktail. If the cocktail was made by hand the ingredient values would be in one of any traditional liquid measurements. In the USA that might be fluid ounces - so a "Double Strike" cocktail would be 1 1/2 oz Vodka, 1 oz Blue Curacao, 3/4 oz Cranberry Juice, 3/8 oz Lime Juice. These measures are approximated as the time in milliseconds required for the pump to pour it's ingredient.

So if you want to add another cocktail, you just update the Block Lists in the App and Add another 'case' in the Arduino Sketch. I would keep the cocktails in alphabetical order to make life easier for the User.

AddToBlockList

You can add a new item to a Block List in any position. Just make sure it's added in the same position in the Arduino Sketch.

Cocktails4.aia (4.3 KB)

Cocktail_16_pump_v4.ino (9.6 KB)

To give you a head start, I completed the cocktail ingredients list. I noticed that you don't have a pump for some of the ingredients such as Vanilla Syrup, Lime Juice, Creme de Violette, Soda Water ... etc

Yeah, I'm adding another 8 relays and pumps...lol started off as 8, then I was like if you added this these 2 cocktail ingredients, it allows you to do 4 more cocktails, and ballooned from there. I like to hold cookouts in the summer so, this is going to be my new thing for next summer. I also started from a regular arduino uno, and ended up going to arduino mega.

...may be you need to add an extension to your house :grin:

I might...lol