Difference between revisions of "Template:Cm4-disp-base-7a-box Guide"

From Waveshare Wiki
Jump to: navigation, search
Line 6: Line 6:
  
 
==USB2.0==
 
==USB2.0==
The USB port is disabled by default on the CM4 to save power. If you need to start, you need to add the following to the config.txt file:
+
The USB port is disabled by default on the CM4 for saving power. If you need to use it, you need to add the following to the config.txt file:
  dtoverlay=dwc2,dr_mode=host
+
<pre>
After restarting <br>
+
dtoverlay=dwc2,dr_mode=host
 +
</pre>
 +
Then reboot the CM4 <br>
  
 
<font color="#ff00ff">
 
<font color="#ff00ff">
 
If you use the latest Raspberry Pi OS (image after October 30, 2021) USB2.0 is OTG mode by default, CM4 will report an error: <br>
 
If you use the latest Raspberry Pi OS (image after October 30, 2021) USB2.0 is OTG mode by default, CM4 will report an error: <br>
  config failed, hub doesn't have any ports! (err -19)
+
<pre>
However, USB can still be used. If you want to remove this error, remove otg_mode=1 in [cm4] of config.txt, and add dtoverlay=dwc2, dr_mode=host (USB cannot be recognized without adding it). <br>
+
config failed, hub doesn't have any ports! (err -19)
 +
</pre>
 +
However, USB can still workable. If you want to remove this error, please remove the ''line otg_mode=1'' in [cm4] of config.txt, and add ''dtoverlay=dwc2, dr_mode=host ''(USB cannot be recognized without adding it). <br>
 
[[FILE:CM4 Burn EMMC_12.png|800px]]<br>
 
[[FILE:CM4 Burn EMMC_12.png|800px]]<br>
 
</font>
 
</font>
  
 
<br>
 
<br>
 
+
==I2C interface==
 +
{{RPI open i2c}}
 +
There are two I2C address were used by the RTC and FAN, please avoid the address when connecting external i2c devices.<br />
 +
*RTC: i2c-1 (0x51)
 +
*FAN: i2c-1 (0x2F)
 
==RS485/RS232==
 
==RS485/RS232==
It is closed by default. If you need to open it, you need to add content in config.txt: <br>
+
They are disabled by default. If you need to use the RS485 or RS232, you need to modify the config.txt: <br>
 +
<pre>
 
sudo nano /boot/config.txt<br>
 
sudo nano /boot/config.txt<br>
  dtoverlay=uart3
+
</pre>
  dtoverlay=uart5
+
And add the following lines:
  reboot
+
<pre>
  ls /dev/ttyAMA*
+
dtoverlay=uart3
<br>
+
dtoverlay=uart5
 +
<pre>
 +
Then reboot the CM4 and check if the corresponding ports were recognized.
 +
<pre>
 +
reboot
 +
ls /dev/ttyAMA*
 +
</pre>
 +
 
 
RS232 occupies GPIO5/GPIO4 (BCM code 4/5), device number ttyAMA1<br>
 
RS232 occupies GPIO5/GPIO4 (BCM code 4/5), device number ttyAMA1<br>
 
RS485 occupies GPIO13/GPIO12 (BCM code 13/12), device number ttyAMA2<br>
 
RS485 occupies GPIO13/GPIO12 (BCM code 13/12), device number ttyAMA2<br>
 
<br>
 
<br>
RS485 can be switched to GPIO15/14, device number ttyS0<br>
+
RS485 can be switched to GPIO15/14 for device number ttyS0<br>
Refer to 27 in the onboard resources, and change the corresponding resistance to the corresponding position<br>
+
Refer to number 27 of the Onboard Resources, change the corresponding resistance to the corresponding position<br>
 
===Test ===
 
===Test ===
 +
<pre>
 
   sudo apt-get install minicom
 
   sudo apt-get install minicom
 
   # RS232
 
   # RS232
Line 38: Line 55:
 
   #RS485
 
   #RS485
 
   sudo minicom -D /dev/ttyAMA2
 
   sudo minicom -D /dev/ttyAMA2
 
+
</pre>
<br>
 
  
 
==GPIO==
 
==GPIO==
The GPIO input/output interface only supports a single mode and does not support switching. The following are the corresponding pins of the interface. <br>
+
The GPIO input/output interface only supports a single-mode and does not support switching. The following are the corresponding pins of the interface. <br>
 
OUT CH1 GPIO17<br>
 
OUT CH1 GPIO17<br>
 
OUT CH2 GPIO27<br>
 
OUT CH2 GPIO27<br>
Line 48: Line 64:
 
IN CH2 GPIO23<br>
 
IN CH2 GPIO23<br>
  
The module only supports 3.3V and 5V and does not support other voltages, which can be switched by jumper caps. <br>
+
The module only supports 3.3V and 5V, which can be switched by jumper caps. <br>
 
<br>
 
<br>
 +
 
==Audio==
 
==Audio==
Add in config,txt
+
Add the following lines to config,txt
  dtparam=audio=on
+
<pre>
  dtoverlay=audremap,pins_18_19
+
dtparam=audio=on
  audio_pwm_mode=2
+
dtoverlay=audremap,pins_18_19
  disable_audio_dither=1
+
audio_pwm_mode=2
Any reboot will do
+
disable_audio_dither=1
If there is no sound, you can check whether it is selected in the image interface. If there is no image interface, check as follows:<br>
+
</pre>
Check playback: aplay -l<br>
+
Reboot the CM4 and check if the new play device is recognized by the command ''aplay -l''
Check for equipment<br>
 
 
<br>
 
<br>
 
After it is turned on, it can be recognized under the audio selection. There may be a problem that the default sound card is not a GPIO sound card.
 
After it is turned on, it can be recognized under the audio selection. There may be a problem that the default sound card is not a GPIO sound card.
Line 66: Line 82:
 
==RTC  FAN==
 
==RTC  FAN==
 
<font color="red">
 
<font color="red">
*Note: Please connect the fan before turning on the power of the expansion board and then complete the test. Please do not connect the fan after the expansion board has been powered on, that is, the fan control chip has been powered on, otherwise the chip will be burned!
+
*Note: Please connect the fan before turning on the power of the expansion board and then complete the test. Please do not connect the fan after the expansion board has been powered on, otherwise the chip will be burned!
 
</font>
 
</font>
 
<font color="#ff0000"> I2C-1 is used by default </font><br/>
 
<font color="#ff0000"> I2C-1 is used by default </font><br/>
Line 73: Line 89:
 
RTC (PCF85063a) on i2c-1, address is 0x51 (7-bit address)<br/>
 
RTC (PCF85063a) on i2c-1, address is 0x51 (7-bit address)<br/>
 
FAN (EMC2301) on i2c-1, address is 0x2f (7-bit address)<br/>
 
FAN (EMC2301) on i2c-1, address is 0x2f (7-bit address)<br/>
 
 
  
 
===RTC===
 
===RTC===
Line 93: Line 107:
 
<syntaxhighlight lang="python">
 
<syntaxhighlight lang="python">
 
  sudo hwclock -s
 
  sudo hwclock -s
  #When the network needs to be closed, or the network pair is closed, the responsibility will be changed back
+
  #The network needs to be closed, or the network pair is closed, or the clock will be changed back
 
  #This command is only for test use, please open it during actual use, the time is more accurate
 
  #This command is only for test use, please open it during actual use, the time is more accurate
 
  #Turn off network timing
 
  #Turn off network timing
Line 104: Line 118:
 
  sudo hwclock --set --date="9/8/2021 16:45:05"
 
  sudo hwclock --set --date="9/8/2021 16:45:05"
 
</syntaxhighlight>
 
</syntaxhighlight>
View hardware clock
+
Check hardware clock
 
<syntaxhighlight lang="python">
 
<syntaxhighlight lang="python">
 
  sudo hwclock -r
 
  sudo hwclock -r
 
</syntaxhighlight>
 
</syntaxhighlight>
Display version information
+
Show version information
 
<syntaxhighlight lang="python">
 
<syntaxhighlight lang="python">
 
  sudo hwclock --verbose
 
  sudo hwclock --verbose
 
</syntaxhighlight>
 
</syntaxhighlight>
<br>
 
 
<br>
 
<br>
  
 
===Fan===
 
===Fan===
When powered on, the fan will spin for 1 second, then stop for 2 seconds, and then spin again, this is a normal phenomenon<br>
+
When powered on, the fan will spin for 1 second, then stop for 2 seconds, this is a normal <br>
 
test driver
 
test driver
 
<syntaxhighlight lang="python">
 
<syntaxhighlight lang="python">
Line 136: Line 149:
  
 
==Screen and camera turned on==
 
==Screen and camera turned on==
Use the old version (buster) system to load the configuration file and restart to identify, the new version (bullseye) system needs to add additional modification files<br>
+
If you use the buster system, you just need to add the configuration file and reboot. <br />
 +
If you use the new version (bullseye) system, additional modifications are required<br>
 
===Load Configuration File ===
 
===Load Configuration File ===
 
When using the camera and DSI, it will occupy three I2C devices: I2C-10, I2C-11, I2C-0<br>
 
When using the camera and DSI, it will occupy three I2C devices: I2C-10, I2C-11, I2C-0<br>
Line 151: Line 165:
  
 
=== Old Version (Buster) ===
 
=== Old Version (Buster) ===
Note: On December 2, 2021, the Raspberry Pi OS for Raspberry Pi split into two branches, the Buster branch and the Bullseye branch.
+
Note: On December 2, 2021, the Raspberry Pi OS for Raspberry Pi split into two branches, the Buster branch, and the Bullseye branch.
  
 
The Buster branch is a continuation of the old system and is more stable. The Bullseye branch adds some new features, uses open source libraries and new interfaces.
 
The Buster branch is a continuation of the old system and is more stable. The Bullseye branch adds some new features, uses open source libraries and new interfaces.
Line 196: Line 210:
 
reboot
 
reboot
  
#Other part of the command:
+
# another part of the command:
 
#Check if the camera is detected
 
#Check if the camera is detected
 
libcamera-hello --list-cameras
 
libcamera-hello --list-cameras

Revision as of 03:53, 9 March 2022

Writing Image


USB2.0

The USB port is disabled by default on the CM4 for saving power. If you need to use it, you need to add the following to the config.txt file:

dtoverlay=dwc2,dr_mode=host

Then reboot the CM4

If you use the latest Raspberry Pi OS (image after October 30, 2021) USB2.0 is OTG mode by default, CM4 will report an error:

config failed, hub doesn't have any ports! (err -19)

However, USB can still workable. If you want to remove this error, please remove the line otg_mode=1 in [cm4] of config.txt, and add dtoverlay=dwc2, dr_mode=host (USB cannot be recognized without adding it).
CM4 Burn EMMC 12.png


I2C interface

Enable I2C Interface

Open a terminal and run the following commands:

sudo raspi-config 
Choose Interfacing Options -> I2C -> Yes.

Reboot Raspberry Pi:

sudo reboot

RPI open i2c.png
There are two I2C address were used by the RTC and FAN, please avoid the address when connecting external i2c devices.

  • RTC: i2c-1 (0x51)
  • FAN: i2c-1 (0x2F)

RS485/RS232

They are disabled by default. If you need to use the RS485 or RS232, you need to modify the config.txt:

sudo nano /boot/config.txt<br>

And add the following lines:

dtoverlay=uart3
dtoverlay=uart5
<pre>
Then reboot the CM4 and check if the corresponding ports were recognized.
<pre>
reboot
ls /dev/ttyAMA*

RS232 occupies GPIO5/GPIO4 (BCM code 4/5), device number ttyAMA1
RS485 occupies GPIO13/GPIO12 (BCM code 13/12), device number ttyAMA2

RS485 can be switched to GPIO15/14 for device number ttyS0
Refer to number 27 of the Onboard Resources, change the corresponding resistance to the corresponding position

Test

  sudo apt-get install minicom
  # RS232
  sudo minicom -D /dev/ttyAMA1
  #RS485
  sudo minicom -D /dev/ttyAMA2

GPIO

The GPIO input/output interface only supports a single-mode and does not support switching. The following are the corresponding pins of the interface.
OUT CH1 GPIO17
OUT CH2 GPIO27
IN CH1 GPIO22
IN CH2 GPIO23

The module only supports 3.3V and 5V, which can be switched by jumper caps.

Audio

Add the following lines to config,txt

 dtparam=audio=on
 dtoverlay=audremap,pins_18_19
 audio_pwm_mode=2
 disable_audio_dither=1

Reboot the CM4 and check if the new play device is recognized by the command aplay -l
After it is turned on, it can be recognized under the audio selection. There may be a problem that the default sound card is not a GPIO sound card.

RTC FAN

  • Note: Please connect the fan before turning on the power of the expansion board and then complete the test. Please do not connect the fan after the expansion board has been powered on, otherwise the chip will be burned!

I2C-1 is used by default

RTC (PCF85063a) on i2c-1, address is 0x51 (7-bit address)
FAN (EMC2301) on i2c-1, address is 0x2f (7-bit address)

RTC

sudo nano /boot/config.txt
 #Add at the end
 dtparam=i2c_arm=on
 dtoverlay=i2c-rtc,pcf85063a
 #Save and exit, restart
 sudo reboot

Hwclock is simple to use

Synchronize System Clock -> Hardware Clock

sudo hwclock -w

Synchronize hardware clock -> system clock

sudo hwclock -s
 #The network needs to be closed, or the network pair is closed, or the clock will be changed back
 #This command is only for test use, please open it during actual use, the time is more accurate
 #Turn off network timing
 # sudo timedatectl set-ntp false
 #Enable network timing
 # sudo timedatectl set-ntp true

Set the hardware clock time:

sudo hwclock --set --date="9/8/2021 16:45:05"

Check hardware clock

sudo hwclock -r

Show version information

sudo hwclock --verbose


Fan

When powered on, the fan will spin for 1 second, then stop for 2 seconds, this is a normal
test driver

wget https://www.waveshare.com/w/upload/b/b9/EMC2301_i2c1_code.zip
unzip -o EMC2301_i2c1_code.zip -d ./EMC2301_i2c1_code
sudo chmod 777 -R EMC2301_i2c1_code
cd EMC2301_i2c1_code/
 
#C
cd c/
make
sudo ./main

#python
cd python/examples
sudo python main.py

Screen and camera turned on

If you use the buster system, you just need to add the configuration file and reboot.
If you use the new version (bullseye) system, additional modifications are required

Load Configuration File

When using the camera and DSI, it will occupy three I2C devices: I2C-10, I2C-11, I2C-0
The camera needs to run raspi-config, select Interfacing Options->Camera->Yes->Finish-Yes, reboot the system, open the enable camera, and then restart to save the changes.
Execute as follows:

wget https://www.waveshare.com/w/upload/7/75/CM4_dt_blob_Source.zip
 unzip -o CM4_dt_blob_Source.zip -d ./CM4_dt_blob_Source
 sudo chmod 777 -R CM4_dt_blob_Source
 cd CM4_dt_blob_Source/
 sudo dtc -I dts -O dtb -o /boot/dt-blob.bin dt-blob-disp0-double_cam.dts
 # After execution, turn off the power and restart the CM4

Old Version (Buster)

Note: On December 2, 2021, the Raspberry Pi OS for Raspberry Pi split into two branches, the Buster branch, and the Bullseye branch.

The Buster branch is a continuation of the old system and is more stable. The Bullseye branch adds some new features, uses open source libraries and new interfaces.

If you use the Buster branch system, the image can be used normally without any modification. View the first connected camera screen:

sudo raspivid -t 0 -cs 0



New Version (Bullseye)

If you are using the Bullseye branch of the system, refer to the following

Show

Comment the following statements in the config.txt file (the config file is located in the root directory of the TF card, namely /boot):

#camera_auto_detect=1
#dtoverlay=vc4-kms-v3d

Add the following statement below [all]:

dtoverlay=vc4-fkms-v3d


After saving, restart the Raspberry Pi

sudo reboot

Camera

libcamera-hello -t 0
or
libcamera-hello

#The default camera model is ov5647, if you need to change it to other cameras, you can check the camera model by yourself
#Add to
dtoverlay=ov5647,cam1
dtoverlay=ov5647,cam0

#where ov5647 is the camera sensor model, and there are other sensors
dtoverlay=ov5647,cam0
dtoverlay=imx219,cam0
dtoverlay=ov9281,cam0
dtoverlay=imx477,cam0

#then restart
reboot

# another part of the command:
#Check if the camera is detected
libcamera-hello --list-cameras

#open camera
libcamera-hello --camera 0

#Taking Pictures
libcamera-jpeg -o test.jpg
#You can add --camera to specify the camera

More instructions click me
Reference Raspberry Pi Manual