Differences

This shows you the differences between two versions of the page.

Link to this comparison view

lkd:laboratoare:04 [2024/05/16 22:37]
127.0.0.1 external edit
lkd:laboratoare:04 [2024/07/11 16:42] (current)
daniel.baluta [Presentation]
Line 1: Line 1:
 ===== Laboratorul 04. ===== ===== Laboratorul 04. =====
  
 +
 +==== Presentation ====
 +
 +  * no slides, all practical
 +
 +==== Practical lab ====
 +
 +
 +=== Exercise 1 ===
 +
 +== Step 1 - Create the hardware setup ==
 +
 +Enable I2C proximity sensor [[https://​www.optimusdigital.ro/​en/​index.php?​controller=attachment&​id_attachment=4892 | vl53l]].
 +
 +Connect GND, VCC(3V), I2C3_SCL_3V3 and I2C3_SDA_3V3 data lines on expansion header and connect the sensor accordingly.
 +
 +{{:​lkd:​laboratoare:​expansion_1.png}}.
 +
 +Setup should look like this:
 +
 +{{:​lkd:​laboratoare:​setup1.jpeg?​500}}.
 +
 +== Step 2 - Find a proper Linux kernel driver ==
 +
 +Look inside ''​~/​work/​nss-linux/​drivers/​iio''​ and find a proper driver for ''​vl53l''​ sensor. Use ''​git grep vl53l''​. Once you find the correct source file look inside the driver and remember the compatible string.
 +
 +Once you found the driver, use ''​make menuconfig''​ and select it to be compiled as a module. ''<​M>''​
 +
 +== Step 3 - Create a proper device tree node ==
 +
 +Look inside ''​arch/​arm64/​boot/​dts/​freescale/​imx8mq-pico-pi.dts''​ and add your node under ''​i2c3''​ node. 
 +
 +Your node should look like this:
 +
 +<code c>
 +&i2c3 {
 +       ​proximity-sensor@XX {
 +           ​compatible = <​compatible-you-found-in-the-driver>;​
 +           reg =<​XX>;​
 +           ​pinctrl-0 = <&​pinctrl_prox>;​
 +           ​status = "​okay";​
 +       };
 +};
 +</​code>​
 +
 +XX - is the address of the I2C device. There are two ways of finding this. You can dig inside the [[https://​www.optimusdigital.ro/​en/​index.php?​controller=attachment&​id_attachment=4892 ​ | datasheet ]] and confirm the address by scanning for devices on i2c3 node on the hardware. Use ''​i2cdetect -y 2''​.
 +
 +The datasheet states that the I2C address is as shown as below, but you need to look closer and also understand the output of i2c scan command ''​i2cdetect -y 2''​.
 +
 +{{:​lkd:​laboratoare:​i2caddr.png}}
 +
 +== Step 4 - Load the driver &  read the distance measured by sensor ==
 +
 +Once the device tree is ready, recompile the kernel and boot the board. On the board, use ''​modprobe <​driver-name>''​ to load the driver. If everything goes well the driver will be correctly loaded and you will be able to read data.
 +
 +<code bash>
 +
 +$ modprobe vl53l0x-i2c
 +$ cat /​sys/​bus/​iio/​devices/​iio:​device0/​in_distance_scale
 +</​code>​
 +
 +Use the following script the poll for proximity measurements every 0.5 seconds:
 +
 +<code bash>
 +
 +$ cat read_meas.sh
 +
 +while true; do
 +cat /​sys/​bus/​iio/​devices/​iio:​device0/​in_distance_raw
 +sleep 0.5
 +done
 +
 +</​code>​
 +
 +
 +=== Exercise 2 ===
 +
 +Control a motor using GPIOs. Use the following {{:​lkd:​laboratoare:​motorcontrolsetup.pdf| Guide }}
 +
 +{{:​lkd:​laboratoare:​motor1.jpeg?​500}}
  
lkd/laboratoare/04.1715888265.txt.gz ยท Last modified: 2024/07/11 15:15 (external edit)
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0