Show Posts
Pages: [1] 2 3 ... 6
1  Using Arduino / Project Guidance / Re: Issues with LCD backlight and display on: November 26, 2013, 10:20:18 am
Good progress! I'll take a dab at the button code when I have time today. Have you tested the button code all by itself and make it do something?

Yea I've used this beffore here:

Code:
  State change detection (edge detection)
 
 Often, you don't need to know the state of a digital input all the time,
 but you just need to know when the input changes from one state to another.
 For example, you want to know when a button goes from OFF to ON.  This is called
 state change detection, or edge detection.
 
 This example shows how to use button state change to perform an action.
 
 The circuit:
 * Momentary pushbutton attached to digital pin 2 from +5V
 * 10K resistor attached to digital pin 2 from ground
 * Servo signal wire attached to digital pin 9
 * Servo power wire connected to 5v
 * Servo ground wire connected to ground
 
 Based off the public domain "State Change Detection" example provided with the
 Arduino software. Code edited 8-14-2011 by Will Lyon (SXRguyinMA) to remove
 the LED and add in a servo.
 
 For the purpose of
 "Integrating Electronics Into Your Next Proect" series of articles on TBCS
 www.thebestcasescenario.com
 
 */

// Include the servo library
#include <VarSpeedServo.h>

// Create a servo object to control a servo
VarSpeedServo myservo;

// this constant won't change:
const int  buttonPin = 2;    // the pin that the pushbutton is attached to


// Variables will change:
int buttonPushCounter = 0;   // counter for the number of button presses
int buttonState = 0;         // current state of the button
int lastButtonState = 0;     // previous state of the button

void setup() {
  // attach the Servo to pin 9
  myservo.attach(9);
  // make sure the servo starts off with the door closed
  myservo.slowmove(20, 15);
  // initialize the button pin as a input:
  pinMode(buttonPin, INPUT);
}


void loop() {
  // read the pushbutton input pin:
  int buttonState = digitalRead(buttonPin);
 
  // compare the buttonState to its previous state
  if (buttonState != lastButtonState) {
    // if the state has changed, increment the counter
    if (buttonState == HIGH) {
      // if the current state is HIGH then the button
      // wend from off to on:
      buttonPushCounter++;
    }
    else {
    }

    // save the current state as the last state,
    //for next time through the loop
    lastButtonState = buttonState;
  }
 
  // moves the servo every other button push by
  // checking the modulo of the button push counter.
  // the modulo function gives you the remainder of
  // the division of two numbers:
  if (buttonPushCounter % 2 == 0) {
   myservo.slowmove(170, 15);
  } else {
   myservo.slowmove(20, 15);
  }
}

I just swapped out the myservo.slowmove commands for the LCD/Serial commands and added the logging. I still can't get the button to do anything and now for some reason I noticed my flow isn't reading anymore. I forgot the 10k pulldown on D2 for the flow so I put that in now it just reads "0". I think something's interfereing with the interrupt function.
2  Using Arduino / Project Guidance / Re: Issues with LCD backlight and display on: November 25, 2013, 01:17:50 pm
OK I figured out the baclight issue - I needed to move this:

Code:
  pinMode(tempIn, INPUT);            // Set in temp to input
  pinMode(tempOut, INPUT);           // Set out temp to input
  pinMode(ambient, INPUT);           // Set ambient temp to input
  pinMode(flow, INPUT);              // Set flow pin to input
  pinMode(redPin, OUTPUT);           // Set red LED pin to output
  pinMode(grnPin, OUTPUT);           // Set green LED pin to output
  pinMode(buttonPin, INPUT);         // Set button pin to input
  attachInterrupt(0, rpm, RISING);   // Attach interrupt for flow meter on digital pin 2

to the TOP of the setup() function. All is good with that. Now all that's left is figuring out this button state thing.
3  Using Arduino / Project Guidance / Re: Issues with LCD backlight and display on: November 25, 2013, 11:14:54 am
I also put the button on digital 9 to get it off the analog seeing how D9 was open. The button press now does something but all it seems to do it freeze the Arduino lol. All LCD outputs and all serial outputs stop when I press the button. Would I be better off putting the button on another interrupt  so it takes immediate effect? Here's the code as it stands right now (compiles and uploads fine for me)

Code:
/*
   **Code for PC Liquid Cooling System Tester. Developed by
   Will Lyon - http://www.computersandcircuits.com
   **Designed to red an input and output temp sensor connected
   to the input and output of a radiator or water block to
   test cooling performance. Ambient temp included for baseline.
   **Flow meter can be used to determine rate of flow drop caused
   by each radiator or water block.
   ** Data is logged to an SD card in a CSV format.
*/

// Libraries
#include "math.h"
#include <LiquidCrystal.h>
#include <SD.h>

