-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
05778e5
commit aeac2a3
Showing
4 changed files
with
165 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#include <SolarCharger.h> | ||
#include <Wire.h> | ||
|
||
SolarCharger solar; | ||
|
||
void setup() { | ||
Wire.begin(); | ||
Serial.begin(9600); | ||
} | ||
|
||
void loop() { | ||
solar.update(); | ||
|
||
if (solar.isConnected()) { | ||
Serial.print("Solar Panel Voltage: "); | ||
Serial.println(solar.getSolarPanelVoltage()); | ||
Serial.print("Battery Voltage: "); | ||
Serial.println(solar.getBatteryVoltage()); | ||
Serial.print("Battery Level: "); | ||
Serial.println(solar.getBatteryLevel()); | ||
Serial.print("Charging: "); | ||
Serial.println(solar.isCharging() ? "Yes" : "No"); | ||
Serial.print("Fast Charging: "); | ||
Serial.println(solar.isFastCharging() ? "Yes" : "No"); | ||
Serial.print("Battery Temperature: "); | ||
Serial.println(solar.getBatteryTemperature()); | ||
} else { | ||
Serial.println("Solar charger not connected."); | ||
} | ||
|
||
delay(1000); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
name=SolarChargerSB041 | ||
version=1.0.0 | ||
author=Dein Name | ||
maintainer=Dein Name <[email protected]> | ||
sentence=Eine Arduino-Bibliothek für das Auslesen des Solarladereglers SB-041. | ||
paragraph=Diese Bibliothek ermöglicht das einfache Auslesen von Daten wie Batterie- und Solarpanel-Spannung, Ladezustand und Temperatur. | ||
category=Sensors | ||
url=https://github.com/dein-repo | ||
architectures=* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#include "SolarChargerSB041.h" | ||
|
||
SolarChargerSB041::SolarChargerSB041(uint8_t address) | ||
: address(address), | ||
connected(false), | ||
solarPanelVoltage(-1), | ||
batteryVoltage(-1), | ||
batteryLevel(-1), | ||
charging(false), | ||
fastCharging(false), | ||
batteryTemperature(-1) {} | ||
|
||
void SolarChargerSB041::update() { | ||
Wire.beginTransmission(address); | ||
byte error = Wire.endTransmission(); | ||
if (error == 0 || error == 2) { | ||
connected = (error == 0); | ||
Wire.requestFrom((uint8_t)address, (uint8_t)4); | ||
|
||
uint8_t vbat_raw = Wire.read(); | ||
batteryVoltage = 0.02 * vbat_raw; | ||
|
||
uint8_t vin_raw = Wire.read(); | ||
solarPanelVoltage = 0.1 * vin_raw; | ||
|
||
uint8_t flags = Wire.read(); | ||
charging = flags & 1; | ||
if (flags & 32) | ||
batteryLevel = 4; | ||
else if (flags & 16) | ||
batteryLevel = 3; | ||
else if (flags & 8) | ||
batteryLevel = 2; | ||
else if (flags & 4) | ||
batteryLevel = 1; | ||
else | ||
batteryLevel = 0; | ||
|
||
fastCharging = flags & 64; | ||
charging = flags & 128; | ||
|
||
batteryTemperature = (int8_t)(Wire.read()); | ||
} else { | ||
connected = false; | ||
fastCharging = false; | ||
charging = false; | ||
batteryVoltage = -1; | ||
solarPanelVoltage = -1; | ||
batteryLevel = -1; | ||
batteryTemperature = -1; | ||
} | ||
} | ||
|
||
bool SolarChargerSB041::isConnected() const { return connected; } | ||
float SolarChargerSB041::getSolarPanelVoltage() const { | ||
return solarPanelVoltage; | ||
} | ||
float SolarChargerSB041::getBatteryVoltage() const { return batteryVoltage; } | ||
int SolarChargerSB041::getBatteryLevel() const { return batteryLevel; } | ||
bool SolarChargerSB041::isCharging() const { return charging; } | ||
bool SolarChargerSB041::isFastCharging() const { return fastCharging; } | ||
float SolarChargerSB041::getBatteryTemperature() const { | ||
return batteryTemperature; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#ifndef SOLARCHARGER_H | ||
#define SOLARCHARGER_H | ||
|
||
#include <Wire.h> | ||
|
||
class SolarCharger { | ||
public: | ||
SolarCharger(uint8_t address = 0x32); | ||
#ifndef SOLARCHARGER_H | ||
#define SOLARCHARGER_H | ||
|
||
#include <Wire.h> | ||
|
||
class SolarCharger { | ||
public: | ||
SolarCharger(uint8_t address = 0x32); | ||
|
||
void update(); | ||
bool isConnected() const; | ||
float getSolarPanelVoltage() const; | ||
float getBatteryVoltage() const; | ||
int getBatteryLevel() const; | ||
bool isCharging() const; | ||
bool isFastCharging() const; | ||
float getBatteryTemperature() const; | ||
|
||
private: | ||
uint8_t address; | ||
bool connected; | ||
float solarPanelVoltage; | ||
float batteryVoltage; | ||
int batteryLevel; | ||
bool charging; | ||
bool fastCharging; | ||
float batteryTemperature; | ||
}; | ||
|
||
#endif // SOLARCHARGER_H | ||
|
||
void update(); | ||
bool isConnected() const; | ||
float getSolarPanelVoltage() const; | ||
float getBatteryVoltage() const; | ||
int getBatteryLevel() const; | ||
bool isCharging() const; | ||
bool isFastCharging() const; | ||
float getBatteryTemperature() const; | ||
|
||
private: | ||
uint8_t address; | ||
bool connected; | ||
float solarPanelVoltage; | ||
float batteryVoltage; | ||
int batteryLevel; | ||
bool charging; | ||
bool fastCharging; | ||
float batteryTemperature; | ||
}; | ||
|
||
#endif // SOLARCHARGER_H |