Hi, I just purchased a teensy 4.0 and I am attempting to use some code I had previously written for my Arduino Uno. I want to use the teensy because of the high speed and form factor. The issue I am running into is while I am using the verify button of the Arduino IDE it gives the following error:
I have also pasted the full .ino file that I am attempting to compile for the Teensy 4.0 below. What I have been finding about this is that it most likely cannot link the .cpp file for some reason which is where the variable that it says is missing is declared. I just do not know how to get the compiler to correctly pull the .cpp file.
Code:
C:\Users\Maxunm\AppData\Local\Temp\arduino_build_213092\sketch\GoOnUserInput.ino.cpp.o: In function `Encoder::update(Encoder_internal_state_t*)':
C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Encoder/Encoder.h:309: undefined reference to `Encoder::interruptArgs'
C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Encoder/Encoder.h:309: undefined reference to `Encoder::interruptArgs'
C:\Users\Maxunm\AppData\Local\Temp\arduino_build_213092\sketch\GoOnUserInput.ino.cpp.o: In function `Encoder::Encoder(unsigned char, unsigned char)':
C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Encoder/Encoder.h:97: undefined reference to `Encoder::interruptArgs'
collect2.exe: error: ld returned 1 exit status
Error compiling for board Teensy 4.0.
I have also pasted the full .ino file that I am attempting to compile for the Teensy 4.0 below. What I have been finding about this is that it most likely cannot link the .cpp file for some reason which is where the variable that it says is missing is declared. I just do not know how to get the compiler to correctly pull the .cpp file.
Code:
#include <SPI.h>
#include <AMIS30543.h>
//#define ENCODER_OPTIMIZE_INTERRUPTS
#include "C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Encoder\Encoder.h"
const uint8_t amisDirPin = 5;//2;
const uint8_t amisStepPin = 6;//3;
const uint8_t amisSlaveSelect = 4;//SS;
AMIS30543 stepper;
int a = 500;
int b = 270;
int usr;
Encoder slidePos(15, 16); //Use pins 15 + 16 as they are both interupt pins.
void setup()
{
SPI.begin();
stepper.init(amisSlaveSelect);
// Drive the NXT/STEP and DIR pins low initially.
digitalWrite(amisStepPin, LOW);
pinMode(amisStepPin, OUTPUT);
digitalWrite(amisDirPin, LOW);
pinMode(amisDirPin, OUTPUT);
// Give the driver some time to power up.
delay(1);
// Reset the driver to its default settings.
stepper.resetSettings();
// Set the current limit. You should change the number here to
// an appropriate value for your particular system.
stepper.setCurrentMilliamps(a);
// Set the number of microsteps that correspond to one full step.
stepper.setStepMode(4);
// Enable the motor outputs.
stepper.enableDriver();
Serial.begin(9600);
stepper.sleep();
}
void loop()
{
while (!Serial) {}
Serial.print("0 for zero, 6 prints current pos, any other # probes\n"); //Going to write a
while (!Serial.available()) {}
while (!Serial.available()) {}
usr = Serial.parseInt();
if (usr == 0) {
slidePos.write(0);
} else if (usr == 6) {
output();
} else {
// Step in the default direction 1000 times.
stepper.sleepStop();
setDirection(0);
for (unsigned int x = 0; x < 100; x++)
{
step();
}
stepper.setCurrentMilliamps(b);
for (unsigned int x = 0; x < 9900; x++)
{
step();
}
output();
delay(500);
stepper.setCurrentMilliamps(1500);
setDirection(1);
// Step in the other direction 1000 times.
for (unsigned int x = 0; x < 10000; x++)//while(slidePos.read()>3)
{
step();
}
stepper.setCurrentMilliamps(a);
Serial.println();
stepper.sleep();
}
}
// Sends a pulse on the NXT/STEP pin to tell the driver to take
// one step, and also delays to control the speed of the motor.
void step()
{
// The NXT/STEP minimum high pulse width is 2 microseconds.
digitalWrite(amisStepPin, HIGH);
delayMicroseconds(3);
digitalWrite(amisStepPin, LOW);
delayMicroseconds(3);
// The delay here controls the stepper motor's speed. You can
// increase the delay to make the stepper motor go slower. If
// you decrease the delay, the stepper motor will go fast, but
// there is a limit to how fast it can go before it starts
// missing steps.
delayMicroseconds(600);
}
// Writes a high or low value to the direction pin to specify
// what direction to turn the motor.
void setDirection(bool dir)
{
// The NXT/STEP pin must not change for at least 0.5
// microseconds before and after changing the DIR pin.
delayMicroseconds(1);
digitalWrite(amisDirPin, dir);
delayMicroseconds(1);
}
void output() {
Serial.print("mm: ");
Serial.print((float)slidePos.read() / 200.0, DEC);
Serial.print("\npulses: ");
Serial.print(slidePos.read(), DEC);
Serial.print("\n");
}