The microspora Arduino thread

Since the microspora firmware on github is for Platformio, I thought it would be helpful to have an Arduino based thread.

From what I understood so far, Arduino doesn’t have a microspora library with example code.
But we can use the STM32 library and pick the right MCU.
Same goes for DRV8316 and MT6701, so the basic package is available.

With other STM32 MCUs I let arduino export a compiled binary and use the ST-Link to flash it.
Maybe it’s different here, IDK yet. (my microspora will take 10-15 days to deliver)

What I wasn’t sure of, is the description of the SPI interface.

Note: This SPI bus is the same one used for the DRV8316 driver, so make sure to configure the driver before you use the SPI bus for other purposes.

I guess, the DRV chip has it’s own CS pin and PC11 is for external devices communicating with the MCU?
I don’t have a usecase for that now, but was curious.

I will post some test code, once I have the board. My focus is on BLDC motors in NEMA17 and 23 size and step/dir interface, but might try the hybrid stepper approach later.

Feel free to post your code snippets and tips&tricks, so we can help others to start with the Microspora

If you look for the right wire housings here is what AI told me:

The exact official counterparts for the JST SH series 6-pin right-angle SMT header (SM06B-SRSS-TB(LF)(SN), 1.0mm pitch) depend on whether you prefer standard crimp housings or IDC (Insulation-Displacement Connector) terminations.

Here are the official parts from JST:

1. Crimp Housing (Standard)

If you want to crimp the wires individually:

  • Housing Part Number: SHR-06V-S or SHR-06V-S-B (6-position female housing)

  • Matching Crimp Contacts (ordered separately):

    SSH-003T-P0.2 (for wire sizes 32 to 28 AWG)

2. IDC Housing (Pre-loaded / Insulation-Displacement)

If you want to press the connector directly onto a wire bundle without crimping individual pins:

  • Housing Part Number: 06SR-3S (suitable for 30 AWG wire)

There are three different connectors of the same family (1x 6-pin, 1x 5-pin 2x 3-pin). Keep that in mind, when ordering.

I was wondering if I can use PA14 or PA15 as enable pin for a step/dir listener interface?
They are both labelled direction.
The driver setup includes an DRV_CS pin, would that work as enable pin?

DRV8316Driver6PWM driver = DRV8316Driver6PWM(PHA_H, PHA_L, PHB_H, PHB_L, PHC_H, PHC_L, DRV_CS, false);

Another question about TIM8 as step-input:
The example code uses TIM8 as hardwaretimer to run motor.loopFOC and motor.move at 10kHz independently from the main loop.
Is it possible to use TIM8 for both or do I have to use a different method for the 10kHz loop?
(eg. comparing millis() with lastmillis )

Hi @o_lampe,

The DRV8316 class in out driver’s repo requires the SPI CS pin as the 7th argument. We can add the ENABLE pin too if needed (it shoulde be connected to the DRIVEROFF pins of the DRV8316) but the board does not have it wired.

Instead on driver disable it will put all the 6PWM outputs to low.

You can use any other timer for the 10kHz real-time loop. Any timer that is not used by the control and the sensors. For example TIM5.

Today, step and dir pins in simplefoc are not managed by timers but with interrupts and any pin of the STM32 could be used bot step or dir.
But stm32 allows using the timer ETR input to count the impulses and I hope to implement it soon, which will make it more robust, but also the users will have to use specific pins. That is why I’ve put the labels on microspora the way they are. Basically step is on the Timer8 ETR and the dir is any one of the remaining pins.

So to answer your question, at the moment you can use any combination of two available pins as step/dir and use the remaining one for enable.
In the future, you will use the tim8 etr as step, and one GPIO pin for dir (PA14 or PA15).

Better yet, use STM32HWEncoder which handles the dir signal in hardware as well. PA14/TIM8_CH2 for step, PA15/TIM8_CH1 for dir, PB6 for enable (which is TIM8_ETR, but doesn’t need to be). I added an encoder_mode setting in STM32HWEncoder a few months ago to allow using the step/dir mode:

ETR can be used to reset the counter on an index pulse, which would be useful for quadrature encoders, but not a big deal to do with interrupt since it doesn’t happen very often, and not necessary in step/dir mode.

The driver-enable signal in 3D printer context is a remain of the past, when drivers were at their limit just from sitting idle. Modern drivers can handle that much better.
But if it is required to boot the printer-FW before enabling the drivers, it becomes relevant again.

In previous cases, I just added a longer pause at the beginning of the arduino code. Enough time to let the main-controller boot.

That new code is already in the main repository?
How do I init the HWencoder for step-dirListener? Just by using the pin numbers and the library does it automatically?

:+1:
THX

Yep, set encoder_mode = TIM_ENCODERMODE_CLOCKPLUSDIRECTION_X1 before calling init and it just works. I was expecting to have to make a new class for it, but the setup was practically identical so that new variable is all that was needed.

I was looking for a wiring set that matches the microspora connector, I found several vendors on ebay selling readymade pigtails, but the prices per unit were high.
Then I found this asorted kit with JST SH1.0 wires and Dupont housings, which is my favourite for now. I guess you can find similar kits on Amazon, too.

That does look like a nice set. Especially having the wires and housings separate so you don’t have to pick them apart first to get the wire colors in the order you want.

The pigtail assemblies are super cheap on LCSC, so that’s a good option if you need other stuff too (shipping would be high if a few cables is all you need). Like this one is 5 cents LNN100-157128-150-3P | Rectangular Cable Assemblies | DEALON | LCSC
To search for others, click “rectangular cable assemblies” in the category line up top and set pitch 1mm (which is a couple of Chinese characters, but is the only parameter with 1mm as an option).