5 - Check the first piece of code using LEDs

 

Before connecting the motor – I wanted to make sure that my code was, at the very least, doing what I thought it was. Just connecting the motor only to find out that nothing happens means you have to work out if there is a problem in your program, your hardware connections or, dare I say, if you’ve managed to fry some of the hardware. What better to give a clue as to what’s going on then our trusted friend the LED!!

 

So with the motor disconnected: so place a 1.6k resistor in series with an LED - which is then connected to ground -  on each of the output pins from the L293D - that is pins 3, 6, 11 and 14 - which we will call outputs 1a, 1b, 2a and 2b respectively.

 

 

The easiest sample code to write is for the ‘Wave Drive’, as discussed previously, which requires us to send pulses as follows:

 

 

T

T + 1

T +2

T + 3

1a

High

Low

Low

Low

1b

Low

Low

High

Low

2a

Low

High

Low

Low

2b

Low

Low

Low

High

 

So here’s some pseudo code:-

 

Set your pins as outputs

 

While(1){

     Pin1a = high, Pin1b = low, Pin2a = low, Pin2b=low

     Wait 1 second

     Pin1a = low, Pin1b = low, Pin2a = high, Pin2b=low

     Wait 1 second

     Pin1a = low, Pin1b = high, Pin2a = low, Pin2b=low

     Wait 1 second

     Pin1a = low, Pin1b = low, Pin2a = low, Pin2b=high

     Wait 1 second

}

 

This should make the LEDs flash in sequence: 1a, 2a, 1b, 2b.

 

Looking at my timing tables for the other two potential driving methods you should easily be able to adapt your test code to the other methods.