// LCD Pin Assignment
LiquidCrystal lcd(3, 4, 5, 6, 7, 8);

// Ints
volatile int NbTopsFan;
const int tempIn = A0;      // Input temp on analog 0
const int tempOut = A1;     // Output temp on analog 1
const int ambient = A2;     // Ambient temp on analog 2
const int grnPin = A4;      // LCD green LED on analog 4
const int redPin = A5;      // LCD red LED on analog 5
const int flow = 2;         // Flow meter on digital 2 (interrupt 0)
const int buttonPin = 9;    // Button input to digital 9
const int chipSelect = 10;  // CS pin to digital 10
int buttonPushCounter = 0;  // Int for button counter
int buttonState = 0;        // Current state of the button
int lastButtonState = 0;    // Previous state of the button
int val;
int Calc;
unsigned long previousMillis = 0;
long interval = 1000;

// Floats
float temp_in;
float temp_out;
float temp_amb;

// RPM Reading Code
typedef struct{
  char fantype;
  unsigned int fandiv;
}fanspec;

fanspec fanspace[3]={{0,1},{1,2},{2,8}};

char fan = 1;
void rpm ()
{
  NbTopsFan++;
}

// Setup
void setup() {
  
// Opening LCD Message
  digitalWrite(redPin, HIGH);        // Turn off red LCD LED
  digitalWrite(grnPin, LOW);         // Turn on green LCD LED
  lcd.begin(16,2);                   // Initialize LCD
  lcd.setCursor(0, 0);
  lcd.print(" Computers  And ");
  lcd.setCursor(0, 1);
  lcd.print("    Circuits    ");
  delay(2000);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print(" LIQUID COOLING ");
  lcd.setCursor(0, 1);
  lcd.print(" TESTING   UNIT ");
  delay(2000);
  
  Serial.begin(9600);              // Begin Serial at 9600
  while (!Serial) {
    ;
  }
  Serial.print("Initializing SD Card...");
  pinMode(10, OUTPUT);
  
  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed or not present");
  }
  Serial.println("SD Card initialized.");
  
  File dataFile = SD.open("datalog.csv", FILE_WRITE);
  if (dataFile) {
    dataFile.print("Temp In, Temp Out, Ambient, Flow");
    dataFile.println();
    dataFile.close();
  } else {
}
  
  pinMode(tempIn, INPUT);            // Set in temp to input
  pinMode(tempOut, INPUT);           // Set out temp to input
  pinMode(ambient, INPUT);           // Set ambient temp to input
  pinMode(flow, INPUT);              // Set flow pin to input
  pinMode(redPin, OUTPUT);           // Set red LED pin to output
  pinMode(grnPin, OUTPUT);           // Set green LED pin to output
  pinMode(buttonPin, INPUT);         // Set button pin to input
  attachInterrupt(0, rpm, RISING);   // Attach interrupt for flow meter on digital pin 2
}

void loop()  {
  temp_in = analogRead(tempIn);
  temp_in = (5.0 * temp_in * 10.0)/1024.0;
  temp_out = analogRead(tempOut);
  temp_out = (5.0 * temp_out * 10.0)/1024.0;
  temp_amb = analogRead(ambient);
  temp_amb = (5.0 * temp_amb * 10.0)/1024.0;
  delay(1000);;
  
  buttonState = digitalRead(buttonPin);
  if (buttonState != lastButtonState)
    if (buttonState == HIGH) {
      buttonPushCounter++;
    }
    else {
    }
    lastButtonState = buttonState;

  if (buttonPushCounter % 2 == 0) {   // Display data on LCD and serial monitor and save to SD card
    digitalWrite(grnPin, HIGH);       // Turn green LCD LED off
    digitalWrite(redPin, LOW);        // Turn red LCD LED on
    Serial.println("Now Recording");
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.write("   RECORDING    ");
    delay(1000);
    lcd.clear();

    // LCD Output
    lcd.setCursor(1, 0);
    lcd.print(" IN");
    lcd.setCursor(7, 0);
    lcd.print("OUT");
    lcd.setCursor(12, 0);
    lcd.print("L/HR");
    lcd.setCursor(0, 1);
    lcd.print(temp_in);
    lcd.setCursor(6, 1);
    lcd.print(temp_out);
  
    // SD Card Output
    File dataFile = SD.open("datalog.csv", FILE_WRITE);
    if (dataFile) {
      dataFile.print(temp_in);
      dataFile.print(",");
      dataFile.print(temp_out);
      dataFile.print(",");
      dataFile.print(temp_amb);
      dataFile.print(",");
      dataFile.print(Calc);
      dataFile.println();
      dataFile.close();
    }
    else {
      Serial.println("Error opening datalog.csv");
    }
  
    // Serial Output
    Serial.print(temp_in);
    Serial.print(",");
    Serial.print(temp_out);
    Serial.print(",");
    Serial.print(temp_amb);
    Serial.print(",");
    Serial.print(Calc);
    Serial.println();
  
    // RPM display info
    unsigned long currentMillis = millis();
    if(currentMillis - previousMillis > interval){
      previousMillis = currentMillis;
      digitalRead(flow);
    NbTopsFan = 0;
  //  sei();
    delay (1000);
  //  cli();
    lcd.setCursor(12, 1);
    Calc = ((NbTopsFan * 60)/fanspace[fan].fandiv);
    if (Calc < 1000) lcd.print (' ');
    if (Calc < 100) lcd.print (' ');
    if (Calc < 10) lcd.print (' ');
    lcd.print (Calc);
  } else {                            // Display info on LCD and serial monitor but do not write to SD card
      digitalWrite(redPin, HIGH);     // Turn red LCD LED off
      digitalWrite(grnPin, LOW);      // Turn green LCD LED on
      Serial.println("Not recording");
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.write(" NOT  RECORDING ");
      delay(1000);
  
    // LCD Output
      lcd.setCursor(1, 0);
      lcd.print(" IN");
      lcd.setCursor(7, 0);
      lcd.print("OUT");
      lcd.setCursor(12, 0);
      lcd.print("L/HR");
      lcd.setCursor(0, 1);
      lcd.print(temp_in);
      lcd.setCursor(6, 1);
      lcd.print(temp_out);
  
    // Serial Output
      Serial.print(temp_in);
      Serial.print(",");
      Serial.print(temp_out);
      Serial.print(",");
      Serial.print(temp_amb);
      Serial.print(",");
      Serial.print(Calc);
      Serial.println();
  
    // RPM display info
      unsigned long currentMillis = millis();
      if(currentMillis - previousMillis > interval){
        previousMillis = currentMillis;
        digitalRead(flow);
      NbTopsFan = 0;
    //  sei();
      delay (1000);
    //  cli();
      lcd.setCursor(12, 1);
      Calc = ((NbTopsFan * 60)/fanspace[fan].fandiv);
      if (Calc < 1000) lcd.print (' ');
      if (Calc < 100) lcd.print (' ');
      if (Calc < 10) lcd.print (' ');
      lcd.print (Calc);
      }
    }
  }
}
4  Using Arduino / Project Guidance / Re: Issues with LCD backlight and display on: November 25, 2013, 11:14:38 am
I'll take a look at what you suggested, thanks for that. Also the code compiles just fine for me, I get this: "Binary sketch size: 18,914 bytes (of a 32,256 byte maximum)"

The button counter code is taken from this and modified for my current application. The bottom 4 lines dictate what to do during a given button state. I simply replaced the "myservo.slowmove" with the code for the lcd and SD output with the latter not having the SD output.:

Code:
/*
  State change detection (edge detection)
 
 Often, you don't need to know the state of a digital input all the time,
 but you just need to know when the input changes from one state to another.
 For example, you want to know when a button goes from OFF to ON.  This is called
 state change detection, or edge detection.
 
 This example shows how to use button state change to perform an action.
 
 The circuit:
 * Momentary pushbutton attached to digital pin 2 from +5V
 * 10K resistor attached to digital pin 2 from ground
 * Servo signal wire attached to digital pin 9
 * Servo power wire connected to 5v
 * Servo ground wire connected to ground
 
 Based off the public domain "State Change Detection" example provided with the
 Arduino software. Code edited 8-14-2011 by Will Lyon (SXRguyinMA) to remove
 the LED and add in a servo.
 
 For the purpose of
 "Integrating Electronics Into Your Next Proect" series of articles on TBCS
 www.thebestcasescenario.com
 
 */

// Include the servo library
#include <VarSpeedServo.h>

// Create a servo object to control a servo
VarSpeedServo myservo;

// this constant won't change:
const int  buttonPin = 2;    // the pin that the pushbutton is attached to


// Variables will change:
int buttonPushCounter = 0;   // counter for the number of button presses
int buttonState = 0;         // current state of the button
int lastButtonState = 0;     // previous state of the button

void setup() {
  // attach the Servo to pin 9
  myservo.attach(9);
  // make sure the servo starts off with the door closed
  myservo.slowmove(20, 15);
  // initialize the button pin as a input:
  pinMode(buttonPin, INPUT);
}


