Tuesday 30 December 2014

Do it Yourself Power-Bank Part-2


This is the 2nd Part of the DIY Powerbank Tutorial. Link to the first part is here

So far we have covered the basic working principle of the Powerbank. List of Parts required and description of some parts.

Now we will work on the part called "Control circuit". This will work as the Brain of the Powerbank. Let me just give you a brief idea of the functions the control circuit will deal with.

  • It will show you the battery level of the Powerbank.
  • Provide a soft turn-on and turn-off mechanism. It is necessary to turn-off the device when not in use otherwise a lot of power will be wasted by the boost converter.
  • Provide indication of charging while the powerbank is charging.
  • Turn-off the boost converter when the internal battery is very low, otherwise the powerbank battery will be so depleted that it can't be charged anymore.
Well to say precisely it is control circuit that can be used for any battery operated device. Because any device that operates on rechargeable batteries requires those above mentioned functions to be carried out by some circuit.


So in the picture the control circuit in the center is shown, on the right is Step-up/boost converter and below it is the Usb socket mounted on a DOT-PCB.

You can see that the circuit is not clean because while designing the circuit i selected a component which was not available in the market and realised the mistake after fabricating the circuit. So i had to fork my way around by cutting traces and using jumpers.

But now i have corrected that error and redesigned the circuit completely. So that anyone can easily fabricate it.

The major components in this circuit are ATTINY45 microcontroller, 74HCT595 shift-register, and BSO119N03S a N-channel Power E-MOSFET, which drops minimum voltage and has very low leakage.

Below is the schematic of the Control circuit.

 However you can download the schematic and board layout files designed in EAGLE from https://github.com/neutronstriker/Powerbank_EC.

And this is the layout

This version is little different than what mine looks like because my actually prototype had some problems. 

Mind that the above image is not according to scale so just download Powerbank_EC.pdf and print in on paper without any scaling then you will get the correct size, or you could download the whole repository from link above and download the eagle files and print them.



After you have fabricated the board you can solder the components on to it by taking help from the above image.

Now the Working:

So i will just briefly explain the working of the circuit. 

The attiny45 is loaded with a program which continuously monitors the battery level of the Powerbank using ADC and Voltage divider configuration. When it falls below the programmed minimum value it will display warning, but when battery falls below reserve threshold the Control Circuit turns of the powerbank automatically.

While the device is off the attiny45 is in powerdown(sleep) mode and boost converter is off because of the MOSFET. 

The switch is connected to INT0 and when the powerbank is off and we press the switch for 3 seconds then it turns on. If i press the switch for 3 seconds when the device is ON it turns off.

When the device is ON and if press the switch for only 1 second then it displays battery level.

The charging socket is connected to PCINT0 and when external charger is connected the Powerbank starts charging and the battery animation is shown.

In this circuit 6 leds are connected to a 74hc595 shift-register which takes input from Attiny45 to drive the leds. But data is sent to 74HC595 using only 1 pin instead of 3 requied(SH_CP, ST_CP, DATA) it has been possible because i am using a modified version of Shift1 technique. You should read more about shift1 it is really very useful tool to multiplex your output pins when you have less number of IO pins.

Even if you don't understand the working now don't worry you can understand it clearly if you read the whole program source code. I have explained the working of the code and its relation and effect on the circuit in the code itself.

So below is the code just read through it and you will be able to understand how it works as i have explained what the code does where ever required.


https://github.com/neutronstriker/Powerbank_TINY  is the link to the source and hex files. It was written using AVR Studio 4 and Winavr. 

Note that in the fusebit settings of ATTINY45, the clock was set to internal 8Mhz RC oscillator, brown out(BOD) was disabled, CKDIV was UNPROGRAMMED and SUT was set to default.

Thats it for now in the next part will be final assembly and demo of its working.

Click here to goto Part-3 of this project.
neutronstriker An Electronics and Tech Enthusiast

I am a Tech enthusiast who loves to build stuff like new gadgets and tinker around with electronic devices doing some DIY stuff, writing some code and in the process providing something back to the community.

Do it Yourself Power-Bank Part-1


Almost everyone nowadays owns a smart-phone. Obviously the merits of having a small computer(smart-phone) in your pocket is not necessary to explain.

But as we know every coin has two sides, this heavy computation power, packed with awe features like stunning graphics, high-speed data connectivity and great multimedia abilities require a great sacrifice of battery power. 

So many smart-phone users spend much of their device usage time connected to the wall-outlet charger.

But while on the run when a wall-outlet was not available came to our save our Great Hero :D the Power-Bank.

So nowadays power-banks are a usual gadget for most users and you can usually get a good bargain for quite a decent capacity power-bank in market.

But i wanted to build one on my own, just for fun and also because that technically i had most of the stuff required to build it lying around my workbench.

And this is what mine looks like :



So lets begin....

I will start by listing out first what parts are required and explaining what role do they play in our project on a need to know basis.

The list:
  • A couple of 18650 batteries. 
  • LM2577 Step-Up or Boost converter.
  • A USB-A Type Socket/receptacle.
  • A control Circuit.(We need to build this one).
  • A piece of Dot-PCB or veroboard for Prototyping.
  • Needless to say a soldering iron, and accessories like solder flux and solder wire.
  • Some general DIY tools.
  • And finally the housing, a box in which we will fit our parts and circuits.
The explanation:-

The working principle of our Power-bank is very simple and is shown in the diagram below.





Now the 5v DC supply available via the USB socket can be used to charge your mobile phone using your data cable. Almost all mobile phones require 5v DC input to charge-up but the current required varies from device to device. 

However most mobile phones chargers provide somewhere around 1A and thats our target too.

And when you are not using your power-bank you can charge its internal battery with your usual mobile charger only.

The Battery:

Now lets focus on the voltage part. It obvious that we are going to take power from those batteries i listed above. 18650 as battery size standard. It is the type of battery that most power-banks in the market contain. It is a lithium-ion rechargeable battery and even most laptop battery-packs contain these 18650 cells internally.

!!Caution!!:- DO NOT EVER TRY TO SHORT-CIRCUIT THESE BATTERIES. IT  CAN LEAD TO EXPLOSIONS AND DON'T USE LEAKY OR SWELLED OR FUMING BATTERIES. 

IF BECAUSE OF ANY REASON THE BATTERIES HEAT-UP, REMOVE ALL CONNECTIONS IMMEDIATELY AND DISPOSE THEM OFF PROPERLY.

DON'T PLAY WITH STUFF YOU DON'T KNOW ABOUT. Read usage and safety information about these batteries in the datasheets if the manufacturer provides any or else the generic ones at here or here, before proceeding any further.


These lithium-ion batteries generally have a full charged voltage of 4.2 - 4.3v max at no load. But when you load them it may decrease to about 3.7v to 4v. So lets assume that the moderate working voltage would between 3.3v to 4v.

You can get a variety of these batteries on ebay or other sites of various capacities and brands at various prices. So choosing the right one would be difficult. 

Most batteries come at standard 2600mAH capacity.

Now the more batteries you connect in parallel more is the total capacity of your battery-pack. Suppose you get 4 x 2600mAH batteries and connect them in parallel, then their voltage will stay the same but their charge capacity will add up, so the total capacity will be 10400mAH.

Capacity of battery-pack directly translates to the number of times you can charge your mobile phone battery. Now some people might have a misconception that "my mobile battery is of 2000mAH and 10400/2000 = 5, so i will be able to charge my mobile battery 5 times" . 

NO thats wrong actually.

How many times you can charge your mobile battery depends on many other factors too.

First of all nearly 10-15 % of the battery energy is wasted as heat during conversion from 3.8v to 5v.

Now we provide 5v to the phone but the phone's internal charging circuitry also wastes some 5 to 10% power.

When we say 2600mAH, we mean the total charge of the battery when used from full charge to full depletion. But if you deplete a rechargeable battery completely then you can't charge it any more, because a irreversible chemical reaction will occur in it . So we can use it until the battery voltage stays above 3v.

So that translates to roughly 70-80% of the total battery energy that is directly going into your mobile battery.

You would be surprised to know that many of us could get these batteries from used up old laptop battery-packs, and actually i built mine from used laptop battery only, but there are some quirks related to using cells from a depleted laptop battery-pack.  So i will explain it in the last post of this series.

OKAY now i think we have enough info regarding batteries, lets proceed to the next part in the list. 

Step-Up Converter:

The LM2577 Step-up(boost) converter. It is a DC-DC conversion circuit which takes any DC input voltage between 2.5 to 27 volts and can provide a constant regulated output anywhere between 3v to 30v, provided that the input voltage doesn't exceed the set output voltage.

If the input voltage exceeds adjusted output voltage then output will start directly following input and no conversion or regulation will take place.




To set the output properly first connect the battery at the input pins keeping in mind the correct polarity and then connect a multimeter across the output and keep turning the trim-pot until you get 5.0v on your multimeter.

Just take look at the video below for further clarification..



Once the output is adjusted, the step-up converter tuning part is complete.

Now just take a piece of dot-pcb (prototyping PCB) and mount the USB socket/receptacle on it and solder its legs firmly, then solder the output pads(O+, O-) of the LM2577 step-up circuits to two wires and solder the other ends to USB socket mounted on the PCB.




So now you have setup the output portion of our project successfully.

We will look into building the Control Circuit in the next part of this blog.

Click here to proceed to the next part in this series. 
neutronstriker An Electronics and Tech Enthusiast

I am a Tech enthusiast who loves to build stuff like new gadgets and tinker around with electronic devices doing some DIY stuff, writing some code and in the process providing something back to the community.

Sunday 28 December 2014

AVR 28-pin Development Board with USB support


So i made a development board for the 28-pin AVR micro-controllers like the ATMEGA 8, 168p, 328p etc. some time ago.

I made my design after i found the Metaboard

The metaboard design fascinated me in that it was a AVR development with built-in programmer(i.e. Usbasploader support)  and also we could upload code from Arduino directly and we can also use the USB interface on-board with the V-USB library.




But i had some extra requirements like a 3.3v regulated supply on-board. Also i did not want to sacrifice 2 pins for the USB connection so added a dip switch to disconnect them whenever necessary and some other changes as mentioned below:-

  1. Added an led which was connected to a digital I/O as well as PWM pin.
  2. Added an extra 47uF capacitor close to VCC and GND pins.(Required to compensate ground bounce when driving motors using L293D or any other motor drivers using the same supply that powers the dev board)
  3. Extra regulation filter capacitor added for power supply stability.
  4. Added a 10uH inductor for AVCC as specified by Atmel Docs for cleaner ADC.
  5. And finally as you can notice in the picture above every I/O pin has dual sockets(both male and female, you will understand the advantage only when you face the need).
You can say that my design is a bit overloaded design with whatever i could possibly add of whatever features i required.

Best of all i have tried to keep the PCB still a Single-sided one so that most people can still build it at home using toner-transfer method and common etching techniques.

Here is the layout (Warning! its not to scale, use pdf from github design files link given below)and :


and this is the schematic :


You can get the board design files from here https://github.com/neutronstriker/Metaboard_mine/tree/master. It was made using Eagle Cad software. You are welcome to make any modifications if you like.




neutronstriker An Electronics and Tech Enthusiast

I am a Tech enthusiast who loves to build stuff like new gadgets and tinker around with electronic devices doing some DIY stuff, writing some code and in the process providing something back to the community.

Saturday 6 December 2014

USB Programmer for 93c46 family EEPROMs


I have seen many people have been searching for a At93c46 programmer. Some time ago i built a programmer for one of my friend. So here i am publishing its source and schematic. 

I built the programmer using ATTINY2313 AVR micro-controller. My programmer uses V-USB library to implement a software based USB protocol handler.



If you want the high-resolution PDF format of the schematic here it is.

I have implemented the programmer using the USI module found in the ATTINY. However there where couple of glitches which came up when interfacing with same chip from different manufacturers. Solution for it is provided in the Host Software.

The USI module of Tiny2313 is configured to run as SPI Master mode 0.

The Source code for the programmer can be found at https://github.com/neutronstriker/VUSB_93C46_PROG.

If you want only the at93c46 interfacing library then you will only need at93c46.h and at93c46.c files from the repository.

The companion windows software is at https://github.com/neutronstriker/UBS93CxxProg

Just enter the program name in the console and press Enter it will show all the commands that are valid.


I built the circuit and fit it into a small transparent case. This is what my final design looks like:




Since I designed the programmer circuit on a perfboard(DOT PCB). So i can't provide any board layouts. But you are welcome to make your own designs. Click here to download the schematic in .sch format.

Until now i have only added support for the c46 chip with 1KBit, but in future i may add support for c56, c66 and other members of the family. Meanwhile if any you are interested to add support for other chips, then just grab the source and modify as you like.

If you have any suggestions or question you can post a comment.
neutronstriker An Electronics and Tech Enthusiast

I am a Tech enthusiast who loves to build stuff like new gadgets and tinker around with electronic devices doing some DIY stuff, writing some code and in the process providing something back to the community.

Friday 5 December 2014

Programming and Interfacing the Serial/UART/RS-232 port of a Computer/PC in Windows and Linux Part-2


So here is the linux part of my tutorial on how to interface a serial port. Windows part is here.

