Why including some libraries... (using EEPROM by Wire)

the sketch used to work (I use the LCD screen and keypad 4 * 3), then including some of my library (even without invoking a single function, but only by including them) the screen does not light up more and not part of the program (at least on the output of LCD who are the first lines of code)?

I can not understand what happens ...
the compiled is 17k (compared to 12k without libraries)

someone can give me a reason?

The invisible sketch?

It is really hard to comment without any information, like which libraries you included.

However I should point out that some libraries pre-instantiate objects, so by simply including the library you get extra data, and therefore the code to support the constructors, destructors etc.

you're right... but I'm making a fairly big project... and post the code can be very much...

I made that...
Tell me what you'd like to see and I'll try to poste... (header, source or ?)

the only thing that comes to mind is that a library use "Wire " and create an external object (as if I misunderstood you mentioned) that starts with a Wire.begin (address);

edit:
I tried to upload a sketch including the libraries at a time, and everything works fine until I include the library that begins with a Wire.begin ...

here is the code

Sockets sock = Sockets();

void Sockets::eepromConnectPage(int page){
	Wire.beginTransmission(EEPROM_ADDRESS);
	Wire.send((int)((page) >> 8));
	Wire.send((int)((page) & 0xFF));
}

void Sockets::eepromRequestData(int nData, bool closeConnection){
	if(closeConnection){
Serial.print(__LINE__);Serial.println();
		Wire.endTransmission();
	}
Serial.print(__LINE__);Serial.println();
	Wire.requestFrom((int) EEPROM_ADDRESS, nData);
}


void Sockets::init(){
	eepromConnectPage(POSITION_STATUS_MEMORY);
	Wire.send((byte) CORRECT_MEMORY);
	Wire.endTransmission();
}

bool Sockets::isMemoryCorrect(){
Serial.println(__LINE__);
Serial.println();
	eepromConnectPage(POSITION_STATUS_MEMORY);
Serial.print(__LINE__);
Serial.println();
	eepromRequestData(SIZE_STATUS_OF_MEMORY);
Serial.print(__LINE__);
Serial.println();
	/*return*/bool x = Wire.receive() == CORRECT_MEMORY;
Serial.print(__LINE__);
Serial.println();	
	return x;
}

Sockets::Sockets(){
Serial.begin(9600);
Serial.print(__LINE__);
Serial.println();
	Wire.begin(EEPROM_ADDRESS);
Serial.print(__LINE__);
	if(!isMemoryCorrect()){
Serial.print(__LINE__);
		init();
	}
Serial.print(__LINE__);
	loadLastProgram();
Serial.print("asdadsads");
}

the last print is 100; the line of this function

void Sockets::eepromRequestData(int nData, bool closeConnection){
	if(closeConnection){
Serial.print(__LINE__);Serial.println(); //[b]line 100[/b]
		Wire.endTransmission();
	}
Serial.print(__LINE__);Serial.println();
	Wire.requestFrom((int) EEPROM_ADDRESS, nData);
}

so I wait the Wire.endTransmission(); because the next Serial.print(LINE); doesn't come

i found that topic
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1274845180

it could be a similar thing

edit:

I tried
http://todbot.com/blog/2009/11/29/i2cscanner-pde-arduino-as-i2c-bus-scanner/
to check the port... and the address I write for the eeprom is correct... but still doesn't work... continued to stop at the same line...

Brig:
I tried to upload a sketch including the libraries at a time, and everything works fine until I include the library that begins with a Wire.begin ...

At the end of Wire.cpp is this:

// Preinstantiate Objects //////////////////////////////////////////////////////

TwoWire Wire = TwoWire();

That would account for the extra memory.

As for the Wire.endTransmission, that will indeed hang if the transmission does not complete. Reasons for that could be a noisy connection, maybe not (low) enough pull-up resistors, maybe your other code turned interrupts off.

I also think that the problem is this ...

and it will be annoying to be solved ..

for now I am working with the native arduino eeprom ..

only, of course, now I have another problem not bad ...
sketch reboots itself ... I do not understand why ... and this looks like a huge problem
there to have fun ... if I really do not understand anything I'll open yet another post ..

only, of course, now I have another problem not bad ...
sketch reboots itself ... I do not understand why

A sketch that restarts itself is not a trivial problem. You are most likely running out of memory. Bear in mind that the Arduino has three kinds of memory - Flash, EEPROM, and SRAM. You know, because you define the addresses to write to, how much EEPROM you are using. You know how much Flash you are using, because the compiler tells you. Knowing how much SRAM you are using is a bit more difficult, because it changes all the time. Search the forum for a function called FreeMemory. It tells you, wherever you call the function, how much SRAM memory you are using.

Or, post all of YOUR code - not the standard libraries, but your sketch(es) and your .h and .cpp files.

I pull up this topic because the problem persists:
he stops on Wire.endTransmission();

C:\Documents and Settings\User\Desktop\arduino-0019\libraries\Sockets\Sockets.cpp: 131
C:\Documents and Settings\User\Desktop\arduino-0019\libraries\Sockets\Sockets.cpp: 136

#define EEPROM_ADDRESS 80
void Sockets::eepromConnectPage(int page){
	Wire.beginTransmission((int) EEPROM_ADDRESS);
	Wire.send((byte)((page) >> 8));
	Wire.send((byte)((page) & 0xFF));
}

byte Sockets::eepromReadData(int page){
Serial.print(__FILE__);
Serial.print(": ");
Serial.print(__LINE__); //row 131
Serial.println();
	eepromConnectPage(page);
Serial.print(__FILE__);
Serial.print(": ");
Serial.print(__LINE__); //row 136
Serial.println();
	Wire.endTransmission();
Serial.print(__FILE__);
Serial.print(": ");
Serial.print(__LINE__); //row 141 here doesn't print...
Serial.println();
	Wire.requestFrom((int) EEPROM_ADDRESS, sizeof(byte));
Serial.print(__FILE__);
Serial.print(": ");
Serial.print(__LINE__);
Serial.println();
	return Wire.receive();
}

But I did a sketch (using the same address of EEPROM) and working properly (apparently)

#include <Wire.h> 

#define EERPOM_1_ADDRESS 80
#define EERPOM_2_ADDRESS 87

#define SIZE_1 10
#define SIZE_2 100  

#define PAGE_1 100
#define PAGE_2 0

void connectPage(int address, int page){
  Wire.beginTransmission(address);
  Wire.send((byte)((page) >> 8));
  Wire.send((byte)((page) & 0xFF));
}

void requestData(int address, int page, int nData){
  connectPage(address, page);
  Wire.endTransmission();
  Wire.requestFrom(address, sizeof(byte) * nData);  
}

void sendData(int address, int page, byte data){
  connectPage(address, page);
  Wire.send(data);
  Wire.endTransmission();
  delay(5);
}

void sendRandomData(int address, int page, int size){
  int j = 0;
  for(int i = 0; i < size; i++){
    sendData(address, page + i, (j = (byte) random()));
    Serial.print(j);
    Serial.print(", ");
  }
  Serial.println();
}

void setup(){
  Serial.begin(9600);
  
  Wire.begin(EERPOM_1_ADDRESS);  
  sendRandomData(EERPOM_1_ADDRESS, PAGE_1, SIZE_1);
  requestData(EERPOM_1_ADDRESS, PAGE_1, SIZE_1);
  while(Wire.available()){
    Serial.print((int) Wire.receive());
    Serial.print(", ");
  }
  
  Serial.println();
  Serial.println("EEPROM2");
    
  Wire.begin(EERPOM_2_ADDRESS);  
  sendRandomData(EERPOM_2_ADDRESS, PAGE_2, SIZE_2);
  requestData(EERPOM_2_ADDRESS, PAGE_2, SIZE_2);
  while(Wire.available()){
    Serial.print((int) Wire.receive());
    Serial.print(", ");
  }
}

void loop(){
}

the output

167, 241, 217, 42, 130, 200, 216, 254, 67, 77, 
167, 241, 217, 42, 130, 200, 216, 254, 67, 77, 
EEPROM2
152, 85, 140, 226, 179, 71, 23, 17, 152, 84, 47, 17, 45, 5, 88, 245, 107, 214, 136, 7, 153, 146, 72, 51, 98, 65, 243, 13, 35, 229, 95, 48, 209, 200, 237, 97, 12, 75, 2, 53, 57, 129, 132, 184, 20, 162, 156, 180, 90, 103, 42, 202, 229, 72, 233, 197, 241, 176, 196, 21, 138, 229, 155, 77, 57, 246, 247, 232, 161, 5, 211, 254, 237, 165, 213, 243, 217, 228, 91, 250, 108, 195, 81, 226, 32, 174, 12, 225, 6, 152, 109, 97, 255, 52, 161, 30, 25, 253, 54, 80, 
152, 85, 140, 226, 179, 71, 23, 17, 152, 84, 47, 17, 45, 5, 88, 245, 107, 214, 136, 7, 153, 146, 72, 51, 98, 65, 243, 13, 35, 229, 95, 48,

Suggestions?

anyone?

As PaulS said, post your sketch. A snippet isn't enough to tell what is happening. So your small "test" sketch works, right? So it isn't hardware. The big sketch must do something strange. Do you clear interrupts? Is this problem function called from an interrupt service routine?

I do not understand ...
because if it goes in one sketch, on the other side wrong? (without changing hw)

then ... summarize quickly:
I have a huge project, and I am a trying library at a time;
now I'm grappling with one that uses external EEPROM (24LC512), the library automatically creates a global object itself, which in the first lines tries to read (obviously unsuccessfully) by the eeprom

sketch

#include <Wire.h>
#include <MemoryFree.h>
#include <myFloat.h>
#include <Sockets.h> 

int nPs = 10;
int timesLen = 0;
short times[] = {MINUTES_BY_MIDNIGHT(0, 0), MINUTES_BY_MIDNIGHT(0, 10), MINUTES_BY_MIDNIGHT(0, 40), MINUTES_BY_MIDNIGHT(0, 59), 
                 MINUTES_BY_MIDNIGHT(1, 15), MINUTES_BY_MIDNIGHT(1, 16), MINUTES_BY_MIDNIGHT(1, 49), MINUTES_BY_MIDNIGHT(1, 50),
                 MINUTES_BY_MIDNIGHT(2, 0), MINUTES_BY_MIDNIGHT(2, 14), MINUTES_BY_MIDNIGHT(2, 30), MINUTES_BY_MIDNIGHT(2, 40), 
                 MINUTES_BY_MIDNIGHT(3, 0), MINUTES_BY_MIDNIGHT(3, 19), MINUTES_BY_MIDNIGHT(3, 31), MINUTES_BY_MIDNIGHT(3, 50), 
                 MINUTES_BY_MIDNIGHT(4, 0), MINUTES_BY_MIDNIGHT(4, 20), MINUTES_BY_MIDNIGHT(4, 35), MINUTES_BY_MIDNIGHT(4, 54), 
                 MINUTES_BY_MIDNIGHT(5, 0), MINUTES_BY_MIDNIGHT(5, 17), MINUTES_BY_MIDNIGHT(5, 39), MINUTES_BY_MIDNIGHT(5, 59),
                 MINUTES_BY_MIDNIGHT(6, 0), MINUTES_BY_MIDNIGHT(6, 16), MINUTES_BY_MIDNIGHT(6, 41), MINUTES_BY_MIDNIGHT(6, 45), 
                 MINUTES_BY_MIDNIGHT(7, 0), MINUTES_BY_MIDNIGHT(7, 10), MINUTES_BY_MIDNIGHT(7, 44), MINUTES_BY_MIDNIGHT(7, 49), 
                 MINUTES_BY_MIDNIGHT(8, 0), MINUTES_BY_MIDNIGHT(8, 11), MINUTES_BY_MIDNIGHT(8, 45), MINUTES_BY_MIDNIGHT(8, 47), 
                 MINUTES_BY_MIDNIGHT(9, 0), MINUTES_BY_MIDNIGHT(9, 12), MINUTES_BY_MIDNIGHT(9, 46), MINUTES_BY_MIDNIGHT(9, 48), 
                 MINUTES_BY_MIDNIGHT(10, 0), MINUTES_BY_MIDNIGHT(10, 13), MINUTES_BY_MIDNIGHT(10, 40), MINUTES_BY_MIDNIGHT(10, 41), 
                 MINUTES_BY_MIDNIGHT(11, 0), MINUTES_BY_MIDNIGHT(11, 5), MINUTES_BY_MIDNIGHT(11, 42), MINUTES_BY_MIDNIGHT(11, 43), 
                 MINUTES_BY_MIDNIGHT(12, 0), MINUTES_BY_MIDNIGHT(12, 19), MINUTES_BY_MIDNIGHT(12, 33), MINUTES_BY_MIDNIGHT(12, 49),
                 MINUTES_BY_MIDNIGHT(13, 0), MINUTES_BY_MIDNIGHT(13, 29), MINUTES_BY_MIDNIGHT(13, 35), MINUTES_BY_MIDNIGHT(13, 50), 
                 MINUTES_BY_MIDNIGHT(14, 0), MINUTES_BY_MIDNIGHT(14, 24), MINUTES_BY_MIDNIGHT(14, 36), MINUTES_BY_MIDNIGHT(14, 38), 
                 MINUTES_BY_MIDNIGHT(15, 0), MINUTES_BY_MIDNIGHT(15, 26), MINUTES_BY_MIDNIGHT(15, 37), MINUTES_BY_MIDNIGHT(15, 39), 
                 MINUTES_BY_MIDNIGHT(16, 0), MINUTES_BY_MIDNIGHT(16, 22), MINUTES_BY_MIDNIGHT(16, 38), MINUTES_BY_MIDNIGHT(16, 50), 
                 MINUTES_BY_MIDNIGHT(17, 0), MINUTES_BY_MIDNIGHT(17, 20), MINUTES_BY_MIDNIGHT(17, 39), MINUTES_BY_MIDNIGHT(17, 51), 
                 MINUTES_BY_MIDNIGHT(18, 0), MINUTES_BY_MIDNIGHT(18, 11), MINUTES_BY_MIDNIGHT(18, 40), MINUTES_BY_MIDNIGHT(18, 55), 
                 MINUTES_BY_MIDNIGHT(19, 0), MINUTES_BY_MIDNIGHT(19, 12), MINUTES_BY_MIDNIGHT(19, 43), MINUTES_BY_MIDNIGHT(19, 59),
                 MINUTES_BY_MIDNIGHT(20, 0), MINUTES_BY_MIDNIGHT(20, 13), MINUTES_BY_MIDNIGHT(20, 49), MINUTES_BY_MIDNIGHT(20, 51), 
                 MINUTES_BY_MIDNIGHT(21, 0), MINUTES_BY_MIDNIGHT(21, 1), MINUTES_BY_MIDNIGHT(21, 41), MINUTES_BY_MIDNIGHT(21, 50), 
                 MINUTES_BY_MIDNIGHT(22, 0), MINUTES_BY_MIDNIGHT(22, 15), MINUTES_BY_MIDNIGHT(22, 38), MINUTES_BY_MIDNIGHT(22, 57), 
                 MINUTES_BY_MIDNIGHT(23, 0), MINUTES_BY_MIDNIGHT(23, 16), MINUTES_BY_MIDNIGHT(23, 39), MINUTES_BY_MIDNIGHT(23, 58), 
                 -1};

const char *socketTypeTimed[] = {"LUCE", "POMPA", "FILTRO", "RISCALDATORE", "RISALITA", "SKIMMER", "VENTOLE", "REFRIGERATORE", "MANGIATOIA", "VENT. MOBILE", "LUCE LUNARE", "REATTORE", "KALKWASSER", "ELETTROV. REATTORE", "ELETTROV. VASCA", "RABBOCCO VASCA", "RABBOCCO SUMP", "ALTRO", "SPENTA", NULL};
const char *socketTypeProbed[] = {"RISCALDATORE SONDATO", "ELETTR. REATTORE SONDATA", "ELETTR. VASCA SONDATA", "RABB. VASCA SONDATO", "RABB. SUMP SONDATO", "REFRIG. SONDATO", "VENTOLE SONDATE", "LUCE LUNARE SONDATA", "ORP SONDATO", NULL};


void printTime(short time, char separator = ':'){
  if(HOURS(time) < 10)
    Serial.print(0);
  Serial.print(HOURS(time));
  Serial.print(separator);
  if(MINUTES(time) < 10)
    Serial.print(0);
  Serial.print(MINUTES(time));
}

void typeSocketToString(int8_t type){
  char toPrint[30];
  toPrint[29] = '\0';
  if(sock.isProbedSocket(type))
    Serial.print(socketTypeProbed[type - HEATER_PROBED]);
  else if(type >= 0 && type < HEATER_PROBED)
    Serial.print(socketTypeProbed[type]);
  else
    Serial.print("unknown");
}

void makeSocket(uint8_t indexSocket){
  int n = random() % MAX_SOCKET_SWITCH, socketType = random() % (ORP_PROBED + 1), j = 0;
  Serial.println();
  Serial.print(indexSocket);
  Serial.print(") ");
  typeSocketToString(socketType);
  if(sock.setPowerSocket(indexSocket, socketType, 0) == CORRECT){
    Serial.print("insert");
    Serial.print(" : ");
    Serial.println(n);
    for(int i = 0; i < n; i++){
      j = random() % timesLen;
      printTime(times[j]);
      Serial.print(" - ");
      printTime(times[(j + 1) % timesLen]);
      if(sock.addTime(indexSocket, times[j], times[(j + 1) % timesLen]) == CORRECT)
        Serial.print("insert");
      else
        Serial.print("not insert");
    }
  }else
    Serial.println("error");
}

int8_t printSocketPreview(uint8_t index){
  int8_t nTurn = 0;
  uint8_t row = 0;
  Serial.println();
  Serial.print((int) index + 1, row++);
  Serial.print(": ");
  typeSocketToString(sock.getPowerSocketType(index));
  switch((nTurn = sock.getPowerSocketNumberSwitching(index))){
    case(OFF_SOCKET):
      Serial.println("ever off");
    break;
    case(PROBE_SOCKET): 
      Serial.print("threshold ");
      Serial.println(sock.getPowerSocketThreshold(index));
    break;
    case(EVER_ON): 
      Serial.println("ever on");
    break;
    default:
      Serial.print(nTurn);
      Serial.println(" switching");
    break;
  }
  return nTurn;
}

void printSockets(){
  uint8_t j = 0, x = 0;
  int nTurn = 0;
  Serial.println();
  Serial.print(sock.getPowerSocketNumber());
  Serial.print(" total sockets");
  for(j = 0; j < sock.getPowerSocketNumber(); j++){
    for(x = 0, nTurn = printSocketPreview(j); x < nTurn; x++){
      Serial.println();
      Serial.print((int) x + 1);
      Serial.print(") ");
      printTime(sock.getPowerSocketSwitchOn(j, x));  
      Serial.print(" - ");
      printTime(sock.getPowerSocketSwitchOff(j, x));
    }
  }
}

void setup(){
  Serial.begin(9600);
  Serial.println("Step 1");
  while(times[timesLen] != -1)
    timesLen++;
    
  Serial.println("Step 2");
  Serial.print("free memory = ");
  Serial.print(freeMemory());
}

void loop(){
  
}

Sockets.h

#ifndef _Sockets_
#define _Sockets_

#include <WProgram.h>
#include <WConstants.h>
#include <stdint.h>

#include <myFloat.h>


#define HOUR_IN_DAY 24
#define MINUTES_IN_HOUR 60
#define DAILY_MINUTES (HOUR_IN_DAY * MINUTES_IN_HOUR) //== 1440
#define MINUTES_BY_MIDNIGHT(hour, minutes) (((hour) * MINUTES_IN_HOUR + (minutes)) % DAILY_MINUTES)
#define MINUTES(minutesByMidnight) ((minutesByMidnight) % MINUTES_IN_HOUR)
#define HOURS(minutesByMidnight) ((minutesByMidnight) / MINUTES_IN_HOUR)



/* power socket types */
#define LIGHT 0 /* luce */
#define PUMP 1 /* pompa */
#define FILTER 2 /* filtro */
#define HEATER 3 /* riscaldatore */
#define LIFTS 4 /* risalita */
#define SKIMMER 5 /* schiumatoio */
#define FANS 6 /* ventole */
#define COOLER 7 /* refrigeratore */
#define MANGER 8 /* mangiatoia */
#define MOBILE_FANS 9 /* ventole del mobile */
#define MOON_LIGHT 10 /* luce lunare */
#define REACTOR 11 /* reattore */
#define KALKWASSER 12
#define REACTOR_SOLENOID 13 /* elettrovalvola reattore */
#define AQUARIUM_SOLENOID 14 /* elettrovalvola acquario */
#define TOPPING_TANK 15 /* rabbocco vasca */
#define TOPPING_SUMP 16 /* rabbocco sump */
#define OTHER 17 /* altro */
#define TURNED_OFF 18 /* spenta */

#define HEATER_PROBED 19
#define REACTOR_SOLENOID_PROBED 20
#define AQUARIUM_SOLENOID_PROBED 21
#define TOPPING_TANK_PROBED 22 /* rabbocco vasca sondato */
#define TOPPING_SUMP_PROBED 23 /* rabbocco sump sondato */
#define COOLER_PROBED 24 /* refrigeratore sondato */
#define FANS_PROBED 25
#define MOON_LIGHT_PROBED 26
#define ORP_PROBED 27


#define MAX_SOCKET 32
#define MAX_SOCKET_SWITCH 6


/* return values */
#define ERROR_ARGUMENT -1
#define ERROR_TOO_MANY_TIME -2
#define PROBE_SOCKET -3
#define NOT_PROBE_SOCKET -4
#define CORRECT 0

#define OFF_SOCKET -10
#define EVER_ON -11
#define TURN_ON -12
#define TURN_OFF -13
#define PROBE_ON -14
#define PROBE_OFF -15
#define MANUAL_ON -16
#define MANUAL_OFF -17


class Sockets{
	public:
		Sockets();

		void init();
		bool isMemoryCorrect();

		int8_t newProgram(uint8_t socketNumber);
		bool loadLastProgram();

		int8_t getPowerSocketNumber();

		bool isSocketOn(uint8_t indexSocket);
		bool isSocketManual(uint8_t indexSocket);
		bool isSocketEverOn(uint8_t indexSocket);

		int getMinutesLastControl();
		uint8_t getDayLastControl();
		int getSocketStatus(uint8_t indexSocket);
		
		int8_t getPowerSocketType(uint8_t indexSocket);
		bool isProbedSocket(uint8_t type);
		
		int8_t getPowerSocketNumberSwitching(uint8_t indexSocket);
		short getPowerSocketSwitchOn(uint8_t indexSocket, uint8_t indexTime);

		short getPowerSocketSwitchOff(uint8_t indexSocket, uint8_t indexTime);
		float getPowerSocketThreshold(uint8_t indexSocket);		
		
		int8_t setPowerSocket(uint8_t indexSocket, uint8_t type, float threshold);
		int8_t resetPowerSocket(uint8_t indexSocket, bool save = false);
		
		int8_t addTime(uint8_t indexSocket, unsigned short minutesByMidnightOn, unsigned short minutesByMidnightOff);
		int8_t setThreshold(uint8_t indexSocket, float threshold);
		int8_t setPowerSocketEverOn(uint8_t indexSocket);
		
		int8_t setPowerSocketManualChange(uint8_t indexSocket, bool onOff, unsigned short end);
		void removePowerSocketManualChange(uint8_t indexSocket);

		void switchingControl(unsigned short now);
	private:
		int8_t _totSocket;
		
		void saveLastControl();

		int calculateSocketOffset(uint8_t indexSocket);
		void saveSocket(uint8_t indexSocket, bool saveType = false, bool saveManualSet = false, bool saveData = false);
		bool loadSocket(uint8_t indexSocket);
		myFloat loadThreshold(uint8_t indexSocket);

		int8_t insertTime(unsigned short minutesByMidnightOn, unsigned short minutesByMidnightOff);
		uint8_t findTimePos(unsigned short minutesByMidnightOn);

