在 Raspberry Pi 上使用 HDMI-CEC

什么是HDMI-CEC

HDMI-CEC 是一种特殊协议,专为电视通过 HDMI 电缆与其他设备进行通信而设计。该协议允许电视控制另一个设备,同时还允许该设备控制电视。

大多数现代电视都支持此协议,但通常必须在电视设置中启用。搜索您的电视型号应该可以帮助您找到此设置的名称。

使用 HDMI-CEC 协议,您可以使用 Raspberry Pi 以各种不同的方式控制电视,例如关闭和打开电视或更改音量。

将 cec-client 安装到 Raspberry Pi

cec-client 是我们将在 Raspberry Pi 上使用的软件包,用于通过 HDMI-CEC 协议控制设备。

软件包安装

1.我们的首要任务是更新 Raspberry Pi 上的软件包列表以及升级当前安装的软件包。

我们可以通过运行以下两个命令来完成此任务。

sudo apt update 
sudo apt -y upgrade 
sudo apt install cec-utils -y

软件的使用方法

  1. 使用 Raspberry Pi 通过 HDMI-CEC 与电视交互

第一个是使用echo和管道(|)。将命令直接传递给cec-client软件,而无需启动它。

此外,我们在软件中同时使用-s和-d选项cec-client。

该-s选项告诉软件我们将发出一个命令。软件将启动,发出命令然后立即退出。

该-d 1选项设置软件的调试级别。通过将其设置为1,cec-client软件将只显示错误。

从 Raspberry Pi 扫描 HDMI-CEC 设备

echo 'scan' | cec-client -s -d 1

2.通过此命令,您应该会看到您的 Raspberry Pi 现在可以访问的设备列表。

您需要识别要与之交互的设备。通常,“ os string:”和“ vendor:”字段将帮助您识别要与之交互的设备。

识别出正确的设备后,记下“ address:”或设备编号。

输出有可能类似下面的内容:

opening a connection to the CEC adapter...
requesting CEC bus information ...
CEC bus information
===================
device #0: TV
address:       0.0.0.0
active source: no
vendor:        Sony
osd string:    TV
CEC version:   1.4
power status:  standby
language:      eng

device #1: Recorder 1
address:       1.0.0.0
active source: no
vendor:        Pulse Eight
osd string:    CECTester
CEC version:   1.4
power status:  on
language:      eng

device #4: Playback 1
address:       3.0.0.0
active source: no
vendor:        Sony
osd string:    PlayStation 4
CEC version:   1.3a
power status:  standby
language:      ???

请注意,device #1: Recorder 1此示例中的“ ”是 Raspberry Pi 自己的 CEC 连接,因此我们可以放心地忽略它。

3.例如,如果我们想控制我们的“索尼电视”,我们可以看到设备号是“ 0”,设备的地址是“ 0.0.0.0”。

获得设备编号或设备地址后,您就可以开始向其发送命令了。

通过 HDMI-CEC发送“ on ”命令

echo 'on <DEVICEADDRESS>' | cec-client -s -d 1

通过 HDMI-CEC发送“待机”命令

echo 'standby <DEVICEADDRESS>' | cec-client -s -d 1

通过 HDMI-CEC关闭设备的示例

使用此命令相对简单。

要将我们的索尼电视置于待机状态,我们需要做的就是发送“ standby”,然后发送我们的设备地址“ 0.0.0.0”。

echo 'standby 0.0.0.0 | cec-client -s -d 1

通过 HDMI-CEC 获取电源状态

echo 'pow <DEVICEADDRESS>' | cec-client -s -d 1

通过 HDMI-CEC 获取电源状态的示例

echo 'pow 0.0.0.0' | cec-client -s -d 1

如果您的设备处于待机状态,您将在终端中看到类似于我们下面的内容。
opening a connection to the CEC adapter...
power status: standby

检索其他 CEC 客户端命令

echo 'h' | cec-client -s -d 1

该命令的作用是检索cec-client软件知道如何处理的可用命令。

从这个命令中,你应该得到一个命令列表,如下所示。

================================================================================
Available commands:

[tx] {bytes}              transfer bytes over the CEC line.
[txn] {bytes}             transfer bytes but don't wait for transmission ACK.
[on] {address}            power on the device with the given logical address.
[standby] {address}       put the device with the given address in standby mode.
[la] {logical address}    change the logical address of the CEC adapter.
[p] {device} {port}       change the HDMI port number of the CEC adapter.
[pa] {physical address}   change the physical address of the CEC adapter.
[as]                      make the CEC adapter the active source.
[is]                      mark the CEC adapter as inactive source.
[osd] {addr} {string}     set OSD message on the specified device.
[ver] {addr}              get the CEC version of the specified device.
[ven] {addr}              get the vendor ID of the specified device.
[lang] {addr}             get the menu language of the specified device.
[pow] {addr}              get the power status of the specified device.
[name] {addr}             get the OSD name of the specified device.
[poll] {addr}             poll the specified device.
[lad]                     lists active devices on the bus
[ad] {addr}               checks whether the specified device is active.
[at] {type}               checks whether the specified device type is active.
[sp] {addr}               makes the specified physical address active.
[spl] {addr}              makes the specified logical address active.
[volup]                   send a volume up command to the amp if present
[voldown]                 send a volume down command to the amp if present
[mute]                    send a mute/unmute command to the amp if present
[self]                    show the list of addresses controlled by libCEC
[scan]                    scan the CEC bus and display device info
[mon] {1|0}               enable or disable CEC bus monitoring.
[log] {1 - 31}            change the log level. see cectypes.h for values.
[ping]                    send a ping command to the CEC adapter.
[bl]                      to let the adapter enter the bootloader, to upgrade
                          the flash rom.
[r]                       reconnect to the CEC adapter.
[h] or [help]             show this help.
[q] or [quit]             to quit the CEC test client and switch off all
                          connected CEC devices.
=======================================================================

至此,您现在应该已经学会了如何cec-client在您的 Raspberry Pi 上使用来控制支持该HDMI-CEC协议的设备。

[Raspberry Pi 新系统]树莓派更新失败处理方法

故障现象:

pi@raspberrypi:~ $ sudo apt-get update
Get:1 http://archive.raspberrypi.org/debian buster InRelease [32.6 kB]
Get:2 http://raspbian.raspberrypi.org/raspbian buster InRelease [15.0 kB]
Reading package lists... Done
E: Repository 'http://raspbian.raspberrypi.org/raspbian buster InRelease' changed its 'Suite' value from 'stable' to 'oldstable'
N: This must be accepted explicitly before updates for this repository can be applied. See apt-secure(8) manpage for details.
E: Repository 'http://archive.raspberrypi.org/debian buster InRelease' changed its 'Suite' value from 'testing' to 'oldstable'
N: This must be accepted explicitly before updates for this repository can be applied. See apt-secure(8) manpage for details.

修复方法:

sudo apt-get -y update --allow-releaseinfo-change

结果如下:

Get:1 http://archive.raspberrypi.org/debian buster InRelease [32.6 kB]
Get:2 http://raspbian.raspberrypi.org/raspbian buster InRelease [15.0 kB]
Get:3 http://raspbian.raspberrypi.org/raspbian buster/contrib Sources [78.5 kB]
Get:4 http://archive.raspberrypi.org/debian buster/main armhf Packages [393 kB]
Get:5 http://raspbian.raspberrypi.org/raspbian buster/main Sources [11.4 MB]
Ign:5 http://raspbian.raspberrypi.org/raspbian buster/main Sources
Get:6 http://raspbian.raspberrypi.org/raspbian buster/non-free Sources [139 kB]
Get:7 http://raspbian.raspberrypi.org/raspbian buster/rpi Sources [1,132 B]
Get:8 http://raspbian.raspberrypi.org/raspbian buster/main armhf Packages [13.0 MB]
21% [8 Packages 443 kB/13.0 MB 3%]

顺利解决~

浪派-造物志

何谓:浪派?

所谓浪派,其实是我和几个朋友一起搞的一个树莓派小车的项目,其核心内容是想在疫情期间无法面基就只好通过网络交互来实现原先的自由自造的折腾行为.其中涉及到原型设计,芯片选型,PCB设计,打样焊接,程序调试等一系列技术栈,在设计之初为了能够让大家都有参与进来的兴趣,还专门采用了kicad设计软件来进行pcb设计...参与的小伙伴各显神通,但是也遭遇过一些小小的滑铁卢...

回忆杀


未完待续,手机更新大拇指压力太大了....

Retropie 设置中文

RetroPie复古游戏模拟系统设置中文

