mBuino with stepper

Playing with the mBuino, considering to attach a stepper motor with the Sparkfun autodriver. Found some nice code on the mbed.org and it could turn out really nicely. But having doubts about connecting it, not sure which pins to use for the 6 wires…??

 #include "mbed.h"
 #include "L6470SDC.h"

int main() {
    //set maximum speed
    l6470.setMaximumSpeed(1, l6470.calcMaxSpd(100));
    //run 300step/s,clockwise
    l6470.run(1, l6470.calcSpd(300), true);
... and more

mBuino pins for ref: [url]https://developer.mbed.org/media/uploads/GHIElectronics/mbuino_pinout.jpg[/url]

Stepper driver board: [url]https://www.sparkfun.com/products/11611[/url]

The code: [url]L6470SDC - Library for STMicroelectronics dSPIN L6470 steppe… | Mbed

@ andre.m - You are right, of course :whistle:

With the risk of being completely off-track, here is my initial plan:
USBTX is P0.18
USBRX is P0.19
SPI_MOSI is P0.21
SPI_MISO is P0.22
SPI_SCK is P0.15
D10 is P0.11 (or another free pin)

Would that work?

Well spotted on the P0.15 which of course should be P1.15.

Not sure about CSN, its the chip select. Maybe looking at the code will help…

The constructor looks like this.

/** Constructor:(Serial, SPI, CS) PinName
    * @ param tx Serial USB_TX PinName
    * @ param rx Serial USB_RX PinName
    * @ param mosi SPI Master-out PinName
    * @ param miso SPI Slave-out PinName
    * @ param sclk SPI Clock PinName
    * @ param csel SPI ChipSelect PinName
    L6470SDC(PinName tx, PinName rx, PinName mosi, PinName miso, PinName sclk, PinName csel);

Csel allows you to pick whatever pin is convenient. Consider it a “free choice”

Edit: Andre.m types faster than I do

Thanks both, makes sense. The driver will instantiated this way then:

 #include "L6470SDC.h"
L6470SDC l6470(P0_18, P0_19, P0_21, P0_22, P0_15, P0_11);

Now comes the wiring…see picture…

And here my skills are not sufficient. I dont understand why the USBTX/RX pins are allocated, but not used?? And I dont see the chip select anywhere??

The list for the MCU controller communication input on the board is:
On the autodriver —> mBuino
3-5V —> 3V3
OSCIN —> ???
SCK —> P0.15
OSCIN —> ???
MOSI —> P0.21
MISO —> P0.22

@ andre.m - nope, but why is that? And what about the USB serial pins?

Hmm, I guess I could instantiate the driver differently, will look into that later…

If you need to synchronize more than one L6470 you can use the oscin pins and an one external oscillator.

TX/RX pins are only for a communication with a terminal to send an command ( start/stop/position ) to your software.

So, I did some reading on the drivers source-code. And now I understand - the serial connection is for debugging information that is printed directly to that connection, so it can be output to a screen when debugging.

I was not in mbed thinking mode, where all debugging goes through the serial connection with printf. ???

Everytime I take a detour into Arduino or mbed world I start appreciating NETMF so much more. :smiley:

Anyway, will let you know if I get the stepper to behave!

Thanks for pointing me in the right directions!

STATUS: Serious uphill battle, only led blinking is workin. :wall:

I have attached the Sparkfun module according to your guidance, supplying 12V for motor and 5v to chip on module. Attached the SPI wires to mBuino, and 5V supply to that as well.

Can I have your hawkeyes look at my test-setup and see if I have done some beginner mistakes…?

PS: Note that I have found an older Sparkfun module, which is doc’ed here:[url]https://www.sparkfun.com/products/retired/10859[/url]

My primary suspect is a really lousy driver, mbed is really difficult to find the good drivers… I am using this one: [url]L6470_lib - L6470 use library | Mbed

OK, I realized I forgot to do my homework :wink:

Here is the setup and the wiring.

The code is here:[url]TrapPowerController_v2 - Testing mBuino libraries | Mbed

I use a 12V good quality power supply with a barrel plug connected to DFRobot breadboard power-converter, which supplies 3V and 5V. I have soldered wires directly to the barrel (blue and white on picture to get access to the 12V).

These are the wires:
From breadboard:
12V → V+ at Stepper module
5V to mBuino 5V
5V to 5V at Stepper module
GND → GND at mBuino
GND → GND at Stepper module power-supply side
GND → GND at Stepper module chip-side

From mBuino:
P0.21 → Stepper module SDI (SPI_MOSI)
P0.22 → Stepper module SDO (SPI_MISO)
P1.15 → Stepper module CK (SPI_SCK)
P0.11 → Stepper module CSN (CSN)

From Stepper module:
01B → Coil1 B
01A → Coil1 A
02B → Coil2 B
02A → Coil2 A

Hope that makes it easier to assist :think:

@ njbuch - reset has to be held high. See that pin marked Stby? it has to go to 5V.

1 Like

@ Mr. John Smith - YOU ROCK! It works now, will start cleaning up some test-code and see if I can get it to run fast and precise!

Thanks man, thank you so much! :smiley: :smiley: :smiley: :smiley: :whistle:

@ njbuch - Welcomes :-[

@ njbuch - As I sit back and ponder over my own experiences with those exact boards, I can only laugh at how many times I’ve pulled my hair out trying to figure out why it’s not working only to realize that yet again I forgot to pull reset high. I can think of 3 instances where that has happened. SparkFun should have added a pull up resistor.

@ Mr. John Smith - I avoided pulling my hair out thanks to you :wink:

The biggest realisation to me though is the fact that mbed development is quick to get started with, but really soon you realise that you need better tools.