Motor not reaching position

Hi W&L,

I recently purchased a W&L Bricktronics Shield from Tindie.com and am using it with an Arduino Uno as well as an Arduino 101.

Sensors work perfectly, but I am having trouble controlling my NXT motors. I tried the “MotorPositionControl” sketch and stripped the loop down to

void loop() {
  Serial.print("Using goToPositionWaitForArrival(540)...");
  m.goToPositionWaitForArrival(540);
  Serial.println("done");
  m.delayUpdateMS(2000);
}

When I run it, the “done” is never printed and the motor is constantly running. I have experimented with the Encoder code and it seems, it cannot read the pins/does not get interrupts so that encoder.stateand encoder.position remain zero.

Any ideas what I could be missing/doing wrong are very much appreciated.

Cheers – TIM

Hi Tim, thanks for the message. Sounds like you’re pretty far along in your investigation, and it sounds like you’re trying all the right things. One thing you might try is to try using the other motor port.

If you could post your entire sketch, I’ll give it a try tomorrow on our reference hardware platform and get back to you.

Hi Matthew, thanks for your quick reply.

The same happens for Motors 1 or 2. Find the stripped sketch below (the forum does not allow uploading an .ino :slight_smile:

// Bricktronics Example: MotorPositionControlBricktronicsShield
// http://www.wayneandlayne.com/bricktronics
//
// TIM's setup:
// * Arduino Uno
// * Bricktronics Shield
// * 2x Lego NXT Motors
// * 9V 2A wall adaptor
// * Arduino 1.8.16
// * https://github.com/wayneandlayne/BricktronicsShield
// * https://github.com/wayneandlayne/BricktronicsMotor
//

#include <BricktronicsShield.h>
#include <BricktronicsMotor.h>

BricktronicsMotor m(BricktronicsShield::MOTOR_2);

void setup() {
  while (!Serial);
  Serial.begin(115200);
  Serial.println("Init");

  BricktronicsShield::begin();

  m.begin();
}

void loop() {
  Serial.print("Current position: ");
  Serial.println(m.getPosition());
  Serial.print("Using goToPositionWaitForArrival(540)...");
  m.goToPositionWaitForArrival(540);
  Serial.println("done");
  m.delayUpdateMS(2000);
}

And here goes the Serial output:

Init
Current position: 0
Using goToPositionWaitForArrival(540)...

Thanks Tim, sorry for the delay getting back to you. I’ll give this a shot on our reference hardware in the next few days and reach out again.

Hi Matthew, no worries, I have been travelling and had not mich time to work on this project.

Today I tried another version. For this I made the member Encoder.encoder public:

#include <BricktronicsShield.h>
#include <BricktronicsMotor.h>

BricktronicsMotor m(BricktronicsShield::MOTOR_1);

#define MOTOR_POSITION 90

void setup() {
  while (!Serial);
  Serial.begin(115200);
  Serial.println("Init");

  BricktronicsShield::begin();

  m.begin();
  m.goToPosition(MOTOR_POSITION);
}

void loop() {
  Serial.print("Current position: "); Serial.print(m.getPosition()); Serial.print(" Current state: "), Serial.println(m._encoder.encoder.state);
  m.update();
  if (m.settledAtPosition(MOTOR_POSITION)) {
    Serial.println("done");
  }
}

which yields

Init
Current position: 0 Current state: 0
Current position: 0 Current state: 0
Current position: 0 Current state: 0
Current position: 0 Current state: 0
.
.
.

endlessly.

I also tried macros ENCODER_USE_INTERRUPTS and ENCODER_DO_NOT_USE_INTERRUPTS – to no avail.

Also adding a

m.pidPrintValues();

in loop() just yields repeated:

SET:90.00
INP:0.00
OUT:255.00

Hi Matthew, problem (finally) solved:

For whatever reason Vcc was not properly connected to the NXT Motor socket pins. With no power, comes no encoder signal… I soldered an extra wire and it works now!

Thanks for your help and also your kind offer to replace the board.

Cheers – TIM

Oh great! Was this on a Bricktronics Shield, Megashield, or Motor Driver board? Was the soldering defect on the socket itself or on the chip that drives the motor?

It was a Bricktronics Shield.

I could not find the exact defect location, since I do not have proper equipment just some basic tools :frowning: