Question Help me fix this Arduino code ?

zwtch_17

Commendable
Dec 18, 2021
47
3
1,545
For the last couple of months I've been making a hot air station based on a OneWire YouTube video. I made my own PCB and simplified the construction. But one thing holding me back is that the Arduino code has errors/bugs. I did fix some sleep/reed switch issue; now the screen is flickering between the main and cooling screens. It is also affecting fan speed and heater control. The original code had no problem controlling both, but the reed switch code was reversed. So you can control it on the holder, but when I take it from the holder, the code becomes bugged and the heater temperature rises uncontrollably while the screen is unresponsive. can you guys help me to fix it?

thank you.

Here is the code link:
https://drive.google.com/file/d/1mPPRUA2n2QjGQ0_JYfQvjZ6wkAEe5ky0/view?usp=drive_link

Video of screen flicker:
 
How confident are you in the physical component connections that have been made?

I realize that the hot air station project is just that - a "project". However if there are connectivity problems then the resulting intermittent flickering etc. may be the root cause of faulty connections versus the code itself.

Could be a combination of both.

For example, I see what appear to be multiple heat shrink splices going into the connector on the left, The mini display appears crooked - certainly cosmetics are not the primary concern but the tilt in the mini screen could indicate some misfit and thus poor connectivity. Not able to see inside the station.....

= = = =

As for the code itself - original source?

I was able to to download the .zip file (Filename = "hot airstation by one wire. zip") and open the code using Notepad. Not sure that that file included all of the necessary code.

Please, for starters, provide some specific references to the code sections in question.

E.g. the screen flickering between the main and cooling modes plus the reed switch being "reversed".

Take a closer look at the code and post some additional comments about what the code is supposed to be doing (while the hot air station is in use) and what is actually happening or not happening.

Include some comments to explain what you believe the problem(s), "bugs and errors" may be.

"Reversed" could simply be a logic error: false when should be true or vice versa. Or some IF and ELSE mixup.

Provide a link that opens into the code via a click and is directly readable as text. No need for downloading editors and/or zipped files.

For the record I am not an Arduino user but "code is code" and I have no problems with asking questions based on what I read in the code....

And there may be other members well versed in Arduino who will immediately note some error(s) of omission or commission in the code. Make that as easy as possible.
 
Not sure that that file included all of the necessary code.
that's for arduino IDE libraries, the other one is for custom font.
How confident are you in the physical component connections that have been made?
I'm confident enough. I'm using jumper cables for easy disassembly if there is any troubles. for AC and DC power using KF301 terminal blocks
"reversed"
I did fix this reed switch issue, correcting the HIGH/LOW on the sleep switch and sleep driver code lines. the flickering problem appeared after changing that.
code sections in question.
My suspicion are in this two codes,
after changing to "if (digitalRead(sleepsw) == HIGH)" and " if ( digitalRead(sleepsw) == LOW && swtrig == false)" it become flickering.

WHEN HANDLE SLEEP SWITCH OFF: Activating the reed switch When I put the blower back to its holder.
SLEEP DRIVE: The cooling and sleep mode after i put the blower back to its holder.

Code:
 //WHEN HANDLE SLEEP SWITCH OFF//
  if (digitalRead(sleepsw) == HIGH) {
    updateMenu();
    swtrig = false;
    
      //SLEEP DRIVE//

  if ( digitalRead(sleepsw) == LOW && swtrig == false) {
    if (teplotaC < 100) {
      drawsleep();
      buzzertone3();
      analogWrite(airflowreg, 0);
      digitalWrite(heaterreg, LOW);
      analogWrite(LED1, 5);

      swtrig = true;
    } else {
      display.clearDisplay();
      display.drawBitmap(95, 15, fan, 25, 25, WHITE);
      display.fillRect(0, 0, (teplotaC * 91) / AppSettings.maxTemp , 13 , WHITE);
      display.setFont(&URW_Gothic_L_Demi_16);
      display.setCursor(5, 33);
      display.setTextColor(WHITE);
      display.print("COOLING");
      display.setCursor(33, 58);
      display.print(teplotaC, 0);
      display.print("*C");
      display.display();
      analogWrite(airflowreg, 225);
      digitalWrite(heaterreg, LOW);
    }
 
Question about when swtrig is being toggled:

In // SLEEP DRIVE // it appears that swtrig is initialized as false.

Then flipped to true in the nested inner IF.

Is it necessary to have swtrig = false somewhere in the ELSE?

Also, as I follow it all, there is a buzzer tone "buzzertone3" being used to confirm that the wand is docked - is that correct?

Why not two different buzzer tones to indicate undocking and docking respectively. Should have some direct correspondence with swtrig as I understand the code. And thus maybe the flickering.

= = = =

One thought that comes to mind is that the flickering is a result of some AND/OR condition(s) that force the display to change as everything cools down.

Is there some point where the temperature reading could be "hovering" (for lack of a better term), changing some "display.print (or something "display.____" and effectively resulting in the appearance of the flickering?

Not uncommon for digital inputs to have some value where the measurement goes back and forth, up and down, around some value or another. "Hovering".....

Would changing (at least temporarity) the text color for each displayed value help discover the culprit?

The color of the flickering potentially revealing the culprit....

Add some lines of code to help trouble shoot - you can always // REMARK // them out or delete the lines out completely as applicable and appropriate.

Try what seems appropriate to you and post accordingly.

In the meantime someone else may spot the problem. I will keep looking also.