To say the truth the programming a serial port is comparatively easier in linux then in windows.

In linux we can open the serial port directly using the terminal emulator. As the terminal emulator has nearly the same settings like a Serial Terminal.

Below is the code for a basic SerialConsole like program which sends any characters typed to the serial port and prints received text in the terminal emulator.



So first we have to override the terminal settings and then apply the settings for the serial port.

You can compile the program directly in linux and run it. Like i wrote above make sure you have proper rights to access the serial port, or better just run the program as root user.

So this is the end of my serial port tutorial.

If you have any questions or suggestions feel free to post a comment.
neutronstriker An Electronics and Tech Enthusiast

I am a Tech enthusiast who loves to build stuff like new gadgets and tinker around with electronic devices doing some DIY stuff, writing some code and in the process providing something back to the community.

Wednesday 3 December 2014

3 wire interface for 16x2 or 8x2 or any other HD44780 based LCDs.


When interfacing with Micro-controllers a LCD display could be a very useful tool either for debugging or displaying messages or to show result of a calculation or some other information.

In embedded World the most popular LCD is a 16x2 display i.e. 16 characters per line and 2 lines on the display. However there are other variants like 8x2 or 20x4 etc. These Displays are run by the very popular lcd controller Hitachi HD44780.



This display controller is the most widely used one and has lot of documentation available on the web. However while interfacing it with micro-controllers one problem arises very often. The scarcity of pins.

The HD44780 operates on a 8bit or 4bit wide bus and requires at-least 2 extra control pins(3 to be exact). So the minimum number of pins required to interface such a display is 6.

So to add a lcd to our micro-controller system we will have to sacrifice at-least 6 pins of our micro-controller. If we are using 40pin ICs like ATMEGA32 or 89C51/89S51 or 40 pin PIC then it is not much of a concern.




But if our chip has about 20 or less than that pins for IO? lets take Arduino UNO for example we have only 14 digital + 6 Analog/Digital pins. Reserving 6 pins for LCD is very tragic.

But what if we could reduce the number of pins required. This can be achieved by a very simple and effective digital logic chip : A Serial in Parallel out shift Register.

So by using a shift register either CD4094 or 74HC595 we can interface the Lcd with the help of only 3 pins.

A serial-in-parallel-out shift-register takes data-in using essentially one pin only(however another pin CLK is required to synchronise the transfer) and it has in general a 8 bit output(i.e. 8 output data pins).




So we send the data using only one pin of the micro-controller and then as usual the 4bit or 8bit data is given to the LCD controller by the Shift-register.

However another pin Strobe is required to enable or disable the output of data on the pins. Because if we keep continuously sending the data and data keeps travelling on the shift-register's output pins continuously then the lcd controller can get mad.

So what we do is we actually hold the outputs until the whole 8 bits are sent into the shift register. Then we release the output pins and data goes into the lcd controller.


But remember since we still need to control the RS(register select) and E(enable) pins of the LCD controller and that is also accomplished by the help of shift-register. 

So what i did was that i connected the RS and EN pins of the LCD to the shift-register output pins and sent the same data or control byte twice; once with EN set(1) and again the same data content and RS value but EN pin value cleared(0).

In this way the EN pin was provided with CLK.

Since i was using 4bit data bus so i had to send 4 nibbles while using Shift-register as opposed to the 2 nibbles when directly connected.

I have made a project to demonstrate this on AVR micro-controller you can get it here. This project also contains an arduino sketch with the same functionality. 

However i have also made a ready made library to to integrate it with your existing programs. Here is the link to the library. You just need to keep two files sipolcd.h and ds.h in the folder of your <main_program>.c file and and before including sipolcd.h  you need to define SIPO_PORT possible values are A,B,C,D or whatever ports your AVR has.

And then SPIN which is the DATA pin of Shift-register, STB i.e. strobe, and CLK is CLOCK.

Let me put an example here.

You can find other keywords in the keywords.txt file in the above mentioned library.

And finally here is the code in action.




We know that to be able to use the LCD with only 3 wires is cool but there are some people who have made it possible to use a lcd with Only 1 wire, That's right only 1 wire is enough. But it is a little tricky and you will have to go a little deeper with R-C time constants and frequencies etc. Here is the link to the Shift1_System.

So as usual guys if you have any suggestions or questions feel free to post a comment.
neutronstriker An Electronics and Tech Enthusiast

I am a Tech enthusiast who loves to build stuff like new gadgets and tinker around with electronic devices doing some DIY stuff, writing some code and in the process providing something back to the community.