Read EERPOM to software on PC

I had written an Qt-GUI library C++ program contains a table interface ,and a “Read Table” button to read values of arduino’s EEPROM addresses from spinbox1 to spinbox2
,like this:

push the “Read Table” button, Table will load the value of EEPROM address from 0~9, map to (row 1,column 1~10).
etc… EEPROM address 10~19 ,map to (row2,column 1~10)
EEPROM address 20~29 ,map to (row3,column 1~10)

here is the c++ code of Read Table button function.

void ArduinoComm::readTable()
{
ui.msgBrowser->append("----------Read table from EEPROM----------");
for(int address=ui.sbFromE->value();address<ui.sbToE->value();address++)
{//sbFromE is the spinbox1,start of the address
//sbToE is spinbox2 , end of the address(none contain)
QString text;
QTextStream(&text)<<’#’<<address<<’$’;//read EEPROM command
port->write(text.toAscii(),text.length());//write command to arduino
}
}

The software send an “Read EEPROM” command = #address$
address is a variable which is the EEPROM address;
As Arduino receive #address$ ,the loop() procedure will decode the command and reply an message #address$value%
value is the EEPROM data of address
Arduino code like this…
if(Serial.available()>0){
readByte=Serial.read();
if(readByte==’#’)//decode start of command
{
state=1;//EEPROM address
digits=0;
}
else if(readByte==’$’)//decode end of command
{
state=2;
digits=0;
value=EEPROM.read(address);
//reply address and value to PC
Serial<<’#’<<address<<’$’<<value<<’%’;

}
else if(readByte-‘0’>=0&&readByte-‘0’<=9)
{//decode address of command from byte/char to int
digits++;
int value=readByte-‘0’;
if(state==1)
{
if(digits==1)address=value;
else address=address*10+value;
}
}

As software receive the reply message #address$value% contains address and value ,the read serial procedure will also decode the message then save the value of address into table.
Software code like this
if(buff*==’#’){*

  • state=4;//EEPROM address*
  • digits=0;*
  • }*
    _ else if(buff*==’$’){_
    _
    state=5;//EEPROM value*_
    * digits=0;*
    * }*
    _ else if(buff*==’%’){
    state=6;//end of EEPROM protocol*
    * digits=0;
    //save the EEPROM value of address to table*
    * this->model->setData (model->index(addressE/10,addressE%10), valueE);
    }
    else if((buff-‘0’)>=0&&(buff-‘0’)<=9)
    { digits++;
    int value=buff-‘0’;
    if(state==4){
    if(digits==1)addressE=value;
    else addressE=addressE10+value;

    * }
    else if(state==5){
    if(digits==1)valueE=value;
    else valueE=valueE10+value;

    * }
    } [/color]*

    Afterall, it is perfect to use these to read EEPROM from address 0 to 10,but arduino dont reply the message when software want to read 50 EEPROMs , like spinbox1=0 ,spinbox2=50, I think it let arduino receives too many serial commands cause to the transmission error. Does anyone has better solution?? Maybe neefing some checksum mechanism or sth?? I have been annoying in the serial communication between arduino and software so long…_

Consider using Bitlash on the Arduino to process your serial commands and send back the contents of the EEPROM. Bitlash is available at http://bitlash.net as an open source library for Arduino 0018.

The Bitlash er() function returns the value stored in a location in EEPROM. You could send "print er(0)" or "print er(1023)" or whatever. (Followed by a newline of course...) Bitlash will send back the value in decimal, followed by a new line and the command prompt. You can do reasonable flow control by just waiting for the '>'.

(For hex values you could send "print er(0):x", the ":x" part forces hex output.)

More at http://bitlash.net and http://entropymouse.com and happy to take followup questions here.

Cheers,

-br http://bitlash.net http://entropymouse.com

thank you very much , i will check that