Show Posts
Pages: [1] 2 3 4
1  Using Arduino / Programming Questions / how to add a second 7 segment display using a 74HC595 on: October 30, 2013, 04:06:59 pm
Hi all,

I have create a Up & Down counter with one 7 segment display using the 74HC595.
The code (below) works fine with the 74HC595, but it count only from 0 till 9

I need some help to add a second 7 segment display so i can count from 0 till 99

this is the code for one 7 segment display
Code:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);               // I2C initialize the library with the numbers of the interface pins

byte Up_Button = 2;                                                          // Up button to digital input pin 2 (see diagram how to connect!!)
byte Down_Button = 3;                                                        // Down button to digital input pin 3 (see diagram how to connect!!)

int speed = 1000;                                                            // used to control speed of counting

                                 //Global variables
int Up_State = 0;                                                            // variable that will read the Up button (either HIGH or LOW)
int Down_State = 0;                                                          // variable that will read the Down button (either HIGH or LOW)
int counter = 0;                                                             // variable that will store the count
int last_Up_State = 0;
int last_Down_State = 0;

const int latchPin = 5;                                                      // Pin connected to Pin 12 of 74HC595 (Latch)
const int dataPin  = 6;                                                      // Pin connected to Pin 14 of 74HC595 (Data)
const int clockPin = 7;                                                      // Pin connected to Pin 11 of 74HC595 (Clock)

unsigned long t1;
unsigned long t2;

const byte numbers[10] = {
  0b11111100,  // 0
  0b01100000,  // 1
  0b11011010,  // 2
  0b11110010,  // 3
  0b01100110,  // 4
  0b10110110,  // 5
  0b10111110,  // 6
  0b11100000,  // 7
  0b11111110,  // 8
  0b11100110,  // 9
};

void setup()
{
  pinMode(Up_Button, INPUT);                                                 // set Up Button as INPUT
  pinMode(Down_Button, INPUT);                                               // set Down Button as INPUT

    t1 = millis();

  pinMode(latchPin, OUTPUT);                                                 // set pins to output
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);

  lcd.begin(16, 2);                                                          // set up the LCD's number of columns and rows:
  lcd.print("     V1.0 ");                                             // print a info message on the LCD
}

void loop()
{
  t2 = millis();                                                             // update digit every second
  if(t2 - t1 > 1000)
  {
    //      counter++;                                                       // automatic counting UP 7 segment display test
    t1 = t2;
    if(counter > 9) {
      counter = 0;
    }
  }
  show(numbers[counter]);
}

void show( byte number)
{
  for(int j=0; j<=7; j++)                                                    // Loop over each segment in the "number" we're about to display, and illuminate only one segment at a time.
  {
    byte toWrite = number & (0b10000000 >> j);

    if(!toWrite) {
      continue;
    }                                                                        // If all bits are 0 then no point writing it to the shift register, so break out and move on to next segment.

    shiftIt(toWrite);                                                        // Otherwise shift it into the register
  }
}

void shiftIt (byte data)
{
  digitalWrite(latchPin, LOW);                                               // Set latchPin LOW while and clock these 8 bits in to the register to illuminate a single segment.

  for (int k=0; k<=7; k++)
  {
    digitalWrite(clockPin, LOW);                                             // clockPin LOW prior to sending bit

    if ( data & (1 << k) )                                                   // Do another bitwise AND against a mask to check the state of each bit as we clock it in.
    {
      digitalWrite(dataPin, LOW);                                            // turn "On"
    }
    else
    {
      digitalWrite(dataPin, HIGH);                                           // turn "Off"
    }
    digitalWrite(clockPin, HIGH);                                            // and clock the bit in
  }
  digitalWrite(clockPin, LOW);                                               //stop shifting out data

  digitalWrite(latchPin, HIGH);                                              //set latchPin to high to lock and send data

  //    delay(100);                                                           // put delay here to check the multiplexing in action!

  Up_State = digitalRead(Up_Button);                                         // read the Up button state
  Down_State = digitalRead(Down_Button);                                     // read the Down button state
  if(Up_State != last_Up_State)                                              // compare Up button state to its last state
  {
    if(Up_State == LOW)                                                      // Up button is pressed
    {
      counter = counter++;                                                   // increment the counter
      lcd.setCursor(0, 1);
      lcd.print("count: ");
      lcd.setCursor(7, 1);
      lcd.print(counter);                                                    // print it on LCD
      lcd.print("   ");                                                      // 3 blank spaces
      delay(speed);                                                          // debounce delay
    }
  }
  last_Up_State = Up_State;

  if(Down_State != last_Down_State)                                          // compare Down state to its lastState
  {
    if(Down_State == LOW)                                                    // Down button is pressed
    {
      counter = counter--;                                                   // decrement the counter
      lcd.setCursor(0, 1);
      lcd.print("count: ");
      lcd.setCursor(7, 1);
      lcd.print(counter);                                                    // print it on LCD
      lcd.print("   ");                                                      // 3 blank spaces
      delay(speed);                                                          // debounce delay
    }
  }
  last_Down_State = Down_State;
}
2  Using Arduino / Programming Questions / Re: Relais and Temperture on: September 22, 2013, 12:27:36 pm
@ wildbill

