Having issues with my scripts/blocks or i am failing to see something cruicial.
I've not used app inventor before or really used much serial communication either. So i anyone can show me what i've done wrong that would be greatly appreciated.
I've been making an app to control an arduino running some addressible LEDs.
The app should do this:
Send strings over BLE to a HM-10 with arduino
The strings: 0 to 15 M / 0 to 10 S / 0 to 100 B / RGB format 255,255,255
The Arduino should:
Receive strings from HM-10 through "SoftwareSerial" and seperate them based on the trailing delimeter (M, S, V, R ,G, B)
Print the strings to "Hardware Serial" monitor for testing
Problem: When pressing buttons the app the arduino seems to miss characters and somethings jams getting stuck on a previous value.
I tried using a clock to limit the button presses in the App but seemed to only make it worse.
I have cut the arduino code down the relevant sections for easier reading
I have never used BLE before but it doesn't make it easy (Regrets mounting )
Example of serial fail below
AIA FILE HERE:
Light_HM10_BLE.aia (796.7 KB)
#include <SoftwareSerial.h>
SoftwareSerial HM10(9, 8);///9 (RX) ///8 (TX)
//byte IncomingChar = ""; //Read Incommingdata as ASCII
char IncomingChar = ""; //Read Incommingdata as Char
String message = ""; ///Combination of Chars
String Command = "";
String RMode = "0";
String RSpeed = "5";
String RBright = "100";
String RRColour = "255";
String RBColour = "255";
String RGColour = "255";
void setup() {
Serial.begin(9600);
HM10.begin(9600);
}
void loop() {
while(HM10.available()) { ///if software serial has data
IncomingChar = HM10.read(); ///take one charater
// Serial.println(IncomingChar);
message += IncomingChar; //Concatinate onto message
if(IncomingChar == 'M' ) { ///Mode Seperator
RMode = message; /// SAVE INCOMING STRING
int Delimter = RMode.indexOf('M');
RMode.remove(Delimter);
Serial.print("RMode:");
Serial.println(RMode);
message = ""; // Clear Message for next cycle
}
if(IncomingChar == 'S' ) { ///Speed Seperator
RSpeed = message; /// SAVE INCOMING STRING
int Delimter = RSpeed.indexOf('S');
RSpeed.remove(Delimter);
Serial.print("RSpeed:");
Serial.println(RSpeed);
message = ""; // Clear Message for next cycle
}
if(IncomingChar == 'V' ) { ///Brightness VALUE seperator
RBright = message; /// SAVE INCOMING STRING
int Delimter = RBright.indexOf('V');
RBright.remove(Delimter);
Serial.print("RBright:");
Serial.println(RBright);
message = ""; // Clear Message for next cycle
}
if(IncomingChar == 'R' ) { ///RED Seperator
RRColour = message; /// SAVE INCOMING STRING
int Delimter = RRColour.indexOf('R');
RRColour.remove(Delimter);
Serial.print("RRColour:");
Serial.println(RRColour);
message = ""; // Clear Message for next cycle
}
if(IncomingChar == 'G' ) { ///GREEN Seperator
RGColour = message; /// SAVE INCOMING STRING
int Delimter = RGColour.indexOf('G');
RGColour.remove(Delimter);
Serial.print("RGColour:");
Serial.println(RGColour);
message = ""; // Clear Message for next cycle
}
if(IncomingChar == 'B' ) { ///BLUE Seperator
RBColour = message; /// SAVE INCOMING STRING
int Delimter = RBColour.indexOf('B');
RBColour.remove(Delimter);
Serial.print("RBColour:");
Serial.println(RBColour);
message = ""; // Clear Message for next cycle
}
}
}
HM-10 Module properties : Notify,Read,WriteNoResponse.
I believe a handshake style connection would work great for allowing a waiting peroid between send and receive but i have idea how to get the app to listen to incomming BLE or get the arduino to send through
BLE. (Technically '/n' should work as a handshake but its clearly not in this case.)
Ideally the end result I am aiming to achieve is
BLE transmittion between Arduino and App both ways with a delay/handshake on app button inputs to prevent flooding the arduinos serial buffer.