the HEX value DE = 222 in DEC
the HEX value AD = 173 in DEC
the HEX value BE = 190 in DEC
the HEX value EF = 239 in DEC
the HEX value FE = 254 in DEC
the HEX value ED = 237 in DEC
I want to write the values "DE" "AD" "BE" "EF" "FE" "ED" to EEPROM. Do have to concert it to DEC first? How to do that and if so, how do I convert it back, when I read the EEPROM. and finally I want to put in to
Remember that all variables in the Arduino are simply sored in binary. Writing a number in the source code as hex doesn't change the binary. Printing the same number out as decimal also doesn't change it. Hex or decimal are just the way we see the number when written or printed out. The EEPROM will store data in binary, too.
value = EEPROM.read(0);
Serial.print("0x");
Serial.println(value,HEX);
Remember, the '0x' is only there in the source code and in the printout. It's not stored in the EEPROM, only the binary representation of ED is (i.e. 11101101).
#include <EEPROM.h>
int value;
void setup()
{
Serial.begin(9600);
EEPROM.write(0,0xDE);
EEPROM.write(1,0xAD);
EEPROM.write(2,0xBE);
EEPROM.write(3,0xEF);
EEPROM.write(4,0xFE);
EEPROM.write(5,0xED);
value = EEPROM.read(0);
Serial.print("0x");
Serial.println(value,HEX);
Serial.print("0x");
value = EEPROM.read(1);
Serial.println(value,HEX);
Serial.print("0x");
value = EEPROM.read(2);
Serial.println(value,HEX);
Serial.print("0x");
value = EEPROM.read(3);
Serial.println(value,HEX);
Serial.print("0x");
value = EEPROM.read(4);
Serial.println(value,HEX);
Serial.print("0x");
value = EEPROM.read(5);
Serial.println(value,HEX);
}
void loop()
{
}
Ok, so this works in the Serial monitor but what I really want is that the input "DE" is written to EEPROM (I can't provide "0xDE") This is because I get the value from a FORM submitted via a webpage. Now I realise I have a problem when reading the values from that FORM. I'll have to solve those first and then this problem will be solved too.
FYI
TextFinder finder(client );
while (client.connected()) {
if (client.available()) {
//hieronder blijven
if( finder.find("GET /") ) {
if (finder.findUntil("setup", "\n\r")){
if (finder.findUntil("SBM", "\n\r")){
byte SET = finder.getValue();
while(finder.findUntil("DT", "\n\r")){
int val = finder.getValue();
if(val >= 1 && val <= 6) {
mac[val - 1] = finder.getValue();
Serial.println(finder.getValue());
}
if(val >= 7 && val <= 10) {
ip[val - 7] = finder.getValue();
}
if(val >= 11 && val <= 14) {
subnet[val - 11] = finder.getValue();
}
if(val >= 15 && val <= 18) {
gateway[val - 15] = finder.getValue();
}
}
for (int i = 0 ; i < 6; i++)
{
EEPROM.write(i + 1,mac[i]);
}
for (int i = 0 ; i < 4; i++)
{
EEPROM.write(i + 7, ip[i]);
}
for (int i = 0 ; i < 4; i++)
{
EEPROM.write(i + 11, subnet[i]);
}
for (int i = 0 ; i < 4; i++)
{
EEPROM.write(i + 15, gateway[i]);
}
//set ID to the known bit, so when you reset the Arduino is will use the EEPROM values
EEPROM.write(0, 0x99);
// if al the data has been written to EEPROM we should reset the arduino
// for now you'll have to use the hardware reset button
}
but what I really want is that the input "DE" is written to EEPROM (I can't provide "0xDE") This is because I get the value from a FORM submitted via a webpage. Now I realise I have a problem when reading the values from that FORM. I'll have to solve those first and then this problem will be solved too.
Yes, you will have to write some code to convert a string like "AD" to a byte, so that you can write it to EEPROM.
It really isn't that difficult. Extract each character. If the character is between '0' and '9', subtract '0' from it. If the character is between 'A' and 'F', subtract 'A' and add 10. If the character is between 'a' and 'f', subtract 'a' and add 10.
If the input is "AD", the characters are 'A' and 'D'. The values that you end up with are 10 and 13. Multiply the first by 16 and add the second. 10 * 16 + 13 = 173. 173 is equal to 0xAD.
As you might know, my actual problem (you can read about that, here: http://arduino.cc/forum/index.php/topic,69600.0.html)
was finder.getValue() that couldn't cope with HEX. So i found a way around the problem with some javascript that converts HEX to DEC and that my friend, I CAN write to EEPROM. So this problem has been solved too