New domain and blog

New domain and blog
Please head over to my new domain to view my blog and current projects

Tuesday, 17 July 2012

LabVIEW: Simulating keyboard events

Another useful trick in LabVIEW using the user32.dll is to simulate keys being pressed on the keyboard. I haven't come across the need very often, however when using console applications, it can be necessary.

I ran into this problem while running a console application that runs a GPS simulator. Getting the application to run was easy and when the simulated trip is complete, the console closes automatically. The problem came in when I wanted to stop the controlling LabVIEW application. When I stopped the LabVIEW application and if the console was still running, I needed to close it and wanted to do it all in one step, instead of forcing the user to stop the LabVIEW application AND close the console window.

After some research I found out that the user32.dll has a keyboard event method so I decided to use that. I first had to make the console window active, find out how here, and then I would run this application as a sub-vi to simulate a Ctrl+C which was needed to stop the GPS simulation and close the console. 


What happens is that the two integers need to be passed to the dll. The first element is the decimal representation of the ASCII character that needs to be simulated and the second is what motion the button makes.

EG: 162 is represents the Ctrl key and 67 is the decimal representation for the ASCII uppercase C. The second integer that is passed to the dll is used to decide what the button is doing. 0 Simulates that the button is being pressed and 2 simulates that the button is being released.

Therefore, by writing each cluster to the dll in a for loop with 50ms delay between loops, Ctrl+C is written to the active console window which will stop the GPS simulation and close the window.

To download the example VI, use this link.

Greg

Friday, 13 July 2012

LabVIEW: Making a window active

A small issue that I have been trying to resolve is when a LabVIEW application runs and multiple windows are open, the need is often there to bring a window to the front as some stages of the application. 

Now I am sure there are many ways to perform this task, but the easiest and most reliable way that I found is to use the user32.dll that is part of the windows installation. This dll is easily accessed by using Call Library Function Node. This can be found in Connectivity >> Libraries & Executables.


The three methods that are used are FindWindowA, SetForegroundWindow and ShowWindow. By wiring these us and adding the correct window name that you want to bring forward, when the program is run whatever window name is selected will be brought to the front. 

There are many other tasks that can be performed by using the user32.dll. I have used it in a few other places in my programs and will add some more posts in the future of where it can be used.

To download the example VI, use this link.

Greg

Thursday, 12 July 2012

2W red LED bicycle light update

If you missed the first post about my modified bicycle light, take a look here

So I used my light last weeks at #moonlightmass and it was super cool. I got a few comments about how bright it is and I suppose it's not a great idea to use this light in a crowd of people. To be seen out on the road by cars, this light is great.


Here is a picture of the modified light mounted on the seat post with the battery pack and controller mounted in a box under the saddle.


Here is a quick video of the light in action.

There are still a few software changes that I need to do like complete the low battery indicator and I also want to add a few more light functions, but that will come when I get a chance.

Greg

Wednesday, 4 July 2012

#moonlightmass in Cape Town

What started in January 2012 as a social experiment over Twitter, has now become the place to be once a month when the moon is full. Meeting on every full moon under the round about in Green Point, the ride goes past the amazing Cape Town Stadium and onto Sea Point promenade. 



The ride then follows the promenade and past the Sea Point library up onto Main Road. Making its way back to the city center, the ride then turns up Long Street. For me this was the best part of the ride because how often do you see so many people riding their bikes up one of the busiest roads in town with zero cars.

At the top of Long Street the ride then crosses over and makes its way down Bree Street where it finishes at Greenmarket Square.

View #moonlightmass route in a larger map

So that is the route that the ride takes. It's a great concept and it was super to see the police out to help with the traffic control. Big up to the City of Cape Town for helping out. I can only imagine that next month is going to be even bigger so looking forward to that. 

Keep an eye on the #moonlightmass website for the next event, it's going to be large.

Greg

Tuesday, 3 July 2012

Bicycle light using two 1W red LED's

I bought a 1200 lumen light the other day so that I can cycle before and after work when it is still dark. It works really well to light my way, but I also wanted a decent back light. After all, the cars generally come from behind and need to see you.

Instead of simply buying one, I decided to make one by recycling an old bicycle light that I had lying around and use two 1W red LED's that I have also had for a while and never used.

The first hurdle I had to overcome was to design a power supply capable of delivering at least 350mA and one that could supply 6.4V, enough for two LED's. I also wanted to use at the most, two 1.2V NiMH batteries.

The next choice I had to make was what controller I wanted to use. I settled on a small, low cost micro controller. I also decided to run the entire circuit off 5V. This would slightly under drive the LED's, but would safely power the micro without using two power supplies.

For the power supply, I went with the LM2623 which is capable of supplying 2A with an input of as low as 0.8V.


For the micro controller I went with the PIC12F615 which has an internal nMCLR pull up and an internal 4MHz oscillator which keeps the pin count low.


To drive the 1W LED's, I am using a BD139 transistor. I am driving it just below its limit, but I had a few lying around so just used one. I am using a PWM signal of 1KHz and the LED's are on for 50ms and then off for 250ms. At the moment I only have one setting but I plan to add more in my next version, different flash rates and solid on.

I use one of the analog inputs to measure the battery voltage. By doing this I can turn on the 3mm LED when the battery voltage goes below 2V. This means that I won't run the battery's too flat and damage them.

The battery's and controller are housed in a plastic box which I have tied neatly under my saddle and the light is attached to my seat post. 

At the moment this is my prototype which works, but isn't 100% complete. I still need to tweak the part of the program that measures the battery voltage and I also want to play around with the current limiting resistor so that I can get the max brightness out of the 1W LED's. I also have to test how long the circuit will run on two AA battery's.

