onsdag den 3. april 2013

Having an astable trigger a monostable


I wanted to have an astable pulse trigger a monostable, using the 555 timer. The main issue here is in that the trigger-pulse that's sent to the monostable 555 can't be longer than the output pulse, unless you add a 'trigger guard' of sorts.

The below schematic does the trick:



The 555 on the left is the astable, it pulses every approx 4-5 seconds. Its output is sent to the input of the 555 to the right, the monostable, which pulses for a significantly lower duration as opposed to its input pulse.

This could be used for an egg-timer, for example, where a variable resistor sounds a buzzer at a selected interval.

mandag den 25. marts 2013

GridView + DetailsView + no update

Updating a GridView based on values changed in a DetailsView, but not finding the changes reflected in the GridView?

In the DetailView's ItemUpdated-method, make sure you have the the GridView.DataBind(), and make sure that in your Page_Load the initial databind, if any, is wrapped in an 'if (! Page.isPostBack)' clause. Which I didn't have, for specific reasons yet preventing the GridView update.

Hope this helps some-/anyone.

onsdag den 6. marts 2013

Arduino: How to wire a relay

Here's my quick tutorial on how to hook up a relay to an Arduino; specifically a electromagnet switch relay from Omron, the G5SB-14.

You can use the relay that's referred to with AC voltage, i.e. to turn on and off mains-powered applications such as lamps and such, BUT DO THIS ONLY ONLY ONLY if you're very confident in your abilities and take your safety seriously. AC POWER KILLS if you are not careful.

Here's a breadboard-look of how it's hooked up:



You'll see the Arduino on the left hand side, providing power to the relay and the accompanying components, and on the right hand side is the red LED I'm powering via it's own battery (you could, if you like, power the LED by the Arduino).

First off, we'll use the Arduino's digital pin 8 to send a signal to the relay, through the other components. So hook up the pin 8 to a 1 kohm resistor. Why the resistor, because the transistor I'm using that will catch the signal from the pin no. 8 can't handle the full 5v voltage from the digital pin.

Next, the transistor. Why use one? Because we can't operate the relay by the signal from the digital pin alone - it hasn't enough juice to switch the relay's internal magnetic switch. So hook up the transistor as per the image, with 1) the center pin - the base - hooked up to the digital pin via the resistor, 2) with the emitter - the left side of the transistor, when you're looking at the flat side of the component - hooked up to ground and 3) the collector - the right side of the transistor - going to the rectifier.

What's a rectifier? Well, it's a diode that guards the curcuitry from electrical flow from the relay when it's switched off, and a sudden change in current flow surges from the relay. To the relay it's like a night-club bouncer preventing the rush of current from entering the delicate transistor and Arduino - like "You behave, you relay, or I'll rectify your ass", so to speak. It's like a one-way street for current. If you're just messing around and reproducing this or a different example, you can go without it, but at your own peril.

Hook up the rectifier (in series) to one end of the relay coil, and hook the other end of the coil to power. It really is a coil inside the relay: Powering the coil creates a magnetic field inside the relay, 'creates' a magnet if you will, that attracts a metal pin inside the relay enclosure, which in turn touches one of two tiny contacts (on and off) and creates a connection between them.

That's the Arduino part of the tutorial. Now we need something for the relay to actually turn on and off. In this case, a red LED, powered by the battery. Hook up the battery, the LED as shown in the picture (don't forget the resistor unless you're willing to sacrifice an LED or two on the alter of trial-and-error), and connect the relay.

In connecting the relay, hook up the relay's 'common' pin to ground. This pin is the one that holds on to one end of the metal pin which is to touch either contact - labelled normally on (NO) and normally closed (NC). Refer to the data sheet of your specific relay to make sure it's hooked up correctly - it's not always such that these labels - NO, NC and COM (for Common) are written on the relay itself.

The way the relay is used, is thus: if you want the relay to turn something off when signalling it from the Arduino, you must connect your application's power source - in this case the battery for our LED - to the normally opened (NO) pin. If on the other hand you want to use the relay to turn something on, you must connect the power source to the normally closed (NC) pin.

