Arduino code - Integers mixed up

Hi guys, I am sitting with a strange problem. I built a prototype circuit, wrote the code in arduino IDE and it works 100%.
OK , let me start off with a description of what my circuit does. I have a H.D.C 1080 humidity / temp sensor connected to Arduino UNO. It gives out a 0-10 Volt and 4-20 mA control signal to a P.L.C ( this set point is set by the user.)Also have a 16x2 LCD and 2 push buttons to increment or decrement the setpoint. There is calculations done on my code regarding how to get the setpoint etc. This will al be done on the PLC

On my vero board prototype, it works great, no problems. Then I went one step further and designed the pcb on KiCAD, my very first, but definitely not my last design. Very chuffed with myself for going this far already.

OK, so I built the prototype pcb, burned the bootloader and flashed my code onto the target. And it works…sort off.

I initialized my “int SPCounter= 25;” and on the vero board proto UNO it displays that SPcounter as 25. Which is correct,exactly what I wanted…but on my prototype, the SPCounter is initialized at 256. Which is not correct…Somehow, somewhere my SPcounter got lost in translation… What is going on ? Any suggestions ?

I have used command prompt avrdude to erase the flash and eeprom, but everytime my SPcounter starts at 256.

If you need me to post the code, please just let me know…I think I have tried just about everything,my final try is going to be to write the code over in C and load it like that…but my C skills is close to non existent at the moment…
Ill attach the code anyways…
Thanks for taking time out to help me

Here is my code:

//21-03-2018 Correct code for prototype PCB
#include <Bounce2.h>
#include <LiquidCrystal.h>
#include <Wire.h>
#include <EEPROM.h>
#include <ClosedCube_HDC1080.h>

ClosedCube_HDC1080 hdc1080;
LiquidCrystal lcd (7,6,5,4,3,2);

const int up = 8;
const int down = 9;
const int LED = 13;
const int OutV = 10;
const int OutmA = 11;

Bounce debouncer1=Bounce();
Bounce debouncer2=Bounce();

float CurHum;
float Temp;
int upState = 0;
int downState = 0;
int SPCounter= 25;
int NewSp;
int chk;
int addr = 0;

void setup() //Setup to run once at startup
{
pinMode(up,INPUT_PULLUP);
debouncer1.attach(up);
debouncer1.interval(5);

pinMode(down,INPUT_PULLUP);
debouncer2.attach(down);
debouncer2.interval(5);

pinMode(LED,OUTPUT);
pinMode(OutV,OUTPUT);
pinMode(OutmA,OUTPUT);

hdc1080.begin(0x40);
lcd.begin(16,2);
lcd.clear();
lcd.setCursor (0,0);
lcd.print (“NEW 2 Anstan”);
lcd.setCursor (0,1);
lcd.print (“Technologies”);
delay (2500);

lcd.clear();
lcd.setCursor (0,0);
lcd.print (“Digital”);
lcd.setCursor (0,1);
lcd.print (“Humidistat Ver2”);
delay (2500);

lcd.setCursor (0,0);
lcd.print (“ID=0x”);
lcd.print (hdc1080.readManufacturerId(),HEX);
lcd.setCursor (0,1);
lcd.print (“DeviceID=0x”);
lcd.print (hdc1080.readDeviceId(),HEX);
delay(3000);
}

void loop()
{
lcd.clear();

CurHum=hdc1080.readHumidity();
Temp=hdc1080.readTemperature();

debouncer1.update();
debouncer2.update();

int value1=debouncer1.read();
int value2=debouncer2.read();

upState=digitalRead(up);
downState=digitalRead(down);
digitalWrite(LED,LOW);

NewSp = EEPROM.read (addr);
SPCounter = NewSp;

if( upState == HIGH || downState == HIGH )
{
digitalWrite(LED,HIGH);
lcd.clear();
lcd.setCursor (0,0);
lcd.print ("Setpoint: ");

if( upState != NewSp )
{
if ( upState == HIGH )
{
SPCounter++;
lcd.print(SPCounter);
}
delay(50);
NewSp = SPCounter;
}
if( downState != NewSp )
{
if ( downState == HIGH )
{
SPCounter–;
lcd.print(SPCounter);
}
delay(50);
NewSp = SPCounter;
}

lcd.setCursor (0,1);
lcd.print ("New SP: ");
lcd.print (NewSp);
delay(500);

}

else
{
digitalWrite(LED,LOW);
lcd.clear();
lcd.setCursor(0,0);
lcd.print(“Rel Hum: “);
lcd.print (hdc1080.readHumidity());
lcd.print (”%”);
lcd.setCursor(0,1);
lcd.print("Temp: ");
lcd.print (hdc1080.readTemperature());
lcd.print(“C”);
delay(2000);
}
EEPROM.write(addr,NewSp);

analogWrite(OutV, NewSp * 2.55);
analogWrite(OutmA, NewSp * 2.55);

}
void printSerialNumber()
{
lcd.print(“Device Serial Number=”);
HDC1080_SerialNumber sernum = hdc1080.readSerialNumber();
char format[12];
sprintf(format, “%02X-%04X-%04X”, sernum.serialFirst, sernum.serialMid, sernum.serialLast);
lcd.println(format);
}

I initialized my "int SPCounter= 25;" and on the vero board proto UNO it displays that SPcounter as 25. Which is correct,exactly what I wanted..but on my prototype, the SPCounter is initialized at 256. Which is not correct..

Are we supposed to assume that your prototype uses the same ATMega328 chip that the UNO uses?

I have used command prompt avrdude to erase the flash and eeprom, but everytime my SPcounter starts at 256.

I'm sorry, but this statement is nonsense. You do NOT display the value in SPCounter until after you have trashed the initial value with what you read from EEPROM and possibly incremented.

255, the default value for uninitialized EEPROM cells, + 1 IS 256.

No amount of diddling with erasing the flash or EEPROM is going to put anything BUT 255 in the cells. YOU must write some other value there if you expect to read some other value.

spitfire79:

//21-03-2018 Correct code for prototype PCB

#include <Bounce2.h>
const int up = 8;
const int down = 9;

Bounce debouncer1=Bounce();
Bounce debouncer2=Bounce();

int upState = 0;
int downState = 0;

void setup()                      //Setup to run once at startup
{
 pinMode(up,INPUT_PULLUP);
 debouncer1.attach(up);
 debouncer1.interval(5);

pinMode(down,INPUT_PULLUP);
 debouncer2.attach(down);
 debouncer2.interval(5);
}

void loop()
{
 debouncer1.update();
 debouncer2.update();

int value1=debouncer1.read();
 int value2=debouncer2.read();

upState=digitalRead(up);
 downState=digitalRead(down);
}

Why bother to set up those two debounce objects and then throw away the values they return?!? You read the debounced values into “value1” and “value2”, never use those values, and read the input pins to get the current state.