Hi,
Firstly a error came:
The library used:
No matching function for call to'DS3231 (const uint8_t &, const uint8_t &) '
I changed: 'DS3231 rtc(SDA, SCL)' into 'DS3231 rtc();' another error:
'Time' does not name a type; did you mean 'Wire'?
ERROR:
Arduino: 1.8.13 (Windows 7), Board: "Arduino Uno"
multiMultimeter_M:115:1: error: 'Time' does not name a type; did you mean 'Wire'?
Time t;
^~~~
Wire
E:\ENGINEERING\DIY\Electronic\meter\Arduino Multimeter\Arduino Multimeter and Components Tester\V2\multiMultimeter_M\multiMultimeter_M.ino: In function 'void setup()':
multiMultimeter_M:132:7: error: request for member 'begin' in 'rtc', which is of non-class type 'DS3231()'
rtc.begin();
^~~~~
exit status 1
'Time' does not name a type; did you mean 'Wire'?
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
Full code:
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Fonts/FreeSans9pt7b.h>
#include <Fonts/FreeSans18pt7b.h>
#include <Fonts/FreeSans12pt7b.h>
#include <DS3231.h>
// Data wire is plugged into pin 2 on the Arduino
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
//// delay(2000);
#define XPOS 0
#define YPOS 1
#define DELTAY 2
//clock image
const unsigned char PROGMEM sat1 [] = {
0x0F, 0x80, 0x01, 0xF0, 0x39, 0xC0, 0x03, 0x9C, 0x61, 0x80, 0x01, 0x86, 0x43, 0x1F, 0xF8, 0xC2,
0xC6, 0x70, 0x0E, 0x63, 0x8D, 0xC0, 0x03, 0xB1, 0x9B, 0x00, 0x00, 0xD9, 0xF6, 0x01, 0x80, 0x6F,
0xEC, 0x01, 0x80, 0x37, 0x58, 0x01, 0x80, 0x1A, 0x10, 0x01, 0x80, 0x08, 0x30, 0x01, 0x80, 0x0C,
0x20, 0x01, 0x80, 0x04, 0x20, 0x01, 0x80, 0x04, 0x20, 0x01, 0x80, 0x04, 0x60, 0x01, 0x80, 0x06,
0x60, 0x01, 0x80, 0x06, 0x60, 0x7F, 0x80, 0x06, 0x60, 0x00, 0x00, 0x06, 0x60, 0x00, 0x00, 0x06,
0x20, 0x00, 0x00, 0x04, 0x20, 0x00, 0x00, 0x04, 0x30, 0x00, 0x00, 0x0C, 0x10, 0x00, 0x00, 0x08,
0x18, 0x00, 0x00, 0x18, 0x08, 0x00, 0x00, 0x10, 0x0C, 0x00, 0x00, 0x30, 0x06, 0x00, 0x00, 0x60,
0x0F, 0x80, 0x01, 0xF0, 0x18, 0xE0, 0x07, 0x18, 0x30, 0x7C, 0x3E, 0x0C, 0x20, 0x0F, 0xF0, 0x04
};
//baterry image
const unsigned char PROGMEM baterja [] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x3F, 0xFF, 0xFF, 0xF0, 0x40, 0x00, 0x00, 0x10, 0x47, 0x3C, 0xE0, 0x18,
0x47, 0xBD, 0xE0, 0x18, 0x45, 0xA5, 0xA0, 0x1E, 0x45, 0xA5, 0xA0, 0x1A, 0x45, 0xA5, 0xA0, 0x1A,
0x45, 0xA5, 0xA0, 0x1A, 0x45, 0xA5, 0xA0, 0x1A, 0x45, 0xA5, 0xA0, 0x1E, 0x47, 0xBD, 0xE0, 0x18,
0x47, 0x3C, 0xE0, 0x18, 0x40, 0x00, 0x00, 0x10, 0x3F, 0xFF, 0xFF, 0xF0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
//continuity test image
const unsigned char PROGMEM continu [] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x1F, 0xF8, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x03, 0xFF, 0xFF, 0xC0, 0x0F, 0xFF, 0xFF, 0xF0,
0x1F, 0xC0, 0x03, 0xF8, 0x7F, 0x00, 0x00, 0xFE, 0xFC, 0x00, 0x00, 0x3F, 0xF8, 0x07, 0xE0, 0x1F,
0xF0, 0x3F, 0xFC, 0x0F, 0x00, 0xFF, 0xFF, 0x00, 0x01, 0xFF, 0xFF, 0x80, 0x03, 0xF0, 0x0F, 0xC0,
0x07, 0xC0, 0x03, 0xE0, 0x03, 0x80, 0x01, 0xC0, 0x01, 0x0F, 0xF0, 0x80, 0x00, 0x1F, 0xF8, 0x00,
0x00, 0x3F, 0xFC, 0x00, 0x00, 0x3C, 0x3C, 0x00, 0x00, 0x38, 0x1C, 0x00, 0x00, 0x01, 0x80, 0x00,
0x00, 0x03, 0xC0, 0x00, 0x00, 0x03, 0xC0, 0x00, 0x00, 0x03, 0xC0, 0x00, 0x00, 0x03, 0xC0, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
//resistor image
const unsigned char PROGMEM resis [] = {
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x06, 0x04, 0x00, 0x00, 0x0F, 0x88,
0x00, 0x00, 0x18, 0xD0, 0x00, 0x00, 0x38, 0x60, 0x00, 0x00, 0x6C, 0x30, 0x00, 0x00, 0xC6, 0x18,
0x00, 0x00, 0x83, 0x08, 0x00, 0x01, 0x81, 0x8C, 0x00, 0x03, 0x00, 0xCC, 0x00, 0x07, 0x80, 0x78,
0x00, 0x0C, 0xC0, 0x30, 0x00, 0x18, 0x60, 0x60, 0x00, 0x38, 0x30, 0xC0, 0x00, 0x6C, 0x1B, 0x80,
0x01, 0xC6, 0x0E, 0x00, 0x03, 0x03, 0x0C, 0x00, 0x07, 0x01, 0x98, 0x00, 0x0D, 0x80, 0xF0, 0x00,
0x18, 0xC0, 0x60, 0x00, 0x30, 0x60, 0xC0, 0x00, 0x30, 0x31, 0x80, 0x00, 0x10, 0x19, 0x00, 0x00,
0x18, 0x0F, 0x00, 0x00, 0x0C, 0x06, 0x00, 0x00, 0x06, 0x0C, 0x00, 0x00, 0x0B, 0x18, 0x00, 0x00,
0x11, 0xF0, 0x00, 0x00, 0x20, 0x60, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00
};
//diode image
const unsigned char PROGMEM dioda [] = {
0x00, 0x07, 0xE0, 0x00, 0x00, 0x1F, 0xF8, 0x00, 0x00, 0x3F, 0xFC, 0x00, 0x00, 0x78, 0x1E, 0x00,
0x00, 0xE0, 0x07, 0x00, 0x00, 0xE0, 0x07, 0x00, 0x00, 0xC0, 0x03, 0x00, 0x01, 0xC0, 0x03, 0x80,
0x01, 0xC0, 0x03, 0x80, 0x01, 0xC0, 0x03, 0x80, 0x01, 0xC0, 0x03, 0x80, 0x01, 0xC0, 0x03, 0x80,
0x01, 0xC0, 0x03, 0x80, 0x01, 0xC0, 0x03, 0x80, 0x07, 0xFF, 0xFF, 0xE0, 0x07, 0xFF, 0xFF, 0xE0,
0x07, 0xFF, 0xFF, 0xE0, 0x07, 0xFF, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x1C, 0x38, 0x00, 0x00, 0x1C, 0x38, 0x00, 0x00, 0x1C, 0x38, 0x00, 0x00, 0x1C, 0x38, 0x00,
0x00, 0x1C, 0x38, 0x00, 0x00, 0x1C, 0x38, 0x00, 0x00, 0x1C, 0x38, 0x00, 0x00, 0x1C, 0x38, 0x00,
0x00, 0x1C, 0x38, 0x00, 0x00, 0x1C, 0x38, 0x00, 0x00, 0x1C, 0x38, 0x00, 0x00, 0x1C, 0x38, 0x00
};
// logo at starting screen
const unsigned char PROGMEM multilogo [] = {
0x00, 0x08, 0x61, 0x86, 0x10, 0x00, 0x00, 0x18, 0x61, 0x86, 0x18, 0x00, 0x00, 0x18, 0x61, 0x86,
0x18, 0x00, 0x00, 0x18, 0x61, 0x86, 0x18, 0x00, 0x00, 0x18, 0x61, 0x86, 0x18, 0x00, 0x00, 0x08,
0x61, 0x86, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00,
0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0x80, 0x01, 0x80, 0x00, 0x00, 0x01, 0x80, 0x01, 0x80, 0x00, 0x00,
0x01, 0x80, 0x79, 0x80, 0x00, 0x00, 0x01, 0x9E, 0xFD, 0x80, 0x00, 0x00, 0x01, 0xBF, 0x01, 0x80,
0x00, 0x00, 0x01, 0x80, 0x01, 0x80, 0x00, 0x00, 0x01, 0x80, 0x01, 0x80, 0x00, 0x00, 0x01, 0x80,
0x01, 0x81, 0xFF, 0xFF, 0x81, 0x80, 0xFD, 0x83, 0xFF, 0xFF, 0xC1, 0xBF, 0xFD, 0x83, 0x80, 0x01,
0xC1, 0xBF, 0x01, 0x83, 0x00, 0x00, 0xC1, 0x80, 0x01, 0x83, 0x00, 0x00, 0xC1, 0x80, 0x01, 0x83,
0x00, 0x00, 0xC1, 0x80, 0x01, 0x83, 0x00, 0x00, 0xC1, 0x80, 0xFD, 0x83, 0x00, 0x00, 0xC1, 0xBF,
0xFD, 0x83, 0x00, 0x00, 0xC1, 0xBF, 0x01, 0x83, 0x00, 0x00, 0xC1, 0x80, 0x01, 0x83, 0x00, 0x00,
0xC1, 0x80, 0x01, 0x83, 0x00, 0x00, 0xC1, 0x80, 0x01, 0x83, 0x00, 0x00, 0xC1, 0x80, 0xFD, 0x83,
0x80, 0x01, 0xC1, 0xBF, 0xFD, 0x83, 0xFF, 0xFF, 0xC1, 0xBF, 0x01, 0x81, 0xFF, 0xFF, 0x81, 0x80,
0x01, 0x80, 0x00, 0x00, 0x01, 0x80, 0x01, 0x80, 0x00, 0x00, 0x01, 0x80, 0x01, 0x80, 0x00, 0x00,
0x01, 0x80, 0xFD, 0x80, 0x00, 0x00, 0x01, 0xBF, 0x79, 0x80, 0x00, 0x00, 0x01, 0x9E, 0x01, 0x80,
0x00, 0x00, 0x01, 0x80, 0x01, 0x80, 0x00, 0x00, 0x01, 0x80, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0x80,
0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x61, 0x86,
0x10, 0x00, 0x00, 0x18, 0x61, 0x86, 0x18, 0x00, 0x00, 0x18, 0x61, 0x86, 0x18, 0x00, 0x00, 0x18,
0x61, 0x86, 0x18, 0x00, 0x00, 0x18, 0x61, 0x86, 0x18, 0x00, 0x00, 0x08, 0x61, 0x86, 0x10, 0x00
};
//// DS3231 rtc(SDA, SCL);
DS3231 rtc();
//// Time t;
Time DateTime;
int pauza = 300; //pause
int raw = 0;
float Vin = 0;
float Vout = 0;
float R1 = 2200;
float R2 = 0;
float vout2 = 0.00;
float vin2 = 0.00;
float res1 = 100000.00; // resistance of R1 (100K)
float res2 = 10000.00; // resistance of R2 (10K)
int val = 0;
float buffer = 0;
void setup() {
rtc.begin();
pinMode(2, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
pinMode(13, OUTPUT);
attachInterrupt(1, pressed, FALLING);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 128x32)
// init done
display.clearDisplay();
display.setFont(&FreeSans9pt7b);
display.setTextColor(WHITE);
display.setCursor(0, 32);
display.print("Multi-");
display.setCursor(0, 48);
display.print("druino");
display.setFont();
display.setTextColor(WHITE);
display.setCursor(0, 0);
display.print("2018");
display.drawBitmap(64, 8, multilogo, 48, 48, 1);
display.display();
delay(2000);
display.clearDisplay();
display.display();
}
int mmax = 1; //max
int mmin = 1024; // min
int button = 0;
int mode = 0; //variable for debouncing button
unsigned long numberOfTimes = 0; //number of times
unsigned long sum = 0;
int ave = 0; //average
int pulse = 125; //starting PWM
unsigned long m = 0;
void loop()
{
if (mode == 0)
{
if (digitalRead(4) == 0) //analoog read
{
delay(100);
mmin = 1024;
mmax = 0;
numberOfTimes = 0;
sum = 0;
ave = 0;
}
display.clearDisplay();
display.setFont(&FreeSans9pt7b);
display.setTextColor(WHITE);
display.setCursor(0, 12);
display.setTextSize(1);
display.print("aRead:");
display.setCursor(95, 0);
int value = analogRead(A0);
numberOfTimes = numberOfTimes + 1;
sum = sum + value;
ave = sum / numberOfTimes;
if (value > mmax)
mmax = value;
if (value < mmin)
mmin = value;
display.setFont();
int lineW = map(value, 0, 1024, 0, 128); // bottom line lenght
float voltaza = readVcc();
display.setCursor(95, 0);
display.print(ave);
display.setCursor(70, 0);
display.print("AVE:");
display.setCursor(70, 10);
display.print("MAX:");
display.setCursor(70, 20);
display.print("MIN:");
display.setCursor(95, 10);
display.print(mmax);
display.setCursor(95, 20);
display.print(mmin);
display.setFont(&FreeSans18pt7b);
display.setCursor(0, 62);
display.print(value);
display.drawLine(0, 31, lineW, 31, 1);
display.display();
if (numberOfTimes > 100000)
{ numberOfTimes = 0;
sum = 0;
}
}
if (mode == 1)
{ // ohm meter
display.clearDisplay();
display.setFont(&FreeSans9pt7b);
display.setCursor(0, 12);
display.print("Ohms:");
display.drawBitmap(96, 0, resis, 32, 32, 1);
raw = analogRead(A2);
Vin = readVcc() / 1000.0;
buffer = raw * Vin;
Vout = (buffer) / 1024.0;
buffer = (Vin / Vout) - 1;
R2 = R1 * buffer;
display.setTextSize(1);
display.setFont(&FreeSans18pt7b);
display.setCursor(0, 62);
if (R2 < 70000)
display.print(R2);
if (R2 > 70000)
display.print("0");
display.display();
delay(pauza);
}
if (mode == 2) //dioda drop
{
display.clearDisplay();
display.drawBitmap(96, 0, dioda, 32, 32, 1);
display.setFont(&FreeSans9pt7b);
display.setCursor(0, 12);
display.print("Voltage");
display.setCursor(0, 30);
display.print("Drop:");
raw = analogRead(A2);
Vin = readVcc() / 1000.0;
buffer = raw * Vin;
Vout = (buffer) / 1024.0;
display.setFont(&FreeSans18pt7b);
display.setCursor(0, 63);
if (Vout == 0)
{
display.print("0");
} else {
display.print(Vin - Vout);
}
display.display();
delay(500);
}
if (mode == 3)
{ //continuiti
display.clearDisplay();
display.drawBitmap(96, -4, continu, 32, 32, 1);
display.setFont(&FreeSans9pt7b);
display.setCursor(0, 12);
display.print("Continuity:");
display.setFont(&FreeSans18pt7b);
display.setCursor(0, 62);
raw = analogRead(A2);
Vin = readVcc() / 1000.0;
buffer = raw * Vin;
Vout = (buffer) / 1024.0;
float rez = Vin - Vout;
if (rez < 1)
{
tone(6, 2250);
display.print("Yes");
digitalWrite(13, 1);
}
if (rez > 1)
{
noTone(6);
digitalWrite(13, 0);
display.print("No");
}
display.display();
}
if (mode == 4)
{ //baterry
display.clearDisplay();
display.drawBitmap(96, -8, baterja, 32, 32, 1);
display.setFont(&FreeSans9pt7b);
display.setCursor(0, 12);
display.print("Battery:");
display.setFont(&FreeSans18pt7b);
display.setCursor(0, 62);
float volt2 = readVcc() / 1000.0;
display.print(volt2);
display.setCursor(69, 62);
display.print("V");
display.display();
delay(pauza);
}
if (mode == 5) // pwm generator
{
if (digitalRead(4) == 0)
{ if (pulse < 255)
{
tone(6, 1200, 10);
pulse = pulse + 5;
}
}
if (digitalRead(2) == 0)
{ if (pulse > 1)
{
tone(6, 1400, 10);
pulse = pulse - 5;
}
}
int lineWidth2 = 0;
analogWrite(9, pulse);
display.clearDisplay();
display.setFont(&FreeSans9pt7b);
display.setCursor(0, 12);
display.print("Pulse");
display.setCursor(0, 28);
display.print("Width:");
display.setFont(&FreeSans18pt7b);
display.setCursor(0, 60);
display.print(pulse);
lineWidth2 = map(pulse, 0, 255, 0, 128);
display.drawLine(0, 63, lineWidth2, 63, 1);
display.display();
}
/* if(stisnuto==6)
{
t=rtc.getTime();
display.clearDisplay();
display.setCursor(0,30);
display.setFont(&FreeSans18pt7b);
display.print(t.hour);
display.setCursor(40,30);
display.print(":");
display.setCursor(50,30);
display.print(t.min);
display.setFont(&FreeSans12pt7b);
display.setCursor(4,62);
display.print(t.sec);
display.drawBitmap(96, 0, sat1, 32, 32, 1);
display.setFont(&FreeSans9pt7b);
display.setCursor(34,62);
display.print("sec");
display.display();
}
}*/
}
void pressed() //midle button presed, changing modes
{
static unsigned long last_interrupt_time = 0;
unsigned long interrupt_time = millis();
// If interrupts come faster than 200ms, assume it's a bounce and ignore
if (interrupt_time - last_interrupt_time > 220)
{
mode++;
tone(6, 2250, 50);
if (mode > 5)
mode = 0;
}
last_interrupt_time = interrupt_time;
}
long readVcc() {
// Read 1.1V reference against AVcc
// set the reference to Vcc and the measurement to the internal 1.1V reference
#if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
ADMUX = _BV(REFS0) | _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
#elif defined (__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
ADMUX = _BV(MUX5) | _BV(MUX0);
#elif defined (__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
ADMUX = _BV(MUX3) | _BV(MUX2);
#else
ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
#endif
delay(2); // Wait for Vref to settle
ADCSRA |= _BV(ADSC); // Start conversion
while (bit_is_set(ADCSRA, ADSC)); // measuring
uint8_t low = ADCL; // must read ADCL first - it then locks ADCH
uint8_t high = ADCH; // unlocks both
long result = (high << 8) | low;
result = 1125300L / result; // Calculate Vcc (in mV); 1125300 = 1.1*1023*1000
return result; // Vcc in millivolts
}