sumochip icon indicating copy to clipboard operation
sumochip copied to clipboard

Add ultrasonic distance sensor support

Open laurivosandi opened this issue 8 years ago • 4 comments

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?

laurivosandi avatar Oct 16 '16 13:10 laurivosandi

  • [ ] Figure out how to properly enable i2c bus 1 (pins 9 and 11)
  • [ ] i2c-1 support - https://bbs.nextthing.co/t/where-to-find-nextthing-kernel-changelogs/10784

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 avatar Oct 16 '16 14:10 plaes

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

plaes avatar Oct 16 '16 14:10 plaes

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.

  • [ ] Figure out if 5V I2C data signal from slave is harmful for CHIP or not

laurivosandi avatar Oct 16 '16 14:10 laurivosandi

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

laurivosandi avatar Oct 16 '16 14:10 laurivosandi