Thursday, July 6, 2017

Interfacing PS3 controller to HC-05 Bluetooth module

This post will describe how I modified the HC-05 to work in HCI mode to connect to PS3 Controller.
Following steps have to be taken

1)Refer to this link to connect the HC-05 in SPI mode. Using this, it's possible to the change the onboard firmware and change PSKEY's. What I did was flash the HC-05 with RN-42 firmware.

2)Once flashed with RN-42 firmware, put your BT address back and change the following PSKEY's
using the PSTool.exe

  1. PSKEY_VM_DISABLE -> 0x0001
  2. PSKEY_ONCHIP_HCI_CLIENT -> 0x0000
  3. PSKEY_HOST_INTERFACE -> UART H4
  4. PSKEY_UART_BAUDRATE -> Same as USART on the micro
it's better to choose a high baud rate or there's a lag. I used 250,000bps by setting this PSKEY to 0x400. The formula to calculate this is given in the description of that 
PSKEY_UART_BAUDRATE. It's Baud = PSKEY_UART_BAUDRATE * 0.004096

3)Use this library for the code : 
https://github.com/Nero7991/HC-05-PS3-Controller-AVR

Thursday, March 24, 2016

Improve MacBook Pro/Air battery life by limiting battery charge

Maximise your Macbook battery life         

        As many of us know that keeping batteries at full charge level decreases its life. Here is a article from Battery University that you may want to read for great detailed analysis : How to prolong battery life
It's not problem for people that travel often since they need fully charged MacBooks for maximum battery life. But for people like me and/or you who most of the times have their Macbooks plugged in for charging, it may be a problem in long time span. When the battery is charged to a 100%, it's voltage is 4.20v for most charging circuits. When battery is maintained at this voltage for periods of time, it induces voltage related stress which badly affects battery life. That's why turning off charging and only powering the Macbook from AC adapter is the solution for us.
         The charger will only provide the power to keep the Macbook running, it won't charge the Macbook. The Macbook will hence remain at the same charge which will be pre charged at optimum level which is about 65%(60%-70%)

How to do this??

      This is how you do it. Cover the middle pin of the charging connector with tape(make sure it can be removed again) and connect it. 
IMPORTANT: Please take care not to damaged the adjacent four pins. If you are not good with doing delicate things, I recommend you stop here. Author of this article won't be responsible for any kind of damage that you may cause.


You'll see that the battery isn't charging anymore. The middle pin is responsible for sending the charger information and turning the LED on. The LED doesn't come ON when it's connected in this way. Since, the Macbook doesn't receive any charger info, it prevents the charger from charging the battery.




 It's more preferable for you to do this if you have a extra MagSafe Adapter, not when you have a single MagSafe Adapter. You can use one for just powering the Macbook when you are at home and the other one for powering as well as charging. The optimum charge level for longer use whilst connected to charger is 60-70%.       
1)  First charge the Macbook to 70% using the normal charger
2)  Connect it to the modified charger when using for longer periods.

Use your Macbook with maximised battery life!!!

How to check MacBook Pro/Air battery voltage

Checking Macbook Battery voltage

        Some people who are interested in electronics and battery statistics may be curious of knowing the voltage of their macbook battery. OS X has built in report where you can find all sorts of hardware information.

    Here's how to check your battery voltage

1) Go to the icon in the top right corner

2)Tap About this Mac

 3)System Report


4) Select Power 

            Here you'll find voltage and Amperage listed. The voltage is listed in millivolt
In my case, it is 11779mV, which is 11.779V

Monday, August 24, 2015

How to Program/burn/flash a AVR microcontroller(Step by step tutorial)

Here we go.....
Things required
  1. Atmel AVR Studio
  2. USBasp(Its about 230Rs in India (2$ in US i think)[Search for "usbasp" on ebay if you don't have one]
  3. AVR Burn-O-Mat(This requires Java)
  4. WinAVR
  5. And of course,the micro to be programmed!
Step 1:
   
    Download and install the Atmel AVR Studio


    I had already installed it so.....this showed up


I won't bother uninstalling and reinstalling. I assume everyone is familiar with installing windows program(even a baby can do it,its that simple). The installation takes a few minutes so be patient.


Step 2:

          Once you've finished installing AVR Studio. The next thing to do is to download and install 
WinAVR. I haven't installed it yet so I'll be able to show you the process!




  Install the program by clicking Next,I Agree and Install



 After the installation completes,click Finish to exit installer.

Step 3:

          Download and install AVR Burn-O-Mat






         Tick "Launch AVR Burn-O-Mat" and click "Finish". If the program launches,it means you already have Java installed(You can skip the Java installation). Others will the get the following message that I get since we don't have Java installed.


 Press OK. Download and install  Java.






         Run the file.



Let the download complete.


  UNTICK the sqaure box.


Click next and the installation begins.


  This completes step 2.

Step 3:

          Buy a USBasb programmer(It's really inexpensive considering the price of Arduino boards)
 Connect it to the computer. Now we'll have to install the driver for it. Download the drivers from here.
This is how to install them...



 Extract the zip file


 Go to My Computer(Windows XP/Vista/7)/This PC(Windows 8.1/10)


Right Click and Properties



  Go to Device Manager


In Other Devices > USBasp
 Right Click and select Update Driver Software


 Select Browse my computer for driver software


Enter the extracted folder path.



 Click Install this driver software anyway.



 You're done with configuring of USBasp. Yay!!

Step 4: Configuring AVR Burn-O-Mat

Go to C Drive and rename "WinAVR-20100110" to "WinAVR".




  Next run AVR Burn-O-Mat.




Select USBasb from the list,apply and ok and you're done with configuring everything. Now you can program a AVR micro.

Step 5: Finally connecting the micro and writing a blinking LED program


Follows the diagram for the connections.
After doing the connections on a breadboard this is how it looks



 OK. Now the connections are done
Now lets write the program.
Start AVR Studio.


 

 And this come up. Allow internet access to AVR Studio by ticking both the boxes.



Click New Project and it will start making the Project file.



You can either make a C/C++ or Assembler Project. Here I'm going with Assembler.
Give the project any name you like. In my case, I named it "Firstone".


Select the micro that you are programming in my case Atmega8.


This is assembly code to blink a LED at 1.9 Hz(You'll have to read the device datasheet to understand the code) The Assembly language is micro dependent. So the above code cannot be used with micro other than Atmega8.

Here's the C code with is micro independent(not in all cases though). Since I'm using the internal timer2 to generate the blinking, this C code will only work with micros that have timer2.


Next, After writing the code,Build it by pressing F7


If there were no syntax error,it'll build successfully.


Start AVR Burn-O-Mat 
Tell the location of hex file
It's stored in the Documents folder.
In Documents>Atmel Studio>6.2 Here you'll find your project folder.


This is final button. Before you press it check if all connections are proper. And the circuit is connected to USB.
Press the write button!!!!
If the led starts blinking you were succcessful 
Congratulations!!!
If not, you must have made some connection error. Refer the tutorial and try again!!
Hope you succeed.


Here's the video showing the blinking LED!!. Didn't work first time though. Missed a instruction
This one
ser r18
out ocr2,r18
But worked after including that. Yay!!!