4x4 board using sample code and Mega2560

So, I am trying to use the sample code which accompanies the 4x4 board here: https://www.sparkfun.com/products/11352 (see the link for Arduino Library link - there is some shift stepper code). The library installed after a slight tweak so the name doesn’t cause a failure, and then there is some sample code at the top of the ShiftStepper.cpp file. The user manual had some of the settings I needed to add (hopefully these are compatible with the Mega2560, since the board was designed for the Uno):

#define DATPIN 4

#define SCLPIN 13

#define LATPIN 7

#define MRPIN 8

#define INDPIN 2

static const uint8_t stepSequence[4] = {0x2, 0x4, 0x1, 0x8};

static const uint8_t motChans0[channelsPerMotor] = {0,2,3,1};

static const uint8_t motChans1[channelsPerMotor] = {4,5,6,7};

static const uint8_t motChans2[channelsPerMotor] = {11,9,10,8};

static const uint8_t motChans3[channelsPerMotor] = {15,14,13,12};

shiftChain *myChain = 0;

shiftStepMotor motor0(channelsPerMotor, stepSequence, motChans0);

shiftStepMotor motor1(channelsPerMotor, stepSequence, motChans1);

shiftStepMotor motor2(channelsPerMotor, stepSequence, motChans2);

shiftStepMotor motor3(channelsPerMotor, stepSequence, motChans3);

shiftDevice *motors[4] = {&motor0, &motor1, &motor2, &motor3};

shiftSixteen board0(4, motors); shiftBoard *boards[1] = {&board0};

shiftChain storeChain(1, boards, DATPIN, SCLPIN, LATPIN, MRPIN, INDPIN);

So, the example showed to have the following in setup():

void setup()

{

myChain = &storeChain;

myChain->startTimer(preScaler32, 0, 2); //this causes my flashing LED code to stay solid

motor0.setSpeed(100); //no effect

pinMode(13, HIGH);

}

void loop()

{

digitalWrite(13, HIGH);

delay(2000);

digitalWrite(13, LOW);

motor0.doSteps(4, 10);

myChain->doTick();

delay(2000);

}

So, I have 4 LEDs connected to outputs 0-3, and when I run the above code, LEDs 0 and 3 light, but no others. The comments at the top of ShiftStepper.cpp seem to indicate using a timer would be best, but this is the first I have ventured past making the LED flash. While I am using LEDs now, I wish to connect up a BLDC to it and drive the motor using this shield. Right now, I just want to prove that I can make the sample code roll through the canned step sequences with the library for this board {0,2,3,1}, etc. I see there are methods for setting the speed and such, but so far I am unable to do anything useful with this thing.

Any ideas?

Thanks,

-Kevin

I contacted the manufacturer and they said DATPIN should be set to 11. Nothing works for me still.

I even tried:

void loop()

{

int highByte = 0;

static int lowByte = 1;

delay(1000);

digitalWrite(7, LOW); // Prepares latch

digitalWrite(8, HIGH); // Deactivates master reset

shiftOut(13, 11, MSBFIRST, highByte); // shift data for OUT8-OUT15

shiftOut(13, 11, MSBFIRST, lowByte); // shift data for OUT0-OUT7

digitalWrite(7, HIGH); // latch data

delay(1000);

lowByte++;

}

The way I have things wired, BTW, is:

DB25 Pin 1 goes to gnd (pin 7 of arduino mega 2560)

DB25 Pin 2 goes to +5V (pin 5 of arduino mega 2560)

DB25 Pin 3 goes to Anode LED0

DB25 Pin 4 goes to Anode LED1

DB25 Pin 5 goes to Anode LED2

DB25 Pin 6 goes to Anode LED3

560 Ohm resistor between Cathode of each LED and gnd

I am using an external 16vDC supply to my arduino, and verified that I have 5V DC on pin 5

First I think you’re referring to this …

http://arduino.cc/en/Reference/ShiftOut

(it’s always good to post a link to your hardware)

