Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- The Pololu Jrk 21v3 USB Motor Controller with Feedback is a versatile motor controller that supports various communication protocols like TTL serial, I2C, and USB. In this example, I'll provide you with an Arduino code to control a motor using the TTL serial interface. Note that this code assumes you are using an Arduino Uno or a similar board.
- First, connect the motor controller to the Arduino as follows:
- TX (Arduino) to RX (Motor Controller)
- RX (Arduino) to TX (Motor Controller)
- GND (Arduino) to GND (Motor Controller)
- Connect the motor to the motor controller's output and supply power to the motor controller as per your motor's requirements. Additionally, connect the feedback sensor (e.g., a potentiometer) to the motor controller's feedback input.
- Upload this code to your Arduino. The motor will move to the position 0 for 2 seconds, then move to the position 4095 for 2 seconds. This process will repeat indefinitely. You can change the target positions as needed within the range of 0 to 4095.
- */
- // Pololu Jrk 21v3 USB Motor Controller with Feedback
- // Example code for Arduino
- #include <SoftwareSerial.h>
- // Motor Controller Pins
- const int rxPin = 10; // Connect the RX pin of the motor controller to Digital Pin 10
- const int txPin = 11; // Connect the TX pin of the motor controller to Digital Pin 11
- // Create a SoftwareSerial object for communication with the motor controller
- SoftwareSerial jrkSerial(rxPin, txPin);
- void setup() {
- Serial.begin(9600); // Initialize the serial communication for debugging
- jrkSerial.begin(9600); // Initialize the software serial communication with the motor controller
- }
- void loop() {
- int target = 0; // Set target position (0-4095)
- setMotorTarget(target);
- delay(2000); // Wait for 2 seconds
- target = 4095; // Set target position (0-4095)
- setMotorTarget(target);
- delay(2000); // Wait for 2 seconds
- }
- void setMotorTarget(int target) {
- // Ensure target is within allowed range
- if (target < 0) {
- target = 0;
- } else if (target > 4095) {
- target = 4095;
- }
- // Send "Set Target" command (0xA3) followed by two data bytes (target split into two bytes)
- jrkSerial.write(0xA3);
- jrkSerial.write(target & 0x1F);
- jrkSerial.write((target >> 5) & 0x7F);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement