Trouble with an ROV project

HI All,

I have been working on a ROV project for the past while.

I did one version of the code which did work but I felt that the program had grown arms and legs plus the code was way too complex than it needed to be.

So I started again. This time, I have written a library so that the motor type definitions and initialization are hidden away.

The problem I am having is that I can only seem to get the right motor (starboard) to work when I push the x-y joystick forwards. It is the same when the joystick is pushed left or right (port of starboard) - only the motor on the right works.

I have tried another motor and checked the continuity of the cables on the umbilical, which buzzed out ok. Changing the motor made no difference.

I am getting y values back of -10 and +10 when the joystick is pushed forwards.

The PWM signals are changing on both sides of the motor driver board (L298N)

The hardware that I am using is

Arduino R3
L298N x2
Arduino 2 axis joysticks x 2.

The code that I am using is

/// Include the necessary libraries
#include <motor.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#include <HardwareSerial.h>

// Define the pins for the joysticks
#define X_JOYSTICK_PIN A0 //Joystick input Port/Starboard pin
#define Y_JOYSTICK_PIN A1 //Joystick input Forward/Reverse pin
#define Z_JOYSTICK_PIN A2 //Joystick input Vertical up/down pin

// Define the pins for the L298N motor controllers
// Starboard Motor L298 Pins
#define stbdPWMPin 3 //PWM pin Starboard Motor
#define stbdIn3Pin 2 //Starboard Motor In3
#define stbdIn4Pin 4 //Starboard Motor In4

// Port Motor L298 Pins
#define prtPWMPin 6 //PWM pin Port Motor
#define prtIn1Pin 5 //Port Motor In1
#define prtIn2Pin 7 //Port Motor In2

//Vertical  Motor PWM Pins
#define vertPWMPin 10 //Vertical Motor PWM Pin
#define vertIn3Pin 8 //Vertical Motor In3 Pin
#define vertIn4Pin 9 //Vertical Motor In4 Pin

// Define variables to store the joystick values
float xValue;
float yValue;
float zValue;

float xMiddle, yMiddle, zMiddle;
float xMiddleHigh, xMiddleLow;
float yMiddleHigh, yMiddleLow;
float zMiddleLow, zMiddleHigh;


//define variables for the PWM values, In1, In2 (port motor), In3 In4 (starboard and vertical motors)
boolean prtIn1, prtIn2;
boolean stbdIn3, stbdIn4;
boolean vertIn3, vertIn4;
int prtPWM, stbdPWM, vertPWM;

// Define the motor objects for the motors
motor motorPort(prtPWMPin, prtIn1Pin, prtIn2Pin);
motor motorStbd(stbdPWMPin, stbdIn3Pin, stbdIn4Pin);
motor motorVert(vertPWMPin,vertIn3Pin, vertIn4Pin);

float fmap(float x, float in_min, float in_max, float out_min, float out_max)
{
  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

int absPWM (int PWM ){
  if (PWM < 0){
    PWM = abs(PWM);
    return PWM;
  }
  else {
    return PWM;
  }
}
// function to return a scaled value of -10 to +10V from the analogue pins
double scaled_value(int pin, int lower_lim, int upper_lim) {
  int raw = analogRead(pin);
  double scaled = fmap(raw, 0, 1023, lower_lim, upper_lim);
  //scaled = scaled + 1; // add 1 so that 0 not returned at minimum 
  return scaled;
}

void setup() {
  // Initialize the serial communication
  Serial.begin(9600);
  // Values for up/down joystick dead value
  zMiddle = 0.2;
  zMiddleHigh = zMiddle/2;
  zMiddleLow = 0 - zMiddleHigh;

  xMiddle = 0.2;
  xMiddleHigh = xMiddle/2;
  xMiddleLow = 0 - xMiddleHigh;

  yMiddle = 0.2;
  yMiddleHigh = yMiddle/2;
  yMiddleLow = 0 - yMiddleHigh;
}

void loop() {
  // Read the joystick values
  xValue = scaled_value(X_JOYSTICK_PIN, -10, 10);
  yValue = scaled_value(Y_JOYSTICK_PIN, -10, 10);
  zValue = scaled_value(Z_JOYSTICK_PIN, -10, 10);
  
  //delay(500);
  //Serial.println("X Value ");
  //Serial.print(xValue);
  delay(500);
  Serial.println("Y Value ");
  Serial.print(yValue);
  //delay(500);
  //Serial.println("Z Value ");
  //Serial.print(zValue);

  // Control the motors using the L298N motor controllers
  // For port & starboard motors
  //-10 V = forwards. 10V = backwards
  if (yValue < yMiddleLow) { //if Y joystick < 0 set motors forwards
    prtIn1 = HIGH;
    prtIn2 = LOW;
    stbdIn3 = HIGH;
    stbdIn4 = LOW;
    prtPWM = map(yValue, -10, 10, -255, 255);
    stbdPWM = map(yValue, -10, 10, -255, 255);
    //check if PWM values are -ve
    prtPWM = absPWM(prtPWM);
    stbdPWM = absPWM(stbdPWM);
    Serial.println ("PrtIn1");
    Serial.print(prtIn1);
    Serial.println ("PrtIn2");
    Serial.print(prtIn2);
    Serial.println("Prt PWM ");
    Serial.print(prtPWM);
    motorPort.setDirection(prtIn1, prtIn2);
    motorPort.speed(prtPWM);
    motorStbd.setDirection(stbdIn3, stbdIn4);
    motorStbd.speed(stbdPWM);
  } else if (yValue > yMiddleHigh) { // If Y Joystick > 0 set motors backwards
      prtIn1 = LOW;
      prtIn2 = HIGH;
      stbdIn3= LOW;
      stbdIn4 = HIGH;
      prtPWM = map(yValue, -10, 10, -255, 255);
      stbdPWM = map(yValue, -10, 10, -255, 255);
      prtPWM = absPWM(prtPWM);
      stbdPWM = absPWM(stbdPWM);
      Serial.println ("PrtIn1");
      Serial.print(prtIn1);
      Serial.println ("PrtIn2");
      Serial.print(prtIn2);
      Serial.println("Prt PWM ");
      Serial.print(prtPWM);
      motorPort.setDirection(prtIn1, prtIn2);
      motorPort.speed(prtPWM);
      motorStbd.setDirection(stbdIn3, stbdIn4);
      motorStbd.speed(stbdPWM);
  } else if (yValue >= yMiddleLow && yValue <= yMiddleHigh){ // If Y value == 0, stop both motors
      motorStbd.stop();
      motorPort.stop();
  }

  if (xValue > xMiddleHigh) { // If X value > 0, turn to starboard 
    prtIn1 = HIGH;
    prtIn2 = LOW;
    stbdIn3= LOW;
    stbdIn4 = LOW;
    prtPWM = map(xValue, -10, 10, -255, 255);
    prtPWM = absPWM(prtPWM);
    motorPort.setDirection(prtIn1, prtIn2);
    motorPort.speed(prtPWM);
    motorStbd.stop();
  } else if (xValue < xMiddleLow) { // If x value <0, turn to port
      prtIn1 = LOW;
      prtIn2 = LOW;
      stbdIn3= HIGH;
      stbdIn4 = LOW;
      stbdPWM = absPWM(stbdPWM);
      motorPort.stop();
      motorStbd.setDirection(stbdIn3, stbdIn4);
      motorStbd.speed(stbdPWM);
  } else if (xValue >= xMiddleLow && xValue <= xMiddleHigh){
      motorStbd.stop();
  }

  // For vertical motor
  //Serial.print("zValue: ");
  //Serial.println(zValue);
  //delay(500);
  if (zValue  > zMiddleHigh) { //If Z Value > 0, set vertical motor forwards
    vertIn3 = HIGH;
    vertIn4 = LOW;
    vertPWM = map(zValue, -10, 10, -255, 255);
    vertPWM = absPWM(vertPWM);
    motorVert.setDirection(vertIn3, vertIn4);
    motorVert.speed(vertPWM);
  } else if (zValue  < zMiddleLow){ // If Z Value < 0, set vertical motor backwards
      vertIn3 = LOW;
      vertIn4 = HIGH;
      vertPWM = map(zValue, -10, 10, -255, 255);
      vertPWM = absPWM(vertPWM);
      motorVert.setDirection(vertIn3, vertIn4);
      motorVert.speed(vertPWM);
  } else if (zMiddleLow >= zValue <= zMiddleHigh ){
      motorVert.stop();
  }
  

  // Print the motor speeds to the serial monitor for debugging
  //Serial.print("Port Motor Speed: ");
  //Serial.println(prtPWM);
  //Serial.print("Starboard Motor Speed: ");
  //Serial.println(stbdPWM);
  //Serial.print("Vertical Motor Speed: ");
  //Serial.println(vertPWM);

  // Add a small delay to prevent the motors from changing too quickly
  delay(100);
}

I have checked and double checked my code, but I can't see anything obvious.

Can anyone else see what the problem is please?

Update.

Sometimes the left motor works, and sometimes it doesn't. It seems that only one motor works at any one time.

I've also checked the 12V battery and it is giving a steady 12V at the L298N supply terminals.

Please post that library.

Hi,

Thanks for the reply. motor.cpp and motor.h pasted below.

Hope this helps,

motor.cpp

#include "motor.h"

motor:: motor(int pwmPin, int inPin1, int inPin2);

void motor::init(int pwm, int in1, int in2) {
  pwm = 0;
  in1= 0;
  in2 = 0;
  pinMode(inPin1, OUTPUT);
  pinMode(inPin2, OUTPUT);
  pinMode(pwmPin, OUTPUT);
  stop();
}

void motor::setDirection(boolean in1, boolean in2) {
  digitalWrite(inPin1, in1);
  digitalWrite(inPin2, in2);
}

void motor::stop() {
  digitalWrite(inPin1, LOW);
  digitalWrite(inPin1, LOW);
  speed(0);
}

void motor::speed(int aSpeed) {
  if (aSpeed >= 0) {
    analogWrite(pwmPin, aSpeed);
  }
}

// The following functions are not used here
// but could be useful in future
void motor::forward() {
  digitalWrite(inPin1, HIGH);
  digitalWrite(inPin1, LOW);
}

void motor::back() {
  digitalWrite(inPin1, LOW);
  digitalWrite(inPin1, HIGH);
}

motor.h
#ifndef MOTOR_H
#define MOTOR_H
#include <Arduino.h>

struct motor {
    int pwmPin;
    int inPin1;
    int inPin2;

  public:
    motor( int pwmPin, int inPin1, int inPin2);
    void setDirection(boolean, boolean);
    void stop();
    void speed(int);
    void motor::forward();
    void motor::back();
  private:
    void init(int pwm, int in1, int in2);
};
#endif

Your sketch does not compile. If you have not done so yet, set Compiler Warnings to All in file / preferences.

These are the errors and warnings that I get:











In file included from /home/wim/Downloads/arduino-1.8.19/portable/sketchbook/forum.arduino.cc/1254477/1254477.post01/1254477.post01.ino:2:0:
/home/wim/Downloads/arduino-1.8.19/portable/sketchbook/forum.arduino.cc/1254477/1254477.post01/motor.h:15:10: warning: extra qualification 'motor::' on member 'forward' [-fpermissive]
     void motor::forward();
          ^~~~~
/home/wim/Downloads/arduino-1.8.19/portable/sketchbook/forum.arduino.cc/1254477/1254477.post01/motor.h:16:10: warning: extra qualification 'motor::' on member 'back' [-fpermissive]
     void motor::back();
          ^~~~~
/home/wim/Downloads/arduino-1.8.19/portable/sketchbook/forum.arduino.cc/1254477/1254477.post01/1254477.post01.ino: In function 'void loop()':
/home/wim/Downloads/arduino-1.8.19/portable/sketchbook/forum.arduino.cc/1254477/1254477.post01/1254477.post01.ino:193:25: warning: comparisons like 'X<=Y<=Z' do not have their mathematical meaning [-Wparentheses]
   } else if (zMiddleLow >= zValue <= zMiddleHigh ) {
              ~~~~~~~~~~~^~~~~~~~~
In file included from /home/wim/Downloads/arduino-1.8.19/portable/sketchbook/forum.arduino.cc/1254477/1254477.post01/motor.cpp:1:0:
/home/wim/Downloads/arduino-1.8.19/portable/sketchbook/forum.arduino.cc/1254477/1254477.post01/motor.h:15:10: warning: extra qualification 'motor::' on member 'forward' [-fpermissive]
     void motor::forward();
          ^~~~~
/home/wim/Downloads/arduino-1.8.19/portable/sketchbook/forum.arduino.cc/1254477/1254477.post01/motor.h:16:10: warning: extra qualification 'motor::' on member 'back' [-fpermissive]
     void motor::back();
          ^~~~~
/home/wim/Downloads/arduino-1.8.19/portable/sketchbook/forum.arduino.cc/1254477/1254477.post01/motor.cpp:3:49: warning: declaration of 'motor::motor(int, int, int)' outside of class is not definition [-fpermissive]
 motor:: motor(int pwmPin, int inPin1, int inPin2);
                                                 ^
/home/wim/Downloads/arduino-1.8.19/portable/sketchbook/forum.arduino.cc/1254477/1254477.post01/motor.cpp: In member function 'void motor::init(int, int, int)':
/home/wim/Downloads/arduino-1.8.19/portable/sketchbook/forum.arduino.cc/1254477/1254477.post01/motor.cpp:5:22: warning: parameter 'pwm' set but not used [-Wunused-but-set-parameter]
 void motor::init(int pwm, int in1, int in2) {
                      ^~~
/home/wim/Downloads/arduino-1.8.19/portable/sketchbook/forum.arduino.cc/1254477/1254477.post01/motor.cpp:5:31: warning: parameter 'in1' set but not used [-Wunused-but-set-parameter]
 void motor::init(int pwm, int in1, int in2) {
                               ^~~
/home/wim/Downloads/arduino-1.8.19/portable/sketchbook/forum.arduino.cc/1254477/1254477.post01/motor.cpp:5:40: warning: parameter 'in2' set but not used [-Wunused-but-set-parameter]
 void motor::init(int pwm, int in1, int in2) {
                                        ^~~
/tmp/ccCdbODE.ltrans0.ltrans.o: In function `global constructors keyed to 65535_0_1254477.post01.ino.cpp.o.2115':
<artificial>:(.text.startup+0x68): undefined reference to `motor::motor(int, int, int)'
<artificial>:(.text.startup+0x7c): undefined reference to `motor::motor(int, int, int)'
<artificial>:(.text.startup+0x90): undefined reference to `motor::motor(int, int, int)'
collect2: error: ld returned 1 exit status
exit status 1
Error compiling for board Arduino Mega or Mega 2560.

I will look further a little later.

Thanks for the reply.

I do have the compiler setting on "All"

The only errors I see when I compile are

H:\Arduino\ROV_Code_AI_Generated_Aduino_Joysticks\ROV_Code_AI_Generated_Aduino_Joysticks.ino: In function 'void loop()':
H:\Arduino\ROV_Code_AI_Generated_Aduino_Joysticks\ROV_Code_AI_Generated_Aduino_Joysticks.ino:194:25: warning: comparisons like 'X<=Y<=Z' do not have their mathematical meaning [-Wparentheses]
} else if (zMiddleLow >= zValue <= zMiddleHigh ){
~~~^

So I don't understand why you have so many errors????

motor:: does not belong in the .h file; look at how you did the other function prototypes

As the message states, this is a declaration; you need an implementation in the .cpp file; e.g. something like which will actually assign the pins to the fields of the struct

motor:: motor(int pwmPin, int inPin1, int inPin2)
{
  this->pwmPin = pwmPin;
  this->inPin1 = inPin1;
  this->inPin2 = inPin2;
}

Because of the above error, you will also get this one at the end

And lastly

The processor does not think like a human :slight_smile:

 } else if (zMiddleLow >= zValue && zValue <= zMiddleHigh ) {

Note:
I do not know why you don't see the warnings (and the error) that I did see. Did you post the correct files?

With those warnings / errors out of the way, a last comment. You never call the init() method of the motor objects so you don't set your pins to the correct mode (OUTPUT); that is probably the cause of your problems. If you try to do it (e.g. add motorPort.init(0, 0, 0); to setup()) you get an error

/home/wim/Downloads/arduino-1.8.19/portable/sketchbook/forum.arduino.cc/1254477/1254477.post01/1254477.post01.ino: In function 'void setup()':
1254477.post01:88:25: error: 'void motor::init(int, int, int)' is private within this context
   motorPort.init(0, 0, 0);
                         ^
In file included from /home/wim/Downloads/arduino-1.8.19/portable/sketchbook/forum.arduino.cc/1254477/1254477.post01/1254477.post01.ino:2:0:
/home/wim/Downloads/arduino-1.8.19/portable/sketchbook/forum.arduino.cc/1254477/1254477.post01/motor.h:18:10: note: declared private here
     void init(int pwm, int in1, int in2);
          ^~~~

The init() method should be public if you want to access it from the main sketch.

Thanks for your help so far.

Yes, I have posted the correct files.

I have made a few changes to the .cpp and .h file, including making the ::init proc public.

But I am getting the errors:-

H:\Arduino\ROV_Code_AI_Generated_Aduino_Joysticks\ROV_Code_AI_Generated_Aduino_Joysticks.ino: In function 'void setup()':
H:\Arduino\ROV_Code_AI_Generated_Aduino_Joysticks\ROV_Code_AI_Generated_Aduino_Joysticks.ino:88:40: error: 'void motor::init(int, int, int)' is private within this context
motorPort.init(prtPWM, prtIn1, prtIn2);
^
In file included from H:\Arduino\ROV_Code_AI_Generated_Aduino_Joysticks\ROV_Code_AI_Generated_Aduino_Joysticks.ino:3:0:
H:\Arduino\libraries\Motor/motor.h:18:10: note: declared private here
void init(int pwm, int in1, int in2);
^~~~
H:\Arduino\ROV_Code_AI_Generated_Aduino_Joysticks\ROV_Code_AI_Generated_Aduino_Joysticks.ino:89:43: error: 'void motor::init(int, int, int)' is private within this context
motorStbd.init(stbdPWM, stbdIn3, stbdIn4);
^
In file included from H:\Arduino\ROV_Code_AI_Generated_Aduino_Joysticks\ROV_Code_AI_Generated_Aduino_Joysticks.ino:3:0:
H:\Arduino\libraries\Motor/motor.h:18:10: note: declared private here
void init(int pwm, int in1, int in2);
^~~~
H:\Arduino\ROV_Code_AI_Generated_Aduino_Joysticks\ROV_Code_AI_Generated_Aduino_Joysticks.ino:90:43: error: 'void motor::init(int, int, int)' is private within this context
motorVert.init(vertPWM, vertIn3, vertIn4);
^
In file included from H:\Arduino\ROV_Code_AI_Generated_Aduino_Joysticks\ROV_Code_AI_Generated_Aduino_Joysticks.ino:3:0:
H:\Arduino\libraries\Motor/motor.h:18:10: note: declared private here
void init(int pwm, int in1, int in2);
^~~~

exit status 1

Compilation error: 'void motor::init(int, int, int)' is private within this context

motor.h

#ifndef MOTOR_H
#define MOTOR_H
#include <Arduino.h>

struct motor {
    int pwmPin;
    int inPin1;
    int inPin2;
    int pwmValue;
    boolean inValue1, inValue2;

  public:
    motor( int pwmPin, int inPin1, int inPin2);
    void setDirection(boolean, boolean);
    void stop();
    void speed(int);
    void motor::forward();
    void motor::back();
    void init(int pwm, boolean in1, boolean in2);
};
#endif

motor.cpp

#include "motor.h"

motor:: motor(int pwmPin, int inPin1, int inPin2);

void motor::init(int pwm, int in1, int in2) {
  pwmValue = pwm;
  inValue1 = in1;
  inValue2 = in2;
  pinMode(inPin1, OUTPUT);
  pinMode(inPin2, OUTPUT);
  pinMode(pwmPin, OUTPUT);
  stop();
}

void motor::setDirection(boolean in1, boolean in2) {
  digitalWrite(inPin1, in1);
  digitalWrite(inPin2, in2);
}

void motor::stop() {
  digitalWrite(inPin1, LOW);
  digitalWrite(inPin1, LOW);
  speed(0);
}

void motor::speed(int aSpeed) {
  if (aSpeed >= 0) {
    analogWrite(pwmPin, aSpeed);
  }
}

// The following functions are not used here
// but could be useful in future
void motor::forward() {
  digitalWrite(inPin1, HIGH);
  digitalWrite(inPin1, LOW);
}

void motor::back() {
  digitalWrite(inPin1, LOW);
  digitalWrite(inPin1, HIGH);
}

I've also tried commenting out the #include <motor.h>, then saving it, but I still get the same error.

Any suggestions???

I suspect that you suffer from a cache problem.

They easiest work around is to start a new sketch and next paste the content of your current ino file in there. Save under a different name it and compile.

The better, but longer way

  1. Enable verbose output during compilation in file / preferences.
  2. Compile.
  3. Once the compile is complete, copy the output into a text editor for easier search / analysis (notepad will do).
  4. You will find directories ....\sketches\long number.
  5. Close the IDE.
  6. Navigate to the ....\sketches directory and delete the one with the matching long number.

I don't have access to IDE 2.x nor to a Windows system at the moment so this is from memory.

Note:
The directory might be hidden; if so, you'll have to enable "show hidden stuff" under options in windows explorer.

Thanks for the reply.

I have looked at the text output from the compiler and can't see any mention of the sketches folders. See below:

FQBN: arduino:avr:uno
Using board 'uno' from platform in folder: C:\Arduino-IDE-Workspace\Arduino-IDE\Settings\packages\arduino\hardware\avr\1.8.6
Using core 'arduino' from platform in folder: C:\Arduino-IDE-Workspace\Arduino-IDE\Settings\packages\arduino\hardware\avr\1.8.6

Detecting libraries used...
C:\Arduino-IDE-Workspace\Arduino-IDE\Settings\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Arduino-IDE-Workspace\Arduino-IDE\Settings\packages\arduino\hardware\avr\1.8.6\cores\arduino -IC:\Arduino-IDE-Workspace\Arduino-IDE\Settings\packages\arduino\hardware\avr\1.8.6\variants\standard C:\Users\RH9485\AppData\Local\Temp\arduino\sketches\19CC16E54C686070E37CF14A80D47A5E\sketch\ROV_Code_AI_Generated_Aduino_Joysticks.ino.cpp -o nul
Alternatives for motor.h: [Motor]
ResolveLibrary(motor.h)
-> candidates: [Motor]
C:\Arduino-IDE-Workspace\Arduino-IDE\Settings\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Arduino-IDE-Workspace\Arduino-IDE\Settings\packages\arduino\hardware\avr\1.8.6\cores\arduino -IC:\Arduino-IDE-Workspace\Arduino-IDE\Settings\packages\arduino\hardware\avr\1.8.6\variants\standard -IH:\Arduino\libraries\Motor C:\Users\RH9485\AppData\Local\Temp\arduino\sketches\19CC16E54C686070E37CF14A80D47A5E\sketch\ROV_Code_AI_Generated_Aduino_Joysticks.ino.cpp -o nul
Alternatives for LiquidCrystal_I2C.h: [LiquidCrystal I2C@1.1.2]
ResolveLibrary(LiquidCrystal_I2C.h)
-> candidates: [LiquidCrystal I2C@1.1.2]
C:\Arduino-IDE-Workspace\Arduino-IDE\Settings\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Arduino-IDE-Workspace\Arduino-IDE\Settings\packages\arduino\hardware\avr\1.8.6\cores\arduino -IC:\Arduino-IDE-Workspace\Arduino-IDE\Settings\packages\arduino\hardware\avr\1.8.6\variants\standard -IH:\Arduino\libraries\Motor -IH:\Arduino\libraries\LiquidCrystal_I2C C:\Users\RH9485\AppData\Local\Temp\arduino\sketches\19CC16E54C686070E37CF14A80D47A5E\sketch\ROV_Code_AI_Generated_Aduino_Joysticks.ino.cpp -o nul
Alternatives for Wire.h: [Wire@1.0]
ResolveLibrary(Wire.h)
-> candidates: [Wire@1.0]
C:\Arduino-IDE-Workspace\Arduino-IDE\Settings\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Arduino-IDE-Workspace\Arduino-IDE\Settings\packages\arduino\hardware\avr\1.8.6\cores\arduino -IC:\Arduino-IDE-Workspace\Arduino-IDE\Settings\packages\arduino\hardware\avr\1.8.6\variants\standard -IH:\Arduino\libraries\Motor -IH:\Arduino\libraries\LiquidCrystal_I2C -IC:\Arduino-IDE-Workspace\Arduino-IDE\Settings\packages\arduino\hardware\avr\1.8.6\libraries\Wire\src C:\Users\RH9485\AppData\Local\Temp\arduino\sketches\19CC16E54C686070E37CF14A80D47A5E\sketch\ROV_Code_AI_Generated_Aduino_Joysticks.ino.cpp -o nul
C:\Arduino-IDE-Workspace\Arduino-IDE\Settings\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Arduino-IDE-Workspace\Arduino-IDE\Settings\packages\arduino\hardware\avr\1.8.6\cores\arduino -IC:\Arduino-IDE-Workspace\Arduino-IDE\Settings\packages\arduino\hardware\avr\1.8.6\variants\standard -IH:\Arduino\libraries\Motor -IH:\Arduino\libraries\LiquidCrystal_I2C -IC:\Arduino-IDE-Workspace\Arduino-IDE\Settings\packages\arduino\hardware\avr\1.8.6\libraries\Wire\src H:\Arduino\libraries\Motor\motor.cpp -o nul
C:\Arduino-IDE-Workspace\Arduino-IDE\Settings\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Arduino-IDE-Workspace\Arduino-IDE\Settings\packages\arduino\hardware\avr\1.8.6\cores\arduino -IC:\Arduino-IDE-Workspace\Arduino-IDE\Settings\packages\arduino\hardware\avr\1.8.6\variants\standard -IH:\Arduino\libraries\Motor -IH:\Arduino\libraries\LiquidCrystal_I2C -IC:\Arduino-IDE-Workspace\Arduino-IDE\Settings\packages\arduino\hardware\avr\1.8.6\libraries\Wire\src H:\Arduino\libraries\LiquidCrystal_I2C\LiquidCrystal_I2C.cpp -o nul
C:\Arduino-IDE-Workspace\Arduino-IDE\Settings\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Arduino-IDE-Workspace\Arduino-IDE\Settings\packages\arduino\hardware\avr\1.8.6\cores\arduino -IC:\Arduino-IDE-Workspace\Arduino-IDE\Settings\packages\arduino\hardware\avr\1.8.6\variants\standard -IH:\Arduino\libraries\Motor -IH:\Arduino\libraries\LiquidCrystal_I2C -IC:\Arduino-IDE-Workspace\Arduino-IDE\Settings\packages\arduino\hardware\avr\1.8.6\libraries\Wire\src C:\Arduino-IDE-Workspace\Arduino-IDE\Settings\packages\arduino\hardware\avr\1.8.6\libraries\Wire\src\Wire.cpp -o nul
C:\Arduino-IDE-Workspace\Arduino-IDE\Settings\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Arduino-IDE-Workspace\Arduino-IDE\Settings\packages\arduino\hardware\avr\1.8.6\cores\arduino -IC:\Arduino-IDE-Workspace\Arduino-IDE\Settings\packages\arduino\hardware\avr\1.8.6\variants\standard -IH:\Arduino\libraries\Motor -IH:\Arduino\libraries\LiquidCrystal_I2C -IC:\Arduino-IDE-Workspace\Arduino-IDE\Settings\packages\arduino\hardware\avr\1.8.6\libraries\Wire\src C:\Arduino-IDE-Workspace\Arduino-IDE\Settings\packages\arduino\hardware\avr\1.8.6\libraries\Wire\src\utility\twi.c -o nul
Generating function prototypes...
C:\Arduino-IDE-Workspace\Arduino-IDE\Settings\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Arduino-IDE-Workspace\Arduino-IDE\Settings\packages\arduino\hardware\avr\1.8.6\cores\arduino -IC:\Arduino-IDE-Workspace\Arduino-IDE\Settings\packages\arduino\hardware\avr\1.8.6\variants\standard -IH:\Arduino\libraries\Motor -IH:\Arduino\libraries\LiquidCrystal_I2C -IC:\Arduino-IDE-Workspace\Arduino-IDE\Settings\packages\arduino\hardware\avr\1.8.6\libraries\Wire\src C:\Users\RH9485\AppData\Local\Temp\arduino\sketches\19CC16E54C686070E37CF14A80D47A5E\sketch\ROV_Code_AI_Generated_Aduino_Joysticks.ino.cpp -o C:\Users\RH9485\AppData\Local\Temp\3030387099\sketch_merged.cpp
C:\Arduino-IDE-Workspace\Arduino-IDE\Settings\packages\builtin\tools\ctags\5.8-arduino11/ctags -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives C:\Users\RH9485\AppData\Local\Temp\3030387099\sketch_merged.cpp
Compiling sketch...
"C:\Arduino-IDE-Workspace\Arduino-IDE\Settings\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7/bin/avr-g++" -c -g -Os -Wall -Wextra -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\Arduino-IDE-Workspace\Arduino-IDE\Settings\packages\arduino\hardware\avr\1.8.6\cores\arduino" "-IC:\Arduino-IDE-Workspace\Arduino-IDE\Settings\packages\arduino\hardware\avr\1.8.6\variants\standard" "-IH:\Arduino\libraries\Motor" "-IH:\Arduino\libraries\LiquidCrystal_I2C" "-IC:\Arduino-IDE-Workspace\Arduino-IDE\Settings\packages\arduino\hardware\avr\1.8.6\libraries\Wire\src" "C:\Users\RH9485\AppData\Local\Temp\arduino\sketches\19CC16E54C686070E37CF14A80D47A5E\sketch\ROV_Code_AI_Generated_Aduino_Joysticks.ino.cpp" -o "C:\Users\RH9485\AppData\Local\Temp\arduino\sketches\19CC16E54C686070E37CF14A80D47A5E\sketch\ROV_Code_AI_Generated_Aduino_Joysticks.ino.cpp.o"
H:\Arduino\ROV_Code_AI_Generated_Aduino_Joysticks\ROV_Code_AI_Generated_Aduino_Joysticks.ino: In function 'void setup()':
H:\Arduino\ROV_Code_AI_Generated_Aduino_Joysticks\ROV_Code_AI_Generated_Aduino_Joysticks.ino:88:40: error: 'void motor::init(int, int, int)' is private within this context
motorPort.init(prtPWM, prtIn1, prtIn2);
^
In file included from H:\Arduino\ROV_Code_AI_Generated_Aduino_Joysticks\ROV_Code_AI_Generated_Aduino_Joysticks.ino:3:0:
H:\Arduino\libraries\Motor/motor.h:18:10: note: declared private here
void init(int pwm, int in1, int in2);
^~~~
H:\Arduino\ROV_Code_AI_Generated_Aduino_Joysticks\ROV_Code_AI_Generated_Aduino_Joysticks.ino:89:43: error: 'void motor::init(int, int, int)' is private within this context
motorStbd.init(stbdPWM, stbdIn3, stbdIn4);
^
In file included from H:\Arduino\ROV_Code_AI_Generated_Aduino_Joysticks\ROV_Code_AI_Generated_Aduino_Joysticks.ino:3:0:
H:\Arduino\libraries\Motor/motor.h:18:10: note: declared private here
void init(int pwm, int in1, int in2);
^~~~
H:\Arduino\ROV_Code_AI_Generated_Aduino_Joysticks\ROV_Code_AI_Generated_Aduino_Joysticks.ino:90:43: error: 'void motor::init(int, int, int)' is private within this context
motorVert.init(vertPWM, vertIn3, vertIn4);
^
In file included from H:\Arduino\ROV_Code_AI_Generated_Aduino_Joysticks\ROV_Code_AI_Generated_Aduino_Joysticks.ino:3:0:
H:\Arduino\libraries\Motor/motor.h:18:10: note: declared private here
void init(int pwm, int in1, int in2);
^~~~

Using library Motor in folder: H:\Arduino\libraries\Motor (legacy)
Using library LiquidCrystal I2C at version 1.1.2 in folder: H:\Arduino\libraries\LiquidCrystal_I2C
Using library Wire at version 1.0 in folder: C:\Arduino-IDE-Workspace\Arduino-IDE\Settings\packages\arduino\hardware\avr\1.8.6\libraries\Wire
exit status 1

Compilation error: 'void motor::init(int, int, int)' is private within this context

I have tried clearing out the cache folders in my Users - App Data folder but this has made no difference.

Also tried uninstalling Arduino IDE - also made no difference

Suggestions?? Apart from "Give up"?

I will look later (probably in 12 hours time); the code with my suggestions compiles here though I have to admit that I did not put your library in the libraries folder. Uninstalling the IDE does not always help as it does not clean out everything that might be relevant.

Spam containing reply removed, along with the reply to the spam.

OK, last attempt.

  1. Remove the library that you have created from the libraries directory; copy the two files to a safe place.
  2. Compile your sketch; it should fail.
  3. Copy the two files of your library to the sketch directory where the ino file lives. The IDE should pick it up automatically (IDE 2.x), else close and open the IDE again; you should have three tabs pages.
  4. [edit] forgot to mention
    Change the include line to #include "motor.h"
    [/edit]
  5. Compile again.

Notes:
You might have deleted the wrong directory under sketches; you can safely delete all subdirectories under sketches.
You replied to a spammer :wink:

Ok. Thanks.

Didn't realize that the last reply was spam.

I've moved the library files to the same folder as the sketch (and it is the correct folder - I named it with "Copy" on the end)

Changed #include <motor.h> to #Include "motor.h"

It still doesn't compile. I just get a message saying that it cannot find "motor.h"

Any other suggestions??

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.