Notifications
Clear all

Save of current reading

15 Posts
6 Users
4 Reactions
1,167 Views
henrik_t7
(@henrik_t7)
Member
Joined: 4 years ago
Posts: 24
Topic starter  

Hello,

I have made a small solar cell charger, with a solarcell and an INA219 to read the current between the solarcell and the TP4056 battery charger, it is all controlled by a Wemos d1 mini ESP8266 and read out on an OLED screen, the current, voltage and power.

 

Can you transfer these 3, the current, voltage and power from Wemos, with wifi to a database, so that you can see how the solar cell supplies the current, voltage and power??

Thanks


   
Quote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 4 years ago
Posts: 7660
 

@henrik_t7 The short, simple answer is yes. At the point in your existing code where you write the Volts etc to the display, just add another statement to write the Volts etc to whatever DB you want. The reason I said short and simple is that writing to a DB can be as simple as writing to a display, or it can be many statements. It all depends on what DB you want to use. It also depends on where the DB is located. If it is not local then you need to send it probably by WiFi.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2571
 

@henrik_t7

As a much simpler alternative, you could just write these data off onto an SD card that you can then load the data from it onto your PC for analysis.

Anything seems possible when you don't know what you're talking about.


   
Ron and Inst-Tech reacted
ReplyQuote
Inst-Tech
(@inst-tech)
Member
Joined: 3 years ago
Posts: 554
 

Posted by: @henrik_t7

Hello,

I have made a small solar cell charger, with a solarcell and an INA219 to read the current between the solarcell and the TP4056 battery charger, it is all controlled by a Wemos d1 mini ESP8266 and read out on an OLED screen, the current, voltage and power.

 

Can you transfer these 3, the current, voltage and power from Wemos, with wifi to a database, so that you can see how the solar cell supplies the current, voltage and power??

Thanks

Hi @henrik_t7, I think what@will has suggested might be simpler, but if I understand your post correctly, you wanted to transmit the data over WiFi.. so I found this link you may be interested in:

https://randomnerdtutorials.com/esp8266-wireless-weather-station-with-data-logging-to-excel/

It appears to be close to what you are attempting to do.. at any rate, good luck, and let us know how it comes out...

regards,

LouisR

 

LouisR


   
ReplyQuote
henrik_t7
(@henrik_t7)
Member
Joined: 4 years ago
Posts: 24
Topic starter  

Thanks for all the replies
Here is a block diagram of it

 

and the code is also attached

#include <Wire.h>
#include <Adafruit_INA219.h>
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Fonts/FreeSerifItalic12pt7b.h>

Adafruit_INA219 ina219;

#define SCREEN_WIDTH 128 // OLED display width, in pixls
#define SCREEN_HEIGHT 64 // OLED display height, in pixls

//declaration for an SSD1306 display connected to I"C (SDA, SCL pins D2 and D1 on an Wemos mini R2)
#define OLED_RESET -1 //reset pin # (or -1 if sharing arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET );
float current_mA = 0;
float loadvoltage = 0;
float power_mW = 0;


void setup() {
  Serial.begin(115200);
  while (!Serial) {
//will pause  until serial console opens
   delay (1);
  }
   uint32_t currentFrequency;

     if (! ina219.begin()) {
    Serial.println("Failed to find INA219 chip");
    while (1) {
      delay(10);
    }
  }

   if (! display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // address 0x3C for 128 x 64
        
      Serial.println(F("SSD1306 allocation failed"));
      for(;;);   // don't proceed, loop forever
   }
   // clear thr buffer

  display.clearDisplay();
  Serial.print("Measuring voltage and current with INA219...");  
  
}

void loop() {
 float shuntvoltage = 0;
 float busvoltage = 0;
 current_mA = 0;
 loadvoltage = 0;
 power_mW =  0; 

 shuntvoltage = ina219.getShuntVoltage_mV ();
 busvoltage = ina219.getBusVoltage_V ();
 current_mA = ina219.getCurrent_mA();
 power_mW = ina219.getPower_mW();
 loadvoltage = busvoltage + (shuntvoltage/1000);

 Serial.print("Load Voltage:  "); Serial.print(loadvoltage); Serial.println(" V");
 Serial.print("Current:       "); Serial.print(current_mA); Serial.println(" mA");
 Serial.print("Power:         "); Serial.print(power_mW); Serial.println(" mW");
 Serial.println("");
 display.clearDisplay();
 voltCurrent();
 delay(2000);
 display.clearDisplay();
 powerr(); 
 delay(2000);

}

 void voltCurrent() {
  display.setFont();
  display.setTextSize(2); // Draw 2X-scale text
  display.setTextColor(WHITE);
  display.setCursor(0, 0);            // Start at top-left corner
  display.print(loadvoltage);
  display.print("V");
  display.setCursor(0, 18);
  display.print(current_mA);
  display.print("mA");
  display.display();
 }

 void powerr(){
  display.setFont(&FreeSerifItalic12pt7b);
  display.setTextSize(1); // Draw 2X-scale text
  display.setTextColor(WHITE);
  display.setCursor(0, 20);            // Start at top-left corner
  display.print(power_mW);
  display.print("mW");
  display.display();

 }

