In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail how Raspberry Pi Python uses 2-bit digital tubes to display CPU temperature. The quality of the article is high, so Xiaobian shares it with you as a reference. I hope you have a certain understanding of relevant knowledge after reading this article.
Display CPU temperature with 2-digit digital tube
overview
Two days ago we learned to use a 1-digit digital tube to display a single-digit countdown. This time we learned to use a 2-digit digital tube to display the CPU temperature.
Through this lesson, we can learn:
Display principle of 2-digit digital tube
Visual Persistence Display Technique
the required hardware
Raspberry Pi x1
breadboard x1
Dupont line x9
2-digit LED x1
rationale
We use today is the 3261BS model of 2-bit common positive digital tube, first look at its circuit schematic:
Through the study of the previous article, we can understand the circuit diagram of the 1-bit digital tube, and the 2-bit digital tube can be simply understood as a combination of 2 1-bit digital tubes.
We look at the bottom picture, pin 10 and pin 5, which are the common anode of the first and second digits of the nixie tube, respectively.
Goal 1: Let the A tubes of the digital tube 1 and the digital tube 2 light up separately
The desired effect of the nixie tube needs to be done to control the circuit. The nixie tube 1A lights up the pin 10 high voltage, the pin 3 low voltage. The nixie tube 2A lights up the pin 5 high voltage, the pin 3 low voltage.
This is the same as operating a 1-digit digital tube, but look at the next goal may be more troublesome:
Goal 2: Let the A tube of the digital tube 1 light up, and at the same time let the A tube of the digital tube 2 not light up.
The desired effect of the digital tube needs to be done to control the circuit. The digital tube 1A is bright. Pin 10 is high voltage. Pin 3 is low voltage. The digital tube 2A is not bright. Pin 5 is high voltage. Pin 3 is high voltage.
The problem is that because pin 3 is shared, this circuit control cannot be achieved. So how do we solve this problem? To solve this problem, we need to use persistence of vision here.
persistence of vision
This principle originated in filmmaking. Scientific experiments have proved that after a certain image disappears, the human eye can still make the object image stay on the retina for about 0.1-0.4 seconds. The film rotates at a constant speed of 24 frames per second, and a series of static frames creates a continuous visual impression due to the persistence of vision, producing realistic motion. The fluorescent lamp commonly used in the home is also this principle, the fluorescent lamp is not always on, but in a very fast frequency to go on and off, when the flashing frequency reaches more than 25 times per second, the human eye thinks it is always on.
This principle can be used, as long as the two digital tube numbers are displayed in a sufficiently short time interval, the human vision will think that the two numbers are displayed at the same time. The way we use in circuit control is to time-share pin 3: 0.01 seconds for the A tube of the digital tube 1, and the next 0.01 seconds for the A tube of the digital tube 2, so that it can be refreshed 50 times within 1 second to ensure that the digital tube does not flicker.
wiring diagram
The first thing to do before starting to connect the hardware circuits is to turn off the Raspberry Pi computer and disconnect the power. Because if the Raspberry Pi motherboard is charged, plugging the circuit may cause the electronic components to burn, so be sure to remember:
The motherboard must be powered off when connecting the circuit.
sample code
#!/ usr/bin/env python
# encoding: utf-8
'''
Wiring diagram:
RPi digital
7 10
11 5
13 3
15 9
29 8
31 6
33 7
35 4
37 1
'''
import RPi.GPIO as GPIO
import time
import os
#Pins used for positive electrodes of digital tubes 1-2 respectively
LED_POWER_1 = 7
LED_POWER_2 = 11
#Pins used for A-G tubes, respectively
LED_A = 13
LED_B = 15
LED_C = 29
LED_D = 31
LED_E = 33
LED_F = 35
LED_G = 37
#Get CPU temperature
def get_cpu_temperature():
return os.popen('vcgencmd measure_temp').read()[5:7]
#Reset the nixie tube, turn off all numbers
def reset():
GPIO.output((LED_POWER_1, LED_POWER_2), GPIO.LOW)
GPIO.output((LED_A, LED_B, LED_C, LED_D, LED_E, LED_F, LED_G), GPIO.HIGH)
#Set the number of LED lights
def set_position(position):
if position == 1:
GPIO.output(LED_POWER_1, GPIO.HIGH)
else:
GPIO.output(LED_POWER_2, GPIO.HIGH)
#Display number 0
def show0(p):
reset()
set_position(p)
GPIO.output((LED_A, LED_B, LED_C, LED_D, LED_E, LED_F), GPIO.LOW)
#Display number 1
def show1(p):
reset()
set_position(p)
GPIO.output((LED_B, LED_C), GPIO.LOW)
#Display number 2
def show2(p):
reset()
set_position(p)
GPIO.output((LED_A, LED_B, LED_D, LED_E, LED_G), GPIO.LOW)
#Show number 3
def show3(p):
reset()
set_position(p)
GPIO.output((LED_A, LED_B, LED_C, LED_D, LED_G), GPIO.LOW)
#Show number 4
def show4(p):
reset()
set_position(p)
GPIO.output((LED_B, LED_C, LED_F, LED_G), GPIO.LOW)
#Show the number 5
def show5(p):
reset()
set_position(p)
GPIO.output((LED_A, LED_C, LED_D, LED_F, LED_G), GPIO.LOW)
#Display number 6
def show6(p):
reset()
set_position(p)
GPIO.output((LED_A, LED_C, LED_D, LED_E, LED_F, LED_G), GPIO.LOW)
#Show number 7
def show7(p):
reset()
set_position(p)
GPIO.output((LED_A, LED_B, LED_C), GPIO.LOW)
#Display number 8
def show8(p):
reset()
set_position(p)
GPIO.output((LED_A, LED_B, LED_C, LED_D, LED_E, LED_F, LED_G), GPIO.LOW)
#Display number 9
def show9(p):
reset()
set_position(p)
GPIO.output((LED_A, LED_B, LED_C, LED_D, LED_F, LED_G), GPIO.LOW)
GPIO.setmode(GPIO.BOARD)
#Initialize pin output mode
GPIO.setup((LED_POWER_1, LED_POWER_2, LED_A, LED_B, LED_C, LED_D, LED_E, LED_F, LED_G), GPIO.OUT)
function_directory = locals()
try:
while True:
cpu_temperature = get_cpu_temperature()
print 'CPU temperature = %s°C'%(cpu_temperature)
loop = 0
while loop < 200:
loop += 1
#Show high first
position = 1
for n in cpu_temperature:
function_directory['show%s'%(n)](position)
time.sleep(0.01)
position += 1
except KeyboardInterrupt:
GPIO.cleanup()
Save it as digital-2.py and run it.
sudo python digital-2.py About Raspberry Pi Python How to use 2-bit digital tube to display CPU temperature is shared here, I hope the above content can be of some help to everyone, you can learn more knowledge. If you think the article is good, you can share it so that more people can see it.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.