added error message if no i2c devices are found

This commit is contained in:
Simon Pirkelmann 2019-06-10 23:16:14 +02:00
parent 2fb69de9c5
commit 79f4fcc032

View File

@ -1,4 +1,5 @@
import machine import machine
import sys
from machine import I2C, Pin from machine import I2C, Pin
import d1motor import d1motor
@ -13,14 +14,19 @@ class Robot:
d1 = Pin(5) d1 = Pin(5)
d2 = Pin(4) d2 = Pin(4)
i2c = I2C(scl=d1, sda=d2) i2c = I2C(scl=d1, sda=d2)
i2c_addr = i2c.scan()[0] i2c_scan = i2c.scan()
print("i2c scan = {}".format(i2c_addr)) if len(i2c_scan) > 0:
print("setting up motors ...") i2c_addr = i2c_scan[0]
self.m1 = d1motor.Motor(0, i2c, address=i2c_addr) print("i2c scan = {}".format(i2c_addr))
self.m2 = d1motor.Motor(1, i2c, address=i2c_addr) print("setting up motors ...")
self.m1.speed(0) self.m1 = d1motor.Motor(0, i2c, address=i2c_addr)
self.m2.speed(0) self.m2 = d1motor.Motor(1, i2c, address=i2c_addr)
print("motor setup complete!") 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] ip = my_ip[0]
# setup socket for remote control # setup socket for remote control