Changing pins in this seemingly difficult sketch..

The creator of this sketch is MIA but gives permission to change it…

I’m trying to change the PIN inputs to change them from the A0 - A6 to the Digital pins 2 - 7… I would like to use the Anlalog inputs for a LCD and other sensors…

/*
  Sketch for use with SimpleDyno
  Developed on Arduino Uno Platform
  DamoRC - 2013-2014
  
  ALWAYS use the Sketch distributed with each new version of SimpleDyno
  
  Transmits:
    1 x Session timestamp 
    1 x Interrupt timestamp and 1 x time interval since last interrupt for INT0 / Pin2 / RPM1
    1 x Interrupt timestamp and 1 x time interval since last interrupt for INT1 / Pin3 / RPM2
    6 x Analog Inputs (A0 and A1 are Voltage and Current, A2 and A3 are Temperature, A4 and A5 are open)
  Values are comma delimeted
  Baud rates selected in SD must match coded values in this Sketch.
 */

  const int NumPortsToRead = 6;
  int AnalogResult[NumPortsToRead];
  volatile unsigned long TimeStamp = 0;
  volatile unsigned long time1 = 0;
  volatile unsigned long time2 = 0;
  volatile unsigned long Oldtime1 = 0;
  volatile unsigned long Oldtime2 = 0;
  volatile unsigned long TempTime1 = 0;
  volatile unsigned long TempTime2 = 0;
  String AllResult = "";

void setup() {
  // Initialize serial communication
  // Ensure that Baud rate specified here matches that selected in SimpleDyno
  // Availailable Baud rates are:
  // 9600, 14400, 19200, 28800, 38400, 57600, 115200
  Serial.begin(9600);
  // Initialize interupts (Pin2 is interrupt 0 = RPM1, Pin3 in interrupt 1 = RPM2)
  attachInterrupt(0,channel1,FALLING);
  attachInterrupt(1,channel2,FALLING);
}

void loop() {
  AllResult = "";
  AllResult += micros();
  AllResult += ",";
  AllResult += TempTime1;
  AllResult += ",";
  AllResult += time1;
  AllResult += ",";
  AllResult += TempTime2;
  AllResult += ",";
  AllResult += time2;
  for (int Looper = 0; Looper < NumPortsToRead;Looper++){
    AnalogResult[Looper] = analogRead(Looper);
    AllResult += ",";
    AllResult += AnalogResult[Looper];
  }
  Serial.println (AllResult);
  Serial.flush();
  delay(1);
}

//Interrupt routine for RPM1
void channel1(){
  TempTime1 = micros();
  time1 = TempTime1-Oldtime1;
  Oldtime1 = TempTime1;
}

//Interrupt routine for RPM2
void channel2(){
    TempTime2 = micros();
  time2 = TempTime2-Oldtime2;
  Oldtime2 = TempTime2;
}

Thanks for looking!!!

Jon

for (int Looper = 0; Looper < NumPortsToRead;Looper++){
    AnalogResult[Looper] = analogRead(Looper);
    AllResult += ",";
    AllResult += AnalogResult[Looper];
  }

Change this to

for (int Looper = 2; Looper <= 7;Looper++){
    AnalogResult[Looper] = digitalRead(Looper);
    AllResult += ",";
    AllResult += AnalogResult[Looper];
  }

Although you should understand that if you have a sensor connected to those analog pins which output an analog signal, then connecting them to 2-7 WILL NOT WORK!!!

Oh and use pinMode() to initialize your pins

Deleted

RayLivingston:
Deleted

Dont think I didn’t see that!

Ps991: Dont think I didn't see that!

See what? :-)

RayLivingston: See what? :-)

What are you talking about?

Thanks for the quick help ps991!! Thanks also for also answering my unasked question if Analog inputs will work in Digital pins...

Cheers!

If you use digital pins 2 through 7 as input pins, you can forget about using pins 2 and 3 for the external interrupt pins.

Gotcha, I see that now Paul.. I think.. Damn I have so much to learn... ;)

"// Initialize interupts (Pin2 is interrupt 0 = RPM1, Pin3 in interrupt 1 = RPM2)"

I'm going to use the mic jack as my RPM pic ups as the program allows.. So this means I can free up Pins A4 and A5 for my LCD and Pin2 and 3 would not be needed as interrupts.. But I am also introducing 2 more sensors (Air Temperature, Humidity and Altitude).. I might be better off just using a 2nd arduino... Can I link 2 together if only one needs to be connected to the computer for collecting the data? The other would be a displayed weather and altitude station and just need power....

I got some reading to do...

Having a second Arduino is inexpensive but leads to interesting communications issues. They do not automatically link together. You will have to decide how they are to communicate, and then do the programming for the communication.

I would avoid the hardware serial pins since they are handy for debugging. Thus, you will have to decide whether to use SoftwareSerial, I2C, or some other method. What will the protocol be?

You can see an example where I used Software Serial to communicate with three Arduinos at http://home.comcast.net/~i.shef/site/?/page/Ian%27s_Arduino_Project/

However, what works for my situation (1 to 4096 Arduinos) does not necessarily apply to your situation (2 Arduinos), so take this as a proof of concept, not something you can build on.