Thank u very much for the solution and code.

I have tested it in the project and now everything is working as planned.

regards,
Ed
3  Using Arduino / Programming Questions / Re: Relais and Temperture on: September 22, 2013, 09:33:08 am
So lets start again, i am a little confused right now.

this is the working code so far. in this code i need to add this protection.

Code:
const int Bias_Switch = A5;                                              // the number of the Bias switch analog input pin A5.    
const int Bias_Relais = 2;                                               // the number of the Bias_Relais digital output pin 2.

boolean mySet = false;
boolean Bias;


void setup() {
  pinMode(Bias_Switch, INPUT);                                           // sets analog pin 5 for input.
  digitalWrite(Bias_Switch, LOW);                                        // turn on pullup resistors
  pinMode(Bias_Relais, OUTPUT);                                          // set the digital pin as output.
}
void loop() {
  Bias = digitalRead(Bias_Switch);                                       // read the value DUMMY.
  Bias = digitalRead(Bias_Switch);                                       // read the value from the Bias_Switch.

  if (Bias==HIGH) mySet = true;                                          // set bolean to true    
  else
    mySet=false;

  digitalWrite(Bias_Relais, mySet);
}

i have test this sketch and it work!.

Now we need to add the to high temperature protection.

status normal operational:
Bias = HIGH
Bias_Relais = HIGH

My temperture sensor named in the code: tempC

status when there is a "to heat" problem.
tempC>100
Bias = HIGH
Bias_Relais = must be switched automatic to LOW and stay LOW. When the problem on site is fixed, I have to reset manual the BIAS switch to LOW and switsch on back to HIGH.

hope i have explain it a little better now.



4  Using Arduino / Programming Questions / Re: Relais and Temperture on: September 22, 2013, 08:56:48 am
Quote
I think that the idea is that someone goes and looks at the site, to try to determine what caused the system to overheat, before the system is turned back on.

Absoluut right
5  Using Arduino / Programming Questions / Re: Relais and Temperture on: September 22, 2013, 08:55:17 am
Quote
How do you detect that a problem occurred? Is that when the temperature rises over 100 degrees?
yes.

Quote
Is the fan supposed to be turned on when the temperature is above 50? Is it to be turned off when the temperature is below 50?
The Fan is seperate controlled by a sensor and speeding from slow to fast when the temperture rises. it will only stop cooling when the temperture is for example <25 celsius
6  Using Arduino / Programming Questions / Re: Relais and Temperture on: September 22, 2013, 08:36:01 am
Hi, PaulS

If i will put the comlete code here, i get to many questions what this is and what for. u will understand.
Quote
That can't be your entire code, you need to post all for someone else to find mistakes.
All my other code is working fine, so i dont need to post.

i tought to put a part and working code in the post to get some help how i can solve this protection.


I dont understand all the questions i get.
I just have a simple on / off switch http://www.rc-point.nl/N_frame.html?http://www.rc-point.nl/schakelaar-toggle-2-standen-ON-OFF-6-polig--nr.-70721-Bubble-N_art_65233.php
+5v = HIGH & gnd = LOW (analog input pin 5)

and want to switch on with the code a relais. this is not the issue, toggle the relais on and off.

i just want to switch the relais (digital output pin 5) automatic off and stay off when the temperture reach the >100 celsius. this can only happend when there a problem with the cooling fan.
it must never switch on again unless we manual the switch first off and then back on afther we have repaired the cooling fan. The fan has it's own control in the code, using for example the LM35 and has nothing to do with this relais issue.


i wanna thank u for the help so far. i hope u still can.
if u want i can send u by email the complete project.

Thank u in advange.
ed.
7  Using Arduino / Programming Questions / Re: Relais and Temperture on: September 22, 2013, 08:16:14 am
ok, Im sorry. i try to explain.

This project i am working on is a Hamradio, Amateur Television Transmitter "Radio Frequency Power moduul" that transmit TV signals so people (Hamradio users) can receive it from a large distance.

The equipement are to far away from our hand to control it.
So, to put the device operational it has a switch to turn it on (the relais turn the power on, on the RF moduul). now this part of the equipement is operational. we go home now.

Afther a few day's  it seems that the Fan to cool down the RF module, is not working anymore, maybe we have buy a cheap one,,
This Fan is cooling the RF module from the transmitter. When this module is to high temperture it will be destroyed.

1, the on/off switch outside the 19" cabinet must toggle the relais on
2, the fan has it's own control in the code, using for example the LM35

is this clear for u?

8  Using Arduino / Programming Questions / Re: Relais and Temperture on: September 22, 2013, 07:48:12 am
like this ?

