MCPcopy Create free account
hub / github.com/RetiredWizard/PyDOS / displayTemp

Function displayTemp

temperature.py:16–109  ·  view source on GitHub ↗
(argv)

Source from the content-addressed store, hash-verified

14 pass
15
16def displayTemp(argv):
17
18 lcdavail = True
19 # The PCF8574 has a jumper selectable address: 0x20 - 0x27
20 DEFAULT_I2C_ADDR = 0x27
21
22 try:
23 i2c = Pydos_hw.I2C()
24 except:
25 lcdavail = False
26
27 if sys.implementation.name.upper() == "CIRCUITPYTHON":
28 if 'temperature' not in dir(cpu):
29 print("Temperature sensor not found")
30 return
31
32 if lcdavail:
33 # circuitpython seems to require locking the i2c bus
34 while i2c.try_lock():
35 pass
36
37 if DEFAULT_I2C_ADDR not in i2c.scan():
38 print("LCD not found at address: ",hex(DEFAULT_I2C_ADDR))
39 i2c.unlock()
40 lcdavail = False
41 else:
42 # 2 lines, 16 characters per line
43 lcd = I2cLcd(i2c, DEFAULT_I2C_ADDR, 2, 16)
44 lcd.move_to(0,0)
45 lcd.putstr("Temperature:")
46 else:
47 if 'ADC' not in dir(machine):
48 print("Temperature sensor not found")
49 return
50
51 try:
52 ID=1
53 lcd=lcd2004.lcd(DEFAULT_I2C_ADDR,i2c)
54 lcd.lcd_backlight(True)
55 lcd.lcd_clear()
56 lcd.lcd_print("Temperature:",1,0)
57 except:
58 lcdavail = False
59
60 print("q to quit...")
61
62 if sys.implementation.name.upper() == "MICROPYTHON":
63 tempsensor = machine.ADC(4)
64 conversionFact = 3.3 /65535
65
66 if argv == "":
67 avgCount = 50
68 else:
69 avgCount = int(argv)
70
71 cmd = ""
72 while cmd.upper() != "Q":
73

Callers 1

temperature.pyFile · 0.85

Calls 9

I2cLcdClass · 0.90
I2CMethod · 0.80
move_toMethod · 0.80
putstrMethod · 0.80
lcd_backlightMethod · 0.80
lcd_clearMethod · 0.80
lcd_printMethod · 0.80
read_keyboardMethod · 0.45

Tested by

no test coverage detected