KiCAD – Creating a custom component with the same name as an existing component

Short Answer – change the name to be unique!

Long Answer – I was creating my own version of the 74HC595 shift register in KiCad and named it exactly that. When adding it to my own library, and using it in my schema, it kept showing me the stock version. So the fix to this was to right-click on the name in the component editor and change it to something else – “MY74HC595” and save. Hey presto! Problem solved ๐Ÿ™‚

Android and Arduino Serial Bluetooth App – BlueSerial

I’ve finally been able to figure out the entire Bluetooth API of Android and I felt it was more difficult than writing Arduino code in Assembly. In it’s current avatar, I think it’s ready for a Beta release. Based on the feedback I receive, I’ll make a few changes and release the code and put it on the Android Play Store (for which I still need to register a developer account).

A quick how-to about the app – The app can be used to communicate with serial (RX-TX/UART) bluetooth devices. This largely includes devices that are used to control microcontrollers and other electronic projects which use bluetooth to send and receive information. I developed this app to use with a bluetooth enabled robot that I had been dying to build for quite some time now. I think it’s pretty self-explanatory and if it’s not, then I need to work a bit more on it. Continue reading

Check if Binary tree is balanced or not

A quick interview exercise is to write code that checks whether a binary tree is balanced or not. Since a binary tree just begs for recursion, I decided to try it out in Scala. Takes less number of lines than I thought it would and it works. Logic works like this:

  1. If left node and right node are empty, tree is balanced
  2. If neither node is empty, just check that both left and right nodes are balanced
  3. If left node is empty, then right node can go down at most one more level
  4. If right node is empty, then left node can go down at most one more level

Hereโ€™s the code for it:

class Tree(val left: Tree, val right: Tree)

def isBalanced(tree: Tree): Boolean = {
  if (tree.left == null && tree.right == null)
    true
  else if (tree.left != null && tree.right != null) {
    isBalanced(tree.left) && isBalanced(tree.right)
  } else if (tree.left != null && tree.right == null) {
    tree.left.left == null && tree.left.right == null
  } else {
    tree.right.left == null && tree.right.right == null
  }

}   

 

How to kill a vbscript running the sendkeys command

It is nearly impossible to stop a wild VBScript running amuck with the sendkeys command on windows. To be sure you can always attempt to open windows taskbar and try to kill the process, if you know its name and if the script gives you enough time to open the taskbar and kill it. But in my experience its impossible to do that without creating a whole mess with sendkeys and sometimes, the only way out is to quickly open or switch to a text editor and wait patiently until it ends.

Scripts that I run frequently, I usually put them in my Quick launch bar so I can kick them off without having to switch windows. The AppActivate() command activates the right window for the script to work on. AppActivate unfortunately doesn’t restore windows if they are minimized. You might have realised this the hard way, as did I, when minimizing all windows and trying to trigger the script from the desktop.

Since VBScript doesn’t provide it’s own way to kill runaway sendkeys commands, it’s up to us to stop it. Every script that I write looks for a file called ‘stopscript.txt’ on the desktop, once every few times the sendkeys is called. If the file exists, it stops and no more sendkeying after that. To create that file, I’ve written another script whose only job is to create an empty file called ‘stopscript.txt’ on the desktop if it doesn’t exist. This script is also placed in my quick launch so it can be started quite easily. So whenever a sendkeys script starts behaving weird, I just start this script and the other one terminates instantly. I’ve found this technique to be a lifesaver in many situations. However, it does require that you be careful and call the file checking function at the right places when developing your script.

Also, always have an empty notepad window open when working with sendkeys. If it goes amuck, you can capture most of the bad commands by bringing the notepad window into focus. This is just another precaution :). Also, you can have your main script delete the stopscript.txt file at the very beginning so that you don’t have to manually switch to the desktop and delete it yourself. To stop it again, click on the stopping script.

VBScript is by no means a great solution for sendkeys automation. There are several professional tools available which can achieve the same. But VBScript comes for free on a windows machine. And when working with clients, sometimes you’re not allowed to install anything on the system and that’s when VBScript comes in handy as the poor man’s automation tool!

Links:

Checking if a file exists and creating it in VBScript

LED Sequencing using Arduino Uno

I’ve recently taken an interest in Hobby Electronics after reading a lot about Arduino. Being a software guy, I’ve always had difficulty getting my head around practical electronics. But after searching a bit around, I came across these two lecture series on Youtube:

Jeremy Blum’s Arduino tutorials

Prof. T S Natarajan’s Basic Electronics tutorials

And bit-by-bit I’m able to make sense of electronics.

Anyways, the best part of Arduino is that is very programmer friendly. Easier to program all this stuff than to do it using hardware components. Here’s a video of LED Sequencing using Arduino Uno. It consists of 12 LEDs connected to 1K/220 Ohm resistors to pins 1-12 on the Arduino. Setting up the breadboard and connections is very straightforward.

You can download the Arduino source code from here:ย View/Download code for LED Sequencing

Load in and Animate content with JQuery

I found out how to load and animate content using this excellent tutorial from tutsplus.com. But I wanted to take it one step further and also show the currently active link highlighted in the menu bar which took a bit of effort.

The full working sample can be downloaded from here.

Here’s the final version of the javascript:

$(document).ready(function(){

var hash = window.location.hash.substr(1);
var href = $(‘#nav li a’).each(function(){
var href = $(this).attr(‘href’);
if(hash==href.substr(0,href.length-5)){
var toLoad = hash+’.html #content’;
$(‘#content’).load(toLoad)
}
});

$(“.nav li a”).click(function(e){

var toLoad = $(this).attr(‘href’)+’ #content’;

var clickedMenuItem = $(this);//Store whatever you clicked over here

var currentMenuItem = $(this);//This is where you’ll store whatever is currently selected (in the next step)

$(“.nav li a”).each(function(){
if($(this).hasClass(“active”)){
currentMenuItem = $(this);//If it is active then set that to the currentMenuItem
return false;//Break out of the each() loop (http://gavinroy.com/jquery-tip-how-to-break-out-of-each)
}
return true;//Just to get rid of the warning “Function doesn’t always return a value”
});
e.preventDefault();
//Change animations to slideUp and slideDown to get the sliding animation
$(“#content”).fadeOut(‘slow’,function(){
$(“#content”).load(toLoad, function(){
$(“#content”).fadeIn(‘slow’);
});
});

window.location.hash = $(this).attr(‘href’).substr(0,$(this).attr(‘href’).length-5);
currentMenuItem.removeClass(“active”);//First remove and then add in case the same link is clicked
clickedMenuItem.addClass(“active”);

});

});