		void switchOnSocket(uint8_t indexSocket, unsigned short now, bool setManualSet = false, bool setAlwaysOn = false);
		void switchOffSocket(uint8_t indexSocket, unsigned short now, bool setManualSet = false);
		
		void eepromConnectPage(int page);
		byte eepromReadData(int page);
		void eepromWriteData(int page, byte data);
};

extern Sockets sock;

#endif

Sockets.cpp

#include "Sockets.h"

#include <Wire.h>


#define EEPROM_ADDRESS 87

#define INCONSISTENT_ON 0
#define INCONSISTENT_OFF 1
#define ON 2
#define OFF 3
#define MANUAL_SET_ON 4
#define MANUAL_SET_OFF 5
#define ALWAYS_ON 7

#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define ABS(a) (((a) < 0) ? -(a) : (a))



#define SIZE_STATUS_OF_MEMORY 1
#define SIZE_LAST_PROGRAM_INDEX 1
#define SIZE_NUMBER_OF_SOCKET 1
#define SIZE_TIPE_NSWITCH 1
#define SIZE_MANUAL_SET 2
#define SIZE_START_TO_FINISH 3
#define SIZE_LAST_CONTROL 2
#define SIZE_THRESHOLD 2

// posizione dati "fissi" nella memoria 
#define POSITION_STATUS_MEMORY 0
#define POSITION_DATA_VERSION 1
#define POSITION_LAST_PROGRAM_USED 2
#define POSITION_PROGRAM_SAVED 3
#define POSITION_FIRST_SOCKET (POSITION_PROGRAM_SAVED + SIZE_LAST_CONTROL + SIZE_NUMBER_OF_SOCKET)

#define EMPTY_MEMORY 0
#define INVALID_MEMORY 1
#define CORRECT_MEMORY 2

#define TOT_DAYS 8

#define XOR(a, b) (((a) && !(b)) || (!(a) && (b)))

#define LS_MAX_DAY (TOT_DAYS + 2)
#define LS_MAX_MINUTES (DAILY_MINUTES + 2)


typedef struct lastControl{
	unsigned int day:4;
	unsigned int minutes:12;
} lastControl_t;

typedef struct fromStartToFinish{
	unsigned int start:11;
	unsigned int end:11;
} fromStartToFinish_t;

typedef struct manualSet{
	unsigned int thereIsManualSet:1;
	unsigned int setOn:1;
	unsigned int end:11;
	unsigned int dayEnd:3;
} manualSet_t;

typedef struct dataTime{
	unsigned int isCorrect:1;
	unsigned int nextTimeIsOn:1;
	unsigned int nextTime:11;
	unsigned int day:3; //e' significativo solo nel caso sia relativo ad un manualSet
} dataTime_t;

typedef union dataSocket{
	dataTime_t time;
	myFloat threshold;
} dataSocket_t;

typedef struct powerSocket{
	unsigned int type:5;
	unsigned int status:3;
	dataSocket_t data;
} powerSocket_t;

static powerSocket_t _ps[MAX_SOCKET];

static uint8_t _indexSocketFsMs;
static fromStartToFinish_t _fs[MAX_SOCKET_SWITCH];
static uint8_t _fsLen;
static manualSet_t _ms;

static lastControl_t _ls;


Sockets sock = Sockets();

Sockets::Sockets(){
Serial.begin(9600);
Serial.print(__FILE__);Serial.print(": ");Serial.print(__LINE__);Serial.println();
	if(!isMemoryCorrect())
		init();
Serial.print(__FILE__);Serial.print(": ");Serial.print(__LINE__);Serial.println();
	loadLastProgram();
Serial.print(__FILE__);Serial.print(": ");Serial.print(__LINE__);Serial.println();
}

void Sockets::eepromConnectPage(int page){
	Wire.beginTransmission((int) EEPROM_ADDRESS);
	Wire.send((byte)((page) >> 8));
	Wire.send((byte)((page) & 0xFF));
}

byte Sockets::eepromReadData(int page){
Serial.print(__FILE__);Serial.print(": ");Serial.print(__LINE__);Serial.println();
	eepromConnectPage(page);
Serial.print(__FILE__);Serial.print(": ");Serial.print(__LINE__);Serial.println();
	Wire.endTransmission();
Serial.print(__FILE__);Serial.print(": ");Serial.print(__LINE__);Serial.println();
	Wire.requestFrom((int) EEPROM_ADDRESS, sizeof(byte));
Serial.print(__FILE__);Serial.print(": ");Serial.print(__LINE__);Serial.println();
	return Wire.receive();
}

void Sockets::eepromWriteData(int page, byte data){
	eepromConnectPage(page);
	Wire.send(data);
	Wire.endTransmission();
	delay(5);
}

void Sockets::init(){
	Wire.begin(EEPROM_ADDRESS);
	eepromWriteData(POSITION_STATUS_MEMORY, CORRECT_MEMORY);
	eepromWriteData(POSITION_STATUS_MEMORY + 1, 0);// versione del programma "0"
	eepromWriteData(POSITION_STATUS_MEMORY + 2, 0);// ultimo programma usato "0"
}

