Hello everyone. I hope you may be able to help me and my (lack of) understanding of the use of Shift Registers. I have an application I am working on that involves switching multiple 12v loads. I was planning to use a Nano with capacitive touch sensors. The Nano would detect a touch of the sensor and toggle the state of each one accordingly. I have tested this with 9 touch pads and all works okay. I have then added optoisolators to operate a series of small relays. This all seems to be working fine.
I then thought about using a smaller Microcontroller, and as I had a couple of ATTiny84s in the form of DigiSparks, I thought it might be fun to try and use one with a couple of 74HC165 and 74HC595 shift registers. I kind of gave up on the Digispark, as it was a bit of a pain updating the scripts as I needed and there weren't really enough pins available. So, I have now moved on to the Seeed XIAO ESP32-C3 which, with its wireless connectivity, could be handy as the project develops.
So, I watched the video by DBW on the shift registers and am in the process of trying these out. I have also read and watched lots of other material on them from elsewhere (not as good I may add). I have done a couple of projects with 595s before that worked out just fine - but I've had a stroke since then and maybe my brain is still a bit out of whack because, for the life of me, I can not get the set up to work as expected.
I have things set up similarly to the DBW scheme but I have two of each register type connected to 16 switches (2 pin momentary) with 10K resistors between the switch and GND. There are 16 LEDs each with a 0.46k resistor and there are 10uf caps on the power rails.
I have dropped the script onto the ESP32 and updated the pins in use etc but when it's running the patterns displayed on the LEDs and the info in the serial monitor show random button presses when no button are being touched. There does seem to be some recognition of actual button presses, but they are inconsistent.
Would anybody be able to help me get this sorted? I would like to have a similar setup to the DBW scheme working but with the extra registers buttons and LEDs. I would then like to better understand how to watch the input reg for button presses and be able to toggle the output to the 595 for the button pressed. Is this even possible with the ESP32 or should I just go back to the Nano? I had seen someone achieve kind of what I am looking for but was using a bare ATTiny IC with with the registers. He may have been using SPI (another mystery box I haven't opened) and I also saw someone making it work with just a 555 and the registers - though for what I want to do with my project down the line, I think these are not the right solutions for me.
Sorry if I have rambled on (I do that), feel free to ask me questions to fill in the blanks but I am still very much a novice. Photos of my current project and the script in use (I've messed with it a bit and not cleaned it up again) with the Serial Output are attached.
/* 74HC595 & 74HC165 Shift Register Demonstration 2 74hc595-to-74ch165-pattern.ino Input from 8 pushbuttons using 74HC165 Output to 8 LEDs using 74HC595 Select LED pattern using pushbuttons DroneBot Workshop 2020 https://dronebotworkshop.com */ // Define Connections to 74HC165 // ST_CP pin 12 const int latchPin = D1; // SH_CP pin 11 const int clockPin = D0; // DS pin 14 const int dataPin = D2; // PL pin 1 int load = D3; // CE pin 15 int clockEnablePin = D4; // Q7 pin 7 int dataIn = D5; // CP pin 2 int clockIn = D6; //Check it works LED int LEDPin = D10; // Define data array int datArray[16]; void setup () { // Setup Serial Monitor Serial.begin(9600); pinMode(LEDPin, OUTPUT); // 74HC165 pins pinMode(load, OUTPUT); pinMode(clockEnablePin, OUTPUT); pinMode(clockIn, OUTPUT); pinMode(dataIn, INPUT); // 74HC595 pins pinMode(latchPin,OUTPUT); pinMode(clockPin,OUTPUT); pinMode(dataPin,OUTPUT); } void loop() { digitalWrite(LEDPin, 1); // Read Switches // Write pulse to load pin digitalWrite(LEDPin, 1); digitalWrite(load,LOW); delayMicroseconds(500); digitalWrite(load,HIGH); digitalWrite(LEDPin, 0); delayMicroseconds(5000); // Get data from 74HC165 digitalWrite(clockIn,HIGH); delayMicroseconds(50); digitalWrite(clockEnablePin,LOW); delayMicroseconds(50); byte incoming = shiftIn(dataIn, clockIn, LSBFIRST); delayMicroseconds(50); digitalWrite(clockEnablePin,HIGH); delayMicroseconds(50); // Print to serial monitor Serial.print("Pin States:\r\n"); Serial.println(incoming, BIN); // Setup array for LED pattern switch (incoming) { case B11111111: datArray[0] = B11111111; datArray[1] = B11111111; datArray[2] = B11111111; datArray[3] = B11111111; datArray[4] = B11111111; datArray[5] = B11111111; datArray[6] = B11111111; datArray[7] = B11111111; datArray[9] = B11111111; datArray[9] = B11111111; datArray[10] = B11111111; datArray[11] = B11111111; datArray[12] = B11111111; datArray[13] = B11111111; datArray[14] = B11111111; datArray[15] = B11111111; break; case B00000000: datArray[0] = B00000001; datArray[1] = B00000001; datArray[2] = B00000001; datArray[3] = B00000010; datArray[4] = B00000010; datArray[5] = B00000010; datArray[6] = B00000001; datArray[7] = B00000010; break; case B11111011: datArray[0] = B10000001; datArray[1] = B01000010; datArray[2] = B00100100; datArray[3] = B00011000; datArray[4] = B00000000; datArray[5] = B00100100; datArray[6] = B01000010; datArray[7] = B10000001; break; case B11110111: datArray[0] = B10101010; datArray[1] = B01010101; datArray[2] = B10101010; datArray[3] = B01010101; datArray[4] = B10101010; datArray[5] = B01010101; datArray[6] = B10101010; datArray[7] = B01010101; break; case B11101111: datArray[0] = B10000000; datArray[1] = B00000001; datArray[2] = B01000000; datArray[3] = B00000010; datArray[4] = B00100000; datArray[5] = B00000100; datArray[6] = B00010000; datArray[7] = B00001000; break; case B11011111: datArray[0] = B11000000; datArray[1] = B01100000; datArray[2] = B00110000; datArray[3] = B00011000; datArray[4] = B00001100; datArray[5] = B00000110; datArray[6] = B00000011; datArray[7] = B10000001; break; case B10111111: datArray[0] = B11100000; datArray[1] = B01110000; datArray[2] = B00111000; datArray[3] = B00011100; datArray[4] = B00001110; datArray[5] = B00000111; datArray[6] = B10000011; datArray[7] = B11000001; break; case B01111111: datArray[0] = B10001000; datArray[1] = B01000100; datArray[2] = B00100010; datArray[3] = B00010001; datArray[4] = B10001000; datArray[5] = B01000100; datArray[6] = B00100010; datArray[7] = B00010001; break; default: break; } // Write to LEDs // Count from 0 to 7 digitalWrite(LEDPin, 1); for(int num = 0; num < 16; num++) { // ST_CP LOW to keep LEDs from changing while reading serial data digitalWrite(latchPin, LOW); // Shift out the bits shiftOut(dataPin,clockPin,MSBFIRST,datArray[num]); // ST_CP HIGH change LEDs digitalWrite(latchPin, HIGH); digitalWrite(LEDPin, 0); delay(100); } }
Ooops, I did it again!
..
Ooops, I did it again!
@mikeburton_2000 What are you doing? Anyways the answer to your question is 42.
First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, 360, fairly knowledge in PC plus numerous MPU's & MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.
@zander I can’t see my original post. Not sure if I posted it wrong.
Ooops, I did it again!
@mikeburton_2000 I had that happen to me about a week ago. It was a long post with a big source file. If that sounds familiar, resort to a zip file for source.
First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, 360, fairly knowledge in PC plus numerous MPU's & MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.
i have connected exactly 4 <a href=" removed link " target="_blank" rel="noopener">74HC595 with 32Bits.
@eric12368 Not enough info.
Hardware, wiring diagram, code, what you expect to happen, what is happening.
First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, 360, fairly knowledge in PC plus numerous MPU's & MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.