Difference between revisions of "Getting Started with M2M"

From Banana Pi Wiki
Jump to: navigation, search
(Update your image)
(Android)
 
(70 intermediate revisions by 4 users not shown)
Line 1: Line 1:
 +
[[zh:快速上手 香蕉派 BPI-M2 Magic]]
 
=Introduction=
 
=Introduction=
 
==BPI-M2M==
 
==BPI-M2M==
 +
[[File:Banana_pi_bpi-m2_magic_5.JPG|thumb|Overview:[[Banana Pi BPI-M2M ]]]]
 
[[File:M2M_ubuntu.png|thumb|Overview: BPI-M2M ubuntu linux]]
 
[[File:M2M_ubuntu.png|thumb|Overview: BPI-M2M ubuntu linux]]
  
Line 13: Line 15:
  
 
=Development=
 
=Development=
==Basic Development==
+
==Android==
===Prepare to develop===
+
  1.You could download latest image from our forum.
  * Prepare 8G/above TF card, USB-Serial interface, PC with Ubuntu System
+
 
  * Using your USB-Serial Connect debug console on M2M
+
  2.Put your TF card into a TF-USB adapter, and then plug adapter in your Windows PC usb interface.
 +
 
 +
  3.Prepare your image, and download image burning tools PhoenixCard.exe.
 +
 
 +
  4.Use "PhoenixCard.exe" to burn android image to TF card.
 +
 
 +
  [[Image:M3_Android_Burning.png | 600px]]
 +
 
 +
  * Download PhoenixCard: https://pan.baidu.com/s/1-fjvPqtG_zewVzqnXf1AHw?pwd=eid9
 +
 
 +
==Linux==
 +
===Prepare===
 +
:1. Prepare 8G/above TF card, USB-Serial cable.
 +
:2. Connect USB-Serial to 40 pin header uart2 for kernel console debug.
 +
 
 +
:'''Note: three pin header uart0 beside usb port is not debug uart for bpi release images''' because SDcard and uart0 are multiplex pin and default bpi images support both SD and eMMC. If you want bootup with emmc only and enable uart0 as debug port without SDcard support, please refer to [http://wiki.banana-pi.org/Getting_Started_with_M2M#Enable_uart0_for_emmc_only_image_debug enable uart0 debug for emmc only image] section.
 
    
 
    
 
   [[Image:M2M__debug_console.png | 240px]]  [[Image:M2M__pin_define.png | 240px]]
 
   [[Image:M2M__debug_console.png | 240px]]  [[Image:M2M__pin_define.png | 240px]]
  
===Compile code===
+
:3. Install bpi-tools on your Linux PC, If you can't access this URL or any other problems, please go to [https://github.com/BPI-SINOVOIP/bpi-tools bpi-tools repo] and download this tools manually.
* git clone https://github.com/BPI-SINOVOIP/BPI-M2M-bsp.git
+
  $ apt-get install pv
[[Image:m2m_code.png]]
+
  $ curl -sL https://github.com/BPI-SINOVOIP/bpi-tools/raw/master/bpi-tools | sudo -E bash
 +
 
 +
:4. Download [http://wiki.banana-pi.org/Banana_Pi_BPI-M2M#Linux_2 latest linux image], and confirm that the md5 checksum is correct.
 +
:5. Defautl login: pi/bananapi or root/bananapi.
 +
 
 +
===Install Image to SDcard===
 +
:1. Install image with bpi-tools on Linux, plug your sd card to your Linux PC
 +
    $ sudo bpi-copy  xxx-bpi-m2m-xxx.img.zip /dev/sdX
 +
 
 +
:2. Install image with dd command on Linux, umount SDcard device /dev/sdX partitions if mounted automatically, Actually bpi-copy is the same as this dd command.
  
After download code, execute "./build.sh" to compile it.
+
    $ sudo apt-get install pv
* ./build.sh
+
    $ sudo unzip -p xxx-bpi-m2m-xxx.img.zip | pv | dd of=/dev/sdX bs=10M status=noxfer
[[Image:m2m_build.png]]
 
  
[[Image:m2m_build_success.png]]
+
:3. Install bpi image with Etcher on Windows, Linux and MacOS
 +
::[https://www.balena.io/etcher/ Balena Etcher] is an open source project by Balena, Flash OS images to SD cards & USB drives
  
===Update your image===
+
===Install Image to EMMC===
After we succeed to the code, Bootloader, kernel, rootfs will be generated in "SD" directory, then how to update the image?
 
  
* cd SD/bpi-m2m
+
:1. Prepare a SDcard  with Linux image flashed and bootup the board with this SDcard.
 +
:2. Copy emmc image to udisk, plugin the udisk to board and mount it.
 +
:3. Install with bpi-tools command
 +
    $ sudo bpi-copy xxx-bpi-m2m-xxx.img.zip /dev/mmcblk1
 +
:4. Or Install with dd command, umount mmcblk1p1 and mmcblk1p2 partition if mounted automatically, Actually bpi-copy is the same as this dd command
 +
    $ sudo apt-get install pv
 +
    $ sudo unzip -p xxxb-bpi-m2m-xxx.img.zip | pv | dd of=/dev/mmcblk1 bs=10M status=noxfer
 +
:5. After flash complete,  power off safely and  eject the sdcard.
  
[[Image:m2m_code_sd.png]]
+
'''Note: If the emmc was flashed android image before, you must erase the boot partition of android before step 3 or step 4.'''
  
Plug in your SD card to Ubuntu PC, then execute "fdisk -l" to check which /dev/sdX were generated by system
+
    root@bpi-iot-ros-ai:/# echo 0 > /sys/block/mmcblk1/mmcblk1boot0/force_ro                             
 +
    root@bpi-iot-ros-ai:/# echo 0 > /sys/block/mmcblk1/mmcblk1boot1/force_ro                             
 +
    root@bpi-iot-ros-ai:/#
 +
    root@bpi-iot-ros-ai:/# dd if=/dev/zero of=/dev/mmcblk1boot0 bs=4096 count=1024                       
 +
    1024+0 records in
 +
    1024+0 records out
 +
    4194304 bytes (4.2 MB, 4.0 MiB) copied, 0.421164 s, 10.0 MB/s
 +
    root@bpi-iot-ros-ai:/# dd if=/dev/zero of=/dev/mmcblk1boot1 bs=4096 count=1024                       
 +
    1024+0 records in
 +
    1024+0 records out
 +
    4194304 bytes (4.2 MB, 4.0 MiB) copied, 0.428427 s, 9.8 MB/s
  
[[Image:m2m_code_sd_dev.png]]
+
===Build Source Code ===
 +
:1. Get the bsp source code
  
* bpi-update -c bpi-m2m.conf -d /dev/sde
+
  $ git clone https://github.com/BPI-SINOVOIP/BPI-M2M-bsp
  
[[Image:m2m_bpi_update.png]]
+
:2. Build the bsp source code
 +
::Please read the source code [https://github.com/BPI-SINOVOIP/BPI-M2M-bsp/blob/master/README.md README.md]
  
===Make your own image===
+
==Advance Development==
 +
 
 +
===Enable uart0 for emmc only image debug===
 +
:1. Enable uart0 node and disable sdc0 node in sunxi-pack/sun8iw5p1/configs/BPI-M2M-LCD7/sys_config.fex.
 +
 
 +
    --- a/sunxi-pack/sun8iw5p1/configs/BPI-M2M-LCD7/sys_config.fex
 +
    +++ b/sunxi-pack/sun8iw5p1/configs/BPI-M2M-LCD7/sys_config.fex
 +
    @@ -262,7 +262,7 @@ twi_sda        = port:PE13<3><default><default><default>
 +
    ;uart_type      = 2:2 wire,4:4 wire,8:8 wire, full function
 +
    ;----------------------------------------------------------------------------------
 +
    [uart0]
 +
    -uart_used      = 0
 +
    +uart_used      = 1
 +
    uart_port      = 0
 +
    uart_type      = 2
 +
    uart_tx        = port:PF02<3><1><default><default>
 +
    @@ -803,7 +803,7 @@ led3_active_low            = 1
 +
    ;    that supports SD3.0 cards and eMMC4.4+ flashes
 +
    ;-------------------------------------------------------------------------------
 +
    [mmc0_para]
 +
    -sdc_used          = 1
 +
    +sdc_used          = 0
 +
    sdc_detmode      = 3
 +
    sdc_buswidth      = 4
 +
    sdc_d1            = port:PF00<2><1><2><default>
 +
 
 +
:2. Build the bsp source code.
 +
:3. Copy the bootloader file SD/bpi-m2m/100MB/BPI-M2M-LCD7-8k.img.gz to udisk. bpi also provide a [https://download.banana-pi.dev/d/ca025d76afd448aabc63/files/?p=%2FImages%2FBPI-M2M%2FUbuntu16.04%2FBPI-M2M-LCD7-eMMC-only-uart0-debug-8k.img.gz prebuild bootloader] for this requirement.
 +
:4. Bootup the m2m board from emmc, plugin the udisk and mount it.
 +
:5. Flash the bootloader to emmc
 +
    $ sudo bpi-bootsel BPI-M2M-LCD7-8k.img.gz /dev/mmcblk0
 +
:or
 +
    $ sudo gunzip -c BPI-M2M-LCD7-8k.img.gz | dd of=/dev/mmcblk0 bs=1024 seek=8
 +
    $ sync
 +
    $ sudo umount /dev/sda1
 +
 
 +
:6. Mout boot partition and set kernel debug console in uEnv.txt
 +
    $ sudo mount -t vfat /dev/mmcblk0p1 /mnt
 +
: Change "console=ttyS2,115200" to "console=ttyS0,115200" in /mnt/bananapi/bpi-m2m/linux/lcd7/uEnv.txt
 +
    $ sudo umount /dev/mmcblk0p1
 +
 
 +
:7. Safely poweroff the board and connect debug uart to uart0 three pin header.
 +
 
 +
===Audio Path===
 +
:1. 2-pin HP header output audio path
 +
 
 +
:{| class="wikitable"
 +
|-
 +
| style="background: PaleTurquoise; color: black" colspan="4"| '''2-pin HP header output audio path'''
 +
|-
 +
|Number id|| Ctl_name || value
 +
|-
 +
| 1|| headphone volume|| 0-63
 +
|-
 +
| 104|| AIF1IN0L Mux|| AIF1_DA0L
 +
|-
 +
| 103|| AIF1IN0R Mux|| AIF1_DA0R
 +
|-
 +
| 100|| DACL Mixer AIF1DA0L Switch|| 1
 +
|-
 +
| 96|| DACR Mixer AIF1DA0R Switch|| 1
 +
|-
 +
| 78|| HP_R Mux|| DACR HPR Switch
 +
|-
 +
| 77|| HP_L Mux|| DACL HPL Switch
 +
|-
 +
| 105|| Headphone Switch|| 1
 +
|}
 +
 
 +
:2. Mic 1 input audio path
 +
 
 +
:{| class="wikitable"
 +
|-
 +
| style="background: PaleTurquoise; color: black" colspan="4"| '''Mic 1 input audio path'''
 +
|-
 +
|Number id|| Ctl_name || value
 +
|-
 +
| 56|| AIF1OUT0L Mux|| AIF1_AD0L
 +
|-
 +
| 55|| AIF1OUT0R Mux|| AIF1_AD0R
 +
|-
 +
| 51|| AIF1 AD0L Mixer ADCL Switch|| 1
 +
|-
 +
| 47|| AIF1 AD0R Mixer ADCR Switch|| 1
 +
|-
 +
| 24|| ADCR Mux|| ADC
 +
|-
 +
| 25|| ADCL Mux|| ADC
 +
|-
 +
| 34|| LEFT ADC input Mixer MIC1 boost Switch|| 1
 +
|-
 +
| 27|| RIGHT ADC input Mixer MIC1 boost Switch|| 1
 +
|-
 +
| 4|| MIC1 boost amplifier gain|| 0-7
 +
|}
 +
 
 +
:3.Alsa configuration file /var/lib/alsa/alsa.state.bpi-m2m already enable 2-pin HP output and Mic 1 input audio path, and restore by /var/lib/bananapi/bpi-autorun.d/S10-audio-bpi-m2m.sh after system bootup.
  
 
===Bluetooth===
 
===Bluetooth===
Line 58: Line 198:
  
 
1. Use commands to setup WiFi client
 
1. Use commands to setup WiFi client
* ip link set wlan0 up
+
  $ sudo su
* iw dev wlan0 scan | grep SSID
+
  # killall wpa_supplicant
* vim /etc/wpasupplicant/wpa_supplicant.conf  
+
  # wpa_passphrase <ssid> <passphrase> > /etc/wpa_supplicant/wpa_supplicant.conf            
* network={    ssid="ssid"    psk="password"    priority=1 }
+
  # ifconfig wlan0 up
* wpa_supplicant -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf
+
  # iwlist wlan0 scan
* dhclient wlan0
+
  # wpa_supplicant -B -iwlan0 -c/etc/wpa_supplicant/wpa_supplicant.conf
 +
  # dhclient wlan0
 +
 
 +
There are some other command line ways, please google for them.
  
 
2. Use UI interface to setup WiFi Client
 
2. Use UI interface to setup WiFi Client
 
===NAS Application===
 
1. Usb hub + sata to usb
 
* HDD is supported
 
[[Image:M2m_connect_hdd.png]]
 
 
[[Image:M2m_connect_hdd_cmd.png]]
 
 
* SSD is supported
 
[[Image:M2m_connect_ssd.png]]
 
 
[[Image:M2m_connect_ssd_cmd.png]]
 
  
 
===Camara function===
 
===Camara function===
Line 91: Line 222:
 
* "./test_ov5640_image_mode.sh" to test picture taking function
 
* "./test_ov5640_image_mode.sh" to test picture taking function
 
* "./cameratest.sh" to test video recording function
 
* "./cameratest.sh" to test video recording function
 
===BPI-Tools===
 
====Install Bpi-tools====
 
* Execute "curl -sL https://github.com/BPI-SINOVOIP/bpi-tools/raw/master/bpi-tools | sudo -E bash - "
 
 
====Update Bpi-tools====
 
* Execute "bpi-tools"
 
[[Image: Bpi-tools.png]]
 
  
 
===RPi.GPIO===
 
===RPi.GPIO===

Latest revision as of 17:18, 19 March 2023

Introduction

BPI-M2M

Overview: BPI-M2M ubuntu linux
  Banana Pi M2M is another ARM SoC powered development board that offers great computing performance in an ultra portable form factor. It is a 51mm square with Allwinner A33 Quad-core A7 SoC and 512MB DDR3 RAM. 

Key Features

  • Quad Core ARM Cortex A7 CPU. R16
  • 512MB DDR3 SDRAM
  • WiFi (AP6212) & Bluetooth onboard

Development

Android

 1.You could download latest image from our forum.
 
 2.Put your TF card into a TF-USB adapter, and then plug adapter in your Windows PC usb interface.
 
 3.Prepare your image, and download image burning tools PhoenixCard.exe.
 
 4.Use "PhoenixCard.exe" to burn android image to TF card.
 
 M3 Android Burning.png
 * Download PhoenixCard: https://pan.baidu.com/s/1-fjvPqtG_zewVzqnXf1AHw?pwd=eid9

Linux

Prepare

1. Prepare 8G/above TF card, USB-Serial cable.
2. Connect USB-Serial to 40 pin header uart2 for kernel console debug.
Note: three pin header uart0 beside usb port is not debug uart for bpi release images because SDcard and uart0 are multiplex pin and default bpi images support both SD and eMMC. If you want bootup with emmc only and enable uart0 as debug port without SDcard support, please refer to enable uart0 debug for emmc only image section.
 M2M debug console.png  M2M pin define.png
3. Install bpi-tools on your Linux PC, If you can't access this URL or any other problems, please go to bpi-tools repo and download this tools manually.
 $ apt-get install pv
 $ curl -sL https://github.com/BPI-SINOVOIP/bpi-tools/raw/master/bpi-tools | sudo -E bash
4. Download latest linux image, and confirm that the md5 checksum is correct.
5. Defautl login: pi/bananapi or root/bananapi.

Install Image to SDcard

1. Install image with bpi-tools on Linux, plug your sd card to your Linux PC
   $ sudo bpi-copy  xxx-bpi-m2m-xxx.img.zip /dev/sdX
2. Install image with dd command on Linux, umount SDcard device /dev/sdX partitions if mounted automatically, Actually bpi-copy is the same as this dd command.
   $ sudo apt-get install pv
   $ sudo unzip -p xxx-bpi-m2m-xxx.img.zip | pv | dd of=/dev/sdX bs=10M status=noxfer
3. Install bpi image with Etcher on Windows, Linux and MacOS
Balena Etcher is an open source project by Balena, Flash OS images to SD cards & USB drives

Install Image to EMMC

1. Prepare a SDcard with Linux image flashed and bootup the board with this SDcard.
2. Copy emmc image to udisk, plugin the udisk to board and mount it.
3. Install with bpi-tools command
   $ sudo bpi-copy xxx-bpi-m2m-xxx.img.zip /dev/mmcblk1
4. Or Install with dd command, umount mmcblk1p1 and mmcblk1p2 partition if mounted automatically, Actually bpi-copy is the same as this dd command
   $ sudo apt-get install pv
   $ sudo unzip -p xxxb-bpi-m2m-xxx.img.zip | pv | dd of=/dev/mmcblk1 bs=10M status=noxfer
5. After flash complete, power off safely and eject the sdcard.

Note: If the emmc was flashed android image before, you must erase the boot partition of android before step 3 or step 4.

   root@bpi-iot-ros-ai:/# echo 0 > /sys/block/mmcblk1/mmcblk1boot0/force_ro                              
   root@bpi-iot-ros-ai:/# echo 0 > /sys/block/mmcblk1/mmcblk1boot1/force_ro                              
   root@bpi-iot-ros-ai:/# 
   root@bpi-iot-ros-ai:/# dd if=/dev/zero of=/dev/mmcblk1boot0 bs=4096 count=1024                        
   1024+0 records in
   1024+0 records out
   4194304 bytes (4.2 MB, 4.0 MiB) copied, 0.421164 s, 10.0 MB/s
   root@bpi-iot-ros-ai:/# dd if=/dev/zero of=/dev/mmcblk1boot1 bs=4096 count=1024                        
   1024+0 records in
   1024+0 records out
   4194304 bytes (4.2 MB, 4.0 MiB) copied, 0.428427 s, 9.8 MB/s

Build Source Code

1. Get the bsp source code
 $ git clone https://github.com/BPI-SINOVOIP/BPI-M2M-bsp
2. Build the bsp source code
Please read the source code README.md

Advance Development

Enable uart0 for emmc only image debug

1. Enable uart0 node and disable sdc0 node in sunxi-pack/sun8iw5p1/configs/BPI-M2M-LCD7/sys_config.fex.
    --- a/sunxi-pack/sun8iw5p1/configs/BPI-M2M-LCD7/sys_config.fex
    +++ b/sunxi-pack/sun8iw5p1/configs/BPI-M2M-LCD7/sys_config.fex
   @@ -262,7 +262,7 @@ twi_sda         = port:PE13<3><default><default><default>
    ;uart_type       = 2:2 wire,4:4 wire,8:8 wire, full function
    ;----------------------------------------------------------------------------------
    [uart0]
   -uart_used       = 0
   +uart_used       = 1
    uart_port       = 0
    uart_type       = 2
    uart_tx         = port:PF02<3><1><default><default>
   @@ -803,7 +803,7 @@ led3_active_low             = 1
    ;     that supports SD3.0 cards and eMMC4.4+ flashes
    ;-------------------------------------------------------------------------------
    [mmc0_para]
   -sdc_used          = 1
   +sdc_used          = 0
    sdc_detmode       = 3
    sdc_buswidth      = 4
    sdc_d1            = port:PF00<2><1><2><default>
2. Build the bsp source code.
3. Copy the bootloader file SD/bpi-m2m/100MB/BPI-M2M-LCD7-8k.img.gz to udisk. bpi also provide a prebuild bootloader for this requirement.
4. Bootup the m2m board from emmc, plugin the udisk and mount it.
5. Flash the bootloader to emmc
   $ sudo bpi-bootsel BPI-M2M-LCD7-8k.img.gz /dev/mmcblk0
or
   $ sudo gunzip -c BPI-M2M-LCD7-8k.img.gz | dd of=/dev/mmcblk0 bs=1024 seek=8
   $ sync
   $ sudo umount /dev/sda1
6. Mout boot partition and set kernel debug console in uEnv.txt
   $ sudo mount -t vfat /dev/mmcblk0p1 /mnt
Change "console=ttyS2,115200" to "console=ttyS0,115200" in /mnt/bananapi/bpi-m2m/linux/lcd7/uEnv.txt
   $ sudo umount /dev/mmcblk0p1
7. Safely poweroff the board and connect debug uart to uart0 three pin header.

Audio Path

1. 2-pin HP header output audio path
2-pin HP header output audio path
Number id Ctl_name value
1 headphone volume 0-63
104 AIF1IN0L Mux AIF1_DA0L
103 AIF1IN0R Mux AIF1_DA0R
100 DACL Mixer AIF1DA0L Switch 1
96 DACR Mixer AIF1DA0R Switch 1
78 HP_R Mux DACR HPR Switch
77 HP_L Mux DACL HPL Switch
105 Headphone Switch 1
2. Mic 1 input audio path
Mic 1 input audio path
Number id Ctl_name value
56 AIF1OUT0L Mux AIF1_AD0L
55 AIF1OUT0R Mux AIF1_AD0R
51 AIF1 AD0L Mixer ADCL Switch 1
47 AIF1 AD0R Mixer ADCR Switch 1
24 ADCR Mux ADC
25 ADCL Mux ADC
34 LEFT ADC input Mixer MIC1 boost Switch 1
27 RIGHT ADC input Mixer MIC1 boost Switch 1
4 MIC1 boost amplifier gain 0-7
3.Alsa configuration file /var/lib/alsa/alsa.state.bpi-m2m already enable 2-pin HP output and Mic 1 input audio path, and restore by /var/lib/bananapi/bpi-autorun.d/S10-audio-bpi-m2m.sh after system bootup.

Bluetooth

  • Use bluetoothctl tool to operate BT
  • Execute "bluetoothctl"
  • If you don't know how to use bluetoothctl, type "help", you will see more commands
  • Execute these commands:

M2M BT bluetoothctl.png

WiFi Client

You have two ways to setup WiFi Client

1. Use commands to setup WiFi client

 $ sudo su
 # killall wpa_supplicant
 # wpa_passphrase <ssid> <passphrase> > /etc/wpa_supplicant/wpa_supplicant.conf              
 # ifconfig wlan0 up
 # iwlist wlan0 scan
 # wpa_supplicant -B -iwlan0 -c/etc/wpa_supplicant/wpa_supplicant.conf
 # dhclient wlan0

There are some other command line ways, please google for them.

2. Use UI interface to setup WiFi Client

Camara function

We use HDF5640 camara.

Ov5640 camara.png

Guvcview

  • Use your UI interface to operate camara
  • Applications -> Sound & Video -> guvcview

Shell

  • We also have built-in command in /usr/local/bin to test camara
  • "./test_ov5640_image_mode.sh" to test picture taking function
  • "./cameratest.sh" to test video recording function

RPi.GPIO

Install RPi.GPIO

  • Execute "git clone https://github.com/BPI-SINOVOIP/RPi.GPIO"
  • after clone the repo, cd RPi.GPIO
  • Execute "sudo apt-get update"
  • Execute "sudo apt-get install python-dev python3-dev"
  • Execute "sudo python setup.py install" or "sudo python3 setup.py install" to install the module

Using RPi.GPIO

  • cd /usr/local/bin
  • Execute "./bpi_test_g40.py" to test RPi.GPIO

RPi GPIO.png

WiringPi

How to Update WiringPi

  • Execute "bpi-update -c pkglist.conf"

Update Pkglist.png

  • Execute "bpi-update -c bpi-pkg-bpi-wiringpi.conf"

Update WringPi.png

RGB 1602 LCD

  • Execute "/usr/local/bin/bpi_test_lcd1602.sh"

WringPi 1602 LCD m2m.png

0.96 Inch OLED Display

  • Execute "/usr/local/bin/bpi_test_52pi.sh"

8x8 RGB LED Martix

  • Firstly you need a GPIO Extend Board for 8x8 LED Martix

WringPi LED Martix Extend Board.png

  • Execute "/usr/local/bin/bpi_test_gpio40.sh"

WringPi LED Martix m2m.png