I will be testing it tonight at Cape Town's #moonlightmass to see how it performs. I will also get some pictures or videos and put them in a follow-up post. 

If you want the DesignSpark schematic and the micro controller code, use this link.

Greg

Thursday, 28 June 2012

Adding source code to Blogger

I have been trying for quite some time to add source code to my blog. Just copying and pasting the code works fine, but there is no proper formatting or colours used in normal source code editors. After browsing the internet and reading many examples, I finally came across this website that helped me get it done.

I have used the SyntaxHighlighter script and from what I have seen, this seems to be the most used method. It supports a number of different programming languages and once set up, very easy to implement.

Please back up your blog before trying this as you need to edit the html template. From your Dashboard, navigate to Template, and then select Edit HTML. A warming will pop up so select Proceed. The HTML template will now be displayed.

Navigate down in the template to find </head>
Copy the code below and paste it above </head>


Preview your template to ensure that it still looks ok. If all is fine, then save the template and close the editor.

The next step is to make the script work. You do this by using the <pre> and </pre> HTML tag. In between these tags is where you add your code. You also need to specify which script to use depending on what language your source code is in. Here is the example I used to display C# source code.

private void UpdateCounter()
{
if (iCounter.Value < 50000)
{ iCounter.Value++;
{
} else iCounter.Value = 1; } }

You need to add the tags and code in the HTML editor. Once the source code has been added, then you can go back the the text editor to complete the post.

That's about it. Once the template has been edited and your set up is correct, adding source code it pretty easy.

Greg

Wednesday, 20 June 2012

Cycling: Making friends with Kloof Nek

A few years ago when I was training for IRONMAN South Africa I used to do this ride and some at least three times a week before work. Back then I was fit and was training with a good group of guys.

Now after a few years with not much cycling, I decided to give Kloof Nek a try. For those that don't know, Kloof Nek is the road between Cape Town and Camps Bay. It's a relatively short climb, but gets rather steep in places and if you not ready for it, it can be quite tough. According to Google Earth, it is 4km long with a maximum elevation of 13% and an elevation gain of 235m. 
The view from the top is magnificent. To make it a bit of a longer climb, you can either turn right at the top and cycle to the top of Signal Hill or turn left and cycle along the face of Table Mountain past the cable way.

The ride down into Camps Bay and back along the coast makes the tough climb well worth it. 

Give this route a go and if you feeling energetic, cycle Kloof Nek, carry on and go over Suikerbossie into Hout Bay and then climb to the top of Chapmans Peak. The views from along the road and the top of all the climbs are amazing. When I'm fitter I will be doing that route and will get it up here. 

To download the Google Earth file, use this link.

Greg

Monday, 18 June 2012

LabVIEW: Event Structure vs While Loop

When I started working with Event Structures in LabVIEW, I wondered what the difference was in terms of CPU usage. In a small program, managing efficiency might not be an issue but in a large testing environment where many processes need to be performed, the need for managing efficiency becomes quite important.

To test the difference in CPU usage between using the standard While Loop, which can get messy very quickly and the Event Structure, I wrote a simple program. The While Loop and Event Structure options are placed in different cases which is selected before the program is run. Both options monitor two buttons, display a message when either button is pressed and has a counter which shows how many times the loop is run.


The Event Structure monitors two buttons and displays a message for each. 


The While Loop also monitors two buttons but as it can be seen from the front panel above, it is quite a bit more messy than the Event Structure. If any more button or inputs need to be monitored, this method can quite easily get out of hand.


Here is the CPU monitor comparison of the two options being run. On the left is the Event Structure only using 5% and on the right is the While Loop which is using 30%. There are ways to slow the While Loop down like adding a loop delay but I wanted to show the extremes.

I hope this helps and can provide some display on the different ways to do a similar process.

To download the example VI, use this link.

Greg

Thursday, 24 May 2012

LabVIEW: Creating custom buttons

It's been something that I have been thinking about for a while but never really got round to trying. Creating custom buttons have a number of different applications and they are really easy to make.

To start off, you either need to decide if you want a button with an emblem (same image for true and false) or if you want a button that has a different image for true and false. You also need to find the images that you want displayed on the buttons. A good place to start is a clipart website like this one.


Download the images and then resize them. I use an image size of about 60px x 60px.
  • Open the LabVIEW start up window and under New, select More
  • Under Other Files, select Custom Control
  • We now need to place a button so we can change what it looks like
  • Place a button control onto the front panel
  • Select your first image by navigating to Edit >> Import Picture to Clipboard
  • Right click on the button and select Import Picture from Clipboard >> True/False/Decal
  • True will display the picture when the button is in a true state. False will display the picture when the button is in a false state. Decal will embed the picture for all states.
  • Do the same process to attach the next image for the other state
  • Save the control and then use it in a normal VI
That's about it. Pretty simple to create custom controls.

To download the example control, use this link.

Greg

Friday, 11 May 2012

LabVIEW: Simple event structure

I searched everywhere to get an example or some help of a simple event structure and a state machine working together. I have used state machines extensively and really like the way they work but never tried implementing an event structure into it.

Here is a very simple state machine which runs through an initialising state and then sits in a running state. The event structure is in the running state and monitors the two button for a state change and also the close window button. 

Initialise button: Takes the program back into the Initialising state.
Stop button: Takes the program into the Stop state and then stops the program.
Close Window: Show a message that the program must first be stopped before it can be closed. Then takes the program into the CloseWindow state and then back to the Running state.


I am sure there are much better ways to perform this task so if you have any tips please leave me a comment. As soon as I find a more efficient process, I will be sure to update this post and program.

To download the example VI, use this link.

Greg