bsch2734 / SpiShiftRegisterChain

A simple Arduino library for controlling any length of chained 595 style shift registers over the built in SPI bus
The Unlicense
0 stars 1 forks source link

Simple Example #1

Open Nezaemmy opened 2 weeks ago

Nezaemmy commented 2 weeks ago

Hello sir, I would like to ask you if you have any simple example of how to use this library. like switch ON and OFF of any pin of shift register.

bsch2734 commented 2 weeks ago

Thanks for reaching out. I have been meaning to get the documentation for this up for a while so this will be a good excuse to finish that. I will try to post something tonight.

On Monday, October 7, 2024 at 10:33:46 AM CDT, Nezaemmy ***@***.***> wrote:  

Hello sir, I would like to ask you if you have any simple example of how to use this library. like switch ON and OFF of any pin of shift register.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you are subscribed to this thread.Message ID: @.***>

Nezaemmy commented 2 weeks ago

Thank you

bsch2734 commented 2 weeks ago

Documentation was added in bfc9f387afa272f2fdbd6b780677add071996595. Please feel free to open another issue if you have any further questions.

Nezaemmy commented 1 week ago

Thank you for the good explanation, I have one question. in the note is written For each additional shift register in the chain:

Connect the data chaining pin, labeled Q7’ or Q7’ Out on most 8 bit registers, of the current register to the Data pin of the next register in the chain. Ground: Connect the GND pins on the shift register and Arduino.

What happen to the Latch Pin and SPI Clock Pin of the additional shift register, we leave those pins open or we connect them in parrallel with the same pins of first shift register? like in the image below 74hc595

bsch2734 commented 1 week ago

Your diagram is correct. You need to connect the latch and clock pins of all registers in the chain. I will clarify the documentation later.

Nezaemmy commented 5 days ago

hello Sir I get this error msg c:\Users\Emugwaneza\Documents\Arduino\libraries\SPIShiftRegister\src\SpiShiftRegisterChain.cpp: In member function 'void SpiShiftRegisterChain::allocateMemory()': c:\Users\Emugwaneza\Documents\Arduino\libraries\SPIShiftRegister\src\SpiShiftRegisterChain.cpp:78:34: error: no matching function for call to 'max(int, unsigned int&)' 78 | _dataArray = new byte[max(4, _dataLengthBytes)]; | ~^~~~~~~ In file included from C:/Users/Emugwaneza/AppData/Local/Arduino15/packages/esp32/tools/esp-x32/2405/xtensa-esp-elf/include/c++/13.2.0/algorithm:61, from C:\Users\Emugwaneza\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.1.0-RC1\cores\esp32/Arduino.h:188, from c:\Users\Emugwaneza\Documents\Arduino\libraries\SPIShiftRegister\src\SpiShiftRegisterChain.h:5, from c:\Users\Emugwaneza\Documents\Arduino\libraries\SPIShiftRegister\src\SpiShiftRegisterChain.cpp:1: C:/Users/Emugwaneza/AppData/Local/Arduino15/packages/esp32/tools/esp-x32/2405/xtensa-esp-elf/include/c++/13.2.0/bits/stl_algo.h:5805:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)' 5805 | max(initializer_list<_Tp> l, _Compare comp) | ^~~ C:/Users/Emugwaneza/AppData/Local/Arduino15/packages/esp32/tools/esp-x32/2405/xtensa-esp-elf/include/c++/13.2.0/bits/stl_algo.h:5805:5: note: template argument deduction/substitution failed: c:\Users\Emugwaneza\Documents\Arduino\libraries\SPIShiftRegister\src\SpiShiftRegisterChain.cpp:78:34: note: mismatched types 'std::initializer_list<_Tp>' and 'int' 78 | _dataArray = new byte[max(4, _dataLengthBytes)]; | ~^~~~~~~ C:/Users/Emugwaneza/AppData/Local/Arduino15/packages/esp32/tools/esp-x32/2405/xtensa-esp-elf/include/c++/13.2.0/bits/stl_algo.h:5795:5: note: candidate: 'template constexpr _Tp std::max(initializer_list<_Tp>)' 5795 | max(initializer_list<_Tp> l) | ^~~ C:/Users/Emugwaneza/AppData/Local/Arduino15/packages/esp32/tools/esp-x32/2405/xtensa-esp-elf/include/c++/13.2.0/bits/stl_algo.h:5795:5: note: template argument deduction/substitution failed: c:\Users\Emugwaneza\Documents\Arduino\libraries\SPIShiftRegister\src\SpiShiftRegisterChain.cpp:78:34: note: mismatched types 'std::initializer_list<_Tp>' and 'int' 78 | _dataArray = new byte[max(4, _dataLengthBytes)]; | ~^~~~~~~ In file included from C:/Users/Emugwaneza/AppData/Local/Arduino15/packages/esp32/tools/esp-x32/2405/xtensa-esp-elf/include/c++/13.2.0/bits/specfun.h:43, from C:/Users/Emugwaneza/AppData/Local/Arduino15/packages/esp32/tools/esp-x32/2405/xtensa-esp-elf/include/c++/13.2.0/cmath:3699, from C:/Users/Emugwaneza/AppData/Local/Arduino15/packages/esp32/tools/esp-x32/2405/xtensa-esp-elf/include/c++/13.2.0/math.h:36, from C:\Users\Emugwaneza\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.1.0-RC1\cores\esp32/esp32-hal.h:30, from C:\Users\Emugwaneza\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.1.0-RC1\cores\esp32/Arduino.h:36: C:/Users/Emugwaneza/AppData/Local/Arduino15/packages/esp32/tools/esp-x32/2405/xtensa-esp-elf/include/c++/13.2.0/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)' 303 | max(const _Tp& a, const _Tp& b, _Compare comp) | ^~~ C:/Users/Emugwaneza/AppData/Local/Arduino15/packages/esp32/tools/esp-x32/2405/xtensa-esp-elf/include/c++/13.2.0/bits/stl_algobase.h:303:5: note: template argument deduction/substitution failed: c:\Users\Emugwaneza\Documents\Arduino\libraries\SPIShiftRegister\src\SpiShiftRegisterChain.cpp:78:34: note: deduced conflicting types for parameter 'const _Tp' ('int' and 'unsigned int') 78 | _dataArray = new byte[max(4, _dataLengthBytes)]; | ~^~~~~~~ C:/Users/Emugwaneza/AppData/Local/Arduino15/packages/esp32/tools/esp-x32/2405/xtensa-esp-elf/include/c++/13.2.0/bits/stl_algobase.h:257:5: note: candidate: 'template constexpr const _Tp& std::max(const _Tp&, const _Tp&)' 257 | max(const _Tp& a, const _Tp& b) | ^~~ C:/Users/Emugwaneza/AppData/Local/Arduino15/packages/esp32/tools/esp-x32/2405/xtensa-esp-elf/include/c++/13.2.0/bits/stl_algobase.h:257:5: note: template argument deduction/substitution failed: c:\Users\Emugwaneza\Documents\Arduino\libraries\SPIShiftRegister\src\SpiShiftRegisterChain.cpp:78:34: note: deduced conflicting types for parameter 'const _Tp' ('int' and 'unsigned int') 78 | _dataArray = new byte[max(4, _dataLengthBytes)]; | ~^~~~~~~

exit status 1

Compilation error: exit status 1

bsch2734 commented 5 days ago

I think I see where this is coming from, but I cannot reproduce it. Can you provide me with a small bit of code that should show the error? My test code looks like this and compiles fine. Let me know if it does not for you:

#include <SpiShiftRegisterChain.h>

SpiShiftRegisterChain chain(3,2);

void setup() {}

void loop() {
  chain.toggleBit(3);
  delay(1000);
}

Once I can reproduce the error on my end it should be an easy fix.

Nezaemmy commented 5 days ago

I used this example

include

include

const int latchPin = 10; const int dataLengthBytes = 4;

SpiShiftRegisterChain shiftRegister(latchPin, dataLengthBytes);

void setup() { SPI.begin(); shiftRegister.setBitOn(0); // Turn on the 1st bit and write data shiftRegister.setBitOff(1, false); // Turn off the 2nd bit without writing shiftRegister.writeData(); // Apply all changes at once delay(1000);

shiftRegister.toggleBit(0); // Toggle the 1st bit and write data delay(1000); }

void loop() { // Your main code here }

bsch2734 commented 3 days ago

Interesting, that also compiles fine on my machine. I think you may just have stricter compiler settings about automatic type conversion than I do. I can work on a fix but I'll need you to check it since I cannot reproduce. It might not be up before Monday though.

Nezaemmy commented 2 days ago

I use ESP32S3 board not arduino AVR board that is the reason it gives me the error. I think it is only compatible with arduino avr board not ESP32 board