Go Down

Topic: Need help with shift register 74HC595 (Read 1 time) previous topic - next topic

m2snd

Tue Nov 29, 2011 5:29 pm
Hello, need help!!!

Please, why in the code below ( in the final parte),when i call the function MorningAlarm()
Code: [Select]
// functions to be called when an alarm triggers:
void MorningAlarm(){
Serial.println("Alarm: - sob estores");
setRegisterPin(0, HIGH);
writeRegisters();
digitalWrite(Pin3, HIGH);
}

the setRegisterPin(0, HIGH), don´t goes HIGH and the digitalWrite(Pin3, HIGH) goes high?

The complete code
Code: [Select]
//infrared
#include <IRremote.h>
#include <Time.h>
#include <TimeAlarms.h>

int SER_Pin = 8; //pin 14 on the 75HC595
int RCLK_Pin = 9; //pin 12 on the 75HC595
int SRCLK_Pin = 10; //pin 11 on the 75HC595
int Pin7 = 7;
int Pin6 = 6;
int Pin5 = 5;
int Pin4 = 4;
int Pin3 = 3;
int Pin13 = 13;
int Pin2 = 2;
//infrared
int RECV_PIN = 11; //ligacao do INFRARED [1ºOUT pin11] 2ºGND 3ºVCC
//comando metronico código 5064(samsung TNT)
IRrecv irrecv(RECV_PIN);
decode_results results;


long fimTempoRele0;
long fimTempoRele1;
long fimTempoRele2;
long fimTempoRele3;
long fimTempoRele4;
long fimTempoRele5;
long fimTempoRele6;
long fimTempoRele7;
long fimTempoRele8;
long fimTempoRele9;
long fimTempoRele10;
long fimTempoRele11;
long fimTempoRele12;
long fimTempoRele13;

long Tempo;


//How many of the shift registers - change this
//CREDITOS http://bildr.org/2011/02/74hc595
#define number_of_74hc595s 1

//do not touch
#define numOfRegisterPins number_of_74hc595s * 8

boolean registers[numOfRegisterPins];

void setup(){
pinMode(SER_Pin, OUTPUT);
pinMode(RCLK_Pin, OUTPUT);
pinMode(SRCLK_Pin, OUTPUT);
pinMode(Pin7, OUTPUT);
pinMode(Pin6, OUTPUT);
pinMode(Pin5, OUTPUT);
pinMode(Pin4, OUTPUT);
pinMode(Pin13, OUTPUT);
pinMode(Pin2, OUTPUT);
pinMode(Pin3, OUTPUT);
pinMode(Pin4, OUTPUT);
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver

setTime(8,29,0,1,1,11); // set time to Saturday 8:29:00am Jan 1 2011
// create the alarms
Alarm.alarmRepeat(8,29,2, MorningAlarm); // 8:30am every day
Alarm.alarmRepeat(8,29,7, EveningAlarm); // 5:45pm every day
Alarm.alarmRepeat(dowSaturday,8,30,30,WeeklyAlarm); // 8:30:30 every Saturday

Alarm.timerRepeat(15, Repeats); // timer for every 15 seconds
Alarm.timerOnce(10, OnceOnly);

//reset all register pins
clearRegisters();
writeRegisters();
}


//set all register pins to LOW
void clearRegisters(){
for(int i = numOfRegisterPins - 1; i >= 0; i--){
registers[i] = LOW;
}
}

//Set and display registers
//Only call AFTER all values are set how you would like (slow otherwise)
void writeRegisters(){

digitalWrite(RCLK_Pin, LOW);
for(int i = numOfRegisterPins - 1; i >= 0; i--){
digitalWrite(SRCLK_Pin, LOW);
int val = registers[i];
digitalWrite(SER_Pin, val);
digitalWrite(SRCLK_Pin, HIGH);
}
digitalWrite(RCLK_Pin, HIGH);
}
//set an individual pin HIGH or LOW
void setRegisterPin(int index, int value){
registers[index] = value;
}

void loop(){
//le codigo infrared
if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);
irrecv.resume(); // Receive the next value
}
digitalClockDisplay();
Alarm.delay(1000); // wait one second between clock display

//-----------------------------------------------------------------cozinha-----------------------------------------------------------

//inicio do código COZINHA subir
if ((results.value) == 0xE0E020DF){
setRegisterPin(1, LOW); //desliga descida
setRegisterPin(0, HIGH); //<<<<<<activa subida
writeRegisters();
fimTempoRele0 = millis() + 15000;

}
if ((millis ()> fimTempoRele0) || ((results.value) == 0xE0E0D12E))
{
setRegisterPin(0, LOW); //<<<<<<<desliga subida

writeRegisters();
}
//descer------ cozinha
if ((results.value) == 0xE0E010EF){
setRegisterPin(0, LOW); //<<<<<<<desliga rele de subir
setRegisterPin(1, HIGH); // liga relé de descer<--------
writeRegisters();
fimTempoRele1 = millis() + 15000;
}
if (( millis () > fimTempoRele1) || ((results.value) == 0xE0E0D12E))
{
setRegisterPin(1, LOW);
writeRegisters();
}
//-------------------------------------------------------------sala de jantar
//subir
if ((results.value) == 0xE0E0A05F){
setRegisterPin(3, LOW); //desliga descida
setRegisterPin(2, HIGH); //<<<<<<activa subida
writeRegisters();
fimTempoRele2 = millis() + 28000;

}
if ((millis ()> fimTempoRele2) || ((results.value) == 0xE0E0D12E))
{
setRegisterPin(2, LOW); //<<<<<<<desliga subida
writeRegisters();
}
//descer------ jantar

if ((results.value) == 0xE0E0906F){
setRegisterPin(2, LOW); //<<<<<<<desliga rele de subir
setRegisterPin(3, HIGH); // liga relé de descer
writeRegisters();
fimTempoRele3 = millis() + 28000;
}
if ((millis () > fimTempoRele3) || ((results.value) == 0xE0E0D12E))
{
setRegisterPin(3, LOW);
writeRegisters();
}

//-------------------------------------------------------------sala de estar
//subir
if ((results.value) == 0xE0E0609F){
setRegisterPin(5, LOW); //desliga descida
setRegisterPin(4, HIGH); //<<<<<<activa subida
writeRegisters();
fimTempoRele4 = millis() + 28000;
}
if ((millis ()> fimTempoRele4) || ((results.value) == 0xE0E0D12E))
{
setRegisterPin(4, LOW); //<<<<<<<desliga subida
writeRegisters();
}
//descer------
if ((results.value) == 0xE0E050AF){
setRegisterPin(4, LOW); //<<<<<<<desliga rele de subir
setRegisterPin(5, HIGH); // liga relé de descer
writeRegisters();
fimTempoRele5 = millis() + 28000;
}
if ((millis () > fimTempoRele5) || ((results.value) == 0xE0E0D12E))
{
setRegisterPin(5, LOW);
writeRegisters();
}

//-------------------------------inicio quarto-Q1
//subir

if ((results.value) == 0xE0E030CF){
setRegisterPin(7, LOW); //desliga descida
setRegisterPin(6, HIGH); //<<<<<<activa subida
writeRegisters();
fimTempoRele6 = millis() + 28000;
}
if ((millis ()> fimTempoRele6) || ((results.value) == 0xE0E0D12E))
{
setRegisterPin(6, LOW); //<<<<<<<desliga subida
writeRegisters();
}
//descer------ Q1
if ((results.value) == 0xE0E0D629){
setRegisterPin(6, LOW); //<<<<<<<desliga rele de subir
setRegisterPin(7, HIGH); // liga relé de descer<----------------------
writeRegisters();
fimTempoRele7 = millis() + 28000;
}
if ((millis () > fimTempoRele7) || ((results.value) == 0xE0E0D12E))
{
setRegisterPin(7, LOW);
writeRegisters();
}