If so, looking at the schematic I think the data pin is pin 11 and the clock is on pin 13.

http://dlnmh9ip6v2uc.cloudfront.net/dat … ematic.pdf

The Arduino ShiftOut function specifies the order of it’s arguments as:

shiftOut(dataPin, clockPin, bitOrder, value)

http://arduino.cc/en/Reference/ShiftOut

You have code that does this :

shiftOut(13, 11, MSBFIRST, highByte); // shift data for OUT8-OUT15
shiftOut(13, 11, MSBFIRST, lowByte); // shift data for OUT0-OUT7

So I believe the 13 and 11 above are in the wrong order. Try :

shiftOut(11, 13, MSBFIRST, highByte); // shift data for OUT8-OUT15
shiftOut(11, 13, MSBFIRST, lowByte); // shift data for OUT0-OUT7

I know this is contrary to the code examples but then again those don’t use pin 11 for either clock or data.

From the example code:

#define DATPIN 13
#define SCLPIN 12
#define LATPIN 7
#define MRPIN 8
#define INDPIN 2

I also note that a comment on the product page (always, always read the comments) says this:

According to the schematic, DATPIN is now pin 11 and SCLPIN is now pin 13, in order to enable the user to write to it using the SPI hardware.

ps - 16V input to the Arduino !?! You might want to check the temp of the voltage regulator. You certainly don’t want to use the onboard 5V to drive much of anything.

pps - if you use the code buttons, your code will appear as above and be easier to read.

(click on to enlarge)

Mee_n_mac,

Thanks for the reply. Unfortunately I tried your suggestions and I got similar results. No magic. The hardware link is here:

http://wiki.logos-electro.com/4x4-driver-shield-manual (for anyone following along). The manual states:

digitalWrite(7, LOW);    // Prepares latch 
digitalWrite(8, HIGH);    // Deactivates master reset
shiftOut(13, 12, MSBFIRST, highByte);    // shift data for OUT8-OUT15
shiftOut(13, 12, MSBFIRST, lowByte);    // shift data for OUT0-OUT7
digitalWrite(7, HIGH);    // latch data

When I emailed the above code to the manufacturer, they said I was using pin 12, rather than 11, which is why I had the code posted as above.

As far as the 16V goes, it was a 12vdc wall wart, but the measured output was around 16V. And I am just driving LEDs for now, so I suspect things should be Ok. I did rewire the power last night, so I have a separate 12V regulator circuit inline which feeds both the Arduino as well as the 4x4 shield (the LEDs get really bright if they happen to come on). This also had no effect on performance/operation, sad to say.

Thanks again,

-Kevin

sfcaveman:
Thanks for the reply. Unfortunately I tried your suggestions and I got similar results. No magic.

When I emailed the above code to the manufacturer, they said I was using pin 12, rather than 11, which is why I had the code posted as above.

Just to be clear when the manufacturer said the above, "*I [u]was using[/u] pin 12, rather than 11*", did they direct you to use pin 11 ? Did you then use pin 11 instead of 12 and in this order below ?
shiftOut(11, 13, MSBFIRST, highByte); // shift data for OUT8-OUT15
shiftOut(11, 13, MSBFIRST, lowByte); // shift data for OUT0-OUT7

If I’ve understood that all correctly and the the above does not work then either the schematic is wrong or there’s something else wrong in your code that I’ve not seen or something in the hardware is broken.

Following up on the above - I just looked at your code again and, doh, there it is. You’ve got highByte = 0 and lowByte = 1. So try (at first) setting both to 0xFF (all 8 bits are ones). That should light all the LEDs. You can then experiment (since I’ve forgotten which is which) with one = 0x00 and the other = 0xFF to see which LEDs are controlled by highByte and which by lowByte. Then use 0x0F and vary MSBFIRST / LSBFIRST (or use 0xF0) to figure out which nibble controls those 4 LEDs. Play games with just 1 bit = one (0x01, 0x02, 0x04, 0x08) and the shift order to map out which LED corresponds to which bit.