Drive motor and read encoder-IIC

1.1 Explanation

Please read 《0. Motor introduction and usage》first to understand the motor parameters, wiring method, and power supply voltage you are currently using. To avoid improper operation and damage to the driver board or motor.

I2C and serial communication cannot be shared, only one can be selected.

The course uses the Arduino UNO board. And use is Arduino 1.8.5 IDE

Hardware wiring:

Motor4-channel motor drive board(Motor)
M2M-
V3V3
AH1A
BH1B
GGND
M1M+
4-channel motor drive boardArduino UNO
SDASDA
SCLSCL
GNDGND
5V5V

When the TYPE-B interface on the UNO motherboard is connected to a computer, you can directly open the serial port to view the printed data without connecting a USB to TTL serial port module.

Serial port configuration: Baud rate 115200, no parity check, no hardware flow control, 1 stop bit

Note: The serial port here is used to print data on the serial port assistant, not for communication with the driver board

1.2 Code analysis

If you need to drive the motor and observe the data, just modify the two numbers at the beginning of the program. No changes are required to the rest of the code.

This is used to store the parameters of the Yahboom motor. By modifying the MOTOR_TYPE parameter above, one-click configuration can be achieved.

In normally, do not modify the code here when using the Yahboom motor.

If you are using your own motor, or if a certain data needs to be modified according to your needs, you can check the course《1.2 Control command》 to understand the specific meaning of each command.

In the loop program, the speed of the four motors will be slowly increased from 0 to 1000. If the motor type is 4, that is, the motor without encoder, the motor's PWM is directly controlled.

At the same time, the data sent by the driver board is read and printed out at the same time.

After getting the data from the driver board, it is shifted, and the shift is required to get the correct data.

1.3 Experimental phenomenon

After the wiring is correct, click the upload button in the Arduino IDE to write the program to the Arduino board. After powering on the Arduino again, you can see that the motor will gradually speed up, then stop, and repeat.

At the same time, you can see the printed motor values changing continuously in the serial port monitor of the ardiono IDE.