I am trying to design a code with attiny45/85 for two voltage readings and current reading. What is this error?
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SH1106.h>
// Define the screen size (SH1106 is usually 128x64 or 128x32)
#define SCREEN_WIDTH 128 // OLED width
#define SCREEN_HEIGHT 64 // OLED height
// I2C address (usually 0x3C or 0x3D)
#define OLED_RESET -1 // Reset pin is not used -1
Adafruit_SH1106 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
// Analog input pins
const int voltageSensorPin1 = A0;
const int voltageSensorPin2 = A1;
const int akimSensorPin = A2;
// Calibration values (adjust according to your sensors)
// For example: For Arduino's 5V supply, the analog value 1023 corresponds to 5V.
// If you are using a resistor divider, you should calculate the part of the input voltage that falls on the analog pin.
// The values below are a general example. You should calibrate according to your own sensors.
const float voltageConversionRatio = 5.0 / 1023.0; // For 5V reference, 10-bit ADC
const float akimSensorOffset = 2.5; // ACS712 reads 0A at 2.5V (for 5V supply)
const float akimConversionRatio = 0.185; // For ACS712 20A model, 185mV/A -> 0.185V/A
void setup() {
Serial.begin(9600);
// Initialize OLED display
if(!display.begin(SH1106_SWITCHCAPVCC, 0x3C)) { // Check the address
Serial.println(F("SH1106 could not be allocated or found"));
for(;;); // Stay in infinite loop
}
// Clear the screen and show the initial message
display.clearDisplay();
display.setTextSize(1); // Text size
display.setTextColor(SH1106_WHITE); // Text color
display.setCursor(0,0);
display.println("Initializing...");
display.display();
delay(2000);
}
void loop() {
// Reading voltage 1
int rawVoltage1 = analogRead(voltageSensorPin1);
float voltage1 = rawVoltage1 * voltageCycleRatio;
// Voltage 2 reading
int rawVoltage2 = analogRead(voltageSensorPin2);
float voltage2 = rawVoltage2 * voltageConversionRatio;
// Current reading (for sensors like ACS712)
int rawCurrent = analogRead(currentSensorPin);
// Convert sensor output to voltage
float voltageCurrentSensor = rawCurrent * voltageConversionRatio;
// Convert voltage to current (pay attention to calibration!)
// (voltageCurrentSensor - currentSensorOffset) / currentConversionRatio -> This formula is critical for direct current sensor calibration.
float current = (voltageCurrentSensor - currentSensorOffset) / currentConversionRatio;
// Clear the screen
display.clearDisplay();
// Display voltage 1
display.setTextSize(2);
display.setCursor(0, 0);
display.print("V1: ");
display.print(String(voltage1, 2)); // 2 decimal places
display.println(" V");
// Display voltage 2
display.setTextSize(2);
display.setCursor(0, 20); // Scroll down Y-axis
display.print("V2: ");
display.print(String(voltage2, 2));
display.println(" V");
// Display current
display.setTextSize(2);
display.setCursor(0, 40); // Scroll down Y-axis
display.print("I: ");
display.print(String(current, 2));
display.println(" A");
// Update the display
display.display();
// Reading interval (milliseconds)
delay(500);
}
error mesage,,,,no matching function for call to 'Adafruit_SH1106::Adafruit_SH1106(int, int, TwoWire*, int)'