void loop() {
  // read the pushbutton input pin:
  int buttonState = digitalRead(buttonPin);
  
  // compare the buttonState to its previous state
  if (buttonState != lastButtonState) {
    // if the state has changed, increment the counter
    if (buttonState == HIGH) {
      // if the current state is HIGH then the button
      // wend from off to on:
      buttonPushCounter++;
    }
    else {
    }

    // save the current state as the last state,
    //for next time through the loop
    lastButtonState = buttonState;
  }
  
  // moves the servo every other button push by
  // checking the modulo of the button push counter.
  // the modulo function gives you the remainder of
  // the division of two numbers:
  if (buttonPushCounter % 2 == 0) {
   myservo.slowmove(170, 15);
  } else {
   myservo.slowmove(20, 15);
  }
}

See next post as all the code was too long for this single post lol
5  Using Arduino / Project Guidance / Re: Issues with LCD backlight and display on: November 25, 2013, 10:07:09 am
Did you also move the button pin? It was in conflict with the sad pins too. Post your code.

I did, I move it to A3 with a 10k to GND, redPin went to A5 and grnPin to A4. Here's the code as it stand now:

Code:
/*
   **Code for PC Liquid Cooling System Tester. Developed by
   Will Lyon - http://www.computersandcircuits.com
   **Designed to red an input and output temp sensor connected
   to the input and output of a radiator or water block to
   test cooling performance. Ambient temp included for baseline.
   **Flow meter can be used to determine rate of flow drop caused
   by each radiator or water block.
   ** Data is logged to an SD card in a CSV format.
*/

// Libraries
#include "math.h"
#include <LiquidCrystal.h>
#include <SD.h>

// LCD Pin Assignment
LiquidCrystal lcd(3, 4, 5, 6, 7, 8);

// Ints
volatile int NbTopsFan;
const int tempIn = A0;      // Input temp on analog 0
const int tempOut = A1;     // Output temp on analog 1
const int ambient = A2;     // Ambient temp on analog 2
const int buttonPin = A3;   // Button input to analog 3
const int grnPin = A4;      // LCD green LED on analog 4
const int redPin = A5;      // LCD red LED on analog 5
const int flow = 2;         // Flow meter on digital 2 (interrupt 0)
const int chipSelect = 10;  // CS pin to digital 10
int buttonPushCounter = 0;  // Int for button counter
int buttonState = 0;        // Current state of the button
int lastButtonState = LOW;  // Previous state of the button
int val;
int Calc;
unsigned long previousMillis = 0;
long interval = 1000;

// Floats
float temp_in;
float temp_out;
float temp_amb;

// RPM Reading Code
typedef struct{
  char fantype;
  unsigned int fandiv;
}fanspec;

fanspec fanspace[3]={{0,1},{1,2},{2,8}};

char fan = 1;
void rpm ()
{
  NbTopsFan++;
}

// Setup
void setup() {
 
// Opening LCD Message
  digitalWrite(redPin, HIGH);        // Turn off red LCD LED
  digitalWrite(grnPin, LOW);         // Turn on green LCD LED
  lcd.begin(16,2);                   // Initialize LCD
  lcd.setCursor(0, 0);
  lcd.print(" Computers  And ");
  lcd.setCursor(0, 1);
  lcd.print("    Circuits    ");
  delay(2000);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print(" LIQUID COOLING ");
  lcd.setCursor(0, 1);
  lcd.print(" TESTING   UNIT ");
  delay(2000);
 
  Serial.begin(9600);              // Begin Serial at 9600
  while (!Serial) {
    ;
  }
  Serial.print("Initializing SD Card...");
  pinMode(10, OUTPUT);
 
  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed or not present");
  }
  Serial.println("SD Card initialized.");
 
  File dataFile = SD.open("datalog.csv", FILE_WRITE);
  if (dataFile) {
    dataFile.print("Temp In, Temp Out, Ambient, Flow");
    dataFile.println();
    dataFile.close();
  } else {
}
 
  pinMode(tempIn, INPUT);            // Set in temp to input
  pinMode(tempOut, INPUT);           // Set out temp to input
  pinMode(ambient, INPUT);           // Set ambient temp to input
  pinMode(flow, INPUT);              // Set flow pin to input
  pinMode(redPin, OUTPUT);           // Set red LED pin to output
  pinMode(grnPin, OUTPUT);           // Set green LED pin to output
  pinMode(buttonPin, INPUT);         // Set button pin to input
  attachInterrupt(0, rpm, RISING);   // Attach interrupt for flow meter on digital pin 2
}

