Save string in EEPROM

I have a problem, and I need your help. I need read rfid token from card. I want save string "msg" in EEPROM and read EEPROM in computer because I dont know token what my card have. "00402B4D533F" is only sample.

#include <EEPROM.h>

char readString;
char c;
String msg;
int led = 4;
String k;



void setup() {
  Serial.begin(9600);
  pinMode(led, OUTPUT);
}

void loop() {
  while(Serial.available()>0){
    c=Serial.read(); 
    msg += c;
  }

  if (msg.length() > 10) {
    msg = msg.substring(1,13);
    if (msg == "00402B4D533F") {
      digitalWrite(led, HIGH);
    }
    else {
      
      digitalWrite(led, HIGH);
      delay(1000);
      digitalWrite(led, LOW);
    }

    msg = "";
  }
    delay(300);
}

rotflol:
read EEPROM in computer because I dont know token what my card have.

What does this mean? How is the computer communicating with the Ardiuno? What is the computer's role in this?

I want save string 'msg' witch my token to EEPROM and read EEPROM with program "SinaProg". I connected by USBasp, so cant use Serial Monitor in Arduino IDE :frowning:

Example EEPROM from "SinaProg":

:20000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00
:20002000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE0
:20004000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC0
:20006000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA0
:20008000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF80
:2000A000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF60
:2000C000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF40
:2000E000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF20
:20010000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
:20012000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFDF
:20014000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFBF
:20016000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF9F
:20018000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7F
:2001A000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5F
:2001C000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3F
:2001E000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF1F
:00000001FF

I'm fluent in 5 dialects of gibberish!

You have an rfid scanner that saves the rf id to eeprom & you don't know the rf id for the tag, you can only see what is represented in the eeprom?

  • I have RFID scaner.
  • I dont know RFID id for the tag.
  • I use USBasp so cant see RFID id in Serial Monitor.
  • I dont have Arduino. I have ATmega8, USBasp, and use Arduino IDE.

I read RFID id and have it in string "msg". String "msg" I want save in EEPROM. When id of my tag is in EEPROM i read it by SinaProg. But.. How to save string "msg" in EEPROM.

I read RFID id and have it in string "msg".

First off, you don't have a string, you have a String. Big difference. You need to iterate through each character, and put it in EEPROM. Alternatively, you can just put them in EEPROM as you read the individual bytes; unless you're doing comparisons, you don't need to put it into a string.

Im a new. Can you give me some examples?

Examples of what? There are plenty of examples for writing to EEPROM and reading serial data.

Yes.. example this..

void zawodnik_save(struct Zawodnik *zawodnik, unsigned int address)
{
    byte *data = (byte *) zawodnik;
    unsigned int size = sizeof(Zawodnik);
    for (unsigned int i=0; i<size; i++)
    {
        EEPROM.write(address+i, data[i]);
    }
}

But how use it in my code.. I'm trying to do this three days, but nothing.

I connected by USBasp, so cant use Serial Monitor in Arduino IDE

Why? Why are you not using a USB cable so you CAN use the Serial Monitor?

I'm trying to do this three days, but nothing.

It does not take three days to post ALL of your code. Get rid of the String class. Learn to use strings (NULL terminated array of char) for fixed length data, like RFID tags.

Why? Why are you not using a USB cable so you CAN use the Serial Monitor?

Because I have only microBoard M8 witch ATmega8 and USBasp. I dont have arduino... but I use Arduino IDE

rotflol:
Because I have only microBoard M8 witch ATmega8 and USBasp. I dont have arduino... but I use Arduino IDE

It's hard to make sense of your description of what you're trying to achieve, but if I understood you correctly then you have a sketch that is obtaining a number from some other device and you want to know what the number is. You can't simply print it over the serial interface because your serial interface is not connected to USB and so you have no obvious way to get data from the 'microBoard' to the PC.

So the question is how to get data from your 'microBoard' to the PC.

Unless your microcontroller vendor provides some other mechanism, I would have thought your best bet was to obtain a TTL-serial-to-USB adapter and use that to provide a serial connection to the PC. They are inexpensive and readily available. If you don't like that then your next option is to buy an Arduino or clone that does provide a USB serial connection, and use a software serial connection to pass the data from the other microcontroller to the Arduino and hence to the PC.

If I am correct in understanding that you don't have any way to get serial output from your device so far, I would consider this a huge inconvenience in its own right so adding a serial-to-USB interface would be invaluable anyway.

Thanks PeterH.