Hello, dear friends.
First of all - sorry if I've chosen a wrong category.
Second - I've read already this topic OLED (SSD1322) display goes blank when using h/w interrupts?! - #7 by david_prentice This is not exactly my case.
So. This is a WaterSystem project for my house. A short intro.
It has 4 "bobber switchers" in the water tank, 2 switchers for 3 way valve (let's call it sensors).
At the moment I use with my Arduino Leonardo (ATmega32U4):
74HC165, 74HC595, OLED SSD1306_128x64
And the last one doesn't want to work with interruptions. And I will concentrate on this problem, putting aside the rest implementation.
There is my code ( As I said, I've deleted things have nothing to do with the problem)
#include <WaterSystem.h> // my lib for timers
#include "defines.h" // project's defines
#include "variables.h" // project's variables
#include <GyverOLED.h> // small OLED lib
// OLED DISPLAY
GyverOLED<SSD1306_128x64, OLED_BUFFER> display;
// TIMER
WaterTimer timerReadSensors("READ_SENSORS", READ_SENSORS_DELAY, "loop", true, ptrReadSensors);
// TIMERS
// Prototypes
void readSensors();
void (*ptrReadSensors)() = readSensors;
unsigned long currentMillis, previousMillis;
void setup()
{
{
// Timer0
OCR0A = 0xAF;
TIMSK0 |= _BV(OCIE0A);
}
Serial.begin(9600);
display.init();
display.clear();
display.home();
display.setScale(1);
display.println("Water system");
display.update();
}
SIGNAL(TIMER0_COMPA_vect)
{
unsigned long currentMillis = millis();
timerBlink.timerCheckUp(currentMillis);
timerReadSensors.timerCheckUp(currentMillis);
}
void loop()
{
}
void readSensors()
{
if (shift.update())
{
byte registers = shift.read();
switch (registers & B11110000)
{
case B0:
{
Serial.println("3WV is working");
break;
}
case B10000:
{
Serial.println("3WV is closed");
break;
}
case B100000:
{
Serial.println("3WV is open");
break;
}
default:
{
Serial.println("3WV state error");
}
}
switch (registers & B00001111)
{
case B0:
{
Serial.println("EMPTY");
break;
}
case B1:
{
Serial.println("FIRST bobber");
//draw_tank(1); - > troubles
break;
}
case B11:
{
Serial.println("SECOND bobber");
// draw_tank(2);- > troubles
break;
}
case B111:
{
Serial.println("THIRD bobber");
// draw_tank(3);- > troubles
break;
}
case B1111:
{
Serial.println("OVERFLOW");
break;
}
default:
{
//draw_tank(4);- > troubles
Serial.print("ERROR ");
Serial.println(registers, BIN);
}
}
}
}
void draw_tank(byte state)
{
display.clear();
display.clearDisplay();
display.drawRect(97, 0, 31, 64, OLED_FILL);
switch (state)
{
case 1:
{
display.fillRect(98, 53, 30, 20, OLED_FILL);
break;
}
/*
=======
the rest states
========
*/
}
display.update();
}
If I use Serial - everything works as it should.
But with OLED the board is hanging completely. I even have to press reboot to have possibility to reload code.
I've tried to change Timer 0 to Timer3 with the same result.
In the WaterTimer class I use millis() to check if it is time to raise an alarm.
I understand that I, probably, have crossed the border of "you shouldn't do a lot of works in the interruption". But it is so cool to have empty loop, that I am still trying to figured out - is it possible to make my code working? Or just - forget it and use interruptions to set flags and that is it... ???