Hi,
A while back I needed some help with my SDCard project and a really nice guy on here helped me to resolve the issues I was having using the strcmp strtok and atoi commands.
I thought I understood how to carry this forward to my next project... how wrong was I. I'll try and put as much info here as possible but if I leave anything important out, please accept my apologies and I'll add that information.
What I want to do:
I have an Arduino that sends a text string message (via a Bluetooth module) when a setting is changed to another Arduino with a small 8x2 LCD connected to it. So I have a Controller and remote
So on the first Arduino (Controller) I have the following lines.
if (line == 1) { Serial.print("Speed ,"); Serial.println(T_degree[tilDegree]); } //should result in "Speed" on lcd(0,0) and "1 - 5/8" for example on lcd(0,1)
if (line == 2 && tilDirec==2)
{ Serial.print("Direc ,"); Serial.println("Up"); }
if (line == 2 && tilDirec==3)
{ Serial.print("Direc ,"); Serial.println("Down"); } //this can be streamlined with else
Basically 'line' refers to a menu line number - there are 7 menus each with at least 2 lines. The current line sends a two string statement with a comma delimiter to separate it into the two lines to be displayed on my LCD.
On the second Arduino (remote) I put the following code
if (Serial.available() > 0)
{
co_data = Serial.readStringUntil('\n');
int commaIndex = co_data.indexOf(',');
String firstLine = co_data.substring(0,commaIndex);
String secondLine = co_data.substring(commaIndex+1);
lcd.setCursor(0,0); lcd.print(firstLine);
lcd.setCursor(0,1); lcd.print(secondLine);
co_data = ""; firstLine =""; secondLine="";
}
The problem with this is that although it works, on the second line of the LCD I get a random looking character after the secondLine string followed by a repeating of the firstline. string So I am guessing my code is repeating itself. and not clearing the buffer(?) plus this doesn't look like a neat way of doing it.
So what I thought was I would try the code given to me by PaulS who previously helped me out.
I figured that using the strcmp strtok and atoi commands must be a better way of doing this, but my knowledge of how to implement this is not what I thought it was and so I can't make it work. and then accidentally closed the wrong window and lost what I had been trying. - need to press ctrl-s more often (then I shorted out one of the Arduinos and fried it. Spare now in its place.)
Can anyone clue me in / show me code replacement for the above on how to:
Serial.print a string i.e "Speed,100%" and then receive it on the other Arduino and lcd.print it out to show
Speed
100%
using the strcmp etc commands.
Many thanks
Steve (in the UK)