Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize DIY Electronic clock by Python

2025-03-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces Python how to achieve DIY electronic clock related knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that everyone after reading this Python how to achieve DIY electronic clock article will have a harvest, let's take a look at it.

First, the purpose of the experiment:

? Learn the method of extending the simple Icano interface in the PC system

? Learn TurnipBit splicing programming

? Learn the connection mode between TurnipBit expansion board and DS3231 clock module

? The use of learning clock module

Second, the required original devices:

? TurnipBit together

? TurnipBit expansion board

? one DS3231 clock module

? Some DuPont lines

? one usb data cable

Third, the experimental principle:

1. The principle of DS3231 clock module

DS3231 (figure 11-12) is a clock module, which is like an electronic clock with its own battery. When the time is set, the DS3231 will go automatically. The communication between the DS3231 and the development board is completed through the I2C interface. I2C bus is a simple, bi-directional two-wire synchronous serial bus developed by Philips Company. It only needs SDA (serial data line) and SCL (serial clock line) to transmit information between devices connected to the bus. Both SDA and SCL are bi-directional I / O lines. When connecting, you only need to connect SDA and SCL on DS3231 to SDA and SCL on TurnipBit expansion board.

4. Connection method:

The TurnipBit expansion board corresponds to the LED interface as follows:

5. Source code:

From microbit import * DS3231_ADDR = 0x68DS3231_REG_SEC = b'\ x00'DS3231_REG_MIN = b'\ x01'DS3231_REG_HOUR = b'\ x02'DS3231_REG_DAY = b'\ x04'DS3231_REG_MONTH = b'\ x05'DS3231_REG_YEAR = b'\ x06'DS3231_REG_TEMP = b'\ x11'class DS3231 (object): def _ init__ (self): pass def DATE (self) Dat= []: if dat== []: t = [] t.append (self.year ()) t.append (self.month ()) t.append (self.day ()) return t else: self.year (dat [0]) self.month (dat [1]) Self.day (dat [2]) def TIME (self Dat= []: if dat== []: t = [] t.append (self.hour ()) t.append (self.min ()) t.append (self.sec ()) return t else: self.hour (dat [0]) self.min (dat [1]) Self.sec (dat [2]) def DateTime (self Dat= []: if dat== []: return self.DATE () + self.TIME () else: self.year (dat [0]) self.month (dat [1]) self.day (dat [2]) self.hour (dat [3]) self.min (dat [4]) self .sec (dat [5]) def dec2hex (self Dat): return (int (dat/10) 4) * 10 + (t) def sec (self, sec=''): if sec= =': return self.getREG_DEC (DS3231_REG_SEC) else: self.setREG (self.dec2hex (sec), DS3231_REG_SEC) def min (self) Min=''): if min= =': return self.getREG_DEC (DS3231_REG_MIN) else: self.setREG (self.dec2hex (min), DS3231_REG_MIN) def hour (self, hour=''): if hour=='': return self.getREG_DEC (DS3231_REG_HOUR) else: self.setREG (self.dec2hex (hour) DS3231_REG_HOUR) def day (self, day=''): if day=='': return self.getREG_DEC (DS3231_REG_DAY) else: self.setREG (self.dec2hex (day), DS3231_REG_DAY) def month (self Month=''): if month=='': return self.getREG_DEC (DS3231_REG_MONTH) else: self.setREG (self.dec2hex (month), DS3231_REG_MONTH) def year (self, year=''): if year=='': return self.getREG_DEC (DS3231_REG_YEAR) else: self.setREG (self.dec2hex (year) DS3231_REG_YEAR) def TEMP (self): i2c.write (DS3231_ADDR,DS3231_REG_TEMP, repeat=False) T1 = i2c.read (DS3231_ADDR,1, repeat=False) [0] i2c.write (DS3231_ADDR,b'\ x12cycles, repeat=False) T2 = i2c.read (DS3231_ADDR,1) Repeat=False) [0] if T1 > 0x7F: return T1-T2 take 256-256 else: return T1 + t2/256ds=DS3231 () ds.DATE ([17je 10je 24]) ds.TIME ([10LJ 03lad 00]) while True: Time=ds.TIME () Time_s='' for i in Time: Time_s+=str (I) +': 'display.scroll (Time_s [:-1] + "-") # print (Time) # print (ds.TEMP ()) sleep (1000) this is the end of the article on "how Python implements DIY Electronic clock". Thank you for reading! I believe that everyone has a certain understanding of the knowledge of "how to achieve DIY electronic clock in Python". If you want to learn more, you are welcome to follow the industry information channel.

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: 216

*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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report