I need a good and easy electronics diagram aps, some suggestions, preferably free


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 4 years ago
Posts: 7660
 

@henrik_t7 Did you follow @will suggestion and @inst-tech suggestion? Both of those will work. 

I assume you know the sketch you provided has the VIN- going to the wrong side of the solar cell.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 4 years ago
Posts: 7660
 

@henrik_t7 I forgot to mention, use the arduino IDE Tools/Autoformat to clean up your code a bit.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 4 years ago
Posts: 7660
 

@henrik_t7 Also, see Bill's article on data logging. Unfortunately only the YT is available right now while Bill updates the website, but it's a start

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
(@davee)
Member
Joined: 3 years ago
Posts: 1866
 

Hi @henrik_t7,

   I am not personally that familiar with the modules you are using, but I advise you to check the following.

Your circuit sketch suggested that you were connecting the ESP8286 to the INA219 and OLED screen via I2C, with the INA219 an OLED screen powered to 5V. The ESP8266 modue can accept 5V power, but the actual ESP8266 device is a 3.3V maximum device, which includes the I2C bus connections.

I appreciate it may appear to work, but I think the I2C connections should have a level conversion between the ESP8266 and the other two modules.

The level conversion can be implemented in a number of ways, a common way is to use a board like:

https://www.adafruit.com/product/757

------

Alternatively, it might be possible to power the INA219 and OLED screen with 3.3V.

------------

Best wishes, Dave


   
rommudoh and Ron reacted
ReplyQuote
henrik_t7
(@henrik_t7)
Member
Joined: 4 years ago
Posts: 24
Topic starter  

Hello

I could imagine that data from the INA219 as shown on an OLED display could be sent to the Arduino IoT Cloud with wifi from the ESP 8266 Wemos Di mini, but I don't know how to do it??

Thanks


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2571
 

@henrik_t7

How about this as a starting point ?

https://siytek.com/wemos-d1-mini-arduino-wifi/

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
Inq
 Inq
(@inq)
Member
Joined: 3 years ago
Posts: 1904
 

@henrik_t7

Per @will, @inst-tech, @zander just pumping out to a CSV file on an SD card transferring to an Excel / Sheets spread sheet would be the simplest.  Since you're using the WeMos D1 Mini, they make hats for those:

"amazon.com/WEMOS-Mini-Micro-SD-Card-Shield/dp/B09TY9FRSM"

If you want to do the Arduino IoT Cloud, you can use Bill's tutorial.  I haven't viewed it, but I see it has an ESP32 version that should be almost identical on an ESP8266 - https://forum.dronebotworkshop.com/2021/arduino-iot-cloud-2021-getting-started-with-arduino-esp32/

You can directly write to say a database on a computer on your network, but that gets way more involved if you don't already have familiarity with databases, like Sybase, MS SQL Server, MySQL etc.  If you're already savvy with those, you could even set up MySQL on a Raspberry Pi.  Even an old Raspberry Pi Zero (that used to be a $5 computer) could easily support any real load you'd be putting on it with this project.  Here is an interesting link along these lines

https://randomnerdtutorials.com/esp32-esp8266-mysql-database-php/

3 lines of code = InqPortal = Complete IoT, App, Web Server w/ GUI Admin Client, WiFi Manager, Drag & Drop File Manager, OTA, Performance Metrics, Web Socket Comms, Easy App API, All running on ESP8266...
Even usable on ESP-01S - Quickest Start Guide


   
ReplyQuote
Inq
 Inq
(@inq)
Member
Joined: 3 years ago
Posts: 1904
 

@henrik_t7

That last link is if you have a website of your own and you want to add the database on the cloud.  This article shows how to set up a Raspberry Pi with the same server software so you can have your own resident web/database server.

https://randomnerdtutorials.com/raspberry-pi-apache-mysql-php-lamp-server/

3 lines of code = InqPortal = Complete IoT, App, Web Server w/ GUI Admin Client, WiFi Manager, Drag & Drop File Manager, OTA, Performance Metrics, Web Socket Comms, Easy App API, All running on ESP8266...
Even usable on ESP-01S - Quickest Start Guide


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 4 years ago
Posts: 7660
 

@henrik_t7 Do you have an Arduino cloud account? I will caution you, however, it's very different coding but if you have a few years of regular programing it's not too hard. As always find an example that is close to what you want and modify it to do what you want.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 4 years ago
Posts: 7660
 

@will I think he is using the IoT cloud, so there is no need to 'use' WiFi directly, it's built in.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote