element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum rebuilding a accordion with esp32
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Not Answered
  • Replies 4 replies
  • Subscribers 389 subscribers
  • Views 1154 views
  • Users 0 members are here
  • esp32
  • shift register
  • accordion
  • 74HC165
Related

rebuilding a accordion with esp32

SWEVRS
SWEVRS over 3 years ago

Hello

I have a project there i planning to convert a accoridion to be digital, but i struggle to get shift registers to work with my esp32
I have manage to wire up and get the code working with 32 buttons.
https://wokwi.com/projects/340811612207186514

but when i dublicated and connected the wires and change the code i can't get it to work properly.
it returns 2 button values
https://wokwi.com/projects/340811464347484755

I really need some help/advice/guidens

  • Sign in to reply
  • Cancel

Top Replies

  • fmilburn
    fmilburn over 3 years ago in reply to SWEVRS +2
    The variable optionSwitch is an unsigned 32-bit integer. The reason that it is set to 24 in the working code is that it reads in 8 bits when the counter i is equal to 24, 16, 8, and 0 and shifts it into…
  • SWEVRS
    SWEVRS over 3 years ago in reply to shabaz +1
    Okey, i Will rebuild The curuit tomorrow and change The things you adviced me, but now i have some things to look i to. So I Will " kill my darling" and begin with a fresh rebuild. ... But i have…
  • skruglewicz
    skruglewicz over 3 years ago in reply to SWEVRS +1
    the loop starts with the value of i set to 24 and i is used then decremented by 8 until it reaches 0. In the 2nd code segment the value of i is set at 56 and i is then used then decremented by 8 until…
  • shabaz
    0 shabaz over 3 years ago

    Hi,

    You've got something weird going on with the switch wiring. The switch has four connections. I've highlighted with blue circles the two connections that are internally permanently connected together, and in yellow are the other two connectors that are internally permanently connected together too. It's a mechanical thing, they are constructed like that for ease of manufacture and mounting.

    Anyway, you have a green wire going to one of the blue connections, and a black wire going to the other blue connection. Since they are internally connected, that means you've got a resistor wired between the supply and ground, which doesn't do anything (except consume current). It also means all the inputs on the '165 chips are actually floating when no button is pressed, which isn't what you probably wanted.

    Also the input on the first '165 chip should be connected to either ground or the supply, it doesn't matter which (it shouldn't be left floating).

    image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • SWEVRS
    0 SWEVRS over 3 years ago in reply to shabaz

    Okey,  i Will rebuild The curuit tomorrow and change The things you adviced me,  but now i have some things to look i to.  So I Will " kill my darling"  and begin with a fresh rebuild. 

    Grin...

    But i have one more question about The for loops

    The 1 loop is to place The Buttons in The right order?

    The 2 loop is to tell how many Button it is?

    Am i right?

    for( int i=24; i>=0; i-=8)
    What does The i=24; mean?   
    In The second code it is i=56
    How is that calculated? 
    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • skruglewicz
    0 skruglewicz over 3 years ago in reply to SWEVRS

    the loop starts with the value of i set to 24 and i is used then decremented by 8 until it reaches 0.

    In the 2nd code segment the value of i is set at 56 and i is then used then decremented by 8 until it reaches 0.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • fmilburn
    0 fmilburn over 3 years ago in reply to SWEVRS

    The variable optionSwitch is an unsigned 32-bit integer.  The reason that it is set to 24 in the working code is that it reads in 8 bits when the counter i is equal to 24, 16, 8, and 0 and shifts it into optionSwitch by the value of i for a total of 32 bits. The loop in the code that doesn't work is trying to shift 64 bits into a 32-bit integer.  Non-working code is shown below.

      // Reading one 74HC165 at a time and combining them into a 32 bit variable
      // The last 74HC165 is at the bottom, but the switches start numbering
      // at the top. So the first byte has to be shifted into the highest place.
      uint32_t optionSwitch = 0;
      for( int i=56; i>=0; i-=8)
      {
        optionSwitch |= ((uint32_t) ReadOne165()) << i;
      }
    
      for( int i = 0; i<64; i++)
      {
        if( bitRead( optionSwitch, i) != bitRead( oldOptionSwitch,i))
        {
          Serial.print( "Switch ");
          Serial.print( i);
          Serial.print( " is now ");
          Serial.println( bitRead( optionSwitch, i) == 0 ? "down ↓" : "up   ↑");
        }
      }

    If your compiler allows uint64_t you can try that for both optionSwitch and oldOptionSwitch.  Else could use two uint32_t.

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube