-->
Page 1 of 2

Add more GPIO via shift register 74HC595 Enjoy! v3.x

PostPosted: Wed Jul 20, 2016 9:49 pm
by forlotto


Ok so I purchased an 8 relay board.

Make sure jumper is set to the right on relay board to be safe (burnt up some electronics the other way.

You will need:
Nodemcu
8 relay board
Project board
5v power supply
SN74HC595N 8bit shift register
dupont wire female to female
dupont pin headers
soldering iron

Solder Shift register on project board.
Break out all pins to pin headers
connect OE pin to GND with jumper wire and solder
connect SERCLEAR to VCC of shift register with jumper wire and solder
D4 goes to Serial Clock AKA CLOCK
D6 goes to Serial AKA DATA
D5 goes to Register Clock AKA LATCH

cut off end of 5v power supply
carefully meter for + and -
using dupont wire hook the following:
hook positive 5v to vcc on 8 relay board and VIN of nodemcu
hook gnd to all 3 devices and tie them together to ensure they are common
hook QA from shift register to in1
hook QB to in2
hook QC to in3
hook QD to in4
hook QE to in5
hook QF to in6
hook QG to in7
hook QH to in8
hook 3v from nodemcu to vcc on shift register
hook gnd from nodemcu to gnd on shift register as I said bond all common gnd somewhere along the line.

now here is the code to add 8 on/off gpio's to your nodemcu only using 3 GPIO's ;)

Code: Select allbutton relay1, [reA]
button relay2, [reB]
button relay3, [reC]
button relay4, [reD]
button relay5, [reE]
button relay6, [reF]
button relay7, [reG]
button relay8, [reH]
wait


[reA]
     ss = ss xor 1
dat = ss
gosub [bitbang]

[reB]
 ss = ss xor 2
dat = ss
gosub [bitbang]
[reC]
 ss = ss xor 4
dat = ss
gosub [bitbang]
[reD]
 ss = ss xor 8
dat = ss
gosub [bitbang]
[reE]
 ss = ss xor 16
dat = ss
gosub [bitbang]
[reF]
 ss = ss xor 32
dat = ss
gosub [bitbang]
[reG]
 ss = ss xor 64
dat = ss
gosub [bitbang]
[reH]
ss = ss xor 128
dat = ss
gosub [bitbang]

[bitbang]

ww = dat
io(po,D4,0)  'clock
for w = 0 to 7
  b = ww and 128
  if b = 0 then
     io(po,D6,1)
  else
     io(po,D6,0)

  end if
  ww = ww << 1
  io(po,D4,1)  'clock
  if w < 7 then
io(po,D4,0)  'clock
end if
next w
if w = 0 then io(po,D5,0)
end if
 io(po,D5,1)
wait



The buttons function as a toggle so you push it turns on you push the same one again it turns off.

This is the basic principal of getting a shift register running on basic I hope you all can appreciate this.


-forlotto

Re: Add more GPIO via shift register 74HC595 Enjoy! v3.x

PostPosted: Thu Jul 21, 2016 9:53 pm
by forlotto
Errr left a few things out. Updated to fix this...

Now all appropriate info should be there ;)

Enjoy!

Re: Add more GPIO via shift register 74HC595 Enjoy! v3.x

PostPosted: Wed Jul 27, 2016 8:12 am
by marcomart
Hello.

I think that there could be a bug error issue regarding the gosub- return statements.I hooked up a pcf8574 expander (more info regarding this later!!) and I try to put return at the end of bitbang subroutine and a goto
to the end of program and everything crash.
I notice that You didn't put and actually work, so I'm a little bit confused.
BTW if you put this piece of code, within bitbang sub instead of the shift register one, it will work also with
I2c pcf8574!!
So I think that should be check GOSUB and GOTO statements for a matter of bugs.

[bitbang]
i2c.begin(39) 'address of pcf8574
i2c.write(dat)
i2c.end
return

Marco.

Re: Add more GPIO via shift register 74HC595 Enjoy! v3.x

PostPosted: Thu Jul 28, 2016 12:07 am
by forlotto
The operation of the shift register is a bit different than the shift register you may wish to have a look at the datasheets I have not had much experience with either chip and I read quite a bit about the 74HC585 before I understood the flaw in code that needed to be fixed to get that to work.

Return is an odd thing it seems to me as well it doesn't actually return to nothing it more or less works like an end program or something I notice you need to use nothing or wait to remain in your program as return doesn't seem to function how it used to or maybe it did but I just did not pay attention. But to me it seems as if there is something wrong here as well.

V3.x is buggy I will say that there are quite a few underlying issues that have not yet surfaced however when and if they do and the effort is put into basic to fix these flaws Basic will be an extremely important tool for IOT I believe in conjunction with the esp8266 and quite possibly the esp32 as well but I think we have a couple of years before the esp32 is useful maybe less because of the gravity of the esp8266 there are a lot more minds on development now.

I cannot promise I will come up with an answer soon on this one have a lot to comprehend myself. I do have a board and am willing to tinker with it as time is afforded to me.

Some things that would help me though are:

The full code you are using preferred if you use the code tags as well so the format of your code is kept to prevent any errors that may result from not using them.

Anyhow keep me updated and post back just used my relay board for another pet project of mine looking into getting another one here soon.

Thanks for sharing and continue it would be nice to get to the bottom of this one. I believe support could be added to basic for shift registers with the code I have all that you would have to do is add commands for the ports to preform the tasks on the three pins to toggle whatver ... So my suggestion for support would be the togsp 0A and then have it store the first status of that port as ON as the first toggle is always on next toggle would be off you could even just use a counter and detect if it is odd or even to know if it is on or off.

Anyhow aside from this it would be interesting to see this other expansion chip working I am all for it.