Go Down

Topic: 2pcs 74HC595 with 16ch led + potentiometer. (Read 1 time) previous topic - next topic

Wawa

Have you got diodes across those relay coils?
The ULN has buildin clamp diodes.
The TPIC has buildin active clamping.
Leo..

Grumpy_Mike

Yes but the power shift register will not have.

Wawa

Yes but the power shift register will not have.
Do you mean the TPIC6B595.

It has active clamping.
A zener between drain and gate.
That stops relay kickback voltage rising above "zener+Vgs(th)".
Leo..

Grumpy_Mike

#48
Sep 13, 2017, 06:18 am Last Edit: Sep 13, 2017, 06:18 am by Grumpy_Mike
Quote
That stops relay kickback voltage rising above "zener+Vgs(th)".
Yes but that is still a hefty wack of back emf. I would think you are better cutting it off at source by having the diode across the relay coil.


gavron04

By assigning a state boolean variable for each relay and having the code that detects the key number toggle that state variable. Then write that state variable to the relay.
So dataPin,latchPin,clockPin is the same pin for all 74HC595 which I have on PCB?


It's first time when I must use boolean variable - Have You some examples how to use it in my circuit?


Grumpy_Mike

Quote
Have You some examples how to use it in my circuit?
I thought I just told you what you had to do in your circuit.

From the Arduino their is a referance section under the help menu, it will bring up this link https://www.arduino.cc/en/Reference/BooleanVariables

gavron04

First:  dataPin,latchPin,clockPin is the same pin for all 74HC595 which I have on PCB (2x 74hc595 to drive 16ch leds and 1x 74hc595 to drive ULN2003) it is correct?


Second:

Code: [Select]
int LEDpin = 5;       // LED on pin 5
int switchPin = 13;   // momentary switch on 13, other side connected to ground

boolean running = false;

void setup()
{
 pinMode(LEDpin, OUTPUT);
 pinMode(switchPin, INPUT);
 digitalWrite(switchPin, HIGH);      // turn on pullup resistor
}

void loop()
{
 if (digitalRead(switchPin) == LOW)
 {  // switch is pressed - pullup keeps pin high normally
   delay(100);                        // delay to debounce switch
   running = !running;                // toggle running variable
   digitalWrite(LEDpin, running);      // indicate via LED
 }
}


I haven't tactswitch/momentary switch. I have remote control. Second I have 74HC595 not only atmega so for me its strange to do this correctly.

Maybe this?

Code: [Select]

int latchPin = 4;
int clockPin = 5;
int dataPin = 3;
int shiftValue = 0;

#define Out1Pin = X; // I don't know which port if I have there 74HC595???

boolean running = false;

#include <IRremote.h>
#define irPin 8  // pin dla TSOP
IRrecv irrecv(irPin);
decode_results results;

void setup()

{

     irrecv.enableIRIn();

   pinMode(latchPin, OUTPUT);
   pinMode(dataPin, OUTPUT); 
   pinMode(clockPin, OUTPUT);
 
   pinMode(Out1Pin, OUTPUT); // OUTPUT?

   digitalWrite(X, LOW); // I don't know which port if I have there 74HC595???

}

void loop() {

if (irrecv.decode(&results))
   {
        if (digitalRead(Out1Pin) == LOW)
       switch (results.value)
                {
                      {
         case 0x801:  // kod klawisza 1
            running = !running;

            break;
                       }
                }
   irrecv.resume();
    }


digitalWrite (latchPin, LOW);
shiftOut (dataPin, clockPin, MSBFIRST, highByte (shiftValue)); // upper 8 bits
shiftOut (dataPin, clockPin, MSBFIRST, lowByte (shiftValue)); // lower 8  bits
digitalWrite (latchPin, HIGH);
  delay(100); // remove this line after testing

                }

Grumpy_Mike

Quote
dataPin,latchPin,clockPin is the same pin for all 74HC595 which I have on PCB (2x 74hc595 to drive 16ch leds and 1x 74hc595 to drive ULN2003) it is correct?
No.
The data pin must go only to the first shift register, the second shift register takes its data from the most significant output of the first and the third from the most significant output of the second.

In that way they are chained.
http://www.lucidtronix.com/tutorials/40

gavron04

#53
Sep 13, 2017, 02:56 pm Last Edit: Sep 13, 2017, 03:09 pm by gavron04
Ok. I will fix this. But.. Please.. I don't know what change in my code to have working boolean.


Fixed. I connected thirds 73hc595 pin DS to QH' second 74HC595

gavron04

#54
Sep 13, 2017, 06:53 pm Last Edit: Sep 13, 2017, 07:36 pm by gavron04
Ok. So I have something whick work in 50% :)

Code: [Select]
const byte LDRpin = A2; // LDR connected to pin A1 and ground (A0 is used for the pot)
const byte PWMpin = 10; // connected to the two OE pins
int lightValue = 50; // change/experiment with this value
int darkValue = 160; // change/experiment with this value
int LDRvalue;
byte PWMvalue;


int SER_Pin = 3;   //pin 14 on the 75HC595
int RCLK_Pin = 4;  //pin 12 on the 75HC595
int SRCLK_Pin = 5; //pin 11 on the 75HC595

int potPin = 0;
int potValue = 0;
int shiftValue = 0;

//How many of the shift registers - change this
#define number_of_74hc595s 3

//do not touch
#define numOfRegisterPins number_of_74hc595s * 8

boolean registers[numOfRegisterPins];

#define VolUpPin 10 //up
#define VolDownPin A1 //down

#include <IRremote.h>
#define irPin 8  // pin dla TSOP

IRrecv irrecv(irPin);
decode_results results;

void setup() {

 
     irrecv.enableIRIn();
    
   pinMode(VolUpPin, OUTPUT);
   pinMode(VolDownPin, OUTPUT);
  
   pinMode(LDRpin, INPUT_PULLUP); // enables the internal pull up resistor
   pinMode(PWMpin, OUTPUT); // make the pin an output

   digitalWrite(10, LOW);
   digitalWrite(A1, LOW);


   pinMode(SER_Pin, OUTPUT);
   pinMode(RCLK_Pin, OUTPUT);
   pinMode(SRCLK_Pin, OUTPUT);


   //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;
  }
  writeRegisters();
}

//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() {
  LDRvalue = analogRead(LDRpin);
  LDRvalue = constrain(LDRvalue, lightValue , darkValue);
  PWMvalue = map(LDRvalue, lightValue, darkValue, 0, 220);
  analogWrite(PWMpin, PWMvalue); // write to the OE pins

if (irrecv.decode(&results))
   {
       switch (results.value)
       {
         case 0x801:  // kod klawisza 1
             setRegisterPin(16, LOW);
            break;
            
         case 0x1:  // kod klawisza 1
             setRegisterPin(16, HIGH);
            break;
            
         case 0x802:  // kod klawisza 2
              setRegisterPin(17, LOW);
            break;
            
         case 0x2:  // kod klawisza 2
              setRegisterPin(17, HIGH);
            break;
            
         case 0x803:  // kod klawisza 3
            //digitalWrite(Out3Pin, LOW);
              setRegisterPin(18, LOW);
            break;
            
         case 0x3:  // kod klawisza 3
              setRegisterPin(18, HIGH);
            break;
            
         case 0x80D:  // kod klawisza 4
              setRegisterPin(19, LOW);
            break;
            
         case 0xD:  // kod klawisza 4
              setRegisterPin(19, HIGH);
            break;

         case 0x807:  // kod klawisza 7 CH1
              setRegisterPin(20, LOW);
            break;
            
         case 0x7:  // kod klawisza 7 CH1
             setRegisterPin(20, HIGH);
            break;      
                  
          case 0x808:  // kod klawisza 8 CH2
            setRegisterPin(21, LOW);
            break;
            
         case 0x8:  // kod klawisza 8 CH2
            setRegisterPin(21, HIGH);
            break;  
                    
          case 0x809:  // kod klawisza 9 CH3
              setRegisterPin(22, LOW);
            break;
            
         case 0x9:  // kod klawisza 9 CH3
              setRegisterPin(22, HIGH);
            break;  

            
         case 0x11:  // kod klawisza 5
            digitalWrite(VolUpPin, LOW);
            delay(250);
            digitalWrite(VolDownPin, LOW);
            break;
            
         case 0x811:  // kod klawisza 5
            digitalWrite(VolUpPin, HIGH);
            delay(250);
            digitalWrite(VolUpPin, LOW);
            break;
            
         case 0x10:  // kod klawisza 6
            digitalWrite(VolDownPin, LOW);
            delay(250);
            digitalWrite(VolUpPin, LOW);
            break;
            
         case 0x810:  // kod klawisza 6
            digitalWrite(VolDownPin, HIGH);
            delay(250);
            digitalWrite(VolDownPin, LOW);
            break;
            
         case 0x80C:  // kod klawisza OFF
            //digitalWrite(Out1Pin, HIGH);
            break;
            
         case 0xC:  // kod klawisza OFF
            //digitalWrite(Out1Pin, LOW);
            break;


         }
   irrecv.resume();
   }

// read pot &  update outputs to 2 daisy chained shift registers
potValue = analogRead(A0);

if ( potValue >=0 && potValue <=20)
{
setRegisterPin(0, LOW);
}

if ( potValue >=20 && potValue <=63)
{
setRegisterPin(1, LOW);
}

if ( potValue >=63 && potValue <=126)
{
setRegisterPin(2, LOW);
}

if ( potValue >=126 && potValue <=189)
{
setRegisterPin(3, LOW);
}

if ( potValue >=189 && potValue <=252)
{
setRegisterPin(4, LOW);
}

if ( potValue >=252 && potValue <=315)
{
setRegisterPin(5, LOW);
}

if ( potValue >=315 && potValue <=378)
{
setRegisterPin(6, LOW);
}

if ( potValue >=378 && potValue <=441)
{
setRegisterPin(7, LOW);
}

if ( potValue >=441 && potValue <=504)
{
setRegisterPin(8, LOW);
}

if ( potValue >=504 && potValue <=567)
{
setRegisterPin(9, LOW);
}

if ( potValue >=567 && potValue <=630)
{
setRegisterPin(10, LOW);
}

if ( potValue >=630 && potValue <=693)
{
setRegisterPin(11, LOW);
}

if ( potValue >=693 && potValue <=756)
{
setRegisterPin(12, LOW);
}

if ( potValue >=756 && potValue <=819)
{
setRegisterPin(13, LOW);
}

if ( potValue >=819 && potValue <=882)
{
setRegisterPin(14, LOW);
}

if ( potValue >=882 && potValue <=945)
{
setRegisterPin(15, LOW);
}

if ( potValue >=945 && potValue <=1010)
{
setRegisterPin(16, LOW);
}

if ( potValue >=1010 && potValue <=1023)
{
setRegisterPin(0, LOW);
}



  writeRegisters();
  delay(100);
  //clearRegisters();
}



Remote control works. But 16ch leds with potentiometer isn't working.







Second question:



It is ok? Only 100nF and 10k for TPIC6C595? (I have this values from datesheet)

gavron04

Code: [Select]
const byte LDRpin = A2; // LDR connected to pin A1 and ground (A0 is used for the pot)
const byte PWMpin = 10; // connected to the two OE pins
int lightValue = 50; // change/experiment with this value
int darkValue = 160; // change/experiment with this value
int LDRvalue;
byte PWMvalue;


int SER_Pin = 3;   //pin 14 on the 75HC595
int RCLK_Pin = 4;  //pin 12 on the 75HC595
int SRCLK_Pin = 5; //pin 11 on the 75HC595

int potPin = 0;
int potValue = 0;
int shiftValue = 0;

//How many of the shift registers - change this
#define number_of_74hc595s 3

//do not touch
#define numOfRegisterPins number_of_74hc595s * 8

boolean registers[numOfRegisterPins];

#define VolUpPin 10 //up
#define VolDownPin A1 //down

#include <IRremote.h>
#define irPin 8  // pin dla TSOP

IRrecv irrecv(irPin);
decode_results results;

void setup() {

 
     irrecv.enableIRIn();
     
   pinMode(VolUpPin, OUTPUT);
   pinMode(VolDownPin, OUTPUT);
   
   pinMode(LDRpin, INPUT_PULLUP); // enables the internal pull up resistor
   pinMode(PWMpin, OUTPUT); // make the pin an output

   digitalWrite(10, LOW);
   digitalWrite(A1, LOW);


   pinMode(SER_Pin, OUTPUT);
   pinMode(RCLK_Pin, OUTPUT);
   pinMode(SRCLK_Pin, OUTPUT);


   //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;
  }
  writeRegisters();
}

//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() {
  LDRvalue = analogRead(LDRpin);
  LDRvalue = constrain(LDRvalue, lightValue , darkValue);
  PWMvalue = map(LDRvalue, lightValue, darkValue, 0, 220);
  analogWrite(PWMpin, PWMvalue); // write to the OE pins

if (irrecv.decode(&results))
   {
       switch (results.value)
       {
         case 0x801:  // kod klawisza 1
             setRegisterPin(16, LOW);
            break;
           
         case 0x1:  // kod klawisza 1
             setRegisterPin(16, HIGH);
            break;
           
         case 0x802:  // kod klawisza 2
              setRegisterPin(17, LOW);
            break;
           
         case 0x2:  // kod klawisza 2
              setRegisterPin(17, HIGH);
            break;
           
         case 0x803:  // kod klawisza 3
            //digitalWrite(Out3Pin, LOW);
              setRegisterPin(18, LOW);
            break;
           
         case 0x3:  // kod klawisza 3
              setRegisterPin(18, HIGH);
            break;
           
         case 0x80D:  // kod klawisza 4
              setRegisterPin(19, LOW);
            break;
           
         case 0xD:  // kod klawisza 4
              setRegisterPin(19, HIGH);
            break;

         case 0x807:  // kod klawisza 7 CH1
              setRegisterPin(20, LOW);
            break;
           
         case 0x7:  // kod klawisza 7 CH1
             setRegisterPin(20, HIGH);
            break;     
                 
          case 0x808:  // kod klawisza 8 CH2
            setRegisterPin(21, LOW);
            break;
           
         case 0x8:  // kod klawisza 8 CH2
            setRegisterPin(21, HIGH);
            break; 
                     
          case 0x809:  // kod klawisza 9 CH3
              setRegisterPin(22, LOW);
            break;
           
         case 0x9:  // kod klawisza 9 CH3
              setRegisterPin(22, HIGH);
            break; 

           
         case 0x11:  // kod klawisza 5
            digitalWrite(VolUpPin, LOW);
            delay(250);
            digitalWrite(VolDownPin, LOW);
            break;
           
         case 0x811:  // kod klawisza 5
            digitalWrite(VolUpPin, HIGH);
            delay(250);
            digitalWrite(VolUpPin, LOW);
            break;
           
         case 0x10:  // kod klawisza 6
            digitalWrite(VolDownPin, LOW);
            delay(250);
            digitalWrite(VolUpPin, LOW);
            break;
           
         case 0x810:  // kod klawisza 6
            digitalWrite(VolDownPin, HIGH);
            delay(250);
            digitalWrite(VolDownPin, LOW);
            break;
           
         case 0x80C:  // kod klawisza OFF
            //digitalWrite(Out1Pin, HIGH);
            break;
           
         case 0xC:  // kod klawisza OFF
            //digitalWrite(Out1Pin, LOW);
            break;


         }
   irrecv.resume();
   }

// read pot &  update outputs to 2 daisy chained shift registers
potValue = analogRead(A0);

if ( potValue >=0 && potValue <=20)
{
setRegisterPin(1, HIGH);
}

if ( potValue >=20 && potValue <=63)
{
setRegisterPin(15, HIGH);
}

if ( potValue >=63 && potValue <=126)
{
setRegisterPin(14, HIGH);
}

if ( potValue >=126 && potValue <=189)
{
setRegisterPin(13, HIGH);
}

if ( potValue >=189 && potValue <=252)
{
setRegisterPin(12, HIGH);
}

if ( potValue >=252 && potValue <=315)
{
setRegisterPin(11, HIGH);
}

if ( potValue >=315 && potValue <=378)
{
setRegisterPin(10, HIGH);
}

if ( potValue >=378 && potValue <=441)
{
setRegisterPin(9, HIGH);
}

if ( potValue >=441 && potValue <=504)
{
setRegisterPin(8, HIGH);
}

if ( potValue >=504 && potValue <=567)
{
setRegisterPin(7, HIGH);
}

if ( potValue >=567 && potValue <=630)
{
setRegisterPin(6, HIGH);
}

if ( potValue >=630 && potValue <=693)
{
setRegisterPin(5, HIGH);
}

if ( potValue >=693 && potValue <=756)
{
setRegisterPin(4, HIGH);
}

if ( potValue >=756 && potValue <=819)
{
setRegisterPin(3, HIGH);
}

if ( potValue >=819 && potValue <=882)
{
setRegisterPin(2, HIGH);
}

if ( potValue >=882 && potValue <=945)
{
setRegisterPin(1, HIGH);
}

if ( potValue >=945 && potValue <=1010)
{
setRegisterPin(0, HIGH);
}

if ( potValue >=1010 && potValue <=1023)
{
setRegisterPin(0, LOW);
}



  writeRegisters();
  delay(10);
  //clearRegisters();
}



Potentiometer works, but only in one direction. If I set 100% and all led are on, then if i go back to 0% all leds are still on.


gavron04

#57
Sep 15, 2017, 07:02 am Last Edit: Sep 15, 2017, 07:11 am by gavron04



Please tell me about SRCLR / CLR pin. It must be connected directly to arduino or it must be connected by 10kR to VCC?


(tpic6C595)

Grumpy_Mike

#58
Sep 16, 2017, 09:31 am Last Edit: Sep 16, 2017, 09:34 am by Grumpy_Mike
Quote
Potentiometer works, but only in one direction. If I set 100% and all led are on, then if i go back to 0% all leds are still on.
That is because your code never turns them off.

Just after the pot reading then have a small loop to set all the register pins to low.

The CLR is a clear pin, when it is taken low all the shift register outputs get set to zero.
If you don't want that feature then pull it up high through a 10K.

The SRCLK is the serial clock sometimes called just clock and must be pulsed by the Arduino.

gavron04

#59
Sep 16, 2017, 09:47 am Last Edit: Sep 16, 2017, 09:59 am by gavron04
Thanks. I will test new code at the weekend.


Just after the pot reading then have a small loop to set all the register pins to low.
If I will set all the register pins to low that will clear my set from third register? Won't it? (Third register works after I press 1,2,3,7,8,9 on remote control - on my code You can see)


Or that will help:

Code: [Select]
if ( potValue >=0 && potValue <=20)
{
setRegisterPin(15, HIGH);
}

if ( potValue >=20 && potValue <=63)
{
setRegisterPin(15, HIGH);
}

if ( potValue >=63 && potValue <=126)
{
setRegisterPin(14, HIGH);
}

if ( potValue >=126 && potValue <=189)
{
setRegisterPin(13, HIGH);
}

if ( potValue >=189 && potValue <=252)
{
setRegisterPin(12, HIGH);
}

if ( potValue >=252 && potValue <=315)
{
setRegisterPin(11, HIGH);
}

if ( potValue >=315 && potValue <=378)
{
setRegisterPin(10, HIGH);
}

if ( potValue >=378 && potValue <=441)
{
setRegisterPin(9, HIGH);
}

if ( potValue >=441 && potValue <=504)
{
setRegisterPin(8, HIGH);
}

if ( potValue >=504 && potValue <=567)
{
setRegisterPin(7, HIGH);
}

if ( potValue >=567 && potValue <=630)
{
setRegisterPin(6, HIGH);
}

if ( potValue >=630 && potValue <=693)
{
setRegisterPin(5, HIGH);
}

if ( potValue >=693 && potValue <=756)
{
setRegisterPin(4, HIGH);
}

if ( potValue >=756 && potValue <=819)
{
setRegisterPin(3, HIGH);
}

if ( potValue >=819 && potValue <=882)
{
setRegisterPin(2, HIGH);
}

if ( potValue >=882 && potValue <=945)
{
setRegisterPin(1, HIGH);
}

if ( potValue >=945 && potValue <=1010)
{
setRegisterPin(0, HIGH);
}

if ( potValue >=1010 && potValue <=1023)
{
setRegisterPin(0, HIGH);
}


//set pin to LOW
if ( potValue >=1010 && potValue <=1023)
{
setRegisterPin(0, LOW);
}

if ( potValue >=945 && potValue <=1010)
{
setRegisterPin(0, LOW);
}


if ( potValue >=882 && potValue <=945)
{
setRegisterPin(1, LOW);
}

if ( potValue >=819 && potValue <=882)
{
setRegisterPin(2, LOW);
}

if ( potValue >=756 && potValue <=819)
{
setRegisterPin(3, LOW);
}


if ( potValue >=693 && potValue <=756)
{
setRegisterPin(4, LOW);
}

if ( potValue >=630 && potValue <=693)
{
setRegisterPin(5, LOW);
}

if ( potValue >=567 && potValue <=630)
{
setRegisterPin(6, LOW);
}

if ( potValue >=504 && potValue <=567)
{
setRegisterPin(7, LOW);
}

if ( potValue >=441 && potValue <=504)
{
setRegisterPin(8, LOW);
}

if ( potValue >=378 && potValue <=441)
{
setRegisterPin(9, LOW);
}

if ( potValue >=315 && potValue <=378)
{
setRegisterPin(10, LOW);
}

if ( potValue >=252 && potValue <=315)
{
setRegisterPin(11, LOW);
}

if ( potValue >=189 && potValue <=252)
{
setRegisterPin(12, LOW);
}

if ( potValue >=126 && potValue <=189)
{
setRegisterPin(13, LOW);
}

if ( potValue >=63 && potValue <=126)
{
setRegisterPin(14, LOW);
}

if ( potValue >=20 && potValue <=63)
{
setRegisterPin(15, LOW);
}

if ( potValue >=0 && potValue <=20)
{
setRegisterPin(15, LOW);
}





The SRCLK is the serial clock sometimes called just clock and must be pulsed by the Arduino.
SRCLK = SRCK?


Have a good day!


Regards

Go Up