Pages: [1]   Go Down
Author Topic: EEPROM Serial Print questions, and formatting  (Read 591 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Total newbie here, just a fair warning..

I'm looking to store an IP address into EEPROM. The IP is then read back from the EEPROM in serial.print fashion.
Would I format this code to make it display the IP address on a single line, seperated by  ".", like this:

IP Address
"192.168.24.253"

Ultimately this is a bigger project planned with the following goals:

1. Have user input to change/enter IP, Gateway, etc..
2. network information gets stored into EEPROM
3. will work from a server-based ethernet interface

The current I have shows the output like this:
IP Address
192
168
24
1

Any helpful tips would be appreciated!
-J

Code:
#include <EEPROM.h>
#include "EXROM.h"



void setup()
{
 
  byte IP[] = {192,168,24,1};
  byte IPsize[sizeof(IP)];
 
  Serial.begin(9600);
 
 
EXROM.write(0, IP, sizeof(IP));         //write the IP to memory
 
 
 EXROM.read(0, IPsize, sizeof(IPsize));  //read the IP from memory
 
 Serial.println("IP ADDRESS");
     for(int i=0;i<sizeof(IP);i++)
  {
    Serial.println(IP[i], DEC);
  }
 
Logged

Offline Offline
Edison Member
*
Karma: 49
Posts: 1668
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Your sample code writes the IP address to exrom and reads it back into IPsize but then prints out the original from IP.
Try this code:
Code:
#include <EEPROM.h>
#include "EXROM.h"

void setup()
{

  byte IP[] = {192,168,24,1};
  byte IPsize[sizeof(IP)];

  Serial.begin(9600);

  EXROM.write(0, IP, sizeof(IP));         //write the IP to memory
  EXROM.read(0, IPsize, sizeof(IPsize));  //read the IP from memory

  Serial.print("IP ADDRESS ");
  for(int i=0;i<sizeof(IPsize);i++)
  {
    Serial.print(IPsize[i], DEC);
    if(i != 3)Serial.print(".");
  }
  Serial.print("\n");
}

void loop(void)
{
}

I can't test the code with exrom but it prints IPsize like this when written to eeprom and read back again:
IP ADDRESS 192.168.24.1

Pete
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank You, your code works well.

Shortly after I posted this, I figured out a couple things -- one thing being the difference between "print" & "println" ( I warned you that I was a newbie); so I got closer on my own..

Then I went further to add the periods, but took a different turn using a FOR loop (which added too many periods, etc..).


I may post more questions as I move along with my program -- thanks again..
Logged

Pages: [1]   Go Up
Jump to: