Categories
matlab Uncategorized

MATLAB 图片常用方法

读取图片

matrix = imread("./abc.png")

显示矩阵图片

imshow(matrix)

打开图片后 调用图片工具处理矩阵

imtool(matrix)

RGB转GRAY

gray = rgb2gray(rgb)

图片二值化处理

boolean = img > threhold 

图片膨胀与腐蚀 (去掉图片噪音)

Categories
linux

香橙派 OPI.GPIO

一般GPIO初始化是执行

GPIO.setmode(mode) #来进行引脚定义初始化

GPIO.BOARD = 10
GPIO.BCM = 11
GPIO.SUNXI = 12 
GPIO.CUSTOM = 13  

其实只是一你骄傲的映射关系 没有真正执行任何代码

但是OPI.GPIO 对不同的香橙派版本 引脚定义不充分

CM4为例子

GPIO.setmode(GPIO.BOARD) #会少了很多引脚的映射

C:\Users\15699\AppData\Local\Programs\Python\Python312\Lib\site-packages\OPi\pin_mappings.py

 BOARD: {
        3: 12,
        5: 11,
        7: 6,
        8: 198,
        10: 199,
        11: 1,
        12: 7,
        13: 0,
        15: 3,
        16: 19,
        18: 18,
        19: 15,
        21: 16,
        22: 2,
        23: 14,
        24: 13,
        26: 10
    },

这时候要不更改这个库文件 按照GPIO.readall 补充所有引脚映射

要不执行 自定义引脚映射初始化

GPIO.setmode({
        3: 140,
        5: 141,
        7: 147,
        8: 25,
        10: 24,
        11: 118,
        12: 119,
        13: 128,
        15: 130,
        16: 131,
        18: 129,
        19: 138,
        21: 136,
        22: 132,
        23: 139,
        24: 134,
        26: 135,
        27: 32,
        28: 33,
        29: 133,
        31: 124,
        32: 144,
        33: 127,
        35: 120,
        36: 125,
        37: 123,
        38: 122,
        40: 121
    })

GPIO.getmode 
# 返回CUSTOM 自定义引脚映射
Categories
python

树莓派 香橙派 PWM问题

查看GPIO引脚

gpio readall

用python调用PWM有两种方法

1.RPi.GPIO

import RPi.GPIO  as GPIO


GPIO.setmode(GPIO.BCM)

GPIO.setup(18,GPIO.OUT) #设置引脚为输出
pwm = GPIO.PWM(18,100) #只有12脚 和 18脚 支持硬件PWM   100为100hz
pwm.start(50) #占空比为50并输出

pwm.changeDutyCycle(20) #改变占空比
pwm.stop() #停止PWM波形输出

2OPI.GPIO

PWM is created in the form of an object.

1. First set up OPi.GPIO and create the object

    .. code:: python

       import OPi.GPIO as GPIO
       PWM_Class = GPIO.PWM(PWM_chip, PWM_pin, frequency_Hz, Duty_Cycle_Percent)


一般PWM_chip 为0 第一块 可以通过
 ls -l /sys/class/pwm/ 查看 一般返回 pwmchip0

PWM_pin 就是引脚了 


    Note currently you do not need to specify setmode before creating the class as for a GPIO
    only the PWM_chip number and the PWM_pin.
    The reson for this and how to find what they are is explained in the sysfs PWM section.

2. Begin the PWM cycle

    .. code:: python

        PWM_Class.start_pwm()

3. Change PWM duty Cycle

    .. code:: python
        PWM_Class.duty_cycle(50)

    Note this changes the Duty cycle to 50%

4. Change the frequency

    .. code:: python
        PWM_Class.change_frequency(500)

    Note this changes the Frequency to 500Hz

5. Stop the PWM device

    .. code:: python
        PWM_Class.stop_pwm()

    Note this stops the signal by setting the duty cycle to 0%

6. Change the Polarity of the signal

    .. code:: python
        PWM_Class.pwm_polarity()

    Note this changes swaps the on-off times. For example a duty cycle set to 75% before
    this will result in the signal being on 75% and off 25% of the time. After this is
    called it would be on 25% and off 75%.

7. Remove PWM Object

    .. code:: python
        PWM_Class.pwm_close()

3.wiringpi

import wiringpi

pwm0 =  wiringpi.GPIO(0)        
pwm0.pinMode(1,pwm0.PWM_OUTPUT)
pwm0.pwmSetMode(pwm0.PWM_MODE_MS)
pwm0.pwmSetClock(25)
pwm0.pwmWrite(1,self.brightness)




import wiringpi

PWM_OUTPUT  = 2
PWM_PIN = 1  #指定第二个PWM接口

# 初始化
wiringpi.wiringPiSetup()
wiringpi.pinMode(PWM_PIN, PWM_OUTPUT)  #初始化第二个PWM接口 18  

wiringpi.pwmSetMode(wiringpi.PWM_MODE_MS)  
#设置PWM工作模式 有两个值PWM_MODE_MS PWM_MODE_BAL
#一般选第一个  PWM_MODE_BAL or PWM_MODE_MS(平衡模式/占空比模式)

wiringpi.pwmSetRange(1024)  


#设置总周期默认1024 所以一个周期是 600khz/1024 约等于600hz

wiringpi.pwmSetClock(32)  
#设置分频 默认32 即600khz 总时钟频率是19.2Mhz 

wiringpi.pwmWrite(PWM_PIN,0) #设置占空比 0~1024  512 为一半  
#0的话相当于写入全部低电平 没有波形输出

while 1:
    for bright in range(0, 1000):
        wiringpi.pwmWrite(PWM_PIN, bright)
        wiringpi.delay(1)
    for bright in range(1000, 0, -1):
        wiringpi.pwmWrite(PWM_PIN, bright)
        wiringpi.delay(1)
Categories
linux

树莓派 电源固件升级问题

树莓派论坛提到

https://forums.raspberrypi.com/viewtopic.php?t=361383

升级方法

Tue Dec 12, 2023 5:44 pm

3B+ v1.4 has a new PMIC and needs Sept 2021 or newer firmware.

Follow https://pip.raspberrypi.com/categories/ ... 6-WP-1.pdf to update the firmware in your image.

树莓派更换了新的PMIC(电源管理芯片)

https://pip.raspberrypi.com/categories/685/documents/RP-003476-WP/RP-003476-WP-1.pdf

该PDF有说明最新固件情况

Updating only the firmware

Sometimes, going through the standard upgrade procedure may not be possible. For example, you may have acustomised distribution with no update facilities, or that cannot be upgraded without causing further issues. In thesecircumstances, and possibly others, you will need to update the firmware files in the distribution manually.You can download the firmware files from the following location:

https://github.com/raspberrypi/firmware/archive/refs/heads/stable.zip

This zip file contains a number of items, but the ones we are interested in at this stage are in the boot folder.

The firmwarefiles have names of the form

start*.elf, and their associated support files are fixup*.dat.

The basic principle is to copy the required start and fixup files from this zip file to replace the same named files in thedestination OS image.

The exact process will depend on how the OS has been set up, but this is an example of how itwould be done for a Raspberry Pi OS image:

1. Extract or open the zip file so you can access the required files.

2. Open up the boot folder in the destination OS image (this could be on an SD card, or a disk-based copy).

3. Determine which start.elf and fixup.dat files are present in the destination OS image.

4. Copy those files from the zip archive to the destination image.The image should now be ready for use on the latest Raspberry Pi Ltd hardware.

其实就是下载最新固件包 在压缩包里打开boot目录

替换start*.elf 和 fixup*.dat.

当然命令行系统 用的是start.elf fixup.dat

桌面系统用的是 start_x.elf fixup_x.dat

Categories
linux

Raspbian OS

全量搜索地址 清华开源镜像网站

https://mirrors.tuna.tsinghua.edu.cn/raspberry-pi-os-images/

Categories
android

orangepi PWM

打开pwm15

echo 0 > /sys/class/pwm/pwmchip2/export

设置频率1khz

echo 1000000 > /sys/class/pwm/pwmchip2/pwm0/period                                                                         

设置占空比 10%

echo 100000 > /sys/class/pwm/pwmchip2/pwm0/duty_cycle                                                                      

开始pwm

echo 1 > /sys/class/pwm/pwmchip2/pwm0/enable                                                  

关闭pwm

echo 0 > /sys/class/pwm/pwmchip2/pwm0/enable    
echo 0 > /sys/class/pwm/pwmchip2/unexport                                              
Categories
android

aosp 设置系统自启动脚本

安卓系统启动后会执行

/vendor/etc/init/hw/init.rk3588.rc

这个文件来源于

device/rockchip/rk3588/init.rk3588.rc

在on boot后添加执行脚本

on boot
    chmod 0666 /dev/mem
    chown root system /dev/mem

    chmod 0666 /dev/i2c-5
    chown root system /dev/i2c-5

以上是启动后 增加几个文件的读写权限

这几个文件跟GPIO控制有关系

Categories
android

ro.build.fingerprint 过长

ro.build.fingerprint 是在编译时决定的

frameworks/base/core/java/android/os/Build.java

publicstatic final String FINGERPRINT = deviceFingerprint()

private stattic String deviceFingerprint(){
 String finger = SystemProperties.get("ro.vuild.fingerprint");
 if(TextUtils.isEmpty(finger)){
  finger = getString("ro.product.brand")+'/'+
    getString("ro.product.name")+'/'+
    getString("ro.product.device")+'/'+
    getString("ro.build.version.release")+'/'+
    getString("ro.build.id")+'/'+
    getString("ro.build.version.incremental")+'/'+
    getString("ro.build.type")+'/'+
    getString("ro.build.tags")+'/'+
 }
 return finger;

}

fingerprint 格式

make file定义在

build/make/core/sysprop.mk

$(PRODUCT_BRAND)/$(TARGET_PRODUCT)/$(TARGET_DEVICE):$(PLATFORM_VERSION)/$(BUILD_ID)/$(BF_BUILD_NUMBER):$(TARGET_BUILD_VARIANT)/$(BUILD_VERSION_TAGS)

要缩短该fingerprint

新更新

安卓系统会读取 system/build.prop

可以在这个文件设置 build.prop

在源码目录out/target/product/rk3588s_s/system/build.prop

设置

ro.build.fingerprint=rk3588s_s/12/SQ3A.220705.003.A1/eng.robin.20240217:userdebug/release-keys

若没有这个out文件夹(删除了out目录)

则需要在build/make/tools/buildinfo.sh

添加

echo "ro.build.fingerprint=$PRODUCT_BRAND/:$PLATFORM_VERSION/$BUILD_ID"

Categories
android

AOSP 源码修改 前置摄像头 镜像

在AOSP中 前置摄像头 (index=0)默认是镜像显示预览

frameworks/av/services/camera/libcameraservice/api1/client2/Parameters.cpp


previewTransform = degToTransform(0,
            cameraFacing == CAMERA_FACING_FRONT);

int Parameters::degToTransform(int degrees, bool mirror) {

degToTransform 第二个参数 是是否镜像显示

修改所有 degToTransform 第二个参数为false

Categories
android

orange pi 系统应用

第一

签名要用系统platform级别的签名

第二

adb remount 挂在system目录为可读写

mv /data/app/* /system/app*

adb 触发事件

adb shell am broadcast -a android.intent.action.BOOT_COMPLETED

am broadcast -a android.intent.action.BOOT_COMPLETED –receiver-include-background