added error message if no i2c devices are found
This commit is contained in:
parent
2fb69de9c5
commit
79f4fcc032
|
@ -1,4 +1,5 @@
|
|||
import machine
|
||||
import sys
|
||||
from machine import I2C, Pin
|
||||
|
||||
import d1motor
|
||||
|
@ -13,7 +14,9 @@ class Robot:
|
|||
d1 = Pin(5)
|
||||
d2 = Pin(4)
|
||||
i2c = I2C(scl=d1, sda=d2)
|
||||
i2c_addr = i2c.scan()[0]
|
||||
i2c_scan = i2c.scan()
|
||||
if len(i2c_scan) > 0:
|
||||
i2c_addr = i2c_scan[0]
|
||||
print("i2c scan = {}".format(i2c_addr))
|
||||
print("setting up motors ...")
|
||||
self.m1 = d1motor.Motor(0, i2c, address=i2c_addr)
|
||||
|
@ -21,6 +24,9 @@ class Robot:
|
|||
self.m1.speed(0)
|
||||
self.m2.speed(0)
|
||||
print("motor setup complete!")
|
||||
else:
|
||||
print("error: no i2c interfaces found!")
|
||||
sys.exit(1)
|
||||
|
||||
ip = my_ip[0]
|
||||
# setup socket for remote control
|
||||
|
|
Loading…
Reference in New Issue
Block a user