guzu
Posts: 19
Joined: Thu Nov 10, 2016 7:25 pm

Temp reading from file showed on 7 seg display.

Fri Dec 30, 2016 4:03 pm

Hello.
I am trying to display a temperature (two digits - 29, 23........) read from a file on a seven segment display.
I am having a hard time reading from the file fast enough so I can turn on and off the digits faster than I can see flicker ont the 7 segment display.
What code would you recommend?
Right now if i print on the raspberry screen the content of the file, i refreshes only once about every second. I need to do it much faster. (or just to read from the file every second or so and still refresh the 7 segment display at about 0.005 sec)

I don't know if I made myself understood.
But any help would be appreciated.

Thanks very much . :D

User avatar
FTrevorGowen
Forum Moderator
Forum Moderator
Posts: 5645
Joined: Mon Mar 04, 2013 6:12 pm
Location: Bristol, U.K.
Contact: Website

Re: Temp reading from file showed on 7 seg display.

Fri Dec 30, 2016 4:20 pm

guzu wrote:Hello.
I am trying to display a temperature (two digits - 29, 23........) read from a file on a seven segment display.
I am having a hard time reading from the file fast enough so I can turn on and off the digits faster than I can see flicker ont the 7 segment display.
What code would you recommend?
Right now if i print on the raspberry screen the content of the file, i refreshes only once about every second. I need to do it much faster. (or just to read from the file every second or so and still refresh the 7 segment display at about 0.005 sec)
I don't know if I made myself understood.
But any help would be appreciated.
Thanks very much . :D
What type of display is it and how is it connected to the Pi? (ie. are you software or hardware multiplexing the digits?**)
What happens if you read a chunk of the file into memory first (the file may be small enough to load all of it) and then display the data?
Trev.
** Some examples:
Software multiplexed:
http://www.cpmspectrepi.uk/raspberry_pi ... OfPio.html (NB.a quite old design)
http://www.cpmspectrepi.uk/raspberry_pi ... splay.html
http://www.cpmspectrepi.uk/raspberry_pi ... ube_Module (First module)
Hardware multiplexed:
http://www.cpmspectrepi.uk/raspberry_pi ... odule.html
Still running Raspbian Jessie or Stretch on some older Pi's (an A, B1, 2xB2, B+, P2B, 3xP0, P0W, 2xP3A+, P3B+, P3B, B+, and a A+) but Buster on the P4B's. See: https://www.cpmspectrepi.uk/raspberry_pi/raspiidx.htm

jahboater
Posts: 5825
Joined: Wed Feb 04, 2015 6:38 pm
Location: West Dorset

Re: Temp reading from file showed on 7 seg display.

Fri Dec 30, 2016 5:06 pm

Or this:
https://thepihut.com/products/zeroseg?v ... 4889655496
This is the same hardware multiplexed chip as above, the MAX7219CNG.

These chips have memory, so you just write the data to it as infrequently as you want.
My clock for instance updates once per minute.

guzu
Posts: 19
Joined: Thu Nov 10, 2016 7:25 pm

Re: Temp reading from file showed on 7 seg display.

Fri Dec 30, 2016 9:00 pm

Thanks for your reply.
The display is a 4 digit 7 segment display with common cathode.
The display is connected without any other chip attached. (the connectors of the display are connected to the GPIO pins)
Can you give me an example of code that reads a chunk of file into memory then use it please? (I am a bit new to python.)

Basically this is what i need to do :
use this code that is a gear indicator. It starts activating the decimal point. Then when you pressa button it shows 1 then you press again it shows 2...and so on. ***this has to run all the time***

Code: Select all

import RPi.GPIO as GPIO
import time
import os
GPIO.setmode (GPIO.BOARD)
GPIO.setwarnings(False)
os.system('modprobe w1-gpio')
os.system('modprobe w1-therm')

GPIO.setup(11, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(13, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

segments = (12, 16, 18, 22, 32, 35, 33, 40)
for segment in segments:
    GPIO.setup(segment, GPIO.OUT)
    GPIO.output(segment, 0)

digits = (36, 37, 38, 31)
for digit in digits:
    GPIO.setup(digit, GPIO.OUT)
    GPIO.output(digit, 1)


gears = {'z' :[33, 40, 22, 16, 12, 35],
         'zz':[32],
         1 :[22, 40],
         10:[12, 16, 18, 35, 33, 32],
         2 :[33, 40, 32, 12, 16],
         20:[35, 22],
         3 :[33, 40, 32, 22, 16],
         30:[12, 35],
         4 :[35, 32, 40, 22],
         40:[33, 16, 12],
         5 :[33, 35, 32, 22, 16],
         50:[40, 12],
         6 :[33, 35, 32, 12, 22, 16],
         60:[40],
         7 :[33, 40, 22],
         70:[35, 32, 12, 16],
         8 :[33, 40, 32, 22, 16, 12, 35],
         80:[],
         9 :[32, 35, 33, 40, 22, 16],
         90:[12]}

i=0
x=0
while(True):
    GPIO.output(36,1)
    GPIO.output(36,0)
    
    while (GPIO.input(11)==0 and i<1):
        GPIO.output(18,1)

    if (GPIO.input(11)==1):
        i+=1
        x+=10
        if i==7:
            i=6
            x=60
        else:
            GPIO.output(gears[i],1)
            GPIO.output(gears[x],0)
            time.sleep(.2)

    if (GPIO.input(13)==1):
        i-=1
        x-=10
        if i==0:
            i=1
            x=10
        GPIO.output(gears[i],1)
        GPIO.output(gears[x],0)
        time.sleep(.2)

Then i need to read a value from a file (that shows temperature) and display it on the already connected and in use 7 segment display with common cathode (without any i2c module, just connected to the GPIO pins directly)
this si the algorithm i thought of:
read file > write content to memory > wait 5 seconds and repeat
read what you have in memory > use it do light up the corresponding segments


But all of this has to run at the same time (the temperature display to be updated every 5 seconds and the numbers to change whenever I press a button)

I am new at this so bare with me :oops:


Thank you for every suggestion.

Return to “Troubleshooting”