Hello. Today I have made enclosures for two of my test motors, where the mt6701 encoder can be located.
I also wanted to control the motors from the outside, using arduino nano.
I found a library that works. But it doesn’t start with simplefoc.
Below are examples of a receiver and a transmitter, maybe someone will help
//send_arduino
#include <SoftwareSerial.h>
#include <GParser.h>
SoftwareSerial mySerial(10, 11); // RX, TX
#include "GBUS.h"
GBUS bus(&mySerial, 5, 20);
struct myStruct {
long val_l;
};
void setup() {
Serial.begin(9600);
Serial.setTimeout(5);
mySerial.begin(9600);
}
void loop() {
if (Serial.available());
long val = Serial.parseInt();
Serial.println(val);
myStruct data;
data.val_l=val;
bus.sendData(3, data);
delay(4000);
}
//read esp32
#include <SoftwareSerial.h>
SoftwareSerial mySerial(34, 4); // RX, TX
#include "GBUS.h"
GBUS bus(&mySerial, 3, 25);
struct myStruct {
int val_i;
};
void setup() {
Serial.begin(9600);
mySerial.begin(9600);
}
void loop() {
bus.tick();
if (bus.gotData()) {
myStruct data;
bus.readData(data);
Serial.println(data.val_i);
Serial.println();
}
}
these two examples work. I can send and receive data. But if I add an example of reception to Simplefoc, then it does not accept data. The engine is initialized at the same time. I wanted to use this communication library since up to 255 receivers can be connected with it :).
Mit freundlichen Grüßen
Iurii
Hey, nice enclosures!
In terms of the comms, it looks ok in principle, but there are couple of things to check:
SoftwareSerial, how does it work - if it uses too much CPU power then it cannot run alongside SimpleFOC…
On the SimpleFOC side, you can read the bus, but only in a “non-blocking” way. E.g. you have to work with something like
if (Serial.available()>=sizeof(int)) {
// handle the incoming value
}
i.e. code which checks that the amount of data available in the serial buffer equals to (or is larger than) the expected message length, and then only process the message once you know you can read all of it without blocking.
if the main loop of the SimpleFOC MCU has to wait on the Serial data, then the move() and loopFOC() won’t be called often enough and motor commutation will fail.