Code:
 Bias = digitalRead(Bias_Switch);                                       // read the value DUMMY.
  Bias = digitalRead(Bias_Switch);                                       // read the value from the Bias_Switch.

  if (Bias==HIGH) mySet = false;                                          // set bolean to
  else  
    mySet=true;
  digitalWrite(Bias_Relais, mySet);
  
  if (Bias==LOW) mySet = false;                                          // set bolean to
  else  
    mySet=false;
  digitalWrite(Bias_Relais, mySet);
  
  if (Bias==HIGH) mySet = true && tempC>100;                                          // set bolean to      
  mySet = false;
      digitalWrite(Bias_Relais, mySet);
}
9  Using Arduino / Programming Questions / Re: Relais and Temperture on: September 22, 2013, 07:16:39 am
@wildbill
Quote
If 100 degrees is reached (how? because it was turned off at 50) a fan comes on and everything else must be off?
the code i had written was >50 and must be original >100 celsius. u right i made a type mistake.

again the explanation where i want to use this for.
I just want to build a safety that it cannot destroy my expansive Amateur TV RF Power Module.
If it reach this very high temp>100 , the problem are the FAN to cool down the RF Power Module.
This is part of a Amateur Television repeater controller, located on top of a building. and not at home.

@ paulS
Quote
Why are you reading the switch twice?
i have read more values in my project, when i do not double readings it affecting the actual reading from other inputs / sensors.

ok, i ll now try to change some code to get this protection work.
10  Using Arduino / Programming Questions / Re: Relais and Temperture on: September 22, 2013, 06:45:29 am
I have only to add the safety protection in the code

Code:
tempC>100

then it must switch off and stay off until i toggle the switch.

but how?
11  Using Arduino / Programming Questions / Re: Relais and Temperture on: September 22, 2013, 06:34:59 am
Quote
Set a boolean flag, beenLow to false. When the switch is LOW, set the flag to true.

is this what u mean ?

Code:

const int Bias_Switch = A5;                                              // the number of the Bias switch analog input pin A5.     
const int Bias_Relais = 2;                                               // the number of the Bias_Relais digital output pin 2.

boolean mySet = false;
boolean Bias;


void setup() {
  pinMode(Bias_Switch, INPUT);                                           // sets analog pin 5 for input.
  digitalWrite(Bias_Switch, LOW);                                        // turn on pullup resistors
  pinMode(Bias_Relais, OUTPUT);                                          // set the digital pin as output.
}
void loop() {
  Bias = digitalRead(Bias_Switch);                                       // read the value DUMMY.
  Bias = digitalRead(Bias_Switch);                                       // read the value from the Bias_Switch.

  if (Bias==true) mySet = true;                                          // set bolean to true     
  else
    mySet=false;

  digitalWrite(Bias_Relais, mySet);
}
12  Using Arduino / Programming Questions / Re: Relais and Temperture on: September 21, 2013, 05:59:19 pm
Hi PaulS

This is part of a Amateur Television repeater controller, located on top of a building.

Dont worry, i know what Im doing or creating with electronics.

Half year ago, i have found the Arduino and this is really nice to create projects for my hobby.

It is sometimes only hard to understand how to write some code, but I am doing well so far and most projects are very nice working.

Thats why i have asked here some help, so i can understand how to do.

Any examples are offcourse welcome.


regards,
Ed.

13  Using Arduino / Programming Questions / Re: Relais and Temperture on: September 21, 2013, 05:34:12 pm
thanks for the answers.

i will try this tomorrow.


Quote
You might explain why this is necessary, though.

I just want to build a safety that it cannot destroy my expansive ATV RF Power Module.
If it reach this very high temp>100 , the problem are the FAN to cool down the RF Power Module.
14  Using Arduino / Programming Questions / Relais and Temperture on: September 21, 2013, 05:12:03 pm
Hi all,

I have the following question:

i have a Temperture controlled relais.
When my Bias_Switch = HIGH and the temperture are below <50 Celsius the relais are switches to HIGH (on).
When the temperture reached >50 the Bias_Relais must switches to LOW.

The problem i have is howto get the Bias_Relais LOW until i have maual switch the Bias_Switch to LOW and then back to HIGH.


Code:
Bias = digitalRead(Bias_Switch);                                         // read the value DUMMY.
      Bias = digitalRead(Bias_Switch);                                         // read the value from the Bias_Switch.

      if (tempC<50  &&  Bias == HIGH)                                          // read two status.

        Bias = HIGH;                                                           // PA is switched ON.

      digitalWrite(Bias_Relais, Bias);

      if (tempC>50  &&  Bias == HIGH)                                          // read two status.

        Bias = LOW;                                                            // PA is switched OFF cozz of HIGH Temperture.

      digitalWrite(Bias_Relais, Bias);

15  Using Arduino / Programming Questions / Re: 2 diffrent analog value influenced eachother on: September 06, 2013, 05:29:47 pm
problem Solved.

solution;
Code:
  Temperature = analogRead(LM35);                         // 1st read the value DUMMY
  Temperature = analogRead(LM35);                         // read the value from the LM35 sensor

and:
Code:
  PAvalue = analogRead(PA);                               // 1st read the value DUMMY
  PAvalue = analogRead(PA);                               // read the value from the PA output driver.

thanks all for the help.
Pages: [1] 2 3 4