void loop()  {
  temp_in = analogRead(tempIn);
  temp_in = (5.0 * temp_in * 10.0)/1024.0;
  temp_out = analogRead(tempOut);
  temp_out = (5.0 * temp_out * 10.0)/1024.0;
  temp_amb = analogRead(ambient);
  temp_amb = (5.0 * temp_amb * 10.0)/1024.0;
  delay(1000);;
 
  buttonState = analogRead(buttonPin);
  if (buttonState != lastButtonState)
    if (buttonState >500) {
      buttonPushCounter++;
    }
    else {
    }
    lastButtonState = buttonState;

  if (buttonPushCounter % 2 == 0) {   // Display data on LCD and serial monitor and save to SD card
    digitalWrite(grnPin, HIGH);       // Turn green LCD LED off
    digitalWrite(redPin, LOW);        // Turn red LCD LED on
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.write("   RECORDING    ");
    delay(1000);
    lcd.clear();

    // LCD Output
    lcd.setCursor(1, 0);
    lcd.print(" IN");
    lcd.setCursor(7, 0);
    lcd.print("OUT");
    lcd.setCursor(12, 0);
    lcd.print("L/HR");
    lcd.setCursor(0, 1);
    lcd.print(temp_in);
    lcd.setCursor(6, 1);
    lcd.print(temp_out);
 
    // SD Card Output
    File dataFile = SD.open("datalog.csv", FILE_WRITE);
    if (dataFile) {
      dataFile.print(temp_in);
      dataFile.print(",");
      dataFile.print(temp_out);
      dataFile.print(",");
      dataFile.print(temp_amb);
      dataFile.print(",");
      dataFile.print(Calc);
      dataFile.println();
      dataFile.close();
    }
    else {
      Serial.println("Error opening datalog.csv");
    }
 
    // Serial Output
    Serial.print(temp_in);
    Serial.print(",");
    Serial.print(temp_out);
    Serial.print(",");
    Serial.print(temp_amb);
    Serial.print(",");
    Serial.print(Calc);
    Serial.println();
 
    // RPM display info
    unsigned long currentMillis = millis();
    if(currentMillis - previousMillis > interval){
      previousMillis = currentMillis;
      digitalRead(flow);
    NbTopsFan = 0;
  //  sei();
    delay (1000);
  //  cli();
    lcd.setCursor(12, 1);
    Calc = ((NbTopsFan * 60)/fanspace[fan].fandiv);
    if (Calc < 1000) lcd.print (' ');
    if (Calc < 100) lcd.print (' ');
    if (Calc < 10) lcd.print (' ');
    lcd.print (Calc);
  } else {                            // Display info on LCD and serial monitor but do not write to SD card
      digitalWrite(redPin, HIGH);     // Turn red LCD LED off
      digitalWrite(grnPin, LOW);      // Turn green LCD LED on
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.write(" NOT  RECORDING ");
      delay(1000);
 
    // LCD Output
      lcd.setCursor(1, 0);
      lcd.print(" IN");
      lcd.setCursor(7, 0);
      lcd.print("OUT");
      lcd.setCursor(12, 0);
      lcd.print("L/HR");
      lcd.setCursor(0, 1);
      lcd.print(temp_in);
      lcd.setCursor(6, 1);
      lcd.print(temp_out);
 
    // Serial Output
      Serial.print(temp_in);
      Serial.print(",");
      Serial.print(temp_out);
      Serial.print(",");
      Serial.print(temp_amb);
      Serial.print(",");
      Serial.print(Calc);
      Serial.println();
 
    // RPM display info
      unsigned long currentMillis = millis();
      if(currentMillis - previousMillis > interval){
        previousMillis = currentMillis;
        digitalRead(flow);
      NbTopsFan = 0;
    //  sei();
      delay (1000);
    //  cli();
      lcd.setCursor(12, 1);
      Calc = ((NbTopsFan * 60)/fanspace[fan].fandiv);
      if (Calc < 1000) lcd.print (' ');
      if (Calc < 100) lcd.print (' ');
      if (Calc < 10) lcd.print (' ');
      lcd.print (Calc);
      }
    }
  }
}

