B-G431B-ESC1: Beginner guide + I2C guide

Hi all,

This is a beginner guide for how to setup the B-G431B-ESC1 with SimpleFOC.

The B-G431B-ESC1 is a small but powefull esc at a great price point. More information on the specs can be found on the site of ST.

The board consists of main board (the ESC) and a daughterboard which is actually a programmer. This can be seen at the figure below:

Step 1: Install PlatformIO
This board is the most easily configured in PlatformIO. You can follow the install instructions of PlatformIO here and a great video of the installation made by @Owen_Williams can be watched here.

Step 2: Add board
Once PlatformIO is configured, the board needs to be added. This board is not a standard board so it needs to be added manually. Therefore the following files made by @Owen_Williams need to be added to the following folders:

  1. Go to C:\Users\wittecactus\.platformio\packages\framework-arduinoststm32\variants\
  2. Copy the folder called board_template and name it DISCO_B_G431B_ESC1
  3. Add/replace the following files: PeripheralPins.c, PinNamesVar.h, ldscript.ld, variant.cpp, variant.h
  4. Go to C:\Users\wittecactus\.platformio\packages\framework-arduinoststm32 and update the boards.txt file
  5. Go to C:\Users\wittecactus\.platformio\platforms\ststm32\boards and add this json file.

Now the board is configured.

Step 3: Run your code! :slight_smile:

Open a new project in PlatformIO. Select your newly configured board. PlatformIO works a bit differenty from the standard Arduino IDE. You put your arduino code in src/main.cpp and configure the libraries in platformio.ini . It is important that you put the following code in your platformio.ini file to make the board working and have serial communication:

Platformio.ini code:

;   Library options: dependencies, extra library storages
;   Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[env:disco_b_g431b_esc1]
platform = ststm32
board = disco_b_g431b_esc1
framework = arduino
monitor_speed = 115200

build_flags =
    -D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC
    -D PIO_FRAMEWORK_ARDUINO_NANOLIB_FLOAT_PRINTF
    -D PIO_FRAMEWORK_ARDUINO_USB_HIGHSPEED_FULLMODE

lib_deps=
    askuric/Simple FOC @ ^2.0.2
    SPI
    Wire 

For your main code do not fotget:

  1. To add #include<Arduino.h> to your sketch (for platformIO)
  2. Use the following 6PWM driver setup: BLDCDriver6PWM driver = BLDCDriver6PWM(PHASE_UH, PHASE_UL, PHASE_VH, PHASE_VL, PHASE_WH, PHASE_WL);

The rest is regular SimpleFOC code! Watch the following guide from @Owen_Williams for more information to make your first SimpleFOC code. For extra information check the datasheet and the following topic.

I hope that I can help some people with this guide! If the real pro’s want to add something or correct me somewhere just say it! Good luck everyone!

Sidenote: I hope to update this guide soon with I2C support.

Greetings,

Wittecactus

6 Likes

Hi all,

I2C Guide

This small update is for getting the I2C working on the B-G431B-ESC1. It is still a bit experimental and sometimes buggy so I will update it again when necessary.

Hardware:

Solder the following pads:

Hardware

It is recommended to use pull-up resistors.

Software:

In the file PeripheralPins.C, uncomment the following lines:

Uncomment

In the file Variant.h, change or add following lines (sometimes also works when you leave out this step but this seems to be more consistent.

Add

Then in your platformio.ini file you must remove the build flags from the previous post and the following flags:

build_flags =
    -D PIN_WIRE_SDA=PB7
    -D PIN_WIRE_SCL=PB8

Other tips:

  • Use the Platform.IO: Clean button to be sure that you are working with a clean configuration.
  • Sometimes it can be useful to add the build flags from the previous post.
  • Sometimes it can be useful to add Wire.setClock(400000);.
  • First add power to the board, then connect it with USB.
  • Remove power when uploading new sketch.
  • To get accurate sensor data, check with external power supply instead of USB power.

Greetings and good luck,

Wittecactus

2 Likes

@Wittecactus - great writeup!
I’ve pushed your changes into my PR (to stm32duino) with this commit. When the PR gets merged your changes will be part of the board definition.

I’ve been thinking about your intermittent i2c problem and I think the hall pullups (10K) are not sufficient for SDA/SCL. Did you add additional pullups externally? You can test this out by pushing a couple of 2.2 or 4.7K into your 2.54mm connector that I can see in your picture.

1 Like

Hi @Owen_Williams,

Really cool to see the changes added! :slight_smile:

Yes I added 4.7K external resistors! It looks like when the power comes from the power supply that everything works fine, but when using power from usb, then the sensor gives incorrect velocity data. For now it is fine.

Greetings,

Wittecactus