vachhaninimiT
Posts: 10
Joined: Sat Apr 12, 2014 5:42 pm

Raspberry Pi and HCF 4094B shift register

Tue Aug 28, 2018 9:00 am

Greetings People,

I have board with 6 digit 7 segment display using HCF4094B shift registers. I have interfaced it with arduino and it displays 6 digits successfully.

Now on Raspberry Pi i want to do the same thing using python. Is it possible ?

User avatar
davidcoton
Posts: 5027
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK
Contact: Website

Re: Raspberry Pi and HCF 4094B shift register

Tue Aug 28, 2018 9:29 am

Yes, but if you need help you will have to give far more details, like:
  • Which model Pi?
  • Which OS (and date)?
  • Show your existing circuit.
  • What else is connected to your Pi?
  • What (if anything) have you tried? What ideas do you have?
Perhaps the most important thing to remember is that the Pi GPIOs run at 3V3. If your Arduino runs at 5V, then you may need level shifters -- or some other adaptation of your existing hardware. Get it wrong, and Bang goes your Pi.
Signature retired

vachhaninimiT
Posts: 10
Joined: Sat Apr 12, 2014 5:42 pm

Re: Raspberry Pi and HCF 4094B shift register

Tue Aug 28, 2018 9:44 am

Well its raspberry Pi 2B.

Below is the code that i have tried...

Code: Select all

import wiringpi
import time

wiringpi.wiringPiSetupGpio()

_DATA 		= 23
_STRB 		= 24
_CLK 		= 25

_DIGITS     = 6
_7SEGTYPE   = 'A'

_DIGITS		= [0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
			# 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, Blank, -
'''
_NUMBERS = [bytes(b'xB11100111'),
			bytes(b'xB10000100'),
			bytes(b'xB11010011'),
			bytes(b'xB11010110'),
			bytes(b'xB10110100'),
			bytes(b'xB01110110'),
			bytes(b'xB01110111'),
			bytes(b'xB11000100'),
			bytes(b'xB11110111'),
			bytes(b'xB11110110'),
			bytes(b'xB00000000'),
			bytes(b'xB00010000')]
'''			
_NUMBERS1 = [231,
			 132,
			 211,
			 214,
			 180,
			 118,
			 119,
			 196,
			 247,
			 246,
			 0,
			 16]


'''
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)

GPIO.setup(_DATA , GPIO.OUT)
GPIO.setup(_STRB , GPIO.OUT)
GPIO.output(_STRB, 1)	
GPIO.setup(_CLK , GPIO.OUT)
'''

wiringpi.pinMode(_DATA, 1)
wiringpi.pinMode(_STRB, 1)
wiringpi.pinMode(_CLK, 	1)

#wiringpi.digitalWrite(_STRB, 0)

def Print(number, digits, dp):
	negate = False
	x = int(dp)
	y = int(0)
	
	tmp = long(number)
	
	if(tmp <  0):
		negate = 1
		tmp = tmp * -1
		if(tmp > 999999):
			tmp /= 10
			if(x > 0):
				x = x-1
	else:
		if(tmp > 999999):
			tmp /= 10
			if(x > 0):
				x = x-1
				
	while(tmp > 0 and y < digits):
		_DIGITS[y] = tmp % 10
		tmp /= 10
		y += 1
		
	while(y < digits):
		_DIGITS[y] = 0
		y += 1
		
	if(negate):
		_DIGITS[digits - 1] = 11
		
	#for x in range(6):
		#print _DIGITS[x]	
		
	PrintDigits(digits, x)	
	
def PrintDigits(digits, dp):
	global _DIGITS
	global _7SEGTYPE
	
	wiringpi.digitalWrite(_STRB, 0)
	
	for i in range(6):		
		dig = _NUMBERS[_DIGITS[i]]
		print dig
		#if(dp > 0):
			#if(i == dp):
				#dig |= xB00001000
				
		if(_7SEGTYPE == 'C'):
			PrintHex(dig, 0)		
		elif (_7SEGTYPE == 'A')	:			
			PrintHex(dig, 0)
	
	wiringpi.digitalWrite(_STRB, 1)

def PrintHex( x, y):	
	wiringpi.shiftOut(_DATA, _CLK, 0, x)
	
if __name__ == "__main__":
	Print(1, 6, 0)	
	

_DATA = 23(according to wiringpi pin#)
_STRB = 24(according to wiringpi pin#)
_CLK = 25(according to wiringpi pin#)

danjperron
Posts: 3502
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Raspberry Pi and HCF 4094B shift register

Tue Sep 04, 2018 5:50 pm

Be aware that if your power on the 74HCF4094 is 5V the VIH is 0.7 * 5V = 3.5V. Then it won't work. You will need to reduce VCC or add a level converter from 3.3V to 5V.


Also Why using wiringpi? it is so simple with spidev

ex:

Code: Select all

import spidev
import time
spi = spidev.SpiDev()
spi.open(0,0)
Counter=0;
#Digits   Convert nibble  value into  the correct segment led  digit 
Digits = [63,6,91,79,102,109,125,7,127,111,119,124,57,94,121,113]
while True:

  D1 =  Digits[Counter % 10]
  D2 =  Digits[(Counter / 10) % 10]
  D3 =  Digits[(Counter / 100) % 10]
  D4 =  Digits[(Counter / 1000) % 10]
  #this is actually the single command to send info ( 4 bytes)
  spi.xfer2([D1,D2,D3,D4]);
  Counter = Counter + 1
  time.sleep(0.1)

Return to “General discussion”