Cannot include "EEPROM.h"

Discussion about Z-Uno product. Visit http://z-uno.z-wave.me for more details.
Post Reply
kina500
Posts: 15
Joined: 21 Jan 2021 20:49

Cannot include "EEPROM.h"

Post by kina500 »

If I include the EEPROM.h in my sketch, then I get following error under compilation/upload:

PRK:
HEX: 00 04 2A 5C EA 78 44 B0 01 68 FE 3E 58 BE 12 02 06 0B 15 83 22 1B 75 23 CE 02 4C C0 78 48 C7 65
DEC:00004-10844-60024-17584-00360-65086-22718-04610-01547-05507-08731-29987-52738-19648-30792-51045
PUK:
HEX: 87 CE 64 0B D4 32 14 57 15 8C F8 E2 D8 92 93 44 80 D9 0F 71 F2 F5 2C 0E A1 F3 25 2A 90 96 81 65
DEC:34766-25611-54322-05207-05516-63714-55442-37700-32985-03953-62197-11278-41459-09514-37014-33125
*****
NEEDED:1 GET:0
NEEDED:1 GET:0
NEEDED:1 GET:0
NEEDED:1 GET:0
NEEDED:1 GET:0
NEEDED:1 GET:0


RAW Info:
----------------------------------------------------------
FIRMWARE DATA
----------------------------------------------------------
(<type 'exceptions.IndexError'>, '<string>', 533)



**** **** **** **** **** *
* * * * * * * * * *
* * * * * * * * * *
**** *** *** * * *** *
* * * * * * * * *
**** * * * * **** * * *



Error 0 Unknown exception "list index out of range"


Somebody experience the same?
I am running on newest Z-Uno firmware.

I think the library mess up with some program memory, as I cannot reprogram the module before I set it rescue mode.... (after this error)
p0lyg0n1
Posts: 242
Joined: 04 Aug 2016 07:14

Re: Cannot include "EEPROM.h"

Post by p0lyg0n1 »

Hi,
Please provide your sketch. We have no problems with EEPROM.h in another sketches.We need your code to reproduce the error.

Best regards,
Alex
kina500
Posts: 15
Joined: 21 Jan 2021 20:49

Re: Cannot include "EEPROM.h"

Post by kina500 »

ZUNO_SETUP_CHANNELS(ZUNO_SWITCH_MULTILEVEL(getterFunction, setterFunction));

// ZUNO_SETUP_SLEEPING_MODE(ZUNO_SLEEPING_MODE_SLEEPING);

ZUNO_SETUP_BATTERY_HANDLER(my_battery_handler);

#include <ZUNO_Buttons.h>
#include "EEPROM.h"

#define INT_PIN 18
#define upPIN 20
#define downPIN 19
#define ledPin 21
#define dirPin 9
#define stepPin 10
#define rstPin 11
#define stepsPerTime 100

PinButton btn1(upPIN, true);
PinButton btn2(downPIN, true);

word currentPosition = 0;
word closedPosition = 20000;
word newPosition = 0;
boolean newValue = 0;
boolean disableOtherLongClick = 0;
word newZwavePosition = 0;
byte zValue = 0;
word lastMillis = 0;
int batVal = 0;
byte batPercent = 0;


void setup() {
Serial.begin(115200);
// zunoSetWUOptions(ZUNO_WUPFLAGS_INT1_LOW);
pinMode(upPIN, INPUT_PULLUP);
pinMode(downPIN, INPUT_PULLUP);
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
pinMode(rstPin, OUTPUT);
delay(300);
Serial.println("Starting...");
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
}

void loop() {
btn1.update();
btn2.update();
disableOtherLongClick = 0;

btn1.startDispatch();
btn2.startDispatch();

if(btn1.isLongClick() && btn2.isLongClick()) {
Serial.println("Both long click");
disableOtherLongClick = 1; // Disable other longclicks from the two buttons
currentPosition = 0; // Set to top/open position for calibration.
CalibrateCurtain();
}
if(btn1.isSingleClick()){
Serial.println("Single click UP");
curtainOpen();
}
if(btn1.isLongClick() && !disableOtherLongClick){
Serial.println("Long click UP");
curtainUp();
}
if(btn2.isSingleClick()){
Serial.println("Single click DOWN");
curtainClosed();
}
if(btn2.isLongClick() && !disableOtherLongClick){
Serial.println("Long click DOWN");
curtainDown();
}
btn1.endDispatch();
btn2.endDispatch();
if(newZwavePosition) {
setNewPosition();
}
if (newValue) {
Serial.print("Current Position ");
Serial.println(currentPosition);
Serial.print("Closed Position ");
Serial.println(closedPosition);
Serial.print("Value from controller ");
Serial.println(zValue);
Serial.println(batPercent);
newValue = 0;
}
batVal = analogRead(A0);
batPercent = (batVal-850)*100/(1023-850); // 1023 is 3,3V, 850 is 2,74V, equal 8,4V-7,26V on battery.
delay(20);
//if (millis() - lastMillis > 5000 ) {
// zunoSendDeviceToSleep();
//}
}

void curtainUp() {
do {
for (int i = 0; i < stepsPerTime; i++) {
digitalWrite(rstPin, HIGH);
digitalWrite(dirPin, HIGH);
digitalWrite(stepPin, HIGH);
delayMicroseconds(900);
digitalWrite(stepPin, LOW);
delayMicroseconds(900);
}
digitalWrite(rstPin, LOW);
currentPosition = currentPosition - stepsPerTime;
newValue = 1;
} while (!digitalRead(20));
// zValue = (1-(currentPosition/closedPosition))*99; // This line for zuno blinds where 0 is closed and 99 is open.
zValue = currentPosition/closedPosition*99; // This line for zuno dimmer switch where 0 is off and 99 is max.
zunoSendReport(1);
lastMillis = millis();
}

void curtainDown() {
do {
for (int i = 0; i < stepsPerTime; i++) {
digitalWrite(rstPin, HIGH);
digitalWrite(dirPin, LOW);
digitalWrite(stepPin, HIGH);
delayMicroseconds(900);
digitalWrite(stepPin, LOW);
delayMicroseconds(900);
}
digitalWrite(rstPin, LOW);
currentPosition = currentPosition + stepsPerTime;
newValue = 1;
} while (!digitalRead(19));
// zValue = (1-(currentPosition/closedPosition))*99; // This line for zuno blinds where 0 is closed and 99 is open.
zValue = currentPosition/closedPosition*99; // This line for zuno dimmer switch where 0 is off and 99 is max.
zunoSendReport(1);
lastMillis = millis();
}

void curtainOpen() {
for (int i = 0; i < currentPosition; i++) {
digitalWrite(rstPin, HIGH);
digitalWrite(dirPin, HIGH);
digitalWrite(stepPin, HIGH);
delayMicroseconds(900);
digitalWrite(stepPin, LOW);
delayMicroseconds(900);
}
digitalWrite(rstPin, LOW);
currentPosition = 0;
newValue = 1;
// zValue = (1-(currentPosition/closedPosition))*99; // This line for zuno blinds where 0 is closed and 99 is open.
zValue = currentPosition/closedPosition*99; // This line for zuno dimmer switch where 0 is off and 99 is max.
zunoSendReport(1);
lastMillis = millis();
}

void curtainClosed() {
for (int i = 0; i < closedPosition-currentPosition; i++) {
digitalWrite(rstPin, HIGH);
digitalWrite(dirPin, LOW);
digitalWrite(stepPin, HIGH);
delayMicroseconds(900);
digitalWrite(stepPin, LOW);
delayMicroseconds(900);
}
digitalWrite(rstPin, LOW);
currentPosition = closedPosition;
newValue = 1;
// zValue = (1-(currentPosition/closedPosition))*99; // This line for zuno blinds where 0 is closed and 99 is open.
zValue = currentPosition/closedPosition*99; // This line for zuno dimmer switch where 0 is off and 99 is max.
zunoSendReport(1);
lastMillis = millis();
}

void CalibrateCurtain() {
for (int i = 0; i < 4000; i++) { // Run first loop to give user change for releasing buttons.
digitalWrite(ledPin, HIGH); // LED goes on to indicate curtain calibration.
digitalWrite(rstPin, HIGH);
digitalWrite(dirPin, LOW);
digitalWrite(stepPin, HIGH);
delayMicroseconds(900);
digitalWrite(stepPin, LOW);
delayMicroseconds(900);
}
currentPosition = 4000;
do {
for (int i = 0; i < 50; i++) { // Run next loop until user press up button.
digitalWrite(rstPin, HIGH);
digitalWrite(dirPin, LOW);
digitalWrite(stepPin, HIGH);
delayMicroseconds(900);
digitalWrite(stepPin, LOW);
delayMicroseconds(900);
}
currentPosition = currentPosition + 50;
} while (digitalRead(20));
digitalWrite(rstPin, LOW);
digitalWrite(ledPin, LOW);
closedPosition = currentPosition;
newValue = 1;
// zValue = (1-(currentPosition/closedPosition))*99; // This line for zuno blinds where 0 is closed and 99 is open.
zValue = currentPosition/closedPosition*99; // This line for zuno dimmer switch where 0 is off and 99 is max.
zunoSendReport(1);
lastMillis = millis();
}

