Skip to main content

USB

You can modify the device tree settings to set it as a USB HOST, allowing you to expand many interfaces using a USB HUB. Friendly reminder:

  • After configuring the device tree for USB HOST mode, the USB virtual network interface cannot be used. For Luckfox Pico and Luckfox Pico A/B, only serial login is available. Luckfox Pico Plus/Pro/Max can use SSH login or serial login.

  • USB port is occupied; power supply can be provided via Waveshare Pico To HAT using Micro USB power or through GPIO, please be cautious with power supply to avoid damaging the development board.

HOST Mode

Use luckfox-config to enable the relevant configuration:

  • Use the and keys on the keyboard to select menu items, the Enter key to enter, the and keys or Tab to select the OK and Cancel buttons, the Esc key to cancel and return, and the spacebar to select an option. Any changes will take effect after rebooting. Note: ADB login cannot use the Arrow keys and Tab, only numbers can be used to select options, and Enter to confirm.
  1. Open the luckfox-config tool in the terminal:

    luckfox-config
  2. Select Advanced Options:
    img

  3. Select USB:
    img

  4. Select host mode:
    img

  5. After pressing Enter to confirm, press Esc to exit:
    img

  6. Reboot the development board.

    reboot

Mounting a USB Flash Drive

  1. Power on the device and check the current USB mode; it should return "host."

    cat /sys/devices/platform/ff3e0000.usb2-phy/otg_mode
  2. Insert a USB flash drive or card reader, and it should be displayed as follows:

    [  143.364405] usb 1-1.4: new high-speed USB device number 3 using xhci-hcd
    [ 143.513956] usb-storage 1-1.4:1.0: USB Mass Storage device detected
    [ 143.517513] usb-storage 1-1.4:1.0: Quirks match for vid 05e3 pid 0749: 520
    [ 143.519454] scsi host1: usb-storage 1-1.4:1.0
    [ 144.536147] scsi 1:0:0:0: Direct-Access Generic MassStorageClass 1536 PQ: 0 ANSI: 6
    [ 144.770829] sd 1:0:0:0: [sdb] 30949376 512-byte logical blocks: (15.8 GB/14.8 GiB)
    [ 144.771907] sd 1:0:0:0: [sdb] Write Protect is off
    [ 144.772903] sd 1:0:0:0: [sdb] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA
    [ 144.780888] sdb: sdb1
    [ 144.785345] sd 1:0:0:0: [sdb] Attached SCSI removable diskk
  3. According to the prompt, the new device is sdb; check the sda file under dev.

    # ls /dev/sd*
    /dev/sdb1 /dev/sdb /dev/sda
  4. Mount sdb1 to the /mnt/sdcard folder.

    mount -t vfat /dev/sdb1 /mnt/sdcard/
  5. Check the files in the sdcard folder.

    ls /mnt/sdcard/

USB Camera

There are various types of USB cameras, and it's not feasible to comprehensively test all models. In this section, we'll use two cameras, OV5640 5MP USB Camera (B) and IMX179 8MP USB Camera (A) , from Waveshare as examples.

Before starting the test, make sure that USB is set to host mode. To avoid power issues, it's recommended to use a USB HUB with power supply functionality.

Kernel

  1. Enable the UVC driver in the kernel by searching for the keyword "Webcam".
  2. In the search results, find and select "USB Video Class (UVC)", then save and exit.
  3. Compile the kernel and test if the UVC driver is loaded successfully.

Buildroot

  1. Compile the kernel and test if the UVC driver is loaded successfully.
  2. Add V4L2 to the buildroot directory by searching for the keyword "libv4l2".

  3. In the buildroot directory, add ffmpeg by searching with the keyword "ffmpeg".

Taking Photos

  1. After inserting the USB camera, check if the device is recognized using the following command:
  1. Capture a photo with the USB camera and save it with a specified filename:

    # fswebcam -d /dev/video0 -r 1920x1080 /root/image01.jpg

    --- Opening /dev/video0...
    Trying source module v4l2...
    /dev/video0 opened.
    No input was specified, using the first.
    --- Capturing frame...
    Captured frame in 0.00 seconds.
    --- Processing captured image...
    Unable to load font 'sans': Could not find/open font
    Disabling the the banner.
    Writing JPEG image to '/root/image01.jpg'.
    • -d /dev/video0: Specifies the device to use.
    • -r 1920x1080: Specifies the resolution of the captured photo.
    • /root/image01.jpg: Specifies the path and name of the output file.

Recording video

  1. The current video recording is based on the Luckfox-Pico-Max development board. Due to the limited memory of Luckfox-Pico series development boards, high-resolution recording is not supported.

    ffmpeg -f v4l2 -video_size 320x240 -framerate 30 -i /dev/video21 output.mp4
  2. If you want to adjust the video resolution, you can use the scale filter to resize the input video frame size to a width of 640 pixels and a height of 480 pixels.

    ffmpeg -f v4l2 -i /dev/video21 -vf "scale=640:480" output1.mp4
  3. Video effect: