Author: Francis Palustre Email: palusf1@unlv.nevada.edu
Date: Last modified on <6/16/2024>
Keywords: Arduino, Raspberry Pi, Python, C++
This tutorial's motivation is to learn how to apply bidirectional communication between a Raspberry Pi and Arduino to move a stepper motor with an AS5600 magnetic encoder attached.
Readers of this tutorial assumes the reader has the following background and interests:
* Know how to read and write Python and/or C++
* Know how to read and write using USB and I2C serial communication
* Know how to read and understand wiring diagrams
* This tutorial may also attract readers who are interested in creating motorized electronics that uses an Arduino and Raspberry Pi, or any similar devices
The rest of this tutorial is presented as follows and should be possible to gain a suitable understanding in a span of 1-2 hours:
To complete this tutorial, you'll need the following items:
Note:
To show the communication process, Python and C++ will be written for the Raspberry Pi to the Arduino. Although, for the examples below, Python will be used.
#The following is the python version
//The following is the c++ version
The wiring diagram applies to all examples.
The following code example is the Raspberry Pi telling the Arduino to rotate the stepper motor in 4 increments, while the encoder reads the current position of the motor.
The following code example is the Raspberry Pi telling the Arduino how many steps to rotate and how much it relates to the actual encoder value.
The following code example is the Raspberry Pi telling the Arduino to revert back to its original position if the stepper motor's shaft has been moved.