void setNewPosition() {
if (newPosition > currentPosition) {
for (int i = 0; i < newPosition-currentPosition; i++) {
digitalWrite(rstPin, HIGH);
digitalWrite(dirPin, LOW);
digitalWrite(stepPin, HIGH);
delayMicroseconds(900);
digitalWrite(stepPin, LOW);
delayMicroseconds(900);
}
digitalWrite(rstPin, LOW);
currentPosition = newPosition;
newValue = 1;
// zValue = (1-(currentPosition/closedPosition))*99; // This line for zuno blinds where 0 is closed and 99 is open.
zValue = currentPosition/closedPosition*99; // This line for zuno dimmer switch where 0 is off and 99 is max.
zunoSendReport(1);
}
if (newPosition < currentPosition) {
for (int i = 0; i < currentPosition-newPosition; i++) {
digitalWrite(rstPin, HIGH);
digitalWrite(dirPin, HIGH);
digitalWrite(stepPin, HIGH);
delayMicroseconds(900);
digitalWrite(stepPin, LOW);
delayMicroseconds(900);
}
digitalWrite(rstPin, LOW);
currentPosition = newPosition;
newValue = 1;
// zValue = (1-(currentPosition/closedPosition))*99; // This line for zuno blinds where 0 is closed and 99 is open.
zValue = currentPosition/closedPosition*99; // This line for zuno dimmer switch where 0 is off and 99 is max.
zunoSendReport(1);
}
newZwavePosition = 0;
lastMillis = millis();
}

byte getterFunction(void) {
return zValue;
}

void setterFunction(byte value) {
// newPosition = (99-value)*(closedPosition/99); // This line for zuno blinds where 0 is closed and 99 is open.
newPosition = ((word)value)*((float)closedPosition/99); // This line for zuno dimmer switch where 0 is off and 99 is max.
Serial.print("Value ");
Serial.println(value);
Serial.print("New Position ");
Serial.println(newPosition);
if (newPosition != currentPosition) {
newZwavePosition = 1;
}
}

byte my_battery_handler() {
byte percents = batPercent;
return percents;
}
p0lyg0n1
Posts: 242
Joined: 04 Aug 2016 07:14

Re: Cannot include "EEPROM.h"

Post by p0lyg0n1 »

Thanks,
We will inspect it. I'll post results here.

Best regards,
Alex.
kina500
Posts: 15
Joined: 21 Jan 2021 20:49

Re: Cannot include "EEPROM.h"

Post by kina500 »

Ok, thank you.
Hope you can help....
kina500
Posts: 15
Joined: 21 Jan 2021 20:49

Re: Cannot include "EEPROM.h"

Post by kina500 »

I now tried a lot of different test on my setup.
My setup is battery operated device.

I have 3 different issues with Z-Uno module.

1. I cannot reflash the zuno without disconnecting the battery and connect it again, not matter if EEPROM.h is included or not, then I get error described above. I also tried with much simpler script.
That do not matter in daily use, but very annoying under development.....

2. When I disconnect the battery and connect it again, I will have to reset the zuno on the reset input a couple of times before wave communication works. It will not connect to wave controller without reset a couple of times, log waiting do not help.
I can see on monitor, and a LED, that the script is working, but zwave communication do not work without a couple of resets.
This behaviour is impossible to have in daily life. I do not plan to have access to the reset button to outside of box, and if a person change battery without reseting a couple of times, it do not work on zwave network.
Is there a workaround for this? Can the script reset the device or something?

3. The reported battery percentage from my script is a byte value, that always are between 0 and 100, and the values measured and calculated in the script are correct. The zwave controller report 1-3% if battery for example are 90-98%.
Should this byte value with percent be converted to other values so that a zwave controller see them correct?

ZUNO_SETUP_CHANNELS(ZUNO_SWITCH_MULTILEVEL(getterFunction, setterFunction));

ZUNO_SETUP_SLEEPING_MODE(ZUNO_SLEEPING_MODE_SLEEPING);

ZUNO_SETUP_BATTERY_HANDLER(my_battery_handler);

#include <ZUNO_Buttons.h>
// #include "EEPROM.h"

