not defined in scope only for certain boards

So i am running arduino 2:1.0.5 on a debian laptop, and I have a massive hangup.

I wrote some code and have it running on an arduino uno, yay. I then tried to run it on a basically clone project and it wouldn't complie. at first I assumed it was user error (copy pasted an old versoin of the code) but now i know for sure it is simply not compiling when i select a nano as my target board.

the sketch consists of two files, posted in their entirety here. basically it says all functions in the second file are out of scope when compileing for a nano w/ a 328, but compiles fine for a mega. It also won't compile for an UNO but I swear that is what is running in my old unit, which has an uno, so Is this an arduino bug or is there something subtle I am missing? please help, I am super late getting a little demo up and running for a friend.

I assume it has to do with my defines on the serial in sthe SMC area, which is a kludge, but please what is going on here. I tried find and replace with just Serial and it still won't compile. There is a massive amount of vestigal code in there due to my super rushed attempt to cobble this together from two working old examples.

I deleted many unused ISRs that are left out w/ #ifdef statements, but otherwise this is my code verbatim

main file

oops, lost the code,

main file

#include <Arduino.h>
#include <TimerHelpers.h>
#include "digitalWriteFast.h"

//minimal code to run two steppers
//using timer controlled pin, no ISR
//uses timers 1 and 2
//          1A  1B           2A  2B
//sanguino: D13 D12        $ D15 D14
//mini:     D9  D10        $ D11 D3
//mega      D11 D12 D13    $ D10 D9
//adding a second output pin that is phase locked
//for use with a second motor slaved to the first

  #ifndef cbi
  #define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
  #ifndef sbi
  #define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))

  // Modes of operation select 1
  #define CONTINUOUS          //Simply run continuosly

// change pulse pins based on board
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
byte step1 = 11;  //pb5/d11 mega
byte step1b = 8; //slave motor step pin
byte step2 = 10;
#define SERIAL_OUT Serial
#if defined(__AVR_ATmega328P__) || defined(__AVR_ATmega168__)
byte step1 = 9;  //pb1/d9 mini
byte step1b = 8;
byte step2 = 11;
#define SERIAL_OUT Serial

const byte dir1  = 10;
const byte dir2  = 12;
const byte enable = 13; //13 on mini in rig
const byte enableRXPin = 3; // pin from RX, check num
const byte isrFlagPin = 16;
const byte isrIntFlagPin = 17;
const byte speedPin1 = A4;
const byte speedPin2 = A5;

const byte guagePin1 = A0;
const byte guagePin2 = A1;

const int numStepsPerRev1 = 200*17/34; //dumb luck, its 100
const int numStepsPerRev2 = 200;
int microSteps1 = 4;
int microSteps2 = 16;
const unsigned int trainGearing1 = 5; //ratio of fast and slow motors
const unsigned int trainGearing2 = 1;

const unsigned int maxTurns1 = 100; //max num turns before action
const unsigned int maxTurns2 = 10; //max num turns before action
const unsigned long maxSteps1 = 100; //max steps before action
const unsigned long maxSteps2 = 27.78*200; //max steps before action

// end variables             ****

volatile unsigned int ocr1aHold = 65200; //try to protect updates
volatile unsigned int ocr2aHold = 200;

const unsigned long maxuSteps1 = maxSteps1*microSteps1;   //takes math out of isr
const unsigned long maxuSteps2 = maxSteps2*microSteps2;   //takes math out of isr
const unsigned int numuStepsPerRev1 = numStepsPerRev1*microSteps1;
const unsigned int numuStepsPerRev2 = numStepsPerRev2*microSteps2;

unsigned int uStepsElapsed1 = 0;
unsigned int uStepsElapsed2 = 0;
int rotElapsed1 = 0;     //ideally CCW or useful direction
int rotElapsed2 = 0;

boolean invertFlag = false;
boolean timeToPrint = true;
boolean timeUpdateOCR = true;
unsigned int printDelay = 5000; //millis between prints
unsigned long lastPrint = 0;
unsigned int ocrDelay = 500; //millis between speed updates
unsigned long lastOcr = 0;

int smcSpeedSetting = 0; //-3200 to 3200 speed setting

float guageVal1 = 0;
float guageVal2 = 0;
float guageScale1 = 127.1172;
float guageScale2 = 127.1172;

unsigned int RXRefresh = 10; // time between checks of RX command
unsigned int RXRefreshDelay = 50;
static unsigned int pumpEnableRX = 1500; //micros of RX flag
boolean pumpEnable = false;

void serialOCRASet();
void sensors(byte cnt, boolean cal);

void setup(){
  pinMode(enable, OUTPUT);
  pinMode(dir1, OUTPUT);
  pinMode(dir2, OUTPUT);
  pinMode(step1, OUTPUT);           //sets pin to output
  pinMode(step2, OUTPUT);
  pinMode(step1b, OUTPUT);
  pinMode(isrFlagPin, OUTPUT);
  pinMode(isrIntFlagPin, OUTPUT);
  digitalWrite(step1, HIGH);
  digitalWrite(step1b, HIGH);
  digitalWrite(step2, HIGH);
  digitalWrite(dir1, LOW);
  digitalWrite(dir2, HIGH);
  digitalWrite(enable, HIGH);  //active low stepper drivers

  pinMode(enableRXPin, INPUT);

   // setup stepper 1 on 1A using library
  Timer1::setMode(4, Timer1::PRESCALE_256, Timer1::TOGGLE_A_ON_COMPARE);
  Timer2::setMode(2, Timer2::PRESCALE_256, Timer2::TOGGLE_A_ON_COMPARE);

  OCR1A = 65000;
  OCR2A = 220;

  //Enable interrupts
  sbi(TIMSK1, OCIE1A);
  sbi(TIMSK2, OCIE2A);


void loop(){
  if((millis() - lastPrint) > printDelay) timeToPrint=true;
  #if defined VERBOSE_SERIAL
  if(timeToPrint){    // print something useful somewhere

  if((millis() - lastOcr) > ocrDelay) timeUpdateOCR=true;
  // if(timeUpdateOCR && Serial.available()>3){
    ocr1aHold = (analogRead(speedPin1))/5+50;
    ocr2aHold = (analogRead(speedPin2))/5+13;
    smcSpeedSetting = map(analogRead(speedPin2), 0, 1023, 3200, 0);
  sensors(3, false);

  // check RC input to turn on/off pump
  if(RXRefresh < millis()) {
    pumpEnableRX = pulseIn(enableRXPin, HIGH, 250000); // 40hz?
    RXRefresh = millis() + RXRefreshDelay;
  // if over halfway but also reasonably valid, enable the pump
  if(pumpEnableRX>1500 && pumpEnableRX<2500) pumpEnable = true;
  else if(pumpEnableRX<=1500 && pumpEnableRX>800) pumpEnable = false;
  else if(pumpEnableRX==0) pumpEnable = false; // if no pulse found, assume bad things

  if(pumpEnable) digitalWrite(enable, LOW); // low is enable
  if(!pumpEnable) {
    digitalWrite(enable, HIGH); // shut it down
    motorBrake(10);             // send a 10 of 32 motor brake command

void serialOCRASet(){
  ocr1aHold = Serial.parseInt();
  ocr2aHold = Serial.parseInt();
  SERIAL_OUT.print("OCR1Ahold = ");
  SERIAL_OUT.print("OCR2Ahold = ");


void sensors(byte cnt, boolean cal)  {
  static float offset1 = 36;
  static float offset2 = 60;

  float pAvg1 = analogRead(guagePin1);
  float pAvg2 = analogRead(guagePin2);

  for (byte i = 1; i<cnt; i++){
    //delay(5); questionable

  float pIn1=pAvg1/cnt; //0-1024
  float pIn2=pAvg2/cnt;


  //pressure = constrain(pIn/PRESSURE_SENSITIVITY, 0, 100);
  guageVal1 = pIn1/guageScale1;
  guageVal2 = pIn2/guageScale2;

  if(cal) {
    offset1 = guageVal1*guageScale1;
    offset2 = guageVal2*guageScale2;

    // #ifdef ISR1AMARKER
    // digitalWriteFast(isrFlagPin, HIGH);
    // #endif
    // gearing steps has been hit, note code only works if
    // usteps per turn is a multiple of the train gearing
    if ((uStepsElapsed1 % trainGearing1) == 0){digitalWriteFast(step1b, HIGH);}
    else {digitalWriteFast(step1b, LOW);}
            //only increments every other time
    if (digitalReadFast(step1) == HIGH){
      OCR1A = ocr1aHold;
      if (uStepsElapsed1 == numuStepsPerRev1){  //full turn has been completed
        // #ifdef ISR1AMARKER
        // digitalWriteFast(isrIntFlagPin, HIGH); //show you are inside if() loop
        // #endif
            //reset step counter
        uStepsElapsed1 = 0;
            //increment total turns
        rotElapsed1 += 1;

    #ifdef ISR2AMARKER
    digitalWriteFast(isrFlagPin, HIGH);
            //only increments every other time
    if (digitalReadFast(step2) == HIGH){
      OCR2A = ocr2aHold;
      if (uStepsElapsed2 == numuStepsPerRev2){  //full turn has been completed
        #ifdef ISR2AMARKER
        digitalWriteFast(isrIntFlagPin, HIGH); //show you are inside if() loop
            //reset step counter
        uStepsElapsed2 = 0;
            //increment total turns
        rotElapsed2 += 1;
      #ifdef ISR2AMARKER
      digitalWriteFast(isrIntFlagPin, LOW);
    #ifdef ISR2AMARKER
    digitalWriteFast(isrFlagPin, LOW);


One quick test would be to load up a simple hello world type example and stick the serial print line inside #ifdef's that match those in this sketch and see which ones cause it to not print. Then at least you know you've got an issue with those.

second file (2 total)

#include <SoftwareSerial.h>
#define rxPin 3     // pin 3 connects to SMC TX
#define txPin 4     // pin 4 connects to SMC RX
#define resetPin 5  // pin 5 connects to SMC nRST
#define errPin 6    // pin 6 connects to SMC ERR
SoftwareSerial SMC_SERIAL = SoftwareSerial(rxPin, txPin);
// some variable IDs
#define ERROR_STATUS 0
#define LIMIT_STATUS 3
#define TARGET_SPEED 20
#define INPUT_VOLTAGE 23
#define TEMPERATURE 24

// some motor limit IDs

#define SMC_SERIAL Serial

// read a serial byte (returns -1 if nothing received after the timeout expires)
int readByte(){
    char c;
    if(SMC_SERIAL.readBytes(&c, 1) == 0){ return -1; }
    return (byte)c;
// required to allow motors to move
// must be called when controller restarts and after any error
void exitSafeStart(){
// speed should be a number from -3200 to 3200
void setMotorSpeed(int speed){
    if (speed < 0)
        SMC_SERIAL.write(0x86); // motor reverse command
        speed = -speed; // make speed positive
        SMC_SERIAL.write(0x85); // motor forward command
    SMC_SERIAL.write(speed & 0x1F); // same as mod 32 to get low byte
    SMC_SERIAL.write(speed >> 5);

unsigned char setMotorLimit(unsigned char limitID, unsigned int limitValue){
    SMC_SERIAL.write(limitValue & 0x7F);
    SMC_SERIAL.write(limitValue >> 7);
    return readByte();

// returns the specified variable as an unsigned integer.
// if the requested variable is signed, the value returned by this function
// should be typecast as an int.
unsigned int getVariable(unsigned char variableID){
    return readByte() + 256 * readByte();

void smcSetup()

    SMC_SERIAL.write(0xAA); // send baud-indicator byte
    //setMotorLimit(FORWARD_ACCELERATION, 4);
    //setMotorLimit(REVERSE_ACCELERATION, 10);
    //setMotorLimit(DECELERATION, 20);
    // clear the safe-start violation and let the motor run

void motorBrake(unsigned char brake){
    // immediatly brake by specified amount 0-32
    // 0 coast 32 hard brake

This "arduino 2:1.0.5" is an extremely outdated and non-standard version of the Arduino IDE. Due to insufficient licensing documentation in the Arduino IDE, they have not been able to add the recent Arduino IDE versions to the package manager. You should try installing Arduino IDE 1.8.3 downloaded from:

so that we can be sure we're not trying to help you with a bug that was already fixed.