Digital Outputs Unreliable?
I am using a D21G board, with some very basic code, but the digital outputs 1 & 2 are not firing reliably.
Here is my sequence of events: Turn on power supply, plug in USB cord, upload provided code, outputs fire normally, unplug USB, turn off power supply, wait 5 seconds, turn on power supply, code no longer fires outputs 1 & 2. Reuploading the code sometimes makes it work, but not usually. The industruino test code always works, so the arduino works. The code displays the text on screen correctly, just doesn't supply power to digital pin 1 or 2. The wiring is not an issue, and it never partially works (as in one output works, one doesn't)
Code:
#include <Indio.h>
#include <Wire.h>
#include <UC1701.h>
// Constants
const int analogInPin = A5; // Analog input pin that the button panel is attached to
const int backlightPin = 26; // PWM output pin that the LED backlight is attached to
const int buttonEnterPin = 24;
const int buttonUpPin = 25;
const int buttonDownPin = 23;
//TODO: Check Pin Status
enum DigitalPins {
PIN_None = 0,
PIN_Valve1Ext = 1,
PIN_Valve1Ret = 2,
PIN_Valve2Ext = 3,
PIN_Valve2Ret = 4,
PIN_Reed1Ext,
PIN_Reed1Ret,
PIN_Reed2Ext,
PIN_Reed2Ret
};
enum AnalogPins {
PIN_ANone,
PIN_RingProx1,
PIN_RingProx2,
PIN_AUnused3,
PIN_AUnused4
};
enum Columns {
COL_Cursor = 0,
COL_Title = 6 * 1,
COL_Option = 6 * 1,
COL_OptValue = 6 * 11,
COL_Count = 128
};
enum Lines {
LINE_Title = 0,
LINE_CurStart = 1,
LINE_CurEnd = 7,
LINE_Count = 8
};
static UC1701 lcd;
int backlightIntensity = 5; // LCD backlight intesity
void printAt(int pos, int line, String text) {
lcd.setCursor(pos, line);
lcd.print(text);
}
void clearScreen() {
for (int ln = 0; ln < LINE_Count; ln++) {
for (int col = 0; col < COL_Count; col++) {
printAt(col, ln, " ");
}
}
}
void setup() {
pinMode(1, OUTPUT);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(PIN_Reed1Ext, INPUT);
pinMode(PIN_Reed1Ret, INPUT);
pinMode(PIN_Reed2Ext, INPUT);
pinMode(PIN_Reed2Ret, INPUT);
pinMode(buttonEnterPin, INPUT);
pinMode(buttonUpPin, INPUT);
pinMode(buttonDownPin, INPUT);
pinMode(backlightPin, OUTPUT);
//Convert backlight intesity from a value of 0-5 to a value of 0-255 for PWM.
analogWrite(backlightPin, (map(backlightIntensity, 5, 1, 255, 0)));
//Setup the screen
lcd.begin();
clearScreen();
//Debugging
Serial.begin(9600);
printAt(20, 3, "Penn Automotive");
delay(500);
clearScreen();
}
void loop() {
while(digitalRead(buttonEnterPin) == LOW)
{
Indio.digitalWrite(PIN_Valve1Ext, HIGH);
Indio.digitalWrite(PIN_Valve1Ret, LOW);
printAt(5, 1, "PRESSED");
}
Indio.digitalWrite(PIN_Valve1Ext, LOW);
Indio.digitalWrite(PIN_Valve1Ret, HIGH);
printAt(5, 1, "RAISED!");
delay(1);
}
Hi Ryan, you need to setup the I/O pins using the Indio library, i.e. Indio.digitalMode(1, OUTPUT or INPUT);
as documented on https://github.com/Industruino/libraries#digital-io
Only the 4 pins of the backlight and buttons are directly connected to MCU pins so can be set with pinMode()
Your answer
Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!
Keep Informed
About This Forum
This community is for professionals and enthusiasts of our products and services.
Read GuidelinesQuestion tools
Stats
Asked: 1/8/18, 10:03 PM |
Seen: 2387 times |
Last updated: 1/8/18, 11:52 PM |
Thanks, for the quick response, I must have missed this when looking through the code samples.