The easiest way to do this would be to use Bitlash (http://bitlash.net/wiki/start). It accepts commands on the serial port, including commands to read from/write to EEPROM.
thanks for your replies , Bitlash looks amazing and works well but it seems too much for what i want , i only need to edit a few eprom locations and bitlash seems like a mini operating system.
where im stuck is ....
The next step is parsing the string, and analyzing the tokens,
ok so typed in terminal .... "set 1=34" ect What i need help with is to get ADR = 1 VAL = 33 and more importantly only act when the string has "set" in it.
Yes. The strtok function will allow you parse the string that you get. The first call to strtok has the string to parse as the first argument, and a list of delimiters. The function returns a pointer to a token, AND MODIFIES THE STRING.
Subsequent calls to strtok take NULL as the first argument. There are no more tokens when strtok returns NULL.
You can convert the token to an integer or float, if appropriate. You can compare the string (strcmp) to "set" or "get" or "Fred" or whatever, to determine what to do.
char *p is a pointer. You need to allocate space for it to point to. You have not done that.
Arrays are treated as pointers, too. So, if you have
char inData[24];
you can pass inData to strtok. You can fill each position of the array with a value read from the serial port. Just make sure to put a NULL in the next position, too.
I outlined the steps required in reply #1. From the response you provided, I assumed that you know how to get the data from the serial port as an array. Now, that appears not to be the case. It's easy, really.
int inPos = 0;
char inData[24]; // Adjust the size as needed
void loop()
{
while(Serial.available() > 0)
{
char aChar = Serial.read(); // Read a character
inData[inPos] = aChar; // Add it to the array
inPos++; // Move the index forward
inData[inPos] = '\0'; // Add a NULL terminator
if(inPos == 23) break; // Make sure there is still room
}
if(inPos > 0)
{
// Parse the string here
// Use the data here
// Reset to save the next packet in the array
inPos = 0;
inData[inPos] = '\0';
}
}
if doesnt seem to like two numbers , have i put into the array wrong ?
int inPos = 0;
char inData[24]; // Adjust the size as needed
char *OUT[24];
int OUTPos = 0;
void setup()
{
Serial.begin(9600);
}
void loop()
{
while(Serial.available() > 0)
{
char aChar = Serial.read(); // Read a character
inData[inPos] = aChar; // Add it to the array
inPos++; // Move the index forward
inData[inPos] = '\0'; // Add a NULL terminator
//Serial.println(inData[inPos]);
if(inPos == 23) break; // Make sure there is still room
}
if(inPos > 0)
{
char *p = inData;
char *str;
while ((str = strtok_r(p, ";", &p)) != NULL){ // delimiter is the semicolon
Serial.println(str);
}
//Parse the string here
// Use the data here
// Reset to save the next packet in the array
inPos = 0;
inData[inPos] = '\0';
}
}
I have one last question , as im getting...
1
2
3
I need to put that back into an array ect so i can asign each to an varible and then use that data like address = 2 value = 3
After the loop to read the whole string, does the string print correctly?
You don't need to create a pointer to the array.
The strtok command needs to be called once with inData (or p if you are determined to use a pointer), to get the first token. Subsequent calls use NULL as the first argument.
char *token = strtok(inData, ";");
if(token)
{
int val = atoi(token);
whle(token = strtok(NULL, ";")
{
val = atoi(token);
}
}
This code also illustrates how to convert the tokens to integers. If you are always sending the same number of tokens, and the order remains the same, you can stuff the output of atoi into the correct variables. Or, keep track of the next position in an integer array, in the same way that you track the position in the character array when reading the serial data.