Micropython Practical turnipbit Development Board DIY electronic Clock

Source: Internet
Author: User
Tags set time

First, the purpose of the experiment:
? Learn how to extend a simple I/O interface in a PC system
? Learn Turnipbit Plug programming
? Learn Turnipbit expansion board and DS3231 Clock module connection wiring method
? Learning the use of clock modules

Second, the required original device:
? Turnipbit piece
? Turnipbit Expansion Board Piece
? DS3231 Clock Module One
? DuPont Line several
? USB Data Cable One Piece

Three, the experimental principle:
1. DS3231 Clock Module principle
DS3231 (Figure 11-12) is a clock module, which is actually like an electronic clock, it has a battery itself, when set time, DS3231 will automatically walk. The communication between the DS3231 and the Development Board is done via the I²c interface. I²c Bus is a simple, bidirectional two-wire synchronous serial bus developed by Philips Corporation. It requires only the SDA (serial data cable) and SCL (serial clock line) Two wires to transfer information between devices connected to the bus. Both SDA and SCL are bidirectional I/O lines, and when connected, only the SDA and SCL on the DS3231 are connected to the SDA and SCL on the Turnipbit expansion board.


Four, wiring method:
The Turnipbit expansion board corresponds to the following table for the light Emitting diode interface:


Five, source code:

 fromMicrobitImport*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'classDS3231 (object):def __init__(self):Pass    defDATE (Self, dat=[]):        ifdat==[]: t=[] T.append (Self.year ()) T.append (Self.month ()) T.append (Self.day ()) returnTElse: Self.year (dat[0]) self.month (dat[1]) self.day (dat[2])                defTime (self, dat=[]):        ifdat==[]: t=[] T.append (Self.hour ()) T.append (Self.min ()) T.append (Self.sec ())returnTElse: Self.hour (dat[0]) self.min (dat[1]) self.sec (dat[2])    defDateTime (Self, dat=[]):        ifdat==[]:            returnSelf. 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])    defDec2hex (self, DAT):return(int (DAT/10) <<4) + (dat%10)    defSetREG (Self, Dat,reg): Buf= ByteArray (2) buf[0]=Reg[0] buf[1] =dat i2c.write (ds3231_addr,buf, repeat=False)defGetreg_dec (Self,reg): I2c.write (ds3231_addr,reg) T= I2c.read (ds3231_addr,1) [0]#print ("--===", T, "----------")        return(t>>4) *10 + (t%16)    defSEC (Self, sec="'):        ifSEC = ="':            returnSelf.getreg_dec (ds3231_reg_sec)Else: Self.setreg (Self.dec2hex (sec), ds3231_reg_sec)defMin (Self, min="'):        ifMin = ="':            returnSelf.getreg_dec (ds3231_reg_min)Else: Self.setreg (Self.dec2hex (min), ds3231_reg_min)defHour (self, hour="'):        ifhour=="':            returnSelf.getreg_dec (Ds3231_reg_hour)Else: Self.setreg (Self.dec2hex (hour), Ds3231_reg_hour)defDay (self, day="'):        ifday=="':            returnSelf.getreg_dec (ds3231_reg_day)Else: Self.setreg (Self.dec2hex (day), Ds3231_reg_day)defMonth (self, month="'):        ifmonth=="':            returnSelf.getreg_dec (ds3231_reg_month)Else: Self.setreg (Self.dec2hex (month), Ds3231_reg_month)defYear (self, year="'):        ifyear=="':            returnSelf.getreg_dec (ds3231_reg_year)Else: Self.setreg (Self.dec2hex (year), ds3231_reg_year)defTEMP (self): I2c.write (ds3231_addr,ds3231_reg_temp, repeat=False) T1= I2c.read (ds3231_addr,1, repeat=False) [0] I2c.write (ds3231_addr,b'\x12', repeat=False) T2= I2c.read (ds3231_addr,1, repeat=False) [0]ift1>0x7f:            returnt1-t2/256-256Else:            returnT1 + t2/256DS=DS3231 () ds. DATE ([17,10,24]) ds. Time ([10,03,00]) whileTrue:time=ds. Time () time_s="'     forIinchtime:time_s+=str (i) +':'Display.scroll (time_s[:-1]+"-")        #print (time)    #Print (ds. TEMP ())Sleep (1000)

Micropython Practical turnipbit Development Board DIY electronic Clock

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.