With this the backlight works fine but the button does nothing. I've never used an analog input for a button before so I'm sure I've got something wrong. I've used the button state code before with another project (https://www.youtube.com/watch?v=afq3R1WhXwI) so I just copy/pasted it over and tweaked the valued for using an analog input via a tutorial I found on the forums somewhere.

I say works fine but the screen doesn't light up during the opening message. Once it doe slight up it lights green for a sec then switched to red and the recording section.
6  Using Arduino / Project Guidance / Re: Issues with LCD backlight and display on: November 24, 2013, 05:38:54 pm
I encourage you to do this simple test: load an sd test sample code, make sure it works, no LCDs. Then add lcd back light control in setup and see if the sample code still works.

You will find out it stops working because you are using the SD pins for lcd back light control.

OK I re-assigned the buttons and LCD LEDs to A3-5. Now the backlight works but it doesn't come on like it should in the SETUP section. It seems to only come on once the loop has started.

Also the button press still has no effect. It goes straight to recording mode. Any ideas?
7  Using Arduino / Project Guidance / Re: Issues with LCD backlight and display on: November 24, 2013, 05:30:12 pm
I encourage you to do this simple test: load an sd test sample code, make sure it works, no LCDs. Then add lcd back light control in setup and see if the sample code still works.

You will find out it stops working because you are using the SD pins for lcd back light control.

OK huge fail on my part - I just noticed that the SD uses 10-13.So I can't use 11 for the button (no biggie it can get moved to analog) and I can't use 1 and 2 for backlight control because they interfere with the TX/RX and the backlight blinks lol. Looks like I need a port expander or something. Unless I control the backlight with analog....
8  Using Arduino / Project Guidance / Re: Issues with LCD backlight and display on: November 24, 2013, 09:16:13 am
Arduino pins may not be able to sink the amount of current on the back light although the back light has proper current limitation on board. Which arduino board do you use? My UNO V2 has trouble with SD card when I use the arduino wifi shield with microsd slot.

I tried it with both my Deumilanove (with the SD shield) and my Adafruit USB Boarduino (without the SD hooked up) and both do the same thing. I've run LCDs straight off the pins in the past with projects and it's switched backlighting just fine. I've also tried several different uC's and it made no difference.
9  Using Arduino / Project Guidance / Re: Issues with LCD backlight and display on: November 23, 2013, 10:56:55 pm
Here's a vid I just uploaded showing what the LCD is doing with the odd output on the interrupt

http://www.youtube.com/watch?v=65pEb58aarM&feature=youtu.be
10  Using Arduino / Project Guidance / Re: Issues with LCD backlight and display on: November 23, 2013, 10:46:46 pm
Did you use any current-limit resistors with your LCD back light? What Arduino board are you using? BTW, your icon, or video icon is distracting. I can't read your post without blocking your video icon with a window.

HAHA sorry it's a GIF, I'll change it.

No current-limiting resistors are needed. This LCD has them built-in so all you need to do is hook the 5V up and hook each color's pin to GND to light that color. If I hook the red pin directly to GND it lights up red, same with the green. However when hooked to the Arduino's assigned pins using digitalWrite(redPin, LOW); should turn the red LED on but it doesn't. Same with green. I tried on both an older Duemilanove with the old bootloader and an Adafruit USB Boarduino with an optiboot chip - neither makes the backlight work.
11  Using Arduino / Project Guidance / Re: Issues with LCD backlight and display on: November 23, 2013, 10:42:41 pm
Code:
while (!Serial) {
    ;
  }

Appears nothing is coming on the serial port, so infinite loop

Strange - it was working with that semicolon there before. I just deleted that line and it's going back to displaying the info on the LCD now. I still can't get the back light or the button to operate properly.


Can you post EXACT copy of your messages on Serial Monitor? Please.
Cheers
Vaclav


here's what I'm getting now that I deleted that line with the semicolon in it:

Quote
Initializing SD Card...Card failed or not present
SD Card initialized.
Error opening datalog.csv
18.12,16.55,17.24,0
Error opening datalog.csv
17.87,16.85,17.48,10880
Error opening datalog.csv
17.92,16.94,17.48,23706
Error opening datalog.csv
17.63,16.75,17.38,7776
Error opening datalog.csv
17.92,17.04,17.48,8548
Error opening datalog.csv
17.14,16.31,16.94,808

It's displaying a reading from the fan that I'm using as a stand-in for the actual flow meter for testing but it's bouncing all over the place as you can see from the last number set in the string
12  Using Arduino / Project Guidance / Issues with LCD backlight and display on: November 23, 2013, 08:01:19 pm
Hi all, I'm working on a unit that will read from three temp sensors and a flow meter and display the info on an LCD as well as store it to an SD card as a CSV file when a button is pressed. When the button is pressed again it will stop storing to the SD but still show data on the LCD.

I had everything working on the SD card end yesterday so this afternoon's project was to interface it with the LCD. I have the LCD display working but the back light will not work at all when hooked to the Arduino. If I hook either the red or green (I'm using an RGB 16x2 character LCD) to GND directly the back light works just fine. There is 5V going into the back light input.

