I’m working on a project (a self-balancing robot) that requires the use of two gimbal motors (iPower GM4108) with AS5048A magnetic sensors using SPI. To control them, I’d like to use two stacked SimpleFOCShields (v2.0.4) on a Wemos D1 R32. I’ve been successful at getting one or the other motor/sensor/shields to work, but have run into difficulties getting both sets working simultaneously, specifically due to the fact that the second one requires the use of either pin 11 or 13 for PWM C (the first set is using pin 6 for PWM C). Unfortunately, pins 11 and 13 are already being used for the magnetic sensors’ SPI (MOSI is pin 11, and SCK is pin 13), and so they are not available for PWM C.
I’ve come up with two possible solutions, but I’m not sure of the feasibility of either, so some advice (or other suggestions) would be greatly suggested.
First, would it be possible to move the SPI to other pins? I’ve seen references to SPI done in software, but that supposedly has speed constraints that would probably preclude its use in a self-balancing bot. But I’ve also seen reference (see page 12 at https://www.halloweenfreak.de/arduino/pdfs/D1_R32_ENG.pdf) to two SPI circuits within the ESP32, a VSPI that maps onto the labelled SPI pins on the Wemos (GPIO23, 19, 18 and 5), and an HSPI that uses different pins (GPIO13, 12, 14 and 15). Is it possibly to use the HSPI for the magnetic encoders (in order to free up pin 11 or 13 for use as PWM C), and if so how would that be accomplished in the program?
As a second possibility, would it be possible to solder a jumper wire between the central solder pad for PWM C and an unused pin on the shield (instead on jumping the central solder pad to the pads for pins 11 or 13)? For example, could a jumper wire be used to connect the central PWM C pad to pin 4 of the shield (GPIO17 on the Wemos, which can be used for PWM)?
Any advice you have on these two possibilities, or others, would be greatly appreciated!
To be clear, we do have two shields, but they are stacked on a single microcontroller. Am I correct in thinking that by “separate”, you mean that they can’t be stacked, but must be individually controlled by their own microcontrollers? That would make coordination between the microcontrollers difficult.
I think the SPI on ESP32 can be done on soft peripherals but your issue will be that I think there are already basically few or no free pins, on the Arduino Uno style shield.
Is I2C possible? The latency will be higher but the shields were designed for be used 2x I2C, not 2x SPI (afaik).
yes you do need two controllers. yes its a complicated problem. you need a third controller to command the two motor controllers using serial or i2c or canbus. your project is nontrivial. perhaps others on this board may have different opinions.
You’ll (of course) need to do the solder bridges on the shields appropriately.
Another thing you might want to explore is buying some simplefoc mini boards (they don’t stack) or just using the shields without stacking them. When ever I’ve used the shields, I’ve never stacked them e.g. if I’m using it with an stm blue pill or a nano style esp32
Thanks, Owen. You were right that remapping the SPI pins was a bit of a pain, but it DID work – we now have two fully controllable gimbals. I received your message when we were partway through remapping the HSPI, so we just continued in that direction (your way would have been a little easier).
For future readers: one of the big advantages of ESP32 is its PinMux - you can reassign SPI pins (and also the PWM outputs) to any (IO-capable) pins you like.
That’s a big difference to the other MCUs, where you’re typically limited to one or a few pin-choices for each peripheral.