arduino wont work properly without soft reset

I recently added ds18b20's to my project and aver aince then my touchscreen code has been being skipped until i press reset, after that it works 100%
Ive been debugging it by turning on and off the pin 13 led at various time and noting the timing of my main loop during normal operation,
I've found that the timing is different during the initial loop after power on, and that my code that maps the xy of the touchscreen ceases to run, basically skipping it
I press reset and it runs fine : /
Anyone have any solutions for me? The only I can think of is to try to self reset only once after power on, probably with this code
void(* resetFunc) (void) = 0; //declare reset function @ address 0
ResetFunc(); //call reset

Problem is id like to not use eeprom to sorta save its already been reset, its for my car which, may turn on and off rapidly during ignition, and I can't add like something that turns off the resetting to the missed code because its only run if its touched

Anyone have any solutions for me? The only I can think of is to try to self reset only once after power on, probably with this code

Hard to say exactly without seeing your complete sketch. However I bet a delay(xxxx); as the first command in your setup() function would help the display behaviour, giving it more time to complete it's power-up reset function. You will have to play around with how long a delay would be needed (the xxxx value), but I've seen that fix work before. Start with delay(3000); and if it works start shorting the value until the symptom returns.

Lefty

The display works fine, along with all the code for it,
the touchscreen is separate and is the 4 wire resistive type
I trid the delay before and after the one wire code thinking that since that's what's causing it I should isolate it it, it seems to only be the actuall communication, becajse if no sensors are on the line its fine

Edit
Here is involved code, the ehole code is 30kb

p = ts.getPoint(); // touch reading code that fails the first powerup, part of main loop

if (p.z > MINPRESSURE && p.z < MAXPRESSURE) { //touch reading refinement
p.x = map(p.x, TS_MINX, TS_MAXX, tft.width(), 0); // x reading
p.y = map(p.y, TS_MINY, TS_MAXY, tft.height(), 0);// y reading

if(brightness = 1){

screentimer = time;
brightness = 0;
digitalWrite(LCD_BRIGHTNESS, brightness);
}
}

sensors.begin(); // part in setup, and the root of all evil, but only the first time assuming a device is on the line
sensors.setResolution(insideThermometer, TEMPERATURE_PRECISION);
sensors.setResolution(outsideThermometer, TEMPERATURE_PRECISION);

temp1 = sensors.getResolution(insideThermometer);
temp2 = sensors.getResolution(outsideThermometer);

if(temp1 !=9){ // these dont cause it, i added afterwards
tft.println("TEMP1 BAD");
}
if(temp1 == 9){
tft.println("TEMP1 GOOD");
temp1 = 1;
}
if(temp2 !=9){
tft.println("TEMP2 BAD");
}
if(temp2 == 9){
tft.println("TEMP2 GOOD");
temp2 = 1;
}
oneWire.reset(); // tried with and without this thought maybe it was hanging

// sensor read code in main loop

if(time - sensorreadtimer > sensreaddelay){
sensorreadtimer = time;
temperature1 = 0;
temperature2 = 0;
sensors.requestTemperatures();
if(temp1 == 1){
temperature1 = sensors.getTempC(insideThermometer);
temperature1 = DallasTemperature::toFahrenheit(temperature1);
}
if(temp2 == 1){
temperature2 = sensors.getTempC(outsideThermometer);
temperature2 = DallasTemperature::toFahrenheit(temperature2);
}

analogRead(A13);
rawvoltage = vref * analogRead(A13); //voltage sensor
rawvoltage = rawvoltage / 1024; // to mv
rawvoltage = rawvoltage * 6.5767; // times the voltage divider constant
batteryvoltage = rawvoltage; // to actual voltage sensed

analogRead(A12);
rawcurrent = vref * analogRead(A12); // conv to mv, not finished
rawcurrent = rawcurrent / 1024;
rawcurrent = rawcurrent - 2.5; ratiometric
rawcurrent = abs(rawcurrent);
batterycurrent = rawcurrent;
}

Hello

try a simple trick. take a diode (1N4148, 1N4001 or similar) and place it between 5v and reset on the arduino.
Specifically connect the cathode (the side with the black or white strip) to 5v and the anode (the other side) to reset.
this should improve the reliability of the auto-reset function when the board is powered up.

see if this helps you

m

if(brightness = 1){
       
       screentimer = time;
       brightness = 0;
       digitalWrite(LCD_BRIGHTNESS, brightness);
     }

Assigning the value of 1 to brightness (=) is not the same as comparing the value in brightness to 1 (==).

sensors.setResolution(insideThermometer, TEMPERATURE_PRECISION);
sensors.setResolution(outsideThermometer, TEMPERATURE_PRECISION);


temp1 = sensors.getResolution(insideThermometer);
temp2 = sensors.getResolution(outsideThermometer);

You just set the resolution. Why do you need to read it? Why is the outside resolution stored in temp1? Wouldn't outsideResolution be a more meaningful name?

Thx for catching that typo I had in brightness, lucky for me it still did what I wanted by just running that anyway, which is why i probably didnt notice, I could probably remove the if(
and temp1 is just shorter lol, I could definetly use or reuse a more. Accurate name but with all the alterations I make sometimes its just easier to define a new variable
And what I do by setting it and checking it is my way of ensuring the device is working properly
if I set it to 9 and it returns something else I know something is fishy or not connected and draws the status to my startup screen

and temp1 is just shorter lol

The reason for using meaningful names, like outsideResolution, is that it is too easy to think that temp1 means the temperature read from device 1, when that is not what is meant at all. If you don't have a temp1 variable (that contains a value that has nothing to do with temperature) and you try to use it, the compiler will inform you of the brain fart. If YOU attempt to use temp1 in a temperature context, the compiler will assume that you know what you are doing...

Figured it out for the record, the delay in the dallas library was messing things up, I had to remove it entirely and just globally request the temperatures a (literal)second before reading it from the ds18b20c, which replaces the 750 ms delay in the original library delay code