#define INT_PIN 18
#define upPIN 20
#define downPIN 19
#define ledPin 21
#define dirPin 9
#define stepPin 10
#define rstPin 11
#define stepsPerTime 100

PinButton btn1(upPIN, true);
PinButton btn2(downPIN, true);

byte zValue = 99;
word lastMillis = 0;
int batVal = 0;
byte batPercent = 0;
boolean disableOtherLongClick = 0;


void setup() {
Serial.begin(115200);
pinMode(upPIN, INPUT_PULLUP);
pinMode(downPIN, INPUT_PULLUP);
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
pinMode(rstPin, OUTPUT);
delay(300);
Serial.println("Starting...");
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
lastMillis = millis();
}

void loop() {
btn1.update();
btn2.update();
disableOtherLongClick = 0;

btn1.startDispatch();
btn2.startDispatch();

if(btn1.isLongClick() && btn2.isLongClick()) {
Serial.println("Both long click");
disableOtherLongClick = 1; // Disable other longclicks from the two buttons
digitalWrite(ledPin, HIGH);
delay(1000);
digitalWrite(ledPin, LOW);
lastMillis = millis();
}
if(btn1.isSingleClick()){
Serial.println("Single click UP");
zValue = 99;
zunoSendReport(1);
lastMillis = millis();
}
if(btn1.isLongClick() && !disableOtherLongClick){
Serial.println("Long click UP");
delay(500);
lastMillis = millis();
}
if(btn2.isSingleClick()){
Serial.println("Single click DOWN");
zValue = 0;
zunoSendReport(1);
lastMillis = millis();
}
if(btn2.isLongClick() && !disableOtherLongClick){
Serial.println("Long click DOWN");
delay(500);
lastMillis = millis();
}
btn1.endDispatch();
btn2.endDispatch();
batVal = analogRead(A0);
batPercent = (batVal-850)*100/(1023-850); // 1023 is 3,3V, 850 is 2,74V, equal 8,4V-7,26V on battery.
delay(20);
if (zValue == 99) {
digitalWrite(ledPin, HIGH);
}
if (zValue == 0) {
digitalWrite(ledPin, LOW);
}
if (millis() - lastMillis > 20000 ) {
Serial.println("Sending to sleep");
zunoSendDeviceToSleep();
}
}

byte getterFunction(void) {
return zValue;
Serial.print("zValue ");
Serial.println(zValue);
}


void setterFunction(byte value) {
zValue = value;
Serial.print("zValue ");
Serial.println(zValue);
}


byte my_battery_handler() {
byte percents = batPercent;
return percents;
}
kina500
Posts: 15
Joined: 21 Jan 2021 20:49

Re: Cannot include "EEPROM.h"

Post by kina500 »

Additional question to number 2 above.

I do not have a power-on reset circuit on my pcb where I use the Z-uno module, it seems like the zuno starts correct up, just not the zwave part.
Do I need a power-up circuit?
Can this power-up circuit be made with single capacitor on reset pin? (is there a pull-up inside the chip on reset input?)
p0lyg0n1
Posts: 242
Joined: 04 Aug 2016 07:14

Re: Cannot include "EEPROM.h"

Post by p0lyg0n1 »

Hi,
I have missed that you use module. So, it's absolutely another thing.
1. About sleeping device & USB. Chip has builtin USB driver and It always switched off when you configure ZUno as sleeping device. So, It's not enough to reset sleeping device to get USB work. You have to send it to "rescue mode" to enable USB. Connect gnd to pin "RST" & to pin "BTN" and then disconnect them in a backward sequence. To wakeup up device you need pin 18 (INT1) connected to gnd.
2. If you use module for non-sleeping devices we highly recommend switch off USB driver for production devices too. Use Serial.end(); in setup() function to achieve that.
3. It's much easy to debug your code using "big" version of Z-Uno and then build your solution using module. Fullsized version has buttons that gives you ability to send device in rescue mode in one touch. On original design "BTN" is connected not only to 23 pin, it's connected to pin 18 too. You have to pullup pin 18 & pin 23 on your module to VCC using 100KOhm resistor to archieve the right behaviour in sleeping mode.

However, we have tried your sketch on fullsized ZUno. It has passed the "interview". So, seems the sketch works and there are no "EEPROM" library issues.

Good luck.

Best regards,
Alex.
kina500
Posts: 15
Joined: 21 Jan 2021 20:49

Re: Cannot include "EEPROM.h"

Post by kina500 »

Thank you Alex
I wrote a private message for you :-)
Post Reply