laurivosandi / sumochip

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

Add infrared distance sensor support #20

Open laurivosandi opened 7 years ago

laurivosandi commented 7 years ago

@plaes said that X1, X2, Y1 and Y2 pins of CHIP which are intended for touchscreen can be used as general purpose ADC-s. We could expose these pins to be used for eg Sharp GP2Y0A21YK0F distance sensors. It's still not very clear what voltage range is intended for the ADC-s, we might have to add some resistors to compensate, the Sharp sensor outputs voltage range 0-3.2V and requires 5V for power supply.

plaes commented 7 years ago

According to A20 datasheet, GPADC voltage reference is 3.0V.

Tree with backported GPADC v6 patches - https://github.com/plaes/linux/commits/chip-iio-adc

plaes commented 7 years ago

HOWTO

  1. Fetch chip-iio-adc branch and compile new kernel using multi_v7_defconfig
  2. Copy newly compiled kernel to CHIP as /boot/iio-zImage.
  3. Attach UART-Serial and boot into u-boot shell
  4. Override bootcmd to tell u-boot to load our own iio-zImage:
    setenv bootcmd 'gpio set PB2; if test -n ${fel_booted} && test -n ${scriptaddr}; then echo (FEL boot); source ${scriptaddr}; fi; mtdparts; ubi part UBI; ubifsmount ubi0:rootfs; ubifsload $fdt_addr_r /boot/sun5i-r8-chip.dtb; ubifsload $kernel_addr_r /boot/iio-zImage; setenv bootargs $bootargs $kernelarg_video; bootz $kernel_addr_r - $fdt_addr_r'
  5. Boot using boot command.
  6. cat /sys/devices/platform/soc@01c00000/1c25000.rtp/sun5i-a13-gpadc-iio.0/iio:device0/in_voltage*

Enjoy ;)

laurivosandi commented 7 years ago

X2 and Y2 confirmed working, nice job @plaes Going to add pins to PCB layout

plaes commented 7 years ago

OK, apparently X1 channel is somewhat buggy, and when reading from all 4 channels, only X2 and Y2 are show correct readouts.

Output voltage for channel is: (value / 4096.) * 3.0 (There should be actually a in_voltage_scale file, but should be fixed in v7 patchset).

plaes commented 7 years ago

Possible fix(es) for channel change stability issue: