Upgrade: Solar-USB-Charger

Introduction

During the last weeks I upgraded my solar-usb-charger system. Here you can find the original design: /bau-dir-ein-apple-solar-ladegerat/ (german article).

What the old design basically did was converting the 12V DC from the solar powered battery system to USB friendly 5V DC.

New Features

I added a couple of features: -OLED-I2C-display (from wide.hk) -Arduino Nano -current sense amplifier board (more information about this board can be found here) -3d printed case for the OLED display (link below)

Wiring

Wiring all boards together is fairly simple:

OLED-I2C-display is connected to the I2C (SDA and SCL) and voltage pins (5V and GND) of the Arduino Nano. The current sense amplifier board output pin is connected to the ADC1 pin of the Arduino Nano. The boards input and load pin are placed into the voltage supply cabling from the solar battery to the DC/DC converter.

There is also a voltage devider connected to the solar battery (input) and the Arduinos ADC0 pin (output of the voltage devider).

A switch connects the 5V power supply from the DC/DC converter to the Arduino 5V pin.

Software

The Arduino measures two voltages with it’s ADC, the first one is the solar battery voltage (nominal 12V DC) and the second voltage comes from the current sense amplifier. It represents the current flowing into the DC/DC converter (12V to 5V). After measuring both voltages, they are used to calculate the solar battery voltage and the current. Both values are then displayed on the OLED display.

//==========================================================//
//-------------------------WWW.WIDE.HK----------------------//
//-----i2c OLED example-------------------------------------//
//-----Function : show 128x64 Graphic , Word and animation--//
//-----SCL = A5  ,  SDA = A4 , VCC = 3.3V-5V , GND----------//

#include //---------------FONT + GRAPHIC-----------------------------// #include //==========================================================//

#define OLED_address 0x3c

unsigned char fill_OLED=0x55; char oledString1[]="Spannung:"; char oledString2[]="Strom:";

extern unsigned char myFont[][8]; extern unsigned char logo[]; extern unsigned char ip[];

char charBuf[50];

int ADCpin0 = A0; // ADC0 for voltage measurement int ADCpin1 = A1; // ADC1 for current shunt measurement (via TS1100)

long voltage = 0; long current = 0;

//==========================================================// void print_a_char(unsigned char ascii=0) { unsigned char i=0; for(i=0;i<8;i++) { SendChar(myFont[ascii-0x20][i]); } }

//==========================================================// void setup() {

Wire.begin(); init_OLED(); delay(10); clear_display(); delay(50);

sendcommand(0x20); //Set Memory Addressing Mode sendcommand(0x02); //Set Memory Addressing Mode ab Page addressing mode(RESET) sendcommand(0xa6); //Set Normal Display (default)

setXY(2,0); sendStr(oledString1);

setXY(4,0); sendStr(oledString2);

}

//==========================================================// void loop() {

//get ADC values voltage = analogRead(ADCpin0);//*5000/1024; current = analogRead(ADCpin1);//*5000/1024;

//calc voltage: get the "real" ADC-input voltage and multiply by the gain of the voltage devider (1/4) voltage = voltage*5000; voltage = voltage/1024; voltage = voltage*4;

//calc current: Vout=2V equals 1A current = current*5000; current = current/1024; current = current/2;

String stringVoltage; stringVoltage += voltage; stringVoltage += "mV "; stringVoltage.toCharArray(charBuf, 50);

setXY(3,1); sendStr(charBuf);

String stringCurrent; stringCurrent += current; stringCurrent += "mA "; stringCurrent.toCharArray(charBuf, 50);

setXY(5,1); sendStr(charBuf);

delay(1000); }

//==========================================================// void sendcommand(char com) { Wire.beginTransmission(OLED_address); //begin transmitting Wire.write(0x80); //command mode Wire.write(com); Wire.endTransmission(); // stop transmitting }

//==========================================================// void clear_display(void) { unsigned char i,k; for(k=0;k<8;k++) { setXY(k,0); { for(i=0;i<128;i++) //clear all COL { SendChar(0); //clear all COL //delay(10); } } } }

//==========================================================// void SendChar(char data) { Wire.beginTransmission(OLED_address); // begin transmitting Wire.write(0x40);//data mode Wire.write(data); Wire.endTransmission(); // stop transmitting }

//==========================================================// void setXY(unsigned char row,unsigned char col) { sendcommand(0xb0+row); //set page address sendcommand(0x00+(8*col&0x0f)); //set low col address sendcommand(0x10+((8*col>>4)&0x0f)); //set high col address }

//==========================================================// void sendStr(char *string) { unsigned char i=0; //setXY(0,0); while(*string) { for(i=0;i<8;i++) { SendChar(myFont[*string-0x20][i]);

// SendChar(*string); delay(10); } *string++; } }

//==========================================================// void init_OLED(void) {

sendcommand(0xae); //display off delay(50); //-----------------------------REVERSE comments-----------------------------// // sendcommand(0xa0); //seg re-map 0->127(default) // sendcommand(0xa1); //seg re-map 127->0 // sendcommand(0xc8); // delay(1000); //-----------------------------REVERSE comments-----------------------------//

sendcommand(0xaf); //display on delay(50);

}

Mechanics

The 3D part for the OLED display can be found here:

https://www.tinkercad.com/things/gpoEs7xHyvj-oled-display-case

After printing the part, I glued the switch and the oled display into the part with silicone glue.

In operation

September 19, 2012
basteln gebasteltes schaltungen/ics technik 3d printed part 3d printer current sense amplifier current shunt monitor oled solar apple charger usb