Page 2 of 2

Re: Controlling a 7 segment 4 digit display with a Raspberry

Posted: Mon Jan 30, 2017 10:35 pm
by DougieLawson
lohtse wrote:Hi all


we have just recieved two of these https://www.aliexpress.com/item/4-Bits- ... spberry-PI. We are looking for any help and advise with wiring and pinouts for use with our Pi-3's Also what would be the best code to use to allow us to use them as clocks??

looking forward to any and all assistance..

regards
Lohtse
That is completely off topic for this thread. Start a new thread and post your question there.

Re: Controlling a 7 segment 4 digit display with a Raspberry

Posted: Tue Jan 31, 2017 6:51 am
by lohtse
DougieLawson wrote:
lohtse wrote:Hi all


we have just recieved two of these https://www.aliexpress.com/item/4-Bits- ... spberry-PI. We are looking for any help and advise with wiring and pinouts for use with our Pi-3's Also what would be the best code to use to allow us to use them as clocks??

looking forward to any and all assistance..

regards
Lohtse
That is completely off topic for this thread. Start a new thread and post your question there.

Eeer why is this OFF TOPIC??

I thought it was relivant due to the device and requirements!?

Will start another thread but would have thought this one was appropriate and within in the RULES of the forum!

Re: Controlling a 7 segment 4 digit display with a Raspberry

Posted: Tue Jan 31, 2017 11:09 am
by DougieLawson
lohtse wrote:
I thought it was relivant due to the device and requirements!?

Will start another thread but would have thought this one was appropriate and within in the RULES of the forum!
It's 100% off topic because you're not wiring your LED directly to a set of 12 GPIO pins and driving them with python.

Re: Controlling a 7 segment 4 digit display with a Raspberry

Posted: Sun May 14, 2017 3:06 pm
by neonj
Hi blachanc,

Thanks for the ramdisk code.

Can you please tell me how do I exit the python script after a set number of seconds.

Regards

Re: Controlling a 7 segment 4 digit display with a Raspberry

Posted: Sun May 14, 2017 3:10 pm
by neonj
blachanc wrote:Well,
I learned something(correct me if I am wrong): a python script does not read the updated env variable value in a terminal. It will keep the values it reads when it is invoked.

SO I reverted back to my second idea of using a file on a ramdisk for communication(and it is working). I still wonder if there would be a better way.

this is the main display loop (display daemon):
display.py

Code: Select all

#!/usr/bin/python
# Bert's code re-written for common anode LED arrays.
#blachanc: used dougie's code and added external data input in ramdisk
import RPi.GPIO as GPIO
import time
import sys
GPIO.setmode(GPIO.BCM)
#GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
GPIO.setup(7, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

#LED pin == GPIO == segment / digit
# 11     ==  24  == a
# 07     ==  12  == b
# 04     ==  19  == c
# 02     ==  21  == d
# 01     ==  23  == e
# 10     ==  22  == f
# 05     ==  15  == g
# 03     ==  11  == dp

segments = (24,12,19,21,23,22,15,11)

for segment in segments:
  GPIO.setup(segment, GPIO.OUT)
  GPIO.output(segment, 1)

# 12     ==  26  == digit 1
# 09     ==  18  == digit 2
# 08     ==  16  == digit 3
# 06     ==  13  == digit 4

digits = (26,18,16,13)
for digit in digits:
  GPIO.setup(digit, GPIO.OUT)
  GPIO.output(digit, 0)

charactere = {' ':(1,1,1,1,1,1,1),
'0':(0,0,0,0,0,0,1),
'1':(1,0,0,1,1,1,1),
'2':(0,0,1,0,0,1,0),
'3':(0,0,0,0,1,1,0),
'4':(1,0,0,1,1,0,0),
'5':(0,1,0,0,1,0,0),
'6':(0,1,0,0,0,0,0),
'7':(0,0,0,1,1,1,1),
'8':(0,0,0,0,0,0,0),
'9':(0,0,0,0,1,0,0)}
counter=100000

##############################
# use a file on ramdisk to get the data to be displayed
# bash commands passed in terminal:
# sudo mkdir /mnt/ramdisk
# sudo mount -t tmpfs -o size=128K tmpfs /mnt/ramdisk
# sudo chown pi:pi /mnt/ramdisk
# echo "1235" > /mnt/ramdisk/display.dat
###############################
def get_data_to_display():
    txt=open("/mnt/ramdisk/display.dat")
    new_string = str(txt.readline())
    txt.close()
    new_string=new_string.rstrip()
	#
	# buf with 0 if less than 4 char
	#
    new_string= str(new_string).rjust(4,"0")
	#
	# limit to 4 chars
	#
    new_string= new_string[0:4]
    return new_string
###########
# main loop
###########
try:
  while True:
    #
	# First we only update the data to display each x loops
	#
    counter +=1
    if (counter > 50):
       counter = 0
       new_string = get_data_to_display()
# for debug only       print  new_string
       data_to_display = new_string

    for digit in range(4):
      for loop in range(0,7):
        GPIO.output(segments[loop], charactere[data_to_display[digit]][loop])
      GPIO.output(digits[digit], 1)
      time.sleep(0.001)
      GPIO.output(digits[digit], 0)

except KeyboardInterrupt:
  GPIO.cleanup()


and this is the data being feed to the display (scrolling numbers) for proof of concept.
feedata.py:

Code: Select all

#!/usr/bin/python

import time
import sys
counter = 0 
data_to_display= "    "
###########
# main loop
###########
try:
  while True:
    counter +=1
    if (counter > 9):
       counter = 0
     #
     # shift the data to be displayed
     #
    data_to_display= data_to_display[1] + data_to_display[2] + data_to_display[3]+ (str(counter))[0]
    txt=open("/mnt/ramdisk/display.dat", "w" )
    txt.write(data_to_display)
    txt.close()
# For debug only    print data_to_display
    time.sleep(.5)
   
except KeyboardInterrupt:
  exit()

Hi blachanc,

Thanks for the nice code, just what I needed.

Can you please tell how to cleanly exit this code after a set number of seconds.

I'm just a beginner so pardon my novice question.

Regards