步骤简述

    1. 下载最新的Retropie镜像,别问我从哪里下载。
    1. 烧录到TF卡,也别问我怎么烧录。
    1. 开机启动后连wifi或者网络, 更别问我怎么连wifi。
    1. 进系统后直接按F4进入终端,在确保联网的情况下输入:
      sudo apt-get update 
      sudo apt-get -y install fonts-droid-fallback
      sudo reboot 

      然后你安装的游戏就算是有中文也没有问题了。

树莓派串口编程

树莓派串口编程

简单做个笔记记录一下串口编程的方法。

  1. 树莓派需要释放蓝牙所占用的的串口。
  2. 编辑/boot/config.txt 或者通过raspi-config启用串口(serial) ,编辑文件的话直接加入enable_uart=1 然后重启。
  3. 添加 dtoverlay = pi3-miniuart-bt 或者:dtoverlay = pi3-disable-bt

    基本思路

    操作示例代码

    • C 语言
      #include <stdio.h>
      #include <string.h>
      #include <errno.h>
      #include <wiringPi.h>
      #include <wiringSerial.h>
      int main ()
      {
      int serial_port ;
      char dat;
      if ((serial_port = serialOpen ("/dev/ttyS0", 9600)) < 0) /* open serial port */
      {
      fprintf (stderr, "Unable to open serial device: %s\n", strerror (errno)) ;
      return 1 ;
      }
      if (wiringPiSetup () == -1)                   /* initializes wiringPi setup */
      {
      fprintf (stdout, "Unable to start wiringPi: %s\n", strerror (errno)) ;
      return 1 ;
      }
      while(1){   
      if(serialDataAvail (serial_port) )
      { 
      dat = serialGetchar (serial_port);      /* receive character serially*/ 
      printf ("%c", dat) ;
      fflush (stdout) ;
      serialPutchar(serial_port, dat);        /* transmit character serially on port */
        }
      }
      }

      编译测试

      gcc -o serialtest -lwiringPi serialtest.c 
      ./serialtest

      结果:

wiringPi updated to 2.52 for the Raspberry Pi 4B

前言

不知道你卖树莓派4B了么?不知道你们是否尝试在树莓派4b上用wiringpi的库,反正是官方的不好用。
那么你该怎么办?

场景展示

  • 如果你用sudo apt -y install wiringpi, 然后执行gpio readall的时候,提示你OPPS, the libararies is fucked.
    那么你就赶紧卸载掉吧!

    sudo apt -y purge wiringpi
    hash -r 

    下载软件包并且安装

    cd /tmp
    wget https://project-downloads.drogon.net/wiringpi-latest.deb
    sudo dpkg -i wiringpi-latest.deb

    检查:

    gpio readall 
    gpio -v 

    正常显示

    补充一下,源码下载的官方站点有点儿不稳定,我下载下来放在我博客上了,有需要的直接下载我这里的deb包安装效果一样的。

    wiringpi-latest.deb.tar
    下载后上传树莓派,通过命令

    tar -xf wiringpi-latest.deb_.tar.gz
    dpkg -i wiringpi-latest.deb

用树莓派制作gif动画

1. 安装树莓派摄像头,得是官方的。

2.更新系统安装imagemagick软件包:

sudo apt-get -y install imagemagick

 

然后;

raspistill -w 800 -h 600 -t 10000 -tl 2000 -o image%02d.jpg
convert -delay 10 -loop 0 image*.jpg animateMe.gif

默认情况下,相机拍摄的分辨率为3280×2464像素,分辨率为72 ppi(p ixels p er inch )。这非常大,因此图像处理时间会更长。在Raspistill中,可以通过说明宽度和高度来调整图像的大小。

  • -w -h 用于将图像大小调整为800 x 600像素
  • -t 表示整个过程花费的总时间(以毫秒为单位)
  • -tl  拍照的频率
  • -o 输出文件名
  • image%02d.jpg自动为带有图像的照片命名,并在右侧为生成的计数器添加两个空格例如:

    • image00.jpg
    • image01.jpg
    • image02.jpg

如果您觉得可拍摄超过99张照片,则可以创建3个甚至4个空格,这样您就可以使用图像%03d.jpg图像%04d.jpg保存数千张图像

convert 是来自ImageMagick的命令。此行将所有已保存的jpeg带有图像前缀,并将它们转换为动画GIF,延迟(-delay)为10/100秒。

-loop 0 表示GIF将永远循环。

树莓派结合ADC做个光敏感应的灯

树莓派结合ADC做个光敏感应灯

前言

其实没有什么想法,就是想把ADC用熟练了,这些小案例都是自己杜撰的,实际上没有那么多场景需要用,但是最近真的用在了智能浇花设备上,土壤湿度采样的传感器是模拟的,所以,可以用ADC秀一波操作。

操作步骤

  • 步骤1:从https://www.raspberrypi.org/downloads/下载最新镜像,然后选择Raspbian。
  • 步骤2:烧录镜像然后启动树莓派。 
  • 步骤3:通过在终端中键入以下命令连接到Internet并更新系统:
    sudo apt-get update
    sudo apt-get upgrade
  • 步骤4:将所有东西连接在一起然后打开你的树莓派,不知道为啥网上给树莓派起名字叫覆盆子,太tm难听了。raspberry就改成树莓不行么?

    手绘电路图,看懂了就过,看不懂就自己学习一下再过。

    接驳示意图,ADC的AIN1 通道采样。中间抽头给树莓派,采集信号信息。

    C语言编程

    下面的内容就是开始编程了,如果你喜欢用C,那么就这样,写个源码:

    #include <stdio.h>
    #include <stdlib.h>
    #include <linux/i2c-dev.h>
    #include <sys/ioctl.h>
    #include <fcntl.h>
    #include <wiringPi.h>
    void main()
    {
    wiringPiSetup(); 
    //Physical Pin = 40, name is GPIO.29 and wPi name is 29, BCM 21.
    pinMode(29, OUTPUT);   
    int file; 
    char *bus = "/dev/i2c-1";
    if ((file = open(bus, O_RDWR)) < 0) 
    {
     printf("Failed to open the bus.\n");
     exit(1);
     } 
    // Get I2C device, ADS1115 I2C address is 0x48(72)
    ioctl(file, I2C_SLAVE, 0x48) 
    // Select configuration register(0x01)
    // AINP = AIN0 and AINN = AIN1, +/- 2.048V 
    // Continuous conversion mode, 128 SPS(0x84, 0x83) 
    char config[3] = {0}; 
    config[0] = 0x01; 
    config[1] = 0xD4; 
    config[2] = 0x83; 
    write(file, config, 3); 
    sleep(1); 
    // Read 2 bytes of data from register(0x00) 
    // raw_adc msb, raw_adc lsb 
    char reg[1] = {0x00};
    write(file, reg, 1); 
    char data[2]={0};
    if(read(file, data, 2) != 2) 
    { 
    printf("Error : Input/Output Error\n");
    }
    else
    { 
    // Convert the data 
    int raw_adc = (data[0] * 256 + data[1]);
    if (raw_adc > 32767) 
    { 
      raw_adc -= 65535; 
    }
    // Output data to screen 
    printf("Analog Data is: %d \n", raw_adc);
    if ( raw_adc > 3200 )
     { 
      printf("Turn on LED\n");
      digitalWrite(29, LOW); // turn on the LED 
      } 
    else { 
        printf("Turn off LED\n"); 
        digitalWrite(29, HIGH);  //turn off the LED
          }
     } 
    }

    编译和测试:

    gcc -o adc -lwiringPi adc.c 

    注意:

  • gcc是编译工具,-o表示定义输出文件名,-lwiringPi表示需要使用wiringPi的库来完成编译代码。
  • 编译后,将在工作目录中获得名为sensor的二进制文件,只需使用此命令执行它:
    while true
    do
    ./adc 
    done

Python编程

  • 如果你喜欢用python好吧,那么就更简单了。直接用adafruit的ads1x15的代码改改就能用。
    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    # Author: Jacky.Li
    # License: Public Domain
    import time
    import Adafruit_ADS1x15
    import os
    adc = Adafruit_ADS1x15.ADS1115()
    # Choose a gain of 1 for reading voltages from 0 to 4.09V.
    # Or pick a different gain to change the range of voltages that are read:
    # - 2/3 = +/-6.144V
    # - 1 = +/-4.096V
    # - 2 = +/-2.048V
    # - 4 = +/-1.024V
    # - 8 = +/-0.512V
    # - 16 = +/-0.256V
    # See table 3 in the ADS1015/ADS1115 datasheet for more info on gain.
    GAIN = 1
    print("Reading ADS1115 values, press Ctrl-C to quit...") 
    # Main loop. 
    while True:
    # Read all the ADC channel values in a list.
    values = [0]*4
    for i in range(4):
    # Read the specified ADC channel using the previously set gain value.
    values[i] = adc.read_adc(i, gain=GAIN) 
    # Note you can also pass in an optional data_rate parameter that controls 
    # the ADC conversion time (in samples/second). Each chip has a different 
    # set of allowed data rate values, see datasheet Table 9 config register 
    # DR bit values. 
    #values[i] = adc.read_adc(i, gain=GAIN, data_rate=128) 
    # Each value will be a 12 or 16 bit signed integer value depending on the   
    # ADC (ADS1015 = 12-bit, ADS1115 = 16-bit). 
    # Print the ADC values. 
    print(values[1]) 
    # print analog data which detected via ADC AIN1 port.
    if values[1] < 3000: 
        os.system("gpio mode 29 out")
        os.system("gpio write 29 1") 
    else: 
        os.system("gpio mode 29 in") 
    os.system("gpio write 29 0") 
    time.sleep(0.25)</span>

    运行看看效果

    python sensor.py

    嗯,就这样吧,开开脑洞就可以玩儿得更愉快。。哈哈, 白了个白~

树莓派ADC采样光敏电阻来做智能家居控制雏形

又是ADC,还是ADS1115的模块,16bit采样率,很适合做模拟采样。接驳方式:

然后,刻录最新的raspbian镜像,可以从官方下载:https://www.raspberrypi.org/downloads/ 并将TF卡插回Raspberry Pi并打开电源。

请记住打开ssh服务并将你的Pi连接到互联网,以便我们可以下载并安装必要的软件包。

  • 打开终端编辑一个文件:
vim.tiny adc.c
  • 然后用下面的代码:
#include <stdio.h> 
#include <stdlib.h>
#include <linux/i2c-dev.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <unistd.h>

void main() 
{
// Create I2C bus
int file;
char *bus = "/dev/i2c-1";

 if ((file = open(bus, O_RDWR)) < 0)
 {
  printf("Failed to open the bus.\n");
  exit(1);
 }
// Get I2C device, ADS1115 I2C address is 0x48(72)
 ioctl(file, I2C_SLAVE, 0x48);
// Select configuration register(0x01)
// AINP = AIN1 and AINN = GND, +/- 2.048V
// Continuous conversion mode, 128 SPS(0x84, 0x83)
  char config[3] = {0};
  config[0] = 0x01;
  config[1] = 0xD4;
  config[2] = 0x83;
  write(file, config, 3);
  sleep(1);
  // Read 2 bytes of data from register(0x00)
  // raw_adc msb, raw_adc lsb
  char reg[1] = {0x00};
  write(file, reg, 1);
  char data[2]={0};
  if(read(file, data, 2) != 2)
   {
    printf("Error : Input/Output Error\n");
    }
    else
    {
    // Convert the data
    int raw_adc = (data[0] * 256 + data[1]);
    if (raw_adc > 32767)
    {
     raw_adc -= 65535;
     }
     // Output data to screen
     printf("Data: %d\n", raw_adc);
     }
} 

* 保存退出后编译:
 ```bash
gcc -o adc adc.c  -O3  
./adc
  • 执行后可以读取一次,用shell脚本简单调用一下,间隔0.2秒刷新,看看数据状态。
  • 然后简单写个脚本检测抓拍并上传到我的博客后台的服务器,当然了,现在已经关闭了,怕不法分子看到乱上传东西,就这么个意思吧,你们理解了操作步骤就好。然后把光敏电阻放在门夹缝的位置上,如果你没有回家,你家人没有回家,但是光敏电阻值发生了变化, 你就会收到一份邮件,拍到一个尝试盗窃的贼? 或者是一个不明飞行物?
    有兴趣就试试看吧,白了个白~

树莓派通过ADC采样音量大小触发告警提示

有一个问题困扰我,当我制作视频时,如果被噪音干扰会导致失败,失败就得重新录,非常痛苦。

我想,如果有一个设备可以帮助我避免这个问题就好了,手里一堆很早以前买的树莓派,一堆。真的是一堆。

所以突然想到用ADC模块用语音传感器模块进行语音采样,然后通过调整阈值来显示文字或语音提示,让大家保持安静。 


首先,您需要这些组件来构建它。

1. Raspberry Pi 3B 或者3B+

2. 8GB Class 10 TF卡 

3. 5v / 2.5A电源 

4. 4CH 16位ADC For RPi (52pi.taobao.com有售)

5.面包板 没有就焊接~

6.语音传感器(模拟) 淘宝上几块钱可以买一堆。

7.大屏幕(电视机) 

8.跳线

步骤1:

下载最新Raspbian的镜像并将其刻录在TF卡上,建议用etcher这个工具,各种平台上都有它的安装包。

步骤2: 接线,语音采样的模块很便宜,所以基本上没有什么芯片在上面帮我做转换,但是我看到了比较器芯片,我这里不要数字信号,因为只有0和1的信号我无法判断音量的大小。

所以我选择了模块的模拟引脚,A0。 

然后因为AIN0 上面接了NTC,所以避开了AIN0 ,直接接在了AIN1 通道上面,就是黄色的线缆,然后供电用的是树莓派的3.3v, GND接树莓派。一切都很自然就搞定了。

当然为了方便展示我开专门插了一个0.91英寸的OLED,虽然这个项目里面没有用到。但是真的很好用,芯片就是ssd1306. 简单粗暴的很~

就像这样连接起来,上面有两个跳线帽,记得要接,一个是I2C地址的跳线帽,就是0x48的哪个, 还有一个是NTC接到AIN0通道的跳线帽,如果接通就可以通过NTC读取模拟的温度值了,实际上并不是温度,而是电压,要通过电压来进行换算的,后面再说这问题。

第3步:

将Raspberry Pi连接到互联网并更新软件,并安装名为“figlet”的软件, 当噪音等级的数量达到一个值的时候,它将被调出并显示“请TM安静!”,当然是显示在你的屏幕上,我觉得可以扩展的东西很多,可以加个超级功放, 然后搞个大功率的喇叭,提前录好声音,猛猛的一嗓子,直接让闹腾的家伙瞬间安静下来。

 

然后编写一个代码来采用adc:

编译一下:  

gcc -o adc adc.c

sudo cp adc  /bin/adc   为了方便使用,我就没有去修改PATH变量的内容,直接将编译出来的工具放在/bin下面了,方便我调用。

然后写个shell脚本,开机自动加载也比较方便。

vim.tiny  notify.sh

保存退出后,给文件执行权,然后测试一下。

chmod +x notify.sh

./notify.sh

对着麦克风来一嗓子,屏幕上应该是这样:

你还可以搞点儿别的什么,反正能够采集声音了,就达到了让树莓派采集ADC的消息的功能,非常方便弄别的项目,你可以自己看看,开开脑洞。

白了个白~

 

 

树莓派串口设置

最近总有人遇到树莓派串口通信的问题, 这里我简单说明一下。

Raspberry Pi和串口

默认情况下,Raspberry Pi的串行端口配置为用于控制台输入/输出。虽然如果您想使用串行端口登录,这虽然在调试时候很有用,但这意味着您无法在程序中使用串行端口。为了能够使用串行端口连接并与其他设备(例如Arduino)通信,需要禁用串行端口控制台登录。

不用说,您需要一些其他方式来登录Raspberry Pi,我们建议使用SSH链接通过网络上执行此操作

禁用串行端口登录

要启用自己使用的串行端口,需要禁用端口上的登录。有两个文件需要编辑

第一个和主要的是 /etc/inittab

此文件具有启用登录提示的命令,需要禁用此命令。编辑文件并移至文件末尾。你会看到类似的一行

T0:23:respawn:/ sbin / getty -L ttyAMA0 115200 vt100

通过在开头添加#字符来禁用它。保存文件。

#T0:23:respawn:/ sbin / getty -L ttyAMA0 115200 vt100

禁用启动信息

当Raspberry Pi启动时,所有启动信息都将发送到串行端口。禁用此启动信息是可选的,您可能希望保持启用状态,因为有时查看启动时发生的情况很有用。如果您在启动时连接了设备(即Arduino),它将通过串行端口接收此信息,因此由您决定是否存在此问题。

您可以通过编辑文件/boot /cmdline.txt 来禁用它。

该文件的内容如下所示

dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait

删除对ttyAMA0的所有引用(这是串行端口的名称)。该文件现在看起来像这样

dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait

重启

为了启用您所做的更改,您需要重新启动Raspberry Pi

sudo shutdown -r now 或者sudo init 6

测试串口

测试串口的一个好方法是使用minicom程序。如果您没有安装此运行

sudo apt-get install minicom

使用适当的串行端口适配器和接线将PC连接到Raspberry Pi串口,然后在PC端打开Putty或类似的串行终端程序。使用9600波特的串行端口设置连接。

现在使用Raspberry Pi运行minicom

minicom -b 9600 -o -D /dev/ttyAMA0

输入minicom终端屏幕的内容应出现在串行PC终端上,反之亦然。

下面想接串口GPS就接上去使用好啦~

如果想用python去读取GPS信号,通过:

pip install pyserial 

然后编写文档:

import serial 

import time

 

ser = serial.Serial('/dev/ttyAMA0',  115200, timeout=2)

try:

    while True:

        if ser.is_open:

            data = ser.read(100)

            print(data)

except Exception as e:

    print(e)

当看到数据了再分析一下就好,时间不多了,我就简单说到这里。

白了个白~

树莓派Nintendo专用退出游戏按钮

小时候玩儿任天堂的游戏的时候,如果想退出游戏,直接按reset键就出来了,可以重新选择,可是我现在用的是retropie模拟任天堂,那么问题来了,如果要映射热键去跳出游戏,默认官方已经设置了select+start的热键是针对LR系列的模拟器,如果是LR系列的模拟器,这样一起按就可以退出游戏回到es界面,但是对于其他的模拟器:如DOSBox、Mupen64plus、DGen、PPSSPP、MAME4ALL、AdvanceMAME等其他非LR系列的模拟器,就不适用于RetroArch的的热键了,这时候要回到ES系統首页,就非常麻烦,所以就可以做一款通过硬件的reset回到ES首页的功能。

硬件需求:

-------------------

1 x  非自锁开关1个

杜邦线若干

树莓派 2B/3B/3B+/3A+/zero /zero w 均可

1x 16GB class 10 SD卡

1x HDMI 线

1x 5v/2.5A电源

---------------------

然后,烧录好retropie系统,并且联网更新,打开ssh, 基本配置搞定了再来接下来的操作。

利用了GPIO的37 pin和39pin ,分别代表 GPIO26和GND

然后软件配置更简单:

1. ssh远程连接到树莓派。

2. 建立一个目录

sudo mkdir  scripts

cd scripts/

sudo touch ExitEmu.py

3. 编辑这个文件然后填写:

from time import sleep 

import os

import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM) # 使用BCM的命名方式

GPIO.setup(26, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

 

def  exitEmulator(channel):

    print('exitEmulator')

   os.system('killall retroarch')

    pids = [pid for pid in os.listdir('/proc') if  pid.isdigit() ]

    for pid in pids:

        try:

            commandpath = open(os.path.join('/proc', pid, 'cmdline'), 'rb').read()

             if commandpath[0:24] == '/opt/retropie/emulators/':

                 os.system('kill -QUIT %s'  %  pid)

                 print('kill -QUIT  %s'  %  pid) 

        except  IOError:

            continue

GPIO.add_event_detect(26, GPIO.RISING, callback=exitEmulator, bouncetime=500)

while True:

    sleep(10)

保存退出后直接执行测试一下:

sudo python ExitEmu.py

然后按下按钮,如果看到屏幕上出现: exitEmulator 及 retroarch两行字符串代表指令成功了。

接下来让它能够开机自动启动就好了。

直接编辑:/etc/rc.local,添加刚才的脚本。

sudo vim.tiny /etc/rc.local 

在exit 0之前填写:

sudo python  /home/pi/scripts/ExitEmu.py &   

然后保存退出后重启你的树莓派,就可以尝试使用你的按键了。是不是感觉非常方便呢?

 

参考:

*  https://forum.recalbox.com/topic/3504/emulator-exit-button-gpio/10

* https://www.element14.com/community/docs/DOC-78055/l/adding-a-shutdown-button-to-the-raspberry-pi-b

* https://learn.adafruit.com/retro-gaming-with-raspberry-pi/adding-controls-software?view=all

* https://www.reddit.com/r/raspberry_pi/comments/2yw4fn/finally_set_up_retropie_complete_with_a_gpio/

* http://raspberrypi.stackexchange.com/questions/40311/how-can-i-add-an-on-off-switch-to-my-raspberry-pi-2