RobotZero and stepper

dnl · 12 · 1140

dnl

  • Full Member
  • ***
    • Posts: 12
    • View Profile
I saw the StarTracker tutorial and decided to try that out. I tried to build the RTC_GPS_IMU code, but soon found myself in dependency despair.

To make progress, I decomposed the effort into the IMU, steppers, and GPS. The IMU code works a treat!

The stepper motors, however, are just not moving.

The serial output appears as expected, but the motor doesn't actually move. I've tried the RobotZero with just the USB cable and USB + 1500mAh battery. I've tried the Motor1 and Motor2 ports with the appropriate code changes.

Code: [Select]
/**********************************************************************
 * RobotZero Peripheral Basics
 * This program illustrates the abilities of the RobotZero processor
 * board by spinning any attached motors while reading the
 * accelerometer data of the onboard 9-Axis sensor.
 *
 * NOTES:
 *   - Serial Monitor must be open for program to run.
 *   - Battery must be plugged in to power motors.
 *
 * Hardware by: TinyCircuits
 * Written by: Ben Rose & Laveréna Wienclaw for TinyCircuits
 *
 * Initialized: June 2019
 * Last modified: Jan 2020
 *
 * Modified by: DNL, Jan 2022
 **********************************************************************/

#include <Wire.h>

#define SerialMonitorInterface SerialUSB // for SAMD21 processors

void setup() {

  // Enable serial
  SerialMonitorInterface.begin( 9600 );
  while (!SerialMonitorInterface); // Halt everything until Serial Monitor is opened
  SerialMonitorInterface.println( "Motors" );

  // Enable Wire
  Wire.begin();

  // Initialize stepper motor driver
  stepperInit();
  delay( 100 );

}

void loop() {

  // Motors go forward
  SerialMonitorInterface.print( "Start..." );
  setMotorCurrent( 100 );
  setMotor( 1, 10 );
  delay( 1000 ); //delay to allow motors to move

  SerialMonitorInterface.println( "Stop." );
  setMotorCurrent( 1 );
  setMotor( 1, 0 );
  delay( 1000 );

}

Cluebats are most welcome!!!

« Last Edit: January 25, 2022, 11:00:49 PM by dnl »


lennevia

  • Administrator
  • Hero Member
  • *****
    • Posts: 357
    • View Profile
Hiya!

It looks like you're using a modified version of this example? - https://github.com/TinyCircuits/TinyCircuits-RobotZero-ASM2027/blob/master/examples/RobotZero-Basic-Motors-Wireling/RobotZero-Basic-Motors-Wireling.ino

Without me testing it, it looks like you're not following the pattern outlined with these functions:

Code: [Select]
void goForward(){
  setMotorCurrent(100);
  setMotor(1, 10);
  setMotor(2, -10);
}

void stopMotors(){
  setMotorCurrent(1);
  setMotor(1, 0);
  setMotor(2, 0);
}

The example you gave also doesn't compile without the header file (the stepperInit() function throws an error). I'd recommend going back to the example and commenting out the unneeded code so you can maintain the working components' order. Let me know if you need help with that!

Cheers,
Réna


dnl

  • Full Member
  • ***
    • Posts: 12
    • View Profile
That is the original source.

Sorry I wasn't clear. The stepper.ino file is present. The code compiles, links, downloads, and executes. Just no motor movement.

I removed everything unrelated to the steppers from setup() and loop() and "inlined" goForward() and stopMotors() functions to focus on the details for motor 1. I did the same type of pruning to use the IMU, and that functions perfectly.

But sure, I'll try it again.


dnl

  • Full Member
  • ***
    • Posts: 12
    • View Profile
[Post comment:  The "SPAM" protection and my Chrome browser hate each other. I have to post with empty code blocks and edit to add the code. This happened on the 1st post, too. The error claims Javascript needs to be enabled, but it is.]

I took the original, commented out all but the stepper code and added 2 lines to show sketch progress.
Code: [Select]
/**********************************************************************
 * RobotZero Peripheral Basics
 * This program illustrates the abilities of the RobotZero processor
 * board by spinning any attached motors or servos, while reading the
 * accelerometer data of the onboard 9-Axis sensor and Color
 * Sensor data for a Color Sensor Wireling attached to port 0.
 *
 * NOTES:
 *   - Serial Monitor must be open for program to run.
 *   - Battery must be plugged in to power motors.
 *
 * Hardware by: TinyCircuits
 * Written by: Ben Rose & Laveréna Wienclaw for TinyCircuits
 *
 * Initialized: June 2019
 * Last modified: Jan 2020
 **********************************************************************/

#include <Wire.h>
//#include <MotorDriver.h> // Download latest here: https://github.com/TinyCircuits/TinyCircuits-TinyShield_Motor_Library/archive/master.zip
//#include <Wireling.h>
//#include "Adafruit_TCS34725.h"  // The library used for the Color Sensor Wireling

//MotorDriver servo(15);// Value passed is the address- RobotZero is always address 15
#define SerialMonitorInterface SerialUSB // for SAMD21 processors
//int aX, aY, aZ, gX, gY, gZ, mX, mY, mZ, tempF; // 9-Axis variables
//uint16_t r, g, b, c, colorTemp, lux; // Color Sensor Wireling variables

//Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_700MS, TCS34725_GAIN_1X);

void setup() {
  // Enable and Power Wireling
  //Wireling.begin();
  //Wireling.selectPort(0);

  SerialMonitorInterface.begin(9600);
  while (!SerialMonitorInterface); // Halt everything until Serial Monitor is opened
  Wire.begin();

  // Initialize stepper motor driver
  stepperInit();

  // Initialize 9-Axis Sensor
  //IMUInit();
  delay(100);

  // Initialize servo driver
  //if(servo.begin(20000)){
    //while(1);
    //SerialMonitorInterface.println("Servo driver not detected!");
  //}

  // Initialize Color Sensor Wireling
  //if (tcs.begin()) {
    //SerialMonitorInterface.println("Found sensor");
  //} else {
    //SerialMonitorInterface.println("No TCS34725 found ... check your connections");
    //while (1);
  //}
}

void loop() {
  //tcs.setInterrupt(false); // Turn onboard Color Sensor Wireling LEDs off

  // Motors go forward
  SerialMonitorInterface.print( "Start..." );
  goForward();
 
  // Command all Servos to rotate
  //servo.writeCommand(COMMAND_SERVO_1,1000);
  //servo.writeCommand(COMMAND_SERVO_2,1000);
  //servo.writeCommand(COMMAND_SERVO_3,1000);
  //servo.writeCommand(COMMAND_SERVO_4,1000);
  delay(1000); //delay to allow motors and servos to move
 
  //tcs.setInterrupt(true); // Turn onboard Color Sensor Wireling LEDs on

  //SerialMonitorInterface.println(" ");
  //tcs.getRawData(&r, &g, &b, &c);
  //colorTemp = tcs.calculateColorTemperature(r, g, b);
  //lux = tcs.calculateLux(r, g, b);

  //SerialMonitorInterface.print("Color Temp: "); SerialMonitorInterface.print(colorTemp); SerialMonitorInterface.print(" K, ");
  //SerialMonitorInterface.print("Lux: "); SerialMonitorInterface.print(lux, DEC); SerialMonitorInterface.print(", ");
  //SerialMonitorInterface.print("R: "); SerialMonitorInterface.print(r, DEC); SerialMonitorInterface.print(", ");
  //SerialMonitorInterface.print("G: "); SerialMonitorInterface.print(g, DEC); SerialMonitorInterface.print(", ");
  //SerialMonitorInterface.print("B: "); SerialMonitorInterface.print(b); SerialMonitorInterface.print(", ");
  //SerialMonitorInterface.print("Clr: "); SerialMonitorInterface.print(c, DEC);
  //SerialMonitorInterface.println(" ");
 
  SerialMonitorInterface.println( "Stop" );
  stopMotors();
  //servo.writeCommand(COMMAND_SERVO_1,2000);
  //servo.writeCommand(COMMAND_SERVO_2,2000);
  //servo.writeCommand(COMMAND_SERVO_3,2000);
  //servo.writeCommand(COMMAND_SERVO_4,2000);
  delay(1000);

  // Read and print 9-Axis Accelerometer and Temperature data
  //(gyro and magentometer data can also be printed using the gX, gY, gZ, mX, mY, and mZ variables)
  //IMURead();
  //SerialMonitorInterface.print("X: ");
  //SerialMonitorInterface.print(aX);
  //SerialMonitorInterface.print(" Y: ");
  //SerialMonitorInterface.print(aY);
  //SerialMonitorInterface.print(" Z: ");
  //SerialMonitorInterface.print(aZ);
  //SerialMonitorInterface.print(" Temp: ");
  //SerialMonitorInterface.println(tempF);
}

void goForward(){
  setMotorCurrent(100);
  setMotor(1, 10);
  //setMotor(2, -10);
}

void stopMotors(){
  setMotorCurrent(1);
  setMotor(1, 0);
  //setMotor(2, 0);
}

Output occurs, but no stepper  movement. Tried with and without battery, tried both steppers in "motor 1" port.
Code: [Select]
$ arduino-cli monitor -p /dev/ttyACM0
Connected to /dev/ttyACM0! Press CTRL-C to exit.
Start...Stop
Start...Stop
Start...Stop
Start...Stop
Start...Stop
Start...Stop
Start...Stop

Cluebats still most welcome.

« Last Edit: January 27, 2022, 02:16:22 PM by dnl »


lennevia

  • Administrator
  • Hero Member
  • *****
    • Posts: 357
    • View Profile
After looking further into the code and previous revisions of the board, and being admittedly confused for a bit, I have a solution for you! So there are two main points.

1. Rev3 boards have the silkscreen swapped around, so Motor 1 is 2, and Motor 2 is 1. This is a little confusing, but you could make a more readable code fix using:

int motor1 = 2;
int motor2 = 1;


or you could directly change the pins in stepper.ino:

const int stepPin1 = 45; // this fix only works when using stepper motors, dc motors would require a different fix
const int dirPin1 = 30;
const int stepPin2 = 44;
const int dirPin2 = 27;


2. Both motors must be enabled for either to work and in this same vein of thought - you must send commands to both motors as well. You can set the 2nd motor speed to 0, but you do need to send something for motor 1 to move. These extra commands sending the stepSpeed to the second motor won't use any noticeable amount of power.

I hope that helps! We need to update our stepper.ino library and add some documentation on both of these points, so thank you for bringing this issue to our attentions.

Cheers,
Réna




dnl

  • Full Member
  • ***
    • Posts: 12
    • View Profile
Thanks for looking into this!

For the above, I just uncommented the other setMotor() calls.
Code: [Select]
void goForward(){
  setMotorCurrent(100);
  setMotor(1, 10);
  setMotor(2, -10);
}

void stopMotors(){
  setMotorCurrent(1);
  setMotor(1, 0);
  setMotor(2, 0);
}
Sadly, no stepper love.


lennevia

  • Administrator
  • Hero Member
  • *****
    • Posts: 357
    • View Profile
You do definitely need the battery to be plugged in. Do the steppers not work with the battery plugged in?

I attached the code I had working yesterday to this message.


dnl

  • Full Member
  • ***
    • Posts: 12
    • View Profile
I downloaded, built, loaded, and ran the code.
No stepper love. I suppose it's the HW...


dnl

  • Full Member
  • ***
    • Posts: 12
    • View Profile
I used a 3.7v battery and stepper motors from TinyCircuits; the motor are labeled "5V DC  25Ω".

Can/should/must I use a 5V battery to power the RobotZero when the steppers are used?


lennevia

  • Administrator
  • Hero Member
  • *****
    • Posts: 357
    • View Profile
The 3.7V batteries we supply should be sufficient. Are you still encountering issues?


dnl

  • Full Member
  • ***
    • Posts: 12
    • View Profile
I wasn't able to get the RobotZero to drive the steppers. The steppers worked OK on another platform.
I gave up on the RobotZero for the steppers. :(

I do have a nice GPS gadget running on a TinyScreen+. I've ordered a barometric pressure TinyShield and temperature Wireling to make an astrophotography gadget (UTC, Lat, Lon, barometric pressure, temp).


lennevia

  • Administrator
  • Hero Member
  • *****
    • Posts: 357
    • View Profile
I sent you an email to get you a replacement. If you're in the US, I might exchange the boards since I'd like to see what's going on with your board. 


 

SMF spam blocked by CleanTalk