umkk.eu

you can also go there !

Stepper motor controller

Hi, in this post i will explain the stepper motor controller, the "smart" part of the driver also called ROAR HB brain module.

There are a few things that should be noted here, this is not just a simple stepper controller it's a smart controller which can be easily updated and changed.

Some advantages of the driver :

  • more drive modes selectable by jumpers or program (normal, half step,  high torque)
  • power saving mode
  • ability to add temperature sensors, limit sensors to protect the machine

The driver is built around a pic16f84 microcontroller, basically the circuit is a tension stabilizer, an oscillator for the pic microcontroller, some components to set pin B0 as interrupt and all the ports pins are connected to pins so they can be easily connected.

WARNING: to create this you will need to program the pic microcontroller, and for that you need a programmer, you can see how to build one on this blog, here : pic 16f84 jdm programmer

Here is a picture with the final product :

stepper driver front view

stepper driver front view

stepper driver back view

stepper driver back view

2 controllers in an 2 axis driver

2 controllers in an 2 axis driver

For the pcb design i used the eagle software (great software) to create first a schematic then the board and then the print files,

here is the schematic :

Stepper controller schematic

Stepper controller schematic

The huge advantage for this is that you have all the port pins connected to pins, and all of them except the pin b0 (which is made to be kept low or high) can be used for anything.

In this case we have pins bo - tact, pin b1 - direction, pins b2- b5 as phases selection.

And now here are the designs for this schematic :

bottom view

bottom view

top view

top view

And here is the file ready to be printed, this file is at the actual dimensions :

stepper controller print

stepper controller print

In the above image the top layer is already mirrored so all you have to do is print it and follow the instructions from this post : How to create PCB’s using toner transfer method

All you have to do now is to program the pic, here is the compiled version : Compiled program

The program is compiled using ccs compiler, if you are interested here is the  source code : source code

And this is is.... have fun.

Mood light

I wanted to build this for o long time... and today I finally had the "mood" and the time to do it... it's a mood light created with a tricolor led and a laptop with a parallel port.
I did this to see what is required to create a mood light, because the plan is to create one with a pic microcontroller and use it as a digital candle.
Here is the youtube movie with it :

As you can see I created a paper cube and inserted the led into it to have a diffuse light, or else the 3 basic colors  will appear as 3 red circles, and we don't want that.

Here are some pictures too :

Mood light

Mood light

the paper cube inside which the led is inserted

the paper cube inside which the led is inserted

the rgb led

the rgb led

And if you are interested in building the paper cube here is the plan (print on an A4 sheet of paper) :

Paper cube

Paper cube

If you are interested here is some theory :

Each color is build using 3 base colors : red, green and blue, the led has 4 pins, a comon one and one for each color, so you can individualy turn on and off each color, so we will use 4 pins from the paralel port.

In my program (which is not yet optimized) each component (rgb) can have a value between 0 and 255, to do this we have a huge while cycle where we show the colors, here is a diagram to make it easier.

Diagram

Diagram

So from diagram is pretty clear, based on each color value we show that color an amount of time, as bigger the value, more the time and brighter the color, a resolution of 255 values for each color is more then enough for this case.

There are more things in the program, for example you can increase or decrease the value for each color using the keyboard to see how diferent colors look like.

Also from the setR, setG, setB functions you can customize what to do for each color, in case you use diferent pins i used pin0: red, pin1:common, pin2: blue, pin3: green, feel free to use any other combination but remember to change those functions.

Any questions are welcome.

How to create PCB’s using toner transfer method

The PCB or printed circuit board is easier to make than you think, even professionally looking ones, on this short tutorial i will explain how to create very nice pcbs starting from a schematic. Each step will be described in details and I also made lots of pictures to document the process and make it easier to understand.

Tools you will use (this is what i used)

  • soldering gun or iron
  • a laser printer
  • old magazine
  • some tape
  • needles (around 10)
  • permanent marker
  • multimeter (or something to check for short circuits)
  • a cutter
  • drilling machine (or a motor) and 1mm drill, if you don't have a drilling machine find a way to attach the drill to the motor axis and drill some 1mm holes.

In this tutorial I used the schematics and the pcb design of the ROAR MPP brain module, but all the other images are from the ROAR HB power module, i hope that this is not confusing for you.  Unfortunate when i created the power module (the h bridge) i created the board directly without creating a schematic first... my mistake, so now I only have the board for that no schematic, the schematic is only on paper.

The steps you will need to complete until the competition of the pcb are.

1.  Install eagle if  you don't already have it.

2. Create you schematics using the circuit design mode in eagle, after that is completed you should have something like this :

3. still using eagle convert this schematic to board, the easiest way to do this is to click the "board" button, that is the 5th button in the top, next to print and cam buttons. Eagle will just put your components there, but now you can drag them around to place them however you want them on the board, I ended with something like this :

board design

board design

After you have the board and the pcb design (routed) you have to print separately the 2 faces of the design. You can do this very easy, using the layers option of eagle, so you should export both sides and print them, you should have something like this :

ROAR HB power module front

ROAR HB power module front

ROAR HB power module bottom

ROAR HB power module bottom

WARNING : those images are just representative do not use them in any board, if you want the board for the ROAR HB power module go to the specific post.

4. Print those images on a pice of magazine, it has to be thin glossy paper, you can also process the images first in some program to make them black, so the maximum of toner will be used, also if your printer has some tonner saving settings disable them, before printing remember to mirror the back image. After you print them, cut the excess of paper aout leaving a margin of about 5mm.

Printed circuit board

Printed circuit board

5. Now cut a pice of the board to match the biggest of the 2 prints, also leave a margin of about 2 mm on each side, we leave all those margins to make sure that both of the prints will fit on the board after we align the holes.

bread board, getting the size

bread board, getting the size

6. After you cut the board to the required size, clean it very well first with acetone and alcohol and then i used some special material used to cleat cooper pipes, this works perfectly and makes the board very clean and shiny, this is important because the toner will stick much better to the board.

the cleaned board

the cleaned board

7. Now secure on of the prints (the one with the most lines on it) on the board using some tape

the print secured

the print secured

8. Now with the iron on the highest setting press the paper on the board for a few seconds (around 30), just press it do not move it, after this interval you can move the iron on all directions to make sure that all the surface is covered very well and the paper is sticking to the board, pres and iron it until you see that the paper is starting to get a yellow, brown color, this means that is starting to get burned.

ironing the paper

ironing the paper

ready paper

ready paper

9. Put the board in war water, be very care full the board is extremely hot you can get burned very very easy because cooper is a very good head conducting material.

move the hot board

move the hot board

board is soaking

board is soaking

10. Let it soak for about 30 minutes, or as much is necessary to get all the paper soaked, you can also boil the water if you want to hurry up the process. After that try to see how easy the paper is coming of, you can remove the pices that are coming off easy

paper coming of

paper coming of

11. Repeat the process, soak->remove paper, until all the paper is off

all paper is removed

all paper is removed

12. Now using something with a sharp end, remove all excess paper, make sure that there is no paper left where is no toner, make sure that there are no connections made between routes, because if you leave any will be harder to correct after this.

cleaning execess paper

cleaning execess paper

13. Cover the other end of the board with some plastic tape (insulating tape used in electric installations is perfect, leave about 2-3 mm excess of tape on each side

back covered with tape

back covered with tape

14. Enter the board in corrosive solution

board in solution

board in solution

15. You can agitate the solution once in a while, and check regularly if the excess cooper has gone away.

checking if the board is ok

checking if the board is ok

16 . Get the board out and clean it really well with water, lots of water, because the solution is highly corrosive and can damage your pipes, after that remove the tape from the back.

cleaning the pcb

cleaning the pcb

removing the tape

removing the tape

17. Now, you have to check again to see if there are any mistakes from the original print, check if there is any cooper left where should not be, and clean it wit something, this may be harder but needs to be done :

celaning excess cooper

cleaning excess cooper

18. We drill some holes on the board, this holes will be used to insert the components, but at this point we need them to align the 2 faces of the board. To make drilling easier we mark the point with something with a rounded tip, just give it 2 hits with a light hammer.

marking the holes

marking the holes

19. We align the second face based on the holes :

align faces

align faces

20. repeat steps 8 to 17 for the second face, and be care full not to miss one because you board can be compromised.

Stepper motor inteligent driver and controller

Now, i'm sure that each one of you has some stepper motors laying around and wanted to test them at a given time but never had the time to build a driver or to buy one. I had the same problem until i decided that is the time to build that cnc machine that am dreaming about, for this i will need at least 3 stepper motors and of course 3 drivers... or one for 3 motors.
I decided to build a separate driver for each axis, will be easier to change if something goes wrong and will be more flexible.

The driver is composed from 2 parts, 2 separates modules the power module (ROAR HB power module)  which contains the H bridges and the control module (ROAR MPP brain module) which will send signals to the power module.

The power module is pretty straight forward, will need 4 input pins, 4 output pins, and in pins for logic supply and power supply. As i was going to use the driver maybe in future robots also i decided to put some leds on the board 2 red led for each supply and 1 led for each input pin, so a total of 6 leds, i also added some pins for the cooling fan for the h bridge as the motor can suck a lot of power the bridge gets pretty hot.

Here is the full driver (the power module and the brain module, and a cooling fan)

full driver

full driver

Here is my final version of the power module a.k.a ROAR HB power module

ROAR HB power module

ROAR HB power module

The huge advantage of this module is that it can use on a multitude of circuits all inputs and outputs are connected to pins. This can also be used to control a robot with 2 motors (control speed and direction for each one).  All the plans and logic you need to build it is available on this web page, if you don't have the time, the mood or the tools to build it, you can post a comment and i'll build one for you on a very good price... 25$ let's say.

The construction pf the power module can be seen in detail on a diferent post. (i'm working on it right now)

Here is the components list for the ROAR HB power module :

  • 1 * L298N (dual full h bridge)
  • 6 * 1k resistor
  • 12 * 1N5819 (fast diode, you can use any fast diode that can handle 30V/1A)
  • 2 * red leds
  • 4 * green leds
  • 19 * pins
  • 2 * jumpers

And finally here is the ROAR MPP brain module :

the driver brain module

the driver ROAR MPP brain module

This module is also very usefull in lots of application because it's fully customizable, on this board is everything the pic needs to run, the pin B0 seted to be used as an interrupt... and a power led.

jQuery popups wizard, web 2.0 ideea and usability

in this post, which i'll try to keep it short i'll explain something about web 2.0 concept and how to make pop ups wizards with jQuery, by popup wizards i understand a series a popup, pretty much like the wizards on your desktop when you install an application.

Web 2.0 is more about user experience and seeing the web as a platform, make the user feel like he is using a very complex, fast and easy to use at the same time application, and for that wizards are great.

In this tutorial i will explain the basic concepts and give an basic wizard example for user authentication and sign up, here is how i wanted the wizard to work :

Wizard steps

Wizard steps

this wizard will only have 3 pop ups, here they are, to be more clear :

Wizard starts

Wizard starts

Login popup on wizard

Login popup on wizard

Create account in wizard

Create account in wizard

As you can see each popup is clear and you can navigate back and forward between them.

Now, some of the advantages of using those wizards :

  • no extra html is loaded when the page loads, all popups are loaded dinamicaly
  • no extra load on browser to create all the popups at load time
  • all have the same style
  • they are very easy to open (just call a function with the popup name)
  • they are stored in a xml file and very easy to change
  • they are very user frendly
  • popups are destroyed on close so no extra load on browser

There are also a lot o feature that i want to implement but they are missing...

So here how it's done in a few easy steps

1. make sure that you added jquery, and jqueryUI with the dialog functionality

2. create a custom jQuery theme, just in case you want to change the design at a later date.

3. create the function that loads and shows a popup, here is the entire file. Just make sure that you change the APP_URL in the file with the url to your project.

4. Create the php file which will send the data to the client (in my case that file is index.php) also you can send more parameters to that if you want only name is mandatory in my case, the name must be the same as the .xml file in which the popup is stored (i'll show the xml file later). Here is the php code which wil generate the data for the javascript part, this is json data :

 
$content = file_get_contents ("popups/".$_POST['name'].".xml");
			$xml =  new SimpleXMLElement($content);
			$res = array();
 
			$res['count'] = $vars['count'];
			$res['title'] = (string)$xml->title;
 
			$res['content'] = (string)$xml->body[0];
			$res['content'] = str_replace("{[","<",$res['content']);
			$res['content'] = str_replace("]}",">",$res['content']);
 
			$res['buttons'] = array();
			foreach($xml->buttons->button as $button)
			{
				$res['buttons'][]=array("label"=>trim((string)$button->label),"action"=>trim((string)$button->action));
			}
 
			die(json_encode($res));
 

As you can see here the xml files are stored in a separate folder to make them easier to organize. Also you need to have the simpleXML (php extension) installed on your server but this is there on 99% of the cases, so no need to worry.

5. The last thing is the xml file that will store the popup, this is my login popup :

 
<?xml version='1.0' standalone='yes'?>
<content>
	<body>
		{[div class='error' id='login_errors']}{[/div]}
		Enter your credentials here :
		{[form]}
			{[div class='form_line']}{[div class='form_label']}Username:{[/div]}{[input type='text' id='login_username' class='form_input'/]}{[/div]}
			{[div class='form_line']}{[div class='form_label']}Password:{[/div]}{[input type='password' id='login_password' class='form_input'/]}{[/div]}
		{[/form]}
	</body>
	<title>Login</title>
	<buttons>
		<button>
			<label>Login</label>
			<action>
				data = new Object();
 
				data.action = "User::auth";
				data.username = $('#login_username').val();
				data.password = $('#login_password').val();
				data.ajax = 1;
 
				$.post(APP_URL+"index.php",data,function(data){
					$('#login_errors').html(data.content);
				},"json");
			</action>
		</button>
		<button>
			<label>Close</label>
			<action>$(this).dialog('close')</action>
		</button>
		<button>
			<label>Back</label>
			<action>
				DialogsManager.getInstance().loadDialog('auth_method');
				$(this).dialog('close');
			</action>
		</button>
	</buttons>
</content>
 

One problem with this is that you can't use "<" and ">" in your xml so you need to replace them, i used "{[" and "]}" so a <div> now it's {[div]}.

And this is it, you should try it and let me know if there are any problems.

Greasemonkey, create a options panel using jQuery

greasemonkey options panel with jquery

greasemonkey options panel with jquery

Hi, this tutorial is also based on the mouse hunt script "facebook mousehunt improvements" created by me, and in this one i will explain how to create an options panel (only check boxes at this time) and save it.

Here is my final result with this script :

If you want to try this, remember to load jquery correctly as described in this post at number #4.

First of all, the data is saved in a cookie as JSON, i have an object where i save all my data and i save that object as JSON on a cookie. Because javascript does not know to convert an object to a json string i used a class which does that, the class is not created by me, I just use it as it is, here is the fie : json
I copied the content of the file inside my script so i don't have to load it remotely, anyway it's just a line :) , so you should also copy this at the beginning of your greasemonkey script.

As i said the data is saved as cookie, here is the functions which will create, and read a cookie :

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
 
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i &lt; ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

Also in my program i read the cookie when the script starts so the data object "myData" in my case will be populated and available in the entire script :

var myData = new Object();
try {
	if(readCookie("gm_pl_data")!=null)
	{
		myData = JSON.parse(readCookie("gm_pl_data"));
	}
	else
	{
		//if there is no cookie we initialize it
		initCookie();
	}
}catch (err)
{
	initCookie();
}

In my case gm_pl_data is the name of the cookie in which i save the data. Here is the initCookie() function, this will just initialize the objects inside the myData object :

function initCookie ()
{
	myData = new Object();
	myData.allLogs = new Object();
	myData.allChese = new Object();
 
	savePersistentData();
}
 
//will be valid 1000000 days
function savePersistentData ()
{
	createCookie("gm_pl_data",JSON.stringify(myData),1000000);
}

I let in there all my init objects so io can see how to initialize them if you have more. You can also notice the savePersistentData function which will update the cookie and save the persistent data :) .

Until here we only had generic information about how data is saved and the functions which save the data. Now I'll go in more details for the actual options panel. The panel is actually a div in which you can enter any thing you want, but the values of the check boxes will be saved  and their status restored when the page reloads.

So here is how my panel looks like :

jQuery("#gm_pl_options_container").append("Show the timer
<input id="gm_pl_check_show_timer" type="checkbox" />
");
	jQuery("#gm_pl_options_container").append("Automaticaly sound the horn
<input id="gm_pl_check_sound_horn" type="checkbox" />
");
	jQuery("#gm_pl_options_container").append("<strong>Kings rewared options</strong>
");
	jQuery("#gm_pl_options_container").append("Play youtube on kings reward
<input id="gm_pl_play_sound_on_reward" type="checkbox" />
");
	jQuery("#gm_pl_options_container").append("Play midi on kings reward
<input id="gm_pl_play_sound_midi_on_reward" type="checkbox" />
");
	jQuery("#gm_pl_options_container").append("Show alert on kings rewared
<input id="gm_pl_show_alert_on_reward" type="checkbox" />
");
 
	setOptions();
 
jQuery("#gm_pl_options_container input").click(function () {saveOptions()});

in this case the id of the div inside which i enter the options is "gm_pl_options_container", and i you can see that setOptions() is called, this will set the default options for the check boxes based on the myData object, here's the code :

function setOptions ()
{
	if(typeof myData["options"] == "object")
	{
		for(i in myData["options"])
		{
			jQuery("#"+i).attr("checked",myData["options"][i]);
		}
	}
}

In my case the options are saved in myData["options"] the myData object is the main script object and all the scripts data is saved there, not just the options.

And after the setOptions function is called we also have an intresting line, this will add an onclick function to each input on that div, and in this function we call saveOptions(), this function will get all the inputs in that div, and save the values in myData['options'] object, and also write the cookie to make sure that the values are not lost on page refresh :

function saveOptions ()
{
	if(!(typeof myData["options"] == "object"))
	{
		myData["options"] = new Object();
	}
	jQuery.each(jQuery("#gm_pl_options_container input"),function () {
		if(this.checked == true)
		{
			myData["options"][this.id] = true;
		}
		else
		{
			myData["options"][this.id] = false;
		}
	});
	savePersistentData();
}

Every thing you have to do now is use those options, there are 2 ways to do this, you can check the status of the check box or you can get the value from the myData['options'] object, they are the same, i use the object :

if(myData["options"]['gm_pl_show_alert_on_reward'] == true)
		{
			alert("You have a king's reward!");
		}

And this is it, if you have any questions let me know, and remember, if you use mouse hunt don't forget to use my script : Facebook mousehunt improvements

My CNC machine, the beginnings, the X axis working

A while ago I started working on a CNC machine (milling machine or 3d plotter), something very simple, very cheap, something that can be built with the stuff you find at local stores, without using very expensive and complicated parts.

The frame of the machine is build from wood and use furniture rails as guides for the moving parts. The stepper motors are from old printers on floppy disk units and they are very different one from each other. The driver motor drivers are build by me from scratch using L298n (i'll ost about the driver later) and a pic micro controller to command the driver (i'll also post about that later).

I'll just post a video with the x axis working and detail each part in later posts.

Autoupdate on greasemonkey script, example from “mousehunt improvements” script.

As you can see on my previews post, i created a great mouse hunt script using grease monkey and jQuery, in this post i will explain how the update is done.

The idea behind this is, that the user will install the script and most probably will never go back and check if there is an update to that script, so you, the developer, will have to fix this problem for the user. I didn't wanted to automatically install software or updates on a users PC so i'm notifying the user that there is an update available, so he can install it by hand (only click on the link).

There are 2 parts for this, the Javascript part (inside the greasemokney script) and the server part (php in my case). The principle is simple, we have a variable inside the gresemonkey script which will contain the version of that script :

var cVersion = "1.14b";

and we have a function which will call an url giving that version as a parameter :

//check if a new version is availble.
	GM_xmlhttpRequest({
method: 'GET',
url: 'http://path.to.your.script.php?version='+cVersion,
headers: {
'User-agent': 'Mozilla/4.0 (compatible) Greasemonkey',
'Accept': 'application/atom+xml,application/xml,text/xml',
},
onload: function(responseDetails) {
$("#gm_pl_version_container").html(responseDetails.responseText);
}
});
 

What this function does is pretty straight forward, will call an url (passing the script's version as a parameter) and put all the returning content (presumed html) inside a div.

Now, we have the server script, which we called earlier. This script also has a variable inside :

$local_version = "1.14b";

which contains the latest version of the script. This script is also pretty straight forward, will compare the latest version of the script, defined here, with the version provided as a parameter, and based on that will return an html, here is the entire script :

 
<?php
$local_version = "1.14b";
if($_GET['version']!= $local_version)
{
	print "
<div style='padding:3px'>
	A new version of this script is available.<br>
	Click <a href='http://userscripts.org/scripts/source/57446.user.js'>here to upgrade</a>
	</div>
 
	";
}
else
{
	print "your script is up to date ($local_version)";
}
?>
 

And this is it.
If you don't want to use Jquery, no problem you will have to replace this :

 $("#gm_pl_version_container").html(responseDetails.responseText);

with :

document.getElementById("gm_pl_version_container").innerHTML(responseDetails.responseText);

where gm_pl_version_container is the id of the element where you want to insert the content.

GreaseMonkey, Jquery and the greatest mouse hunt script.

I started using mouse hunt a while ago... and really enjoy it, i loved when i got a new trap and i could buy more cheese, more traps... and craft more items, but as time passed along i got bored with that and I just wanted to catch as many mice as possible, and be fast in what i do, also i wanted to have a script that sounds the horn and let me know when a king's reward has appeared, so i decided to create my own mouse hunt script, the greatest mouse hunt script ever created...

I started working on ma spare time in this... was not easy because some things ware hard to test... bunt eventually i did it.

You can see the script here : http://userscripts.org/scripts/show/57446 the script has been around for about a month and already has 1200 installs and going up, and it's becoming "the mouse hunt script" :D .

Now i will explain some of the problems i encountered on creating the script.

1. Saving persistent data, grease monkey does not have a very good way for this, so i decided to create an object where i save all the data and then save the object as JSON in a cookie

2. Updates, i was thinking that it would be nice to notify users when an update is available, so i did this by creating a .php file in a server and store there the latest version number, the script checks that version with it's current version and if is different will show a message

3. Passing parameters on a function attached to an event, this was the most tricky one... was pretty complicated... here is the solution :

$.each($(".huntername"), function (i,o) {
 
			var id = 0;
			var childs = $(o).children("a");
			var link = $(childs[0]).attr("href");
			var name = $(childs[0]).html();
 
			id = link.substr(link.indexOf("=")+1);
 
			$(o).html($(o).html()+"<a id="gmpl_af_&quot;+i+&quot;" onclick="return false" href="#">(add to links)</a>");
			_e("gmpl_af_"+i+"").addEventListener("click",function () {gmpl_addFriend(id,name)},false);
		});

4. How to use jquery in a grese monkey script, actually for this i fond the solution somewhere on the internet... : http://joanpiedra.com/jquery/greasemonkey/

// Add jQuery
    var GM_JQ = document.createElement('script');
    GM_JQ.src = 'http://jquery.com/src/jquery-latest.js';
    GM_JQ.type = 'text/javascript';
    document.getElementsByTagName('head')[0].appendChild(GM_JQ);
 
// Check if jQuery's loaded
    function GM_wait() {
        if(typeof unsafeWindow.jQuery == 'undefined') { window.setTimeout(GM_wait,100); }
    else { $ = unsafeWindow.jQuery; letsJQuery(); }
    }
    GM_wait();
 
// All your GM code must be inside this function
    function letsJQuery() {
        alert($); // check if the dollar (jquery) function works
    }

And all your code should go where the alert($) is. Only if you have some functions you should put them outside that function.

Testing my stepper motor driver and software

this is a simple test for a driver for stepper motors it uses a l298 IC and runs great, i'll post more details later.

and here is a unipolar motor controlled by the driver.

Also in this second video i use different sources for powering the circuit board and the power source for the motor.