Attempting to verify the code for Arduino IDE for Kralyn3d's battery bank

This page summarizes the projects mentioned and recommended in the original post on /r/arduino

Our great sponsors
  • WorkOS - The modern identity platform for B2B SaaS
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • SaaSHub - Software Alternatives and Reviews
  • Arduino-X9C

    Arduino library for Intersil X9C series of digital potentiometers

  • #include // Default Arduino library #include // Analog MuxDemux library: https://github.com/ajfisher/arduino-analog-multiplexer #include // X9C digital potentiometel library: https://github.com/philbowles/Arduino-X9C // General pin declarations int batteryTempRAW; int chargingTempRAW; int caseTempRAW; int moduleTempRAW; int moduleConnectRAW; int batteryVoltageRAW; int inputVoltageRAW; int powerbankAmpRAW; int chargingAmpRAW; // X9C digital potentiometer definitions #define X9C_INC 2 // X9C INC pin #define X9C_UD 3 // X9C UD pin #define X9C_CS 4 // X9C CS pin X9C pot; // Default initialization of X9C digital pot instance // Analog multiplexer definitions // Either use admux::Mux to access the Mux class definition from Mux.h, or // import the associated namespace of Mux.h // to make the class Mux available without having to add 'admux' in front of it via: // // using namespace admux; // Mux inMux(...); admux::Mux inMux( admux::Pin(A7, INPUT, admux::PinType::Analog), admux::Pinset(5, 6, 7)); // Alternative (equally valid) definition to approximate the original code more closely: // using namespace admux; // Mux inMux(A7, INPUT, Pintype::Analog, 5, 6, 7); // using namespace admux; // Mux inMux(Pin(A7, INPUT, PinType::Analog), Pinset(5, 6, 7)); // General Functions section // Test function for X9C pot functionality in loop void test_X9C() { // Try two random variables, 10 and 20: pot.setPot(10); delay(500); pot.setPot(20); delay(500); // Try max, min value of pot pot.setPotMax(); delay(500); pot.setPotMin(); delay(500); } // Test function to read fictional sensors for Mux inMux void readSensors() { batteryTempRAW = inMux.read(4); // Read overall powerbank power consumption chargingTempRAW = inMux.read(6); // Read module power consumptionn caseTempRAW = inMux.read(5); // Read USB & wireless charging power consumption moduleTempRAW = inMux.read(7); // Read battery temp raw batteryVoltageRAW = inMux.read(0); // Read charging circuit temp inputVoltageRAW = inMux.read(3); // Read battery voltage powerbankAmpRAW = inMux.read(2); // Read charging input voltage chargingAmpRAW = inMux.read(1); // Check if module 1 is connected moduleConnectRAW = analogRead(A6); // Read module connect status } // Setup, Loop section void setup() { // Initialize serial at 9600 baud Serial.begin(9600); // Pinmode definitions // Pinmode(PIN, OUTPUT); ... // Initialize X9C potentiometer pot.begin(X9C_CS, X9C_INC, X9C_UD); } void loop() { // Check if X9C digital pot functionality compiles test_X9C(); // Check if Mux inMux tomfoolery compiles readSensors(); // 1s pause after each loop delay(1000); }

  • arduino-analog-multiplexer

    Library for Arduino in order to use Analog Multiplexer / DeMultiplexers easily

  • #include // Default Arduino library #include // Analog MuxDemux library: https://github.com/ajfisher/arduino-analog-multiplexer #include // X9C digital potentiometel library: https://github.com/philbowles/Arduino-X9C // General pin declarations int batteryTempRAW; int chargingTempRAW; int caseTempRAW; int moduleTempRAW; int moduleConnectRAW; int batteryVoltageRAW; int inputVoltageRAW; int powerbankAmpRAW; int chargingAmpRAW; // X9C digital potentiometer definitions #define X9C_INC 2 // X9C INC pin #define X9C_UD 3 // X9C UD pin #define X9C_CS 4 // X9C CS pin X9C pot; // Default initialization of X9C digital pot instance // Analog multiplexer definitions // Either use admux::Mux to access the Mux class definition from Mux.h, or // import the associated namespace of Mux.h // to make the class Mux available without having to add 'admux' in front of it via: // // using namespace admux; // Mux inMux(...); admux::Mux inMux( admux::Pin(A7, INPUT, admux::PinType::Analog), admux::Pinset(5, 6, 7)); // Alternative (equally valid) definition to approximate the original code more closely: // using namespace admux; // Mux inMux(A7, INPUT, Pintype::Analog, 5, 6, 7); // using namespace admux; // Mux inMux(Pin(A7, INPUT, PinType::Analog), Pinset(5, 6, 7)); // General Functions section // Test function for X9C pot functionality in loop void test_X9C() { // Try two random variables, 10 and 20: pot.setPot(10); delay(500); pot.setPot(20); delay(500); // Try max, min value of pot pot.setPotMax(); delay(500); pot.setPotMin(); delay(500); } // Test function to read fictional sensors for Mux inMux void readSensors() { batteryTempRAW = inMux.read(4); // Read overall powerbank power consumption chargingTempRAW = inMux.read(6); // Read module power consumptionn caseTempRAW = inMux.read(5); // Read USB & wireless charging power consumption moduleTempRAW = inMux.read(7); // Read battery temp raw batteryVoltageRAW = inMux.read(0); // Read charging circuit temp inputVoltageRAW = inMux.read(3); // Read battery voltage powerbankAmpRAW = inMux.read(2); // Read charging input voltage chargingAmpRAW = inMux.read(1); // Check if module 1 is connected moduleConnectRAW = analogRead(A6); // Read module connect status } // Setup, Loop section void setup() { // Initialize serial at 9600 baud Serial.begin(9600); // Pinmode definitions // Pinmode(PIN, OUTPUT); ... // Initialize X9C potentiometer pot.begin(X9C_CS, X9C_INC, X9C_UD); } void loop() { // Check if X9C digital pot functionality compiles test_X9C(); // Check if Mux inMux tomfoolery compiles readSensors(); // 1s pause after each loop delay(1000); }

  • WorkOS

    The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.

    WorkOS logo
  • PlatformIO

    Your Gateway to Embedded Software Development Excellence :alien:

  • Setting it up can be confusing, but I use the PlatformIO extension for Visual Studio Code since managing projects is much easier with it, importing multiple libraries as well. It can access the official Arduino libraries directly & you can import Github libraries by simply adding the link to the .git to the config file of your project on a per-project base.

  • Visual Studio Code

    Visual Studio Code

  • Setting it up can be confusing, but I use the PlatformIO extension for Visual Studio Code since managing projects is much easier with it, importing multiple libraries as well. It can access the official Arduino libraries directly & you can import Github libraries by simply adding the link to the .git to the config file of your project on a per-project base.

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts