okay lets try another approach (USB)
Standard version of Raspian on the PI with NO changes to files.
Connected ultrasonic sensor to port 5 on my ultimate 2. (megapi)
plug in USB A cable on makeblock.
power up PI (mine is a PI 3B)
ls /dev/tty*
plug in USB cable from makeblock to PI (I used top left USB slot)
ls /dev/tty*
record any changes between two ls commands.
In my case /dev/ttyUSB0 is added. that is the port to use with bot.start
here is my code to check for the ultrasonic (the posting loses indentation)
from megapi import *
distance = 123
def onRead(v):
global distance
print(“distance:”+str(v)+" cm")
distance = v
bot=MegaPi()
bot.start(’/dev/ttyUSB0’)
sleep(2)
print (“start test”)
while 1:
sleep(2)
bot.ultrasonicSensorRead(5,onRead)
print (distance)
idist = int(distance)
if idist < 12:
print("time to turn")