Analog input pins as DOs problem.

Hello all, I have an Arduino Uno R3 connected to a 4 digit, 7 segment display (the part number is not on the display but it has 6 pins in a row at the top back and 6 on the bottom if that helps). Anyhow, this display works fine when connected to 12 Uno DI pins. However, I thought it would be useful to connect the top 6 display pins to the Uno AI pins (using A0 to A5) to shorten up and simplify the wiring when the display is mounted on a breadboard shield.

So, I began switching the top display pin wires to the Uno AI pins one at a time starting with a connection going to A5 - it worked fine. Then went to A4, A3 and A2 with the next connections and all OK. The problem started with connecting to A1 - the display digit segment controlled by that connection was dead and same issue occurred with a similar connection to A0. I have tried the pinMode(A1, OUTPUT); statement but was of no help.

I guess the question is, is there something different about the A0 and A1 pins? I can't think of anything else to try and would appreciate any assistance.

TIA!

There should be no difference. Please post a schematic. Also your code, in code tags please...

Sorry, don't have a schematic but the code follows. As noted, the code works, (displaying time of day, temperature and humidity and, with an IR control to adjust the time); problem arises when switching display pin connections from digital pins to analogs. I wonder if the problem is in the SevSeg.h library??

/*Time of day clock showing hours & minutes plus temperature & humidity on 4 digit 7 segment display
   Uses a no-block timer "millisDelay" so display can be continually refreshed (required for non-flicker o/p)
   Uses IR remote reader to set current hours and minutes

  Requires the following Arduino libraries (for temperature & humidity sensor):
  - DHT Sensor Library: https://github.com/adafruit/DHT-sensor-library
  - Adafruit Unified Sensor Lib: https://github.com/adafruit/Adafruit_Sensor
*/

#include "DHT.h" //Humid & Temp sensor ("DHT")
#include <millisDelay.h> //Non-blocking delay library - for 2 second clock increment trigger
#include "SevSeg.h" //7 segment display //To display time, temperature & humidity
#include "IRremote.h" //IR receiver //For setting correct hours & minutes

int receiver = A0; // Signal Pin of IR receiver to Arduino Analog Pin A0
IRrecv irrecv(receiver);    // create instance of 'irrecv'
decode_results results;     // create instance of 'decode_results'

millisDelay clockDelay; //Initiate a delay object
SevSeg sevseg; //Initiate a seven segment controller object

#define DHTPIN A1     // Pin connected to the DHT sensor (use an AI as a DI as the display uses all the DI pins)
#define DHTTYPE DHT11   // DHT 11 type sensor

// Initialize DHT sensor.
DHT dht(DHTPIN, DHTTYPE);

int hours;
int minutes;
int seconds;
int displaytime;
int countr;

float t;
float h;

void setup() {

  Serial.begin(9600); // Initialize the serial printer (for debugging)
  dht.begin(); // Initialize the DHT sensor

  clockDelay.start(1000);  // start a 1 sec delay (1,000 msec)
  hours = 1; minutes = 0; seconds = 0; //Start with this time
  countr = 0; //If countr = 0, display time; if = 1, display temperature; if = 2, display humidity (& switch at 1 second intevals)

  byte numDigits = 4; //Set pin assignments for display

  pinMode(A1, OUTPUT); 

  /*byte digitPins[] = {2, 3, 4, 5}; //Original example program arrangement
    byte segmentPins[] = {6, 7, 8, 9, 10, 11, 12, 13};
  
  byte digitPins[] = {2, 5, 6, 13}; //Arrangement for connectors to go straight from display pins to Arduino w/o criss-crossing
  byte segmentPins[] = {3, 7, 11, 9, 8, 4, 12, 10};
*/
  
  byte digitPins[] = {A5, A2, A1, 13}; //Arrangement for top 6 display pins to connect to Arduino AI pins (to simplify & shorten wiring)
  
  byte segmentPins[] = {A4, 7, 11, 9, 8, A3, 12, 10};
  // All AIs work except A1 (and A0).

  // variable below indicates that 4 resistors were placed on the digit pins.
  // set variable to 1 if you want to use 8 resistors on the segment pins.
  bool resistorsOnSegments = 0;

  sevseg.begin(COMMON_CATHODE, numDigits, digitPins, segmentPins, resistorsOnSegments); //Initialize the display
  sevseg.setBrightness(90); //Doesn't seem to change brightness much
  irrecv.enableIRIn(); // Initialize the IR receiver
}

void loop() {

  // Check if delay has timed out - if so, increment clock by 2 seconds & read temperature & humidity
  if (clockDelay.justFinished()) { // Only returns TRUE once.
    clockDelay.start(2000);  // Restart delay - 2,000 ms

    seconds = seconds + 2;
    if (seconds == 60) {
      seconds = 0;  //Adjust minutes & hours accordingly
      minutes = minutes + 1;
    }
    if (minutes == 60) {
      minutes = 0;
      hours = hours + 1;
    }
    if (hours > 12) {
      hours = 1;
    }

    displaytime = hours * 100 + minutes; //Calculate time number to display

    countr = countr + 1; //To display next value
    if (countr == 3) {
      countr = 0; //Ranges from 0 to 2
    }

    if (countr == 1) { // Read temperature - takes about 250 mseconds
      // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
      // Read temperature as Celsius (the default)
      t = dht.readTemperature();
      t = t * 0.96; // Correction factor (as compared to other thermometers)
    }

    if (countr == 2) { //Read humidity
      h = dht.readHumidity();
      h = h * .95; // Humidity correction factor
    }
  }
  if (countr == 0) { //Display time (in hours & minutes)

    sevseg.setNumber(displaytime, 2); // 2nd variable sets decimal point position (0 for RHS digit up to 3 for LHS digit)
    sevseg.refreshDisplay(); // Must run repeatedly & rapidly for persistance of vision effect
  }

  if (countr == 1) { //Display temperature
    sevseg.setNumber(t, 1); // 2nd variable sets decimal point position (0 for RHS digit up to 3 for LHS digit)
    sevseg.refreshDisplay(); // Must run repeatedly & rapidly for persistance of vision effect
  }

  if (countr == 2) { //Display humidity
    sevseg.setNumber(h, 0); // 2nd variable sets decimal point position (0 for RHS digit up to 3 for LHS digit)
    sevseg.refreshDisplay();
  }

  if (irrecv.decode(&results)) { // Have we received an IR signal from remote control?

    if (results.value == 0xFFA857) { //VOL- remote button
      minutes = minutes - 1;
      seconds = 0;
    }
    if (results.value == 0xFF629D) { //VOL+ remote button
      minutes = minutes + 1;
      seconds = 0;
    }
    if (results.value == 0xFF22DD) { // Fast backward
      hours = hours - 1;
    }
    if (results.value == 0xFFC23D) { // Fast forward
      hours = hours + 1;
    }
    irrecv.resume(); // receive the next IR value
  }
}

Thanks for any suggestions!

The sketch is using A0 for an infrared receiver and A1 for the DHT pin. You can't also use them for the disply.

johnwasser:
The sketch is using A0 for an infrared receiver and A1 for the DHT pin. You can't also use them for the disply.

Thanks John, I just noticed that a minute ago. Forgot to change the pin assignments for the IR and DHT. :confused:

Doh!

If you had a schematic, you would have noticed. :slight_smile:

aarg:
If you had a schematic, you would have noticed. :slight_smile:

Workin' on it :slight_smile:
Do you have a recommendation for a schematic editor/simulator?
BTW, have just migrated from PicAxe to Arduino. Pretty nice so far but I do miss the debug capability.