Serial.read() returns a Char, that is a single Character. A sample of the code that I tend to use is below…
Please bear in mind that this will not compile in itself… It is just a snippit.
Darryl
static char inData[51]; // Allocate some space for the string
static char inChar=-1; // Where to store the character read
static int pos= 0; // Index into array; where to store the character
while (Serial1.available()){
if (pos < 45){
inChar = Serial1.read();
inData[pos] = inChar;
pos++;
inData[pos] = 0;
if (inChar == 0x0A || inChar == 0x0D){
// End of line... Process things here...
pos = 0;
inData[pos] = 0;
}
} else {
pos = 0;
inData[pos] = 0;
}
}
Thats exactly what i was after! Thanks for the fast reply
@vk2tds Im guessing your into radio stuff? Been working on a little side project for my old man, a tuner for a mag loop antenna. basically just a stepper on a VVC at the moment with tune up and tune down buttons. might have a look at putting a spark on it to one day and some kind of antenna analyzer so its self tuning all you have to do is enter a frequency
Glad I could help… I was doing some programming on the spark and just needed a little distraction. I am still coming up to speed on the Spark myself… and as the textbook in my bookcase says, I have “C as a second language”. These days I don’t do enough programming to stay up to speed with any language.
And I guess you could call me a radio geek… Amongst other bits and pieces.
Next question… reading a number… i thought it would be easier… if i type 2 into the terminal it gives me 50… so its ascii equivalent of the char??
How would i make ‘c’ be the right number… you know what i mean?
Serial.println("Select user from List:");
while(!Serial.available());
int c = Serial.read();
Serial.print("Updating User number:"); Serial.println(c);
if ( c >= 0 && c <= Usernamecount) {
if (SD.exists(UsernameFile)) {
dbFile = SD.open(UsernameFile, FILE_WRITE);
if (dbFile) {
db.open(0);
db.updateRec(c, EDB_REC Username);
dbFile.close();
}
}
Normally when you enter numbers they are more than one digit long, so you would need to look at the numbers in a string. There is a function called atoi, and another called atof. That is Ascii to Integer, and Ascii to Float. Google them. You could use sscanf but it will take up more flash, or at least did in my case.
Might be a good idea to find a good resource for ‘C’ string processing. I actually refer back to the manual that came with Microsoft Quick C back in 1990 occasionally, as the manual was excellent whilst Quick C was horrid!
Awesome… I’ll give it a go I normally do lots of searching on this forum and arduino forum… but it’s hard when you don’t understand what your searching for. I came up with some going the other way but not the way I needed.
I’ll have a look at those tomorrow when my eyes aren’t so square!
For now I have made it work with a very simple atoi thingy… This fingerprint and rfid project is really coming together now… All I need to do is put everything together… And maybe a lot of optimisation as my code is terrible but it works. Then maybe look at security and see if I can make it better in any way.