Skip to main content

CAN Bus

In this tutorial, we will explore how to control the Aotenjo One board via CAN Bus and run closed loop angle control.

If you haven't set up the CAN Bus yet, please refer to the Aotenjo One CAN Bus tutorial for detailed instructions on wiring and configuration.

Prerequisites

In this tutorial, the following hardware is used:

You need a ST-LINK V2 Clone to upload the firmware to the board. You can purchase a cheap clone ST-LINK V2 under $5.

Installation

VScode with PlatformIO

You can install PlatformIO from the VSCode extension marketplace.

STM32CubeProgrammer

You need this to flash the firmware to the board.

Clone the repository

git clone https://github.com/aotenjo-xyz/master.git
cd master

Quickstart

  1. Connect the Aotenjo Master board to the ST-LINK V2 programmer.

    ST-LINK V2 <-> Aotenjo Master
    3.3V <---> 3.3V
    GND <---> GND
    SWDIO <---> SWDIO
    SWCLK <---> SWCLK
    RST <---> NRST
    info

    Unlike the blackpill board, you need to connect the NRST pin to the ST-LINK V2 programmer for STM32G4 series. Alternatively, you can press and hold the NRST button on the Aotenjo Master board during the upload process to achieve the same effect.

  2. Connect the ST-LINK V2 programmer to your computer.

  3. Open the project folder in VSCode.

  4. Click on the PlatformIO tab on the left sidebar and click on the Upload button to upload the firmware to the board.

  5. Disconnect the ST-LINK V2 programmer, then connect the JST XH cables for power and JST PH cables for CAN Bus between Aotenjo Master and Aotenjo One board/s.

  6. Connect the Aotenjo Master board to the computer via USB.

  7. Click on the PlatformIO tab on the left sidebar and click on the Monitor button to open the serial monitor. PlatformIO Monitor

  8. Turn on the power supply, and the motor will start rotating to initialize the FOC (Field Oriented Control).

  9. Input the following command in the serial monitor and press enter:

    M06.28

    The M0 motor will complete one full rotation and stop at the initial position. You can adjust the target angle by changing the value in radians. You can also rotate the motor in the opposite direction by entering a negative value, such as M0-6.28.

    To read the current angle of the M0 motor, enter:

    M0P

    To put the motor into sleep mode, use the following command:

    ESTOP

This is exactly how our winding machine is controlled using CAN Bus communication with Aotenjo Master and Aotenjo One boards! Hope you enjoy building your projects with Aotenjo!