2025年6月24日火曜日

FY25 Raspi 立ち上げ

 久しぶりのRPIの立ち上げになります。

  1. 標準的と思われるイメージで作りました。

  2. SDを入れて起動。
    画面を繋げました。
  3. Wifiを繋げて。
  4. 次は固定IP化
    1. デフォルトのWi-Fiの設定にはNetworkManagerというものを使うようにOS自体が変更になったようです。そのためIP固定の設定方法も大きく変わっていたとのことでした。
    2. ipaddressはifconfigで確認できる。
    3. デフォルトゲートウェイは routeで確認できる。
    4. DNSサーバーの情報が表示されます。また、cat /etc/resolv.conf
    5. 結局 GUIからマニュアル設定を実施。
  5. 日本語化 sudo apt-get install ibus-mozc
  6. Keyボードの日本語化
    1. 「ラズベリーアイコン>Preferences>Keyboard and Mouse>Keyboard」をクリックする。
    2. 以下のように設定する。
      1. Model:Generic 105-key PC (intl.)
      2. Layout:Japanese
      3. Variant:Japanese (OADG 109A)
  7. SSH IPアドレスを固定したら、問題なくつながった。
    インストールの時にSSH ONとしたかもしれない。

2025年6月3日火曜日

Python String

 なんか 雑多な事ばかりですが、、、

PicoはC言語、Windowsからの制御はPython頭がおかしくなる。。。

str_data = "Hello world"
str_data1 = "Hello world"
str_data2 = "abcde"

if(str_data1 == str_data2) :
    print("True")
else :
    print("Falese")

2025年6月1日日曜日

Rpi Pico なんとなくの再検討 PWM キー入力 LED点灯

 蛍とかキー入力とかなんとかこれで動いた。

Cのコード

#include "pico/stdlib.h"
#include "hardware/pwm.h"

int main() {
#ifndef PICO_DEFAULT_LED_PIN
#warning blink example requires a board with a regular LED
#else
    const uint LED_PIN = 22;
    const uint LED_PIN1 = 25;
    const uint input_PIN = 20;
    gpio_init(input_PIN);
    gpio_set_dir(input_PIN, GPIO_IN);
    gpio_init(LED_PIN);
    gpio_set_dir(LED_PIN, GPIO_OUT);
    gpio_set_function(LED_PIN, GPIO_FUNC_PWM);
    gpio_init(LED_PIN1);
    gpio_set_dir(LED_PIN1, GPIO_OUT);
    gpio_put(LED_PIN1, 1);
    uint slice_num = pwm_gpio_to_slice_num(22); //pin 22 slice No = 22
    /*例えばPWM周波数を1KHzに、PWMの分解能を8ビット(0~255)に設定したい場合、
    sysclock = 125,000,000Hz、wrap = 255、f=1000Hz より
    clkdiv = sysclock / ((wrap+1) ⋅ f )
    分周比 clkdiv = 488.2812 となる。*/
    pwm_set_clkdiv(slice_num, 488.2812);
    pwm_set_wrap(slice_num, 255);

    // チャンネルPWMのHigh期間を設定
    //pwm_set_chan_level(slice_num, 0, 5);
    //pwm_set_enabled(slice_num, true);

    int i=0;
    int flag=0;
    int flaga=0;

    while (true) {

    if(gpio_get(input_PIN) == 0)
     {
        gpio_put(LED_PIN1, 0);
        flaga=0;
        while(flaga<3){
    if(flag==0){
        i=i+1;
        if(i==256) flag=1;
        else ;    
    }
    else if(flag==1) {
        sleep_ms(500);
        flag=2;
    }  
    else if(flag==2) {
        i=i-1;
        if(i==0) flag=3;
        else ;
    }
    else
    {
        sleep_ms(1000);
        flag=0;
        i=0;
        flaga=flaga+1;
     
        }

    pwm_set_chan_level(slice_num, 0, i);
    pwm_set_enabled(slice_num, true);
    sleep_ms(10);
    //pwm_set_enabled(slice_num, false);
   
    }
      gpio_put(LED_PIN1, 1);
    }

else;
#endif
}

}

Makeがこちら

# Generated Cmake Pico project file

cmake_minimum_required(VERSION 3.13)

set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# Initialise pico_sdk from installed location
# (note this can come from environment, CMake cache etc)



# == DO NOT EDIT THE FOLLOWING LINES for the Raspberry Pi Pico VS Code Extension to work ==
if(WIN32)
    set(USERHOME $ENV{USERPROFILE})
else()
    set(USERHOME $ENV{HOME})
endif()
set(sdkVersion 2.1.1)
set(toolchainVersion 14_2_Rel1)
set(picotoolVersion 2.1.1)
set(picoVscode ${USERHOME}/.pico-sdk/cmake/pico-vscode.cmake)
if (EXISTS ${picoVscode})
    include(${picoVscode})
endif()
# ====================================================================================
set(PICO_BOARD pico CACHE STRING "Board type")

# Pull in Raspberry Pi Pico SDK (must be before project)
include(pico_sdk_import.cmake)

project(hotal2 C CXX ASM)

# Initialise the Raspberry Pi Pico SDK
pico_sdk_init()

# Add executable. Default name is the project name, version 0.1

add_executable(hotal2 hotal2.c )


pico_set_program_name(hotal2 "hotal2")
pico_set_program_version(hotal2 "0.1")

# Modify the below lines to enable/disable output over UART/USB
pico_enable_stdio_uart(hotal2 0)
pico_enable_stdio_usb(hotal2 0)




# Add the standard library to the build
target_link_libraries(hotal2
        pico_stdlib)


# Add the standard include files to the build
target_include_directories(hotal2 PRIVATE
        ${CMAKE_CURRENT_LIST_DIR}
)

# Pull in our pico_stdlib which pulls in commonly used features        
target_link_libraries(hotal2 pico_stdlib hardware_pwm)


pico_add_extra_outputs(hotal2)