laurivosandi / sumochip

Sumorobot platform on top of CHIP board
MIT License
17 stars 13 forks source link

Add ultrasonic distance sensor support #22

Open laurivosandi opened 7 years ago

laurivosandi commented 7 years ago

SRF08 could be used as optional enemy finding upgrade for the robots. For that we need to expose I2C pins on the PCB. There are two I2C buses on CHIP. Which one could we use for that?

plaes commented 7 years ago

On 4.4.11-ntc kernel with 0x21 ALPHA HW, there are two i2c buses available: 0 and 2

SRF08 works fine on bus 2 (U14 pins 25 and 26), i2c bus 0 is not exposed to GPIO.

plaes commented 7 years ago

Working example:

import smbus
import time
bus = smbus.SMBus(2)
address = 0x70

# SRF08 REQUIRES 5V

def write(value):
        bus.write_byte_data(address, 0, value)
        return -1

def lightlevel():
        light = bus.read_byte_data(address, 1)
        return light

def range():
        range1 = bus.read_byte_data(address, 2)
        range2 = bus.read_byte_data(address, 3)
        range3 = (range1 << 8) + range2
        return range3

while True:
        write(0x51)
        time.sleep(0.7)
        lightlvl = lightlevel()
        rng = range()
        print lightlvl
        print rng
laurivosandi commented 7 years ago

Note that SRF08 was connected to 5V power supply rail, at 3.3V it was not functioning properly. The clock from CHIP-s 3.3V pin seems to work fine for SRF08, but if the slave is transmitting data at 5V while CHIP expects 3.3V might blow up something.

laurivosandi commented 7 years ago

Note that for Raspberry Pi commonly used ultrasonic distance sensor is HC-SR04. It seems to be much easier (electrically) to interface that instead: https://www.modmypi.com/blog/hc-sr04-ultrasonic-range-sensor-on-the-raspberry-pi