bool Sockets::isMemoryCorrect(){
	return eepromReadData(POSITION_STATUS_MEMORY) == CORRECT_MEMORY;
}
int Sockets::getSocketStatus(uint8_t indexSocket){return ERROR_ARGUMENT;}
int Sockets::getMinutesLastControl(){return ERROR_ARGUMENT;}
uint8_t Sockets::getDayLastControl(){return ERROR_ARGUMENT;}
bool Sockets::isSocketOn(uint8_t indexSocket){return false;}
bool Sockets::isSocketManual(uint8_t indexSocket){return false;}
void Sockets::switchOnSocket(uint8_t indexSocket, unsigned short now, bool setManualSet, bool setAlwaysOn){}
void Sockets::switchOffSocket(uint8_t indexSocket, unsigned short now, bool setManualSet){}
bool Sockets::isProbedSocket(uint8_t type){return false;}
void Sockets::switchingControl(unsigned short now){}
myFloat Sockets::loadThreshold(uint8_t indexSocket){return 0;}
int8_t Sockets::setPowerSocket(uint8_t indexSocket, uint8_t type, float threshold){return ERROR_ARGUMENT;}
int8_t Sockets::resetPowerSocket(uint8_t indexSocket, bool save){return ERROR_ARGUMENT;}
int8_t Sockets::setPowerSocketEverOn(uint8_t indexSocket){return ERROR_ARGUMENT;}
int8_t Sockets::addTime(uint8_t indexSocket, unsigned short minutesByMidnightOn, unsigned short minutesByMidnightOff){return ERROR_ARGUMENT;}
uint8_t Sockets::findTimePos(unsigned short minutesByMidnightOn){return ERROR_ARGUMENT;}
int8_t Sockets::insertTime(unsigned short minutesByMidnightOn, unsigned short minutesByMidnightOff){return ERROR_ARGUMENT;}
int8_t Sockets::setPowerSocketManualChange(uint8_t indexSocket, bool onOff, unsigned short end){return ERROR_ARGUMENT;}
int8_t Sockets::setThreshold(uint8_t indexSocket, float threshold){return ERROR_ARGUMENT;}
void Sockets::removePowerSocketManualChange(uint8_t indexSocket){}
int8_t Sockets::getPowerSocketNumber(){return ERROR_ARGUMENT;}
int8_t Sockets::getPowerSocketType(uint8_t indexSocket){return ERROR_ARGUMENT;}
int8_t Sockets::getPowerSocketNumberSwitching(uint8_t indexSocket){return ERROR_ARGUMENT;}
short Sockets::getPowerSocketSwitchOn(uint8_t indexSocket, uint8_t indexTime){return ERROR_ARGUMENT;}
short Sockets::getPowerSocketSwitchOff(uint8_t indexSocket, uint8_t indexTime){return ERROR_ARGUMENT;}
float Sockets::getPowerSocketThreshold(uint8_t indexSocket){return 0.0;}
bool Sockets::isSocketEverOn(uint8_t indexSocket){return false;}
int8_t Sockets::newProgram(uint8_t socketNumber){return ERROR_ARGUMENT;}
void Sockets::saveLastControl(){}
bool Sockets::loadLastProgram(){return false;}
void Sockets::saveSocket(uint8_t indexSocket, bool saveType, bool saveManualSet, bool saveData){}
bool Sockets::loadSocket(uint8_t indexSocket){return false;}
int Sockets::calculateSocketOffset(uint8_t indexSocket){return ERROR_ARGUMENT;}
void Sockets::init(){
	Wire.begin(EEPROM_ADDRESS);
	eepromWriteData(POSITION_STATUS_MEMORY, CORRECT_MEMORY);
	eepromWriteData(POSITION_STATUS_MEMORY + 1, 0);// versione del programma "0"
	eepromWriteData(POSITION_STATUS_MEMORY + 2, 0);// ultimo programma usato "0"
}

You have set your own address as the EEPROM address. That isn't going to help. It will try to send to itself. Just use:

	Wire.begin();

And this:

byte Sockets::eepromReadData(int page){
Serial.print(__FILE__);Serial.print(": ");Serial.print(__LINE__);Serial.println();
	eepromConnectPage(page);
Serial.print(__FILE__);Serial.print(": ");Serial.print(__LINE__);Serial.println();
	Wire.endTransmission();
Serial.print(__FILE__);Serial.print(": ");Serial.print(__LINE__);Serial.println();
	Wire.requestFrom((int) EEPROM_ADDRESS, sizeof(byte));
Serial.print(__FILE__);Serial.print(": ");Serial.print(__LINE__);Serial.println();
	return Wire.receive();
}

Get rid of the prints - they will slow it down so much it will probably fail.

[quote author=Nick Gammon link=topic=60093.msg446082#msg446082 date=1305852878]

void Sockets::init(){
	Wire.begin(EEPROM_ADDRESS);
	eepromWriteData(POSITION_STATUS_MEMORY, CORRECT_MEMORY);
	eepromWriteData(POSITION_STATUS_MEMORY + 1, 0);// versione del programma "0"
	eepromWriteData(POSITION_STATUS_MEMORY + 2, 0);// ultimo programma usato "0"
}

You have set your own address as the EEPROM address. That isn't going to help. It will try to send to itself. Just use:

Wire.begin();[/quote]

I've ever used Wire.begin(address); for the LCD & keypad I2C, for the DS1307 even in the sketch for try eeprom... it's a problem? this is the only case that give me trouble...

for the Serial.print, i've put it for debug... i can try without the Serial.print... let's hope...

i've remove the Serial.print, and modified Wire.begin(), but doesn't goes...

Brig:
I've ever used Wire.begin(address); for the LCD & keypad I2C, for the DS1307 even in the sketch for try eeprom... it's a problem? this is the only case that give me trouble...

I don't think the device actually talks to itself but it is just wrong. The Wire.begin (n) sets n as your slave address. It shouldn't be used for the master. And certainly the slave address shouldn't be the address of another slave.

I do not understand ...
because if it goes in one sketch, on the other side wrong? (without changing hw)
...
then ... summarize quickly:
I have a huge project, and I am a trying library at a time;

I'm sorry, it's hard to help without seeing it all, and I don't understand the problem description.

If you have turned off interrupts, and I can't see if you have or not, then the Wire.endTransmission will hang. You really need a logic analyzer on the I2C pins and watch what is happening.

Your code is incredibly cluttered, it is almost impossible to read. How about changing:

Serial.print(__FILE__);Serial.print(": ");Serial.print(__LINE__);Serial.println();

into a #define? Like this:

#define SHOW_LINE Serial.print(__FILE__);Serial.print(": ");Serial.print(__LINE__);Serial.println();

And then when you want to print out a debug just put this:

byte Sockets::eepromReadData(int page){
SHOW_LINE
	eepromConnectPage(page);
	Wire.endTransmission();
	Wire.requestFrom((int) EEPROM_ADDRESS, sizeof(byte));
SHOW_LINE
	return Wire.receive();
}

And don't you find this very wordy?

/var/folders/1A/1AUycq24Ev4PKBlyDOFIG++++TI/-Tmp-/build8941409027164292956.tmp/sketch_may19a.cpp: 20
/var/folders/1A/1AUycq24Ev4PKBlyDOFIG++++TI/-Tmp-/build8941409027164292956.tmp/sketch_may19a.cpp: 33
/var/folders/1A/1AUycq24Ev4PKBlyDOFIG++++TI/-Tmp-/build8941409027164292956.tmp/sketch_may19a.cpp: 20
/var/folders/1A/1AUycq24Ev4PKBlyDOFIG++++TI/-Tmp-/build8941409027164292956.tmp/sketch_may19a.cpp: 33

So instead of FILE use: PRETTY_FUNCTION

That shows the function name and arguments (or just FUNCTION which shows the function name).

[quote author=Nick Gammon link=topic=60093.msg446700#msg446700 date=1305936972]
I don't think the device actually talks to itself but it is just wrong. The Wire.begin (n) sets n as your slave address. It shouldn't be used for the master. And certainly the slave address shouldn't be the address of another slave.[/quote]
Ok, i'll change all Wire.begin(x); with Wire.begin(); (hoping that this will solve another problem, now I'm not dealing with ... But ... who knows ...)

[quote author=Nick Gammon link=topic=60093.msg446700#msg446700 date=1305936972]
I'm sorry, it's hard to help without seeing it all, and I don't understand the problem description.[/quote]
unfortunately I've posted all the code (sketch, header and source) in 3 different messages (in page 1) because it's too much characters to stay in a single post...

[quote author=Nick Gammon link=topic=60093.msg446700#msg446700 date=1305936972]
If you have turned off interrupts, and I can't see if you have or not, then the Wire.endTransmission will hang. You really need a logic analyzer on the I2C pins and watch what is happening.[/quote]
what's a logic analyzer? (have some link?)
and I haven't touch the interrupts;

[quote author=Nick Gammon link=topic=60093.msg446700#msg446700 date=1305936972]
into a #define? [/quote]
you're right! I'm a fun of the #define, but, in this case, because it isn't the final code but especially because i'm heartbroken by the problem... i've think only to the substance, not to the form

[quote author=Nick Gammon link=topic=60093.msg446700#msg446700 date=1305936972]
And don't you find this very wordy?[/quote]
the first version has more than a library and so I need to know whitch file is printing :stuck_out_tongue:

Brig:

[quote author=Nick Gammon link=topic=60093.msg446700#msg446700 date=1305936972]
I'm sorry, it's hard to help without seeing it all, and I don't understand the problem description.

unfortunately I've posted all the code (sketch, header and source) in 3 different messages (in page 1) because it's too much characters to stay in a single post...
[/quote]

I don't see "myfloat.h" so I can't compile the sketch myself and see what is happening.