Command prompt design issue

Hello below i am having issues building a command prompt system for my arduino. so i may interface between the serial monitor and see the hardwares voltages and such.

I am trying an approach to read in a word in the serial monitor and place into a character array. Then i wish to index each letter in the array into a variable called txtMsg, to give me a numerical value (ascii) that i can apply to a selection statement. I have realized though the Serial. read function only does one char at a time and this is not what iam looking for.

Short: I need a differnt serial.read () function that will simply read in each charachter and place them into a character array.

Command_prompt.ino (6.64 KB)

Simple: post your code.

The serial input basics tutorial may have information that you can use.

If you use single letter commands, you won't have to save them.

The state machine example in Nick Gammon's serial input tutorial covers letter-number combinations.

http://gammon.com.au/serial

I have sketches to make a keyword list with up to 255 variable-length words stored in flash. It reads text and finds where in the list it can be with help from links, if a char does not match and there is a link to another word that that starts the same but is different for that letter, there is a link to it and if that doesn't match there is either a link to another or the code flags a no-match.

If that seems tricky, it is. I wrote one sketch just to take a new word list and generate Arduino source code for all the tables be put in flash/PROGMEM. There is one function that you feed input chars to one at a time (as they arrive in serial) and it returns status of the match process each time. The rest is whatever sketch uses it.

What it gives is a serial keyword match routine that tells you what word was matched on the arrival of the last char of the word. Methods that buffer then compare start on arrival of the final char, just fine for one at a time command entry. The difference is that mine finds matches as they happen without needing to stop between. I fed it long lines of keywords at 250000 baud and it kept up. The example prints trace data to show what was read and where it points in the data while doing that.

BTW, I've done this kind of thing before in the 80's and 90's. I think it's still regarded as work.

I am working on a smaller version that stores list and links in EEPROM. There would be 255 bytes of list space including delimiters. 50-60 commands would be in the park, it could go farther if the keys combine but that's if I get it done.

Hi, Welcome to the forum.

Please read the first post in any forum entitled how to use this forum. http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code. It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom.. :)

Ryansand: Short: I need a differnt serial.read () function that will simply read in each charachter and place them into a character array.

Create a char array as buffer and a byte as counter (or unsigned int if your buffer is >255).

When there's a character available: read the character; place it in a buffer; increase your counter; wait for the next to arrive. I do assume your loop() will be much faster than the transmission of a single character. Upon receipt of the terminator character process the string.

I hope you're aware of the dangers of buffer overruns (keep track of how many characters you got; don't trust the source to not send too many in one go).

Ryansand: Short: I need a differnt serial.read () function that will simply read in each charachter and place them into a character array.

Sounds like Serial.readBytes(): https://www.arduino.cc/reference/en/language/functions/communication/serial/readbytes/ Note that the default timeout on this function is 1000 ms. That can be changed via Serial.setTimeout().