//----------------------------------------------------------------------------------inicio quato 2
//subir
if ((results.value) == 0xE0E0B04F){
digitalWrite(Pin7, LOW); //desliga descida
digitalWrite(Pin6, HIGH); //<<<<<<activa subida
fimTempoRele8 = millis() + 28000;
}
if ((millis ()> fimTempoRele8) || ((results.value) == 0xE0E0D12E))
{
digitalWrite(Pin6, LOW); //desliga descida
}
//descer------ Q1
if ((results.value) == 0xE0E08877){
digitalWrite(Pin6,LOW);
digitalWrite(Pin7, HIGH); // liga relé de descer<----------------------
fimTempoRele9 = millis() + 28000;
}
if ((millis () > fimTempoRele9) || ((results.value) == 0xE0E0D12E))
{
digitalWrite(Pin7, LOW);
}
//----------------------------------------------------------inicio quarto 3
//subir
if ((results.value) == 0xE0E0708F){
digitalWrite(Pin4, LOW); //desliga descida
digitalWrite(Pin5, HIGH); //<<<<<<activa subida
fimTempoRele10 = millis() + 28000;
}
if ((millis ()> fimTempoRele10) || ((results.value) == 0xE0E0D12E))
{
digitalWrite(Pin5, LOW); //desliga descida
}
//descer------ Q3
if ((results.value) == 0xE0E0807F){
digitalWrite(Pin5,LOW);
digitalWrite(Pin4, HIGH); // liga relé de descer<----------------------
fimTempoRele11 = millis() + 28000;
}
if ((millis () > fimTempoRele11) || ((results.value) == 0xE0E0D12E))
{
digitalWrite(Pin4, LOW);
}


}//end do loop


// functions to be called when an alarm triggers:
void MorningAlarm(){
Serial.println("Alarm: - sob estores");
setRegisterPin(0, HIGH);
writeRegisters();
digitalWrite(Pin3, HIGH);
}

void EveningAlarm(){
Serial.println("Alarm: - desce estores");

}
void WeeklyAlarm(){
Serial.println("Alarm: - its Monday Morning");
}

void ExplicitAlarm(){
Serial.println("Alarm: - this triggers only at the given date and time");
}

void Repeats(){
Serial.println("15 second timer");
}

void OnceOnly(){
Serial.println("This timer only triggers once");
}

void digitalClockDisplay()
{
// digital clock display of the time
Serial.print(hour());
printDigits(minute());
printDigits(second());
Serial.println();
}

void printDigits(int digits)
{
Serial.print(":");
if(digits < 10)
Serial.print('0');
Serial.print(digits);
}


Thanks

PaulS

You don't suppose that this:
Code: [Select]
Serial.begin(9600);
has anything to do with the failure of the code the manipulate pin 0 (or 1) do you?
The art of getting good answers lies in asking good questions.

m2snd

I think not. The problem is when i call the shift register pin 0 or other shift pin, the led blink once and stay off.

Grumpy_Mike


graynomad

#4
Nov 30, 2011, 09:38 am Last Edit: Nov 30, 2011, 09:43 am by Graynomad Reason: 1
I can't see that the OP does use pin 0 anywhere, despite the confusing statement

Quote
call the shift register pin 0


and misleading comments in the code.

It seems to boil down to these three functions

Code: [Select]
//Set and display registers
//Only call AFTER all values are set how you would like (slow otherwise)
void writeRegisters(){

digitalWrite(RCLK_Pin, LOW);
for(int i = numOfRegisterPins - 1; i >= 0; i--){
digitalWrite(SRCLK_Pin, LOW);
int val = registers[i];
digitalWrite(SER_Pin, val);
digitalWrite(SRCLK_Pin, HIGH);
}
digitalWrite(RCLK_Pin, HIGH);
}
//set an individual pin HIGH or LOW
void setRegisterPin(int index, int value){
registers[index] = value;
}

// functions to be called when an alarm triggers:
void MorningAlarm(){
Serial.println("Alarm: - sob estores");
setRegisterPin(0, HIGH);
writeRegisters();
digitalWrite(Pin3, HIGH);
}


And I can't see anything wrong.

OP, are you saying that all the shift reg pins work except the last one?

Quote
and the digitalWrite(Pin3, HIGH) goes high?

What has pin3 got to do with it? Or is that just a test to see if the code executes?


______
Rob
Rob Gray aka the GRAYnomad www.robgray.com

pYro_65

Would there be any problem that you are declaring 32-bit constants. is there native support for 32 bit storage on the Arduino. ( not the soon to be released due )

Code: [Select]
if ((results.value) == 0xE0E0807F){
Forum Mod anyone?
https://arduino.land/Moduino/

m2snd

Sorry my english

Ok,  I'll try to explain again. The original code, works perfectly. This is for open and close the blind windows in my house, with a remote control and works great.

I would the like to implement, the blind windows to open and close at morning and evening.i´m trying to use the TimeAlarms library for that. When i put HIGH with the remote in the blind of the kitchen:
Code: [Select]
//inicio do código COZINHA subir//kitchen blind open
  if ((results.value) == 0xE0E020DF){
    setRegisterPin(1, LOW); //desliga descida    OFF for  down
    setRegisterPin(0, HIGH); //<<<<<<activa subida  ON for UP  ----->    here the shift register pin 0 goes high
    writeRegisters();
    fimTempoRele0 = millis() + 15000;

the setRegister(0, HIGH), goes high and the blind opens.

but when i call to high the same shift register here:

Code: [Select]
void MorningAlarm(){
  Serial.println("Alarm: - sob estores");   //open blind 
  setRegisterPin(0, HIGH);
  writeRegisters();
  digitalWrite(Pin3, HIGH);
}
the shift register pin 0, or another shift resgister  blinks once, and stay off.  the digitalWrite(Pin3, HIGH) is for test only

thanks for the reply


Grumpy_Mike

While this is probably not causing you any problem it is wrong:-
Code: [Select]
void writeRegisters(){

digitalWrite(RCLK_Pin, LOW);
for(int i = numOfRegisterPins - 1; i >= 0; i--){
digitalWrite(SRCLK_Pin, LOW);
int val = registers[i];
digitalWrite(SER_Pin, val);
digitalWrite(SRCLK_Pin, HIGH);
}
digitalWrite(RCLK_Pin, HIGH);
}

That creates many instances of the variable val, only use the int function on code that gets executed once in a function, so it should read:-
Code: [Select]
void writeRegisters(){
int val;
digitalWrite(RCLK_Pin, LOW);
for(int i = numOfRegisterPins - 1; i >= 0; i--){
digitalWrite(SRCLK_Pin, LOW);
val = registers[i];
digitalWrite(SER_Pin, val);
digitalWrite(SRCLK_Pin, HIGH);
}
digitalWrite(RCLK_Pin, HIGH);
}


better still you don't need val at all, do this:-

Code: [Select]
void writeRegisters(){

digitalWrite(RCLK_Pin, LOW);
for(int i = numOfRegisterPins - 1; i >= 0; i--){
digitalWrite(SRCLK_Pin, LOW);
digitalWrite(SER_Pin, registers[i]);
digitalWrite(SRCLK_Pin, HIGH);
}
digitalWrite(RCLK_Pin, HIGH);
}


While this might not cure your problem you should make the changes to avoid burning up memory unnecessarily.

Have you cot the capacitor on the latch line of the shift register like it shows in the tutorial, if so then remove it, this is a bad mistake but they are reluctant to correct it.

m2snd


Grumpy_Mike

Quote
i made the change, still same....

Yes I said that.

Quote
the setRegisterPin(0, HIGH), don´t goes HIGH and the digitalWrite(Pin3, HIGH) goes high?

Do some debug printing, find out if your setRegisterPin() function is actually changing bit 0 in the way it seems to be changing bit 3.


Go Up