The below pictures show the orientation of the pins on the Omron relay that's used here, the
G5SB-14:



If you hook up the example-breadboard, you should be able to do what did I: Play an Arduino sketch which turns the relay on and off every 5 seconds. Here's the example code:



// connect digital pin 8 to the transistor, via a resistor
int led = 8;

// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {

delay(5000); // wait for 5 seconds
digitalWrite(led, HIGH); // turn the relay off
delay(5000); // wait for a second
digitalWrite(led, LOW); // turn the relay on
}


That's it - that's how you hook up a relay to the Arduino. Happy switching on and off!

I'm including a bunch of pictures below, of how I've set it up on my breadboard. Hopefully the pictures might be helpful.

torsdag den 21. februar 2013

Plug-in warning with embedded SVG files

Quick SVG-tip:

If you get a plug-in warning in Firefox or your Google Chrome browser immediately takes to downloading an embedded SVG file in your HTML-page, this is because you're referencing the SVG-file locally, i.e.


<embed src="../images/info_icon.svg" type="image/svg+xml" />


... as opposed to absolutely:


<embed src="http://your_web_server/studentExchange/images/info_icon.svg" type="image/svg+xml" />


If you reference the SVG file absolutely, the plug-in warning will go away.

Hooking up the UsbTinyISP to an Arduino Uno

The UsbTinyISP is a micro-controller flashing interface, which will allow you to flash the code on various Atmel micro-processors. The below image references how to hook it up to an Arduino Uno development board - I couldn't find a suitable reference-image so I thought I'd provide it.



So when in doubt, turn the boards the same way as in the image and look for the red strand of the wire.

Then, for flashing an Arduino bootloader to the chip, it's a simple matter of selecting the UsbTinyISP in the Arduino (it's in the 'tools' menu) and clicking 'burn bootloader' (also in the 'tools' menu).

Remember - the UsbTinyISP must be installed with the appropriate drivers and it's only the UsbTinyISP that should be connected to the PC - not the Arduino Uno.

The Arduino IDE runs a version of the AVRDude-tool and will also take care of any setting of fuses on the micro-controller. Burning the bootloader takes about a minute or so, beyond which you can program the micro-controller in the IDE and then yank it from the Uno development board and put it in your own project.

Happy flashing!

Hooking up a microcontroller to the AVR Dragon

The AVR Dragon is a development board for Atmel micro-controllers, used in conjunction with Atmel's AVR Studio.

In using this board it's not only necessary to add a micro-controller to the board, but this micro-controller must also be hooked up to the board's connectors (one is expected to solder pins to the board's through-holes) or the AVR Studio will not be able to see the micro-controller.

These are the connections that must be made with jumper wires:



I recommend Derek Molloy's terrific video on the subject.



mandag den 7. januar 2013

Modal detailsview


Simple tip, this,

if you're displaying an asp.net DetailsView on your aspx-page, you'll perhaps consider showing it with a modal-background so as to bring focus on it.

This is easily implemented by showing a hitherto hidden panel on the page. Here's the mark-up for that - put it at the very top of the page:




test



Then, in the code-behind code which shows the DetailsView, you'll include a bit of javascript (using Jquery here, but you don't have to) to show the hidden div:



newLanguageDetailsView.ChangeMode(DetailsViewMode.Insert);
detailsPanel.Visible = true;

System.Text.StringBuilder sbScript = new System.Text.StringBuilder("");

sbScript.Append("");

ScriptManager.RegisterStartupScript(this, this.GetType(), "@@@@MyPopUpScrip1t", sbScript.ToString(), false);



The only thing you'll need to remember to do is to add css to your DetailsView, to position it and add a z-index higher than the modalBackground, so it'll be presented above the gray full-screen background. So add this as the css-class attribute value for your DetailsView:

.zindexedDetailsview {
z-index: 100;
position: relative;
}


That's all there is to it. All other solutions I've seen include the Ajax framework and specifically the use of the ModalPopupExtender, so here's a lighter weighted alterantive.

Works for me with VS2012, .net 4.5, Jquery 1.8.3. Cheers!