#HelloWorld
It’s been a long time since I’ve posted any of my personal projects here so I decided to do a quick update on what I’ve been working on.
#HelloWorld
It’s been a long time since I’ve posted any of my personal projects here so I decided to do a quick update on what I’ve been working on.

I finally received the PCBs for the variable power supply I mentioned in a previous post. After spending part of the weekend soldering and testing the board, it’s finally done! Here are some pictures:
Continue reading
I’m currently working on a project that requires a stand-alone microcontroller as the “brain” of the system. A few weeks ago I designed the PCB and sent it to get manufactured. It finally arrived and I was able to test it. So far everything functions well. Continue reading
Last week I designed a PCB based on the power supply circuit I discussed in the last blog post and I sent it to get manufactured. In the meantime I’ve been testing a resistive current sensor I made, and I also found this board with all kinds of sensors I made a while back for a robot project. It has an accelerometer&gyroscope (MPU6050), a photocell, thermistor and a distance sensor (HC-SR04).
I’m using the Arduino Mega for this project. The accelerometer communicates via I2C and it uses the SDA and SCL pins on the Arduino. Continue reading
Here’s my latest project. I’ve spent the last week researching, prototyping and building a variable power supply to use with my other electronics projects. I just got tired of trying to assemble batteries together to provide enough power for my designs and decided to build a power supply that will give me a wide voltage range and most importantly will allow me to monitor the current drawn by the electronics.
Let’s specify our power supply features:
This will be a long post so I will split the design in several parts:
Let’s get started!
I usually post tutorials using Arduinos but recently I went back to programming 32 bit microcontrollers such as the STM32F100 Discovery Kit. It’s not too different from the Arduino in terms of programming steps. What I mean by that is as with the Arduino you still need to initialize the pins on the board as input or output, digital or analog; there are similar commands for analog/digital read; setting the pin values high or low. The difference is that this board is a bit more sophisticated in terms for options you have and is based on the 32bit ARM Cortex M3 architecture (compared to AVR, 8bit Arduino). However, if you’ve worked with an Arduino and know C/C++, hex and binary then adapting to this platform should not be too difficult. The syntax is a bit different but not too hard to understand. There are a few tutorials to get you started programming with the board. I prefer programming it through the CooCox IDE.
Here are a few sample programs to get you started and familiar with the STM32 Discovery.
The first program is very simple and will turn on/off one of the LEDs on the board using the user push button.
#include "stm32f10x.h"
int main(void)
{
//RCC - Reset and Clock Control
//APB2 - peripheral clock enable register
//Enable GPIOA and GPIOC pins *See 6.3.7 reference manual pg.91
// 0x14 in binary = 00010100 = [0001][0100] = [IOPF IOPE IOPD IOPC IOPB IOPA Res. AFIO]
RCC ->APB2ENR |= 0x10 | 0x04;
//CRH - Port Configuration Register High *pins 8-15
//Set Pin 8 to general purpose output *7.2.2 in reference manual pg. 112
GPIOC ->CRH = 0x01;
//CRL - Port Configuration Register Low *pins 0-7
//*on STM32F100RB User button is connected to PA0
//Set Pin A0 to floating input *7.2.1 in reference manual
GPIOA ->CRL = 0x04; //00000100
//run forever
while (1)
{
//Read the button
//IDR - Input Data Register
//if pin 0 is HIGH
if((GPIOA ->IDR & 0x1) == 1)
{
//set Pin 8 HIGH
//BSRR - Bit Set/Reset
GPIOC ->BSRR = 1<<8;
}else
{
//set Pin 8 LOW (Reset)
GPIOC ->BSRR = 1<<24;
}
}
}
The same result can be accomplished using the gpio.h library
Continue reading
I found an old Nintendo clone controller so I decided to see if I can make it communicate with a PC via bluetooth and emulate keyboard key commands. The setup proved rather difficult since there isn’t much space inside the controller for a battery, bluetooth module, a 3-axis gyro-accelerometer, Arduino Mini Pro, buttons, switch, a DC-DC converter and LOTS! of wires.
Once I had the controller setup, the real challenge was communicating with the computer. First I tried using Processing (processing.org) along with the Java Robot library. It worked well however, many programs/games did not respond to the simulated key strokes. Then I decided to try something I’ve done before, using a PS/2 to USB adapter along with the ps2dev.h library for Arduino. I’ve demonstrated another version of a game controller here: https://sourcelion.wordpress.com/2014/02/24/arduino-game-controller/ . However, in this example the controller was wired. This time, the design is a bit more complicated since it incorporates a bluetooth module and not a direct communication with the computer.
Here’s the result. I’ll add the source files once I’ve cleaned up the code.
As promised, here’s the rest of the code for the battery management system. The BMS now reads the voltage of each battery cell and balances each cell until the battery voltage across all cells is closely matched; +/-0.03V.
I also included a box with a switch and an LCD display. Some extra components are included such as a small trimmer potentiometer to adjust the LCD brightness, DIP switch with 4 contacts, toggle switch to turn power-off and on and a box to store the components.
This is what the new setup looks like:


And here’s the result:
1.This is the starting position of the 4 lithium batteries.

2. Then the batteries begin to discharge.

3. And at the end, the battery voltages are closely matched.

Here’s the new code:
Continue reading
For a while now I’ve been looking into battery management systems as part of the Solar Car club at the university. I started designing a BMS a while back but I ran into problems and I paused the project for a while. Now I’m back at it and I finally have it working. The battery management system (BMS) consists of an LTC6802-2 (http://cds.linear.com/docs/en/datasheet/68022fa.pdf) battery stack monitoring chip. This chip can monitor as well as balance a lithium battery pack consisting of no more than 12 cells. However, the chip registers need to be programmed via a microcontroller. The communication is done via SPI. A digital isolator such as the Si8441AB (https://www.silabs.com/Support%20Documents/TechnicalDocs/si844x.pdf) between the monitoring chip and the microcontroller can also be included for extra protection. Once set-up, the LTC6802-2 chip sends the voltage data to the microcontroller via the SPI interface. The diagram below shows the typical setup for a single monitoring chip connected to a microcontroller. In this case we use the Arduino Uno as the microcontroller. *Visit the Arduino website for more on the SPI interface.
Continue reading
It’s been a while since my last post so I decided to include a tutorial on interfacing the Arduino with Labview. Why? Because it is sometimes useful to see the inputs/outputs to the microcontroller when designing something new. It will give you an idea of what happens inside the Arduino and also give you control over the board via PC without actual C/C++ programming.
Let’s get started!