sumochip icon indicating copy to clipboard operation
sumochip copied to clipboard

Add infrared distance sensor support

Open laurivosandi opened this issue 8 years ago • 5 comments

@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.

laurivosandi avatar Sep 23 '16 07:09 laurivosandi

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

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 ;)

plaes avatar Oct 16 '16 12:10 plaes

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

laurivosandi avatar Oct 16 '16 13:10 laurivosandi

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

Possible fix(es) for channel change stability issue:

  • http://code.bulix.org/29344w-107051
  • http://code.bulix.org/q71nva-107053

plaes avatar Oct 31 '16 11:10 plaes