Prior to adding the LCD section the SD logging was perfect (albeit I had not implemented the button yet, it was just logging constantly. Somehow something got changed when implementing the LCD where it will not get past the opening message. If you look at the code I've got an opening message in the setup section for the LCD. It just sticks with "Liquid cooling system testing unit" constantly displayed. If I open the serial monitor it does the SD initialization and it initializes just fine but then that's it. No readings are displayed.

Can anyone help me out here and point out where I screwed up? I'm using an Arduino Duemilnaove with the Adafruit SD shield and Adafruit 16x2 RGB negative LCD.

Here's the code as it stands now:

Code:
/*
   **Code for PC Liquid Cooling System Tester. Developed by
   Will Lyon - http://www.computersandcircuits.com
   **Designed to red an input and output temp sensor connected
   to the input and output of a radiator or water block to
   test cooling performance. Ambient temp included for baseline.
   **Flow meter can be used to determine rate of flow drop caused
   by each radiator or water block.
   ** Data is logged to an SD card in a CSV format.
*/

// Libraries
#include "math.h"
#include <LiquidCrystal.h>
#include <SD.h>

// LCD Pin Assignment
LiquidCrystal lcd(3, 4, 5, 6, 7, 8);

// Ints
volatile int NbTopsFan;
const int tempIn = A0;      // Input temp on A0
const int tempOut = A1;     // Output temp on A1
const int ambient = A2;     // Ambient temp on A2
const int flow = 2;         // Flow meter on digital 2 (interrupt 0)
const int grnPin = 9;       // LCD green LED on digital 9
const int chipSelect = 10;  // CS pin to digital 10
const int buttonPin = 11;   // Button input to digital 11
const int redPin = 12;      // LCD red LED on digital 12
int buttonPushCounter = 0;  // Int for button counter
int buttonState = 0;        // Current state of the button
int lastButtonState = LOW;  // Previous state of the button
int val;
int Calc;
long previousMillis = 0;
long interval = 1000;

// Floats
float temp_in;
float temp_out;
float temp_amb;

// RPM Reading Code
typedef struct{
  char fantype;
  unsigned int fandiv;
}fanspec;

fanspec fanspace[3]={{0,1},{1,2},{2,8}};

char fan = 1;
void rpm ()
{
  NbTopsFan++;
}

// Setup
void setup() {
 
// Opening LCD Message
  digitalWrite(redPin, HIGH);        // Turn off red LCD LED
  digitalWrite(grnPin, LOW);         // Turn on green LCD LED
  lcd.begin(16,2);                   // Initialize LCD
  lcd.setCursor(0, 0);
  lcd.print(" Computers  And ");
  lcd.setCursor(0, 1);
  lcd.print("    Circuits    ");
  delay(2000);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print(" LIQUID COOLING ");
  lcd.setCursor(0, 1);
  lcd.print(" TESTING   UNIT ");
  delay(2000);
 
  Serial.begin(9600);              // Begin Serial at 9600
  while (!Serial) {
    ;
  }
  Serial.print("Initializing SD Card...");
  pinMode(10, OUTPUT);
 
  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed or not present");
    // don't do anything more:
    return;
  }
  Serial.println("card initialized.");
 
  File dataFile = SD.open("datalog.csv", FILE_WRITE);
  if (dataFile) {
    dataFile.print("Temp In, Temp Out, Ambient, Flow");
    dataFile.println();
    dataFile.close();
  } else {
}
 
  pinMode(tempIn, INPUT);            // Set in temp to input
  pinMode(tempOut, INPUT);           // Set out temp to input
  pinMode(ambient, INPUT);           // Set ambient temp to input
  pinMode(flow, INPUT);              // Set flow pin to input
  pinMode(redPin, OUTPUT);           // Set red LED pin to output
  pinMode(grnPin, OUTPUT);           // Set green LED pin to output
  pinMode(buttonPin, INPUT);         // Set button pin to input
  attachInterrupt(0, rpm, RISING);   // Attach interrupt for flow meter on digital pin 2
}

void loop()  {
  temp_in = analogRead(tempIn);
  temp_in = (5.0 * temp_in * 10.0)/1024.0;
  temp_out = analogRead(tempOut);
  temp_out = (5.0 * temp_out * 10.0)/1024.0;
  temp_amb = analogRead(ambient);
  temp_amb = (5.0 * temp_amb * 10.0)/1024.0;
  delay(1000);
 
  buttonState = digitalRead(buttonPin);
  if (buttonState != lastButtonState)
    if (buttonState == HIGH) {
      buttonPushCounter++;
    }
    else {
    }
    lastButtonState = buttonState;

  if (buttonPushCounter % 2 == 0) {   // Display data on LCD and serial monitor and save to SD card
    digitalWrite(grnPin, HIGH);       // Turn green LCD LED off
    digitalWrite(redPin, LOW);        // Turn red LCD LED on
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.write("   RECORDING    ");
    delay(1000);
    lcd.clear();

    // LCD Output
    lcd.setCursor(1, 0);
    lcd.print(" IN");
    lcd.setCursor(7, 0);
    lcd.print("OUT");
    lcd.setCursor(12, 0);
    lcd.print("L/HR");
    lcd.setCursor(0, 1);
    lcd.print(temp_in);
    lcd.setCursor(6, 1);
    lcd.print(temp_out);
 
    // SD Card Output
    File dataFile = SD.open("datalog.csv", FILE_WRITE);
    if (dataFile) {
      dataFile.print(temp_in);
      dataFile.print(",");
      dataFile.print(temp_out);
      dataFile.print(",");
      dataFile.print(temp_amb);
      dataFile.print(",");
      dataFile.print(flow);
      dataFile.println();
      dataFile.close();
    }
    else {
      Serial.println("Error opening datalog.csv");
    }
 
    // Serial Output
    Serial.print(temp_in);
    Serial.print(",");
    Serial.print(temp_out);
    Serial.print(",");
    Serial.print(temp_amb);
    Serial.print(",");
    Serial.print(flow);
    Serial.println();
 
    // RPM display info
    unsigned long currentMillis = millis();
    if(currentMillis - previousMillis > interval){
      previousMillis = currentMillis;
      digitalRead(flow);
    NbTopsFan = 0;
  //  sei();
    delay (1000);
  //  cli();
    lcd.setCursor(12, 1);
    Calc = ((NbTopsFan * 60)/fanspace[fan].fandiv);
    if (Calc < 1000) lcd.print (' ');
    if (Calc < 100) lcd.print (' ');
    if (Calc < 10) lcd.print (' ');
    lcd.print (Calc);
  } else {                            // Display info on LCD and serial monitor but do not write to SD card
      digitalWrite(redPin, HIGH);     // Turn red LCD LED off
      digitalWrite(grnPin, LOW);      // Turn green LCD LED on
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.write(" NOT  RECORDING ");
      delay(1000);
 
    // LCD Output
      lcd.setCursor(1, 0);
      lcd.print(" IN");
      lcd.setCursor(7, 0);
      lcd.print("OUT");
      lcd.setCursor(12, 0);
      lcd.print("L/HR");
      lcd.setCursor(0, 1);
      lcd.print(temp_in);
      lcd.setCursor(6, 1);
      lcd.print(temp_out);
 
    // Serial Output
      Serial.print(temp_in);
      Serial.print(",");
      Serial.print(temp_out);
      Serial.print(",");
      Serial.print(temp_amb);
      Serial.print(",");
      Serial.print(flow);
      Serial.println();
 
    // RPM display info
      unsigned long currentMillis = millis();
      if(currentMillis - previousMillis > interval){
        previousMillis = currentMillis;
        digitalRead(flow);
      NbTopsFan = 0;
    //  sei();
      delay (1000);
    //  cli();
      lcd.setCursor(12, 1);
      Calc = ((NbTopsFan * 60)/fanspace[fan].fandiv);
      if (Calc < 1000) lcd.print (' ');
      if (Calc < 100) lcd.print (' ');
      if (Calc < 10) lcd.print (' ');
      lcd.print (Calc);
      }
    }
  }
}
13  Using Arduino / Programming Questions / Re: Gui advice on: November 20, 2013, 09:16:46 pm
I'm looking for something similar. I don't know any C/Java, etc. All i want is a simple GUI that will read three temps sensors and a flow meter and plot the outputs on a graph. I've got the code working already and it's saving the data to an SD as a CSV file but I want something easier to use. Thoughts?
14  Using Arduino / Interfacing w/ Software on the Computer / Re: Serial Monitor for your toolbox - TOOL FINISHED on: November 20, 2013, 09:13:56 pm
This may be exactly what I'm looking for. I'm looking for a way to monitor 4 sensors (3 temp and one flow meter) and plot data to a graph. I'll have to play with this and see what I can come up with. Thanks!
15  Using Arduino / Programming Questions / Re: Funny readings when trying to read PWM fan RPM on: June 16, 2013, 01:07:57 pm
Code:
    digitalRead(fan1);
Why? If you don't want the value that digitalRead() returns, why ask for it?

Code:
  sei();
  delay (1000);
//  cli();
This is still crap.

Well if I don't read interrupts don't I need digitalRead instead?


Take a look at this page and it might help you understand what is happening.
http://www.bearblain.com/fan_speed_control.htm

The 3-wire fan (quarter way down the page) uses the "+" input as the power supply for the tach output through resistor R1. If you use PWM on the "+" input, the tach output will also go high and low at the PWM frequency.

The 4-wire fan (halfway down the page) has a separate input for the PWM pulses, and the power supply is used for the hall effect transistor and tach output.


I'm not using PWM for the 3-wire fans, those will be adjusted via voltage. Only the 4-wire ones will use the PWM as they should. Any 3-wire fan I plug in has no issue with the RPM reading. If I lower the voltage the reading drops accordingly. It's only PWM (4-wire) fans that I'm having the issue with the funky readings so it's got to be something with the PWM. The 3-wire fan sI've used seem to fluctuate by a couple hundred RPM (~1200 ~ 1400) but not nearly as bad as the PWM fans (~1100 ~ 9200).
Pages: [1] 2 3 ... 6