とりあえず生、やってみた。(PNA)

電子工作を中心とした、日々の出来事。

Raspberry Piの作業手順(インストール)

2021-09-03 14:40:13 | Raspberry Pi
久々にラズパイを触ったので忘却録として書きます。

------------- ラズパイにOSとNode-Redを新規インストールをする方法
高速なmicroSD(v30規格など)又は
高速なUSBメモリ(書き込み速度最大80MBなど)を購入する。
間違えても速度をうたっていない遅いものは買わない。
(最初遅いUSBを買ったため起動に7分もかかった。)

------------- インストール作業手順
windows又はmacパソコンで
1.Raspberry Pi imager
https://www.raspberrypi.org/software/
又は
Disk FORMATTER(管理者権限)で32GB以上でもFAT32でフォーマットする。(win)
https://www.buffalo.jp/support/download/detail/?dl_contents_id=60879
又は
本体のディスクユーティリティで32GB以上でもFAT32でフォーマットする。(mac)

2.Raspberry Pi imagerを使ってインストールする。

3.マイクロSDやUSBメモリをラズパイに入れて起動する。

4.設定ーRasperry Pi の設定ーローカライゼーションの順に行って、
  ローカル、タイムゾーン、キーボード、無線LANの国を設定する。

------------- 日本語のインストール -----------------------
ターミナルから
sudo apt update
sudo apt upgrade
sudo apt-get install fcitx-mozc -y
im-config -n fcitx
sudo reboot
又は
sudo apt install ibus-mozc
sudo reboot

------------- VNCサーバーの設定 -----------------------
左上のラズパイマークからー設定ーRasperry Pi の設定ーインターフェイス
SSHとVNCを有効にする。

右上のVNCマークを開きIPを確認する。

------------- ファイル共有Sambaのインストール -----------------------
ターミナルから
sudo apt update
sudo apt upgrade
sudo apt install samba

pi@raspberrypi ~ $ sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.bak
pi@raspberrypi ~ $ sudo nano /etc/samba/smb.conf

ファイルの変更内容について

参考サイト
https://tool-lab.com/raspberrypi-startup-14/

以下 抜粋

まず、最初の方に [global] ブロックがありますので、ここに文字コードを以下のように追加記入します。
--
変更前:

[global]

変更後:

[global]
unix charset = UTF-8
dos charset = CP932

#======================= Share Definitions =======================

というところがあります。このブロックで以下の3か所の変更をします。

まず1つ目です。これはファイルの書き込みを許可するように変更する設定です。
--
変更前:

# By default, the home directories are exported read-only. Change the
# next parameter to 'no' if you want to be able to write to them.
read only = yes

変更後:

# By default, the home directories are exported read-only. Change the
# next parameter to 'no' if you want to be able to write to them.
read only = no

2つ目はファイルのパーミッションを緩くする設定です。
--
変更前:

# File creation mask is set to 0700 for security reasons. If you want to
# create files with group=rw permissions, set next parameter to 0775.
create mask = 0700

変更後:

# File creation mask is set to 0700 for security reasons. If you want to
# create files with group=rw permissions, set next parameter to 0775.
create mask = 0664
--
変更前:

# Directory creation mask is set to 0700 for security reasons. If you want to
# create dirs. with group=rw permissions, set next parameter to 0775.
directory mask = 0700

変更後:

# Directory creation mask is set to 0700 for security reasons. If you want to
# create dirs. with group=rw permissions, set next parameter to 0775.
directory mask = 0775

これで設定が終わりましたので、control + Oで保存、Control + Xでnanoを終了します。

以上抜粋
-----------------------------------------------------------
・書き換えたファイル内容です。下記内容をコピペでOK 2021/09/03

ここから
#
# Sample configuration file for the Samba suite for Debian GNU/Linux.
#
#
# This is the main Samba configuration file. You should read the
# smb.conf(5) manual page in order to understand the options listed
# here. Samba has a huge number of configurable options most of which
# are not shown in this example
#
# Some options that are often worth tuning have been included as
# commented-out examples in this file.
# - When such options are commented with ";", the proposed setting
# differs from the default Samba behaviour
# - When commented with "#", the proposed setting is the default
# behaviour of Samba but the option is considered important
# enough to be mentioned here
#
# NOTE: Whenever you modify this file you should run the command
# "testparm" to check that you have not made any basic syntactic
# errors.

#======================= Global Settings =======================

[global]
unix charset = UTF-8
dos charset = CP932

## Browsing/Identification ###

# Change this to the workgroup/NT-domain name your Samba server will part of
workgroup = WORKGROUP

#### Networking ####

# The specific set of interfaces / networks to bind to
# This can be either the interface name or an IP address/netmask;
# interface names are normally preferred
; interfaces = 127.0.0.0/8 eth0

# Only bind to the named interfaces and/or networks; you must use the
# 'interfaces' option above to use this.
# It is recommended that you enable this feature if your Samba machine is
# not protected by a firewall or is a firewall itself. However, this
# option cannot handle dynamic or non-broadcast interfaces correctly.
; bind interfaces only = yes



#### Debugging/Accounting ####

# This tells Samba to use a separate log file for each machine
# that connects
log file = /var/log/samba/log.%m

# Cap the size of the individual log files (in KiB).
max log size = 1000

# We want Samba to only log to /var/log/samba/log.{smbd,nmbd}.
# Append syslog@1 if you want important messages to be sent to syslog too.
logging = file

# Do something sensible when Samba crashes: mail the admin a backtrace
panic action = /usr/share/samba/panic-action %d


####### Authentication #######

# Server role. Defines in which mode Samba will operate. Possible
# values are "standalone server", "member server", "classic primary
# domain controller", "classic backup domain controller", "active
# directory domain controller".
#
# Most people will want "standalone server" or "member server".
# Running as "active directory domain controller" will require first
# running "samba-tool domain provision" to wipe databases and create a
# new domain.
server role = standalone server

obey pam restrictions = yes

# This boolean parameter controls whether Samba attempts to sync the Unix
# password with the SMB password when the encrypted SMB password in the
# passdb is changed.
unix password sync = yes

# For Unix password sync to work on a Debian GNU/Linux system, the following
# parameters must be set (thanks to Ian Kahan < for
# sending the correct chat script for the passwd program in Debian Sarge).
passwd program = /usr/bin/passwd %u
passwd chat = *Enter\snew\s*\spassword:* %n\n *Retype\snew\s*\spassword:* %n\n *password\supdated\ssuccessfully* .

# This boolean controls whether PAM will be used for password changes
# when requested by an SMB client instead of the program listed in
# 'passwd program'. The default is 'no'.
pam password change = yes

# This option controls how unsuccessful authentication attempts are mapped
# to anonymous connections
map to guest = bad user

########## Domains ###########

#
# The following settings only takes effect if 'server role = primary
# classic domain controller', 'server role = backup domain controller'
# or 'domain logons' is set
#

# It specifies the location of the user's
# profile directory from the client point of view) The following
# required a [profiles] share to be setup on the samba server (see
# below)
; logon path = \\%N\profiles\%U
# Another common choice is storing the profile in the user's home directory
# (this is Samba's default)
# logon path = \\%N\%U\profile

# The following setting only takes effect if 'domain logons' is set
# It specifies the location of a user's home directory (from the client
# point of view)
; logon drive = H:
# logon home = \\%N\%U

# The following setting only takes effect if 'domain logons' is set
# It specifies the script to run during logon. The script must be stored
# in the [netlogon] share
# NOTE: Must be store in 'DOS' file format convention
; logon script = logon.cmd

# This allows Unix users to be created on the domain controller via the SAMR
# RPC pipe. The example command creates a user account with a disabled Unix
# password; please adapt to your needs
; add user script = /usr/sbin/adduser --quiet --disabled-password --gecos "" %u

# This allows machine accounts to be created on the domain controller via the
# SAMR RPC pipe.
# The following assumes a "machines" group exists on the system
; add machine script = /usr/sbin/useradd -g machines -c "%u machine account" -d /var/lib/samba -s /bin/false %u

# This allows Unix groups to be created on the domain controller via the SAMR
# RPC pipe.
; add group script = /usr/sbin/addgroup --force-badname %g

############ Misc ############

# Using the following line enables you to customise your configuration
# on a per machine basis. The %m gets replaced with the netbios name
# of the machine that is connecting
; include = /home/samba/etc/smb.conf.%m

# Some defaults for winbind (make sure you're not using the ranges
# for something else.)
; idmap config * : backend = tdb
; idmap config * : range = 3000-7999
; idmap config YOURDOMAINHERE : backend = tdb
; idmap config YOURDOMAINHERE : range = 100000-999999
; template shell = /bin/bash

# Setup usershare options to enable non-root users to share folders
# with the net usershare command.

# Maximum number of usershare. 0 means that usershare is disabled.
# usershare max shares = 100

# Allow users who've been granted usershare privileges to create
# public shares, not just authenticated ones
usershare allow guests = yes

#======================= Share Definitions =======================

[homes]
comment = Home Directories
browseable = no

# By default, the home directories are exported read-only. Change the
# next parameter to 'no' if you want to be able to write to them.
read only = no

# File creation mask is set to 0700 for security reasons. If you want to
# create files with group=rw permissions, set next parameter to 0775.
create mask = 0664

# Directory creation mask is set to 0700 for security reasons. If you want to
# create dirs. with group=rw permissions, set next parameter to 0775.
directory mask = 0775

# By default, \\server\username shares can be connected to by anyone
# with access to the samba server.
# The following parameter makes sure that only "username" can connect
# to \\server\username
# This might need tweaking when using external authentication schemes
valid users = %S

# Un-comment the following and create the netlogon directory for Domain Logons
# (you need to configure Samba to act as a domain controller too.)
;[netlogon]
; comment = Network Logon Service
; path = /home/samba/netlogon
; guest ok = yes
; read only = yes

# Un-comment the following and create the profiles directory to store
# users profiles (see the "logon path" option above)
# (you need to configure Samba to act as a domain controller too.)
# The path below should be writable by all users so that their
# profile directory may be created the first time they log on
;[profiles]
; comment = Users profiles
; path = /home/samba/profiles
; guest ok = no
; browseable = no
; create mask = 0600
; directory mask = 0700

[printers]
comment = All Printers
browseable = no
path = /var/spool/samba
printable = yes
guest ok = no
read only = yes
create mask = 0700

# Windows clients look for this share name as a source of downloadable
# printer drivers
[print$]
comment = Printer Drivers
path = /var/lib/samba/printers
browseable = yes
read only = yes
guest ok = no
# Uncomment to allow remote administration of Windows print drivers.
# You may need to replace 'lpadmin' with the name of the group your
# admin users are members of.
# Please note that you also need to set appropriate Unix permissions
# to the drivers directory for these users to have write rights in it
; write list = root, @lpadmin

ここまで
------------- sambaのユーザー登録 -----------------------
ユーザー登録を行うため
ターミナルから
sudo smbpasswd -a pi

下記のように表示されるのでパスワードを入れる。

New SMB password: [ここでパスワードを入力]
Retype new SMB password: [もう一度パスワードを入力]
Added user pi.

------------- mplayerのインストール -----------------------
sudo apt-get install -y mplayer

mplayer [フルパス]

で再生できるはずですが、鳴らない時
パルスオーディオの削除と出力先設定
ターミナルから
sudo apt-get remove pulseaudio

sudo raspi-config
起動したら
systemOptionからS2 Audio

それでもダメな時

ご参考
https://takuya-1st.hatenablog.jp/entry/2016/04/18/011246

ターミナルから
mplayer -vo null -ao alsa:device=plughw=1.0 test.mp4
と打てば
test.mp4が再生される。
test.mp4の所をフルパスで書けばどこのファイルでも再生できる。
node-redで鳴らない時はこの指定で鳴った。

pulseaudioを使う時は
ご参考
https://raspida.com/rpios-verup20201202

------------- mpg123 mpg 321のインストール -----------------------
ターミナルから
sudo apt-get install mpg123
sudo apt-get install mpg321

------------- 注意 -----------------------
mpg 321はmp3再生時に音がおかしくなった事があった。
vlcはコマンドラインからアクセスする時はcvlcを使う。

------------- node-redのインストール -----------------------
bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered)

node-redの自動起動設定

sudo systemctl enable nodered.service


アクセス方法
(ノードレッドと同じラズパイの時)
http://localhost:1880

(ノードレッドと違うパソコンの時)
http://(ラズパイのIPアドレス):1880

ファイルの保存位置は(不可視で)/home/pi/.node-red
--------------CPUの温度と周波数のアプレットの表示方法 ------------------
CPUの温度と周波数のアプレットの表示方法

一番上のバーで右クリックしてパネル設定を選ぶ
パネルアプレットから
CpuFreq フロントエンド
Cpu Temperature Monitor
を追加

----------------- シェルスクリプトの実行権付与 ---------------------------
chmod +x (フルパス+ファイル名).sh

----------------- 出来上がったメディアのバックアップ ---------------------------
左上のラズパイマークからアクセサリ ー SD Card Copierと選択
上(from)が書き込み元 で 下(to)が書き込み先



忘却録としてまとめて書いたけどほんまに動くのか心配w。

LED電球の改造

2021-08-03 14:47:42 | 電子工作
イオンで購入した100V用のLED電球が点滅を始めましたので、分解して12V仕様に改造しました。
LEDは3灯入りのLEDが6並列に並んでいて、さらに8段の直列になっていました。
消費電力の表示が12.8wだったので消費電流は128mA位なのでしょう。
6並列なので20mA程度がLEDに流れていると考えました。
LM317Tで120mAの定電流回路を組み、ダイナミック点灯で8ユニットを順番に点灯させました。
元々の電力の1/8になって暗くなってしまったので、仕様書が無いので定格は超えるかもしれませんが、
電流を約400mAにして点灯させました。
だいぶ明るくなったので、天井に取り付ける予定です。
写真は明るすぎたので電圧を落として暗くしてあります。

Raspberry piにsmbとnode-redを入れた時のLink

2020-10-01 14:17:28 | Raspberry Pi
—————————————————————————————————————
Raspberry Pi向けに64GB以上のmicroSDをFAT32にフォーマットする@windows7
https://qiita.com/Higemal/items/2034ef9f772416b4dbb7

Disk Formatter
https://www.buffalo.jp/support/download/detail/?dl_contents_id=60879#1

Raspberry Pi4のUSB(HDD)起動設定
https://qiita.com/eurogrve/items/4802d18321cfbe72157b

Raspberry Pi 4 の 64bit版と USB Boot
https://qiita.com/tkyonezu/items/6c2a4638e3b8aee390e2

SDカードからUSB接続ブートへ変更
https://www.miki-ie.com/raspberry-pi/raspberry-pi-3b-sd%E3%82%AB%E3%83%BC%E3%83%89%E3%83%96%E3%83%BC%E3%83%88%E3%81%8B%E3%82%89usb%E3%83%96%E3%83%BC%E3%83%88%E3%81%B8%E5%A4%89%E6%9B%B4/

Raspberry PiをUSB(HDD)だけで動かす(SD不要)
https://jyn.jp/raspberrypi-usb-only-boot/

Raspberry Pi4にOSをインストール(Raspberry Pi Imager編) ~その1~
http://yarufu101.hateblo.jp/entry/2020/03/11/012658

Raspberry Pi の HDMI 出力の設定
http://s-edword.hatenablog.com/entry/2018/01/09/000357

ラズベリーパイのCPUクロックと電圧をいじってみる
http://www.ezto.info/stpress/2017/05/976.html

【ラズパイ】Raspberry PiへFirefoxをインストールする方法
https://thenewsinpu.hatenablog.jp/entry/2018/06/04/222902

Raspberry Piの日本語入力メソッドは、fcitx-mozcで決まり!
https://www.fabshop.jp/raspberrypi-fcitx-mozc/

—————————————————————————————————————
Sambaファイルサーバーの構築
https://raspida.com/rpi-samba-build

第14回 Raspberry Piのファイルサーバ設定
https://tool-lab.com/raspberrypi-startup-14/

Raspberry Pi Zeroから自宅のNASにアクセスしてみよう
https://codezine.jp/article/detail/11183

—————————————————————————————————————
HTML5 の Web Audio API を使ってオーディオファイルを再生する
http://dotnsf.blog.jp/archives/1072420283.html

HTML5 のプラグインを使わずに音声を再生する
https://www.tagindex.com/html5/embed/audio.html

動画、ラジオ再生
https://books.google.co.jp/books?id=3BtxDgAAQBAJ&pg=PT98&lpg=PT98&dq=%E3%82%B3%E3%83%9E%E3%83%B3%E3%83%89%E3%83%A9%E3%82%A4%E3%83%B3%E3%80%80%E3%82%B9%E3%83%88%E3%83%AA%E3%83%BC%E3%83%9F%E3%83%B3%E3%82%B0%E9%85%8D%E4%BF%A1&source=bl&ots=p2UBpVsQEk&sig=ACfU3U3sXhHORu4pdjjvrszqjVh63uMg-A&hl=ja&sa=X&ved=2ahUKEwit0tCG7rzqAhWKd94KHf-gARMQ6AEwBXoECGMQAQ#v=onepage&q=%E3%82%B3%E3%83%9E%E3%83%B3%E3%83%89%E3%83%A9%E3%82%A4%E3%83%B3%E3%80%80%E3%82%B9%E3%83%88%E3%83%AA%E3%83%BC%E3%83%9F%E3%83%B3%E3%82%B0%E9%85%8D%E4%BF%A1&f=false

MPlayer
https://wiki.archlinux.jp/index.php/MPlayer

ラズパイ: VLCをコマンドで操作
https://qiita.com/mt08/items/b6aa433e66b0b58b5022

mpg123 - コマンド (プログラム) の説明 - Linux コマンド集 一覧表
https://kazmax.zpp.jp/cmd/m/mpg123.1.html

[Raspberry Pi] コマンドラインで音を鳴らす
https://raspi.ryo.sc/raspi_play_sound/

コマンドラインからyoutubeを再生する
https://qiita.com/yuki_ycino/items/594c27426c5580450bf2


デスクトップ環境なしでUbuntuにFirefoxをインストールすることは可能ですか?
https://qastack.jp/ubuntu/1150493/is-it-possible-to-install-firefox-on-ubuntu-with-no-desktop-enviroment

Ubuntu14:xvfbとfirefoxのインストール
https://web-dev.hatenablog.com/entry/linux/ubuntu/install-firefox-xvfb

リモート(SSH)からFirefoxをCUIで起動
https://okwave.jp/qa/q7459327.html

ターミナルを使用して現在のタブFirefoxを閉じる
https://www.it-swarm-ja.tech/ja/command-line/%e3%82%bf%e3%83%bc%e3%83%9f%e3%83%8a%e3%83%ab%e3%82%92%e4%bd%bf%e7%94%a8%e3%81%97%e3%81%a6%e7%8f%be%e5%9c%a8%e3%81%ae%e3%82%bf%e3%83%96firefox%e3%82%92%e9%96%89%e3%81%98%e3%82%8b/961501132/

【 ps 】コマンド――実行中のプロセスを一覧表示する
https://www.atmarkit.co.jp/ait/articles/1603/28/news022.html

【 kill 】コマンド/【 killall 】コマンド――実行中のプロセスを終了させる (2/2)
https://www.atmarkit.co.jp/ait/articles/1604/05/news022_2.html

RaspberryPiでよく使うLinuxコマンド集
https://jellyware.jp/kurage/raspi/linux_command.html

[Raspberry Pi] xdotool でマウスを自動操作
https://ameblo.jp/chlolucas746/entry-12601614412.html

[Raspberry Pi] xautomation でマウス、キーボード操作を自動化する
https://blog.withachristianwife.com/2018/12/04/sumulate-mouse-and-keyboard-with-xautomation/
——————————————————————————————————
音声合成
https://www.ai-j.jp/demonstration/
効果音>アナウンス音
https://otologic.jp/free/se/announce01.html
効果音フリー
http://www.music-style.info/music-style/html/002_007p3.html
——————————————————————————————————
Node-REDをインストールする
https://nodered.jp/docs/getting-started/raspberrypi

Raspberry Pi にNode-RED をインストールする
https://qiita.com/HeRo/items/432e4d28055571f1acfb

chmod? chown? よくわからんって人のための、ファイル権限系まとめ
https://qiita.com/t-a-run/items/239ed690ece7a011804a

Node-REDの起動とアクセス
https://sanuki-tech.net/micro-bit/raspberry-pi/start-node-red/

enebularでif分岐やwhileループのようなデータの流れを組むときのTIPS
https://blog.enebular.com/enebular/enebular-if-for-case/

Node-RED で if 分岐処理は意外と面倒?
http://dotnsf.blog.jp/archives/1070090259.html

node-redで論理演算(andやor)ができない
https://teratail.com/questions/130891

Node-REDでオリジナルノードを作ってみよう
https://tibbo-pi.co-works.co.jp/blog/node-red%E3%81%A7%E3%82%AA%E3%83%AA%E3%82%B8%E3%83%8A%E3%83%AB%E3%83%8E%E3%83%BC%E3%83%89%E3%82%92%E4%BD%9C%E3%81%A3%E3%81%A6%E3%81%BF%E3%82%88%E3%81%86/

Node-RED+python-shellでNode-REDからpythonを呼び出すノードを自作する
https://qiita.com/yasunari_matsuo/items/411affc9893211a9b523

Node-REDで時刻を画面表示するアプリを作ってみた
https://qiita.com/takana-at/items/339b748813da4dfd1a49

Raspberry PiとNode-redで、リビングに飾れる美しい「スマートホームコントローラ」を作ってみた
https://dream-soft.mydns.jp/blog/developper/smarthome/2020/05/1246/

Node-RED と Sonos で学校チャイムシステムを作ってみた。
https://qiita.com/kitazaki/items/928b132a71dc27a405ef

ラズパイゼロの準備とNode-REDとMQTTのお話し
https://bit-trade-one.co.jp/blog/201806301/

はじめての電気とIoT (7) MQTTで温度をやり取り
https://www.denshi.club/pc/raspi/iot7mttq.html

第13回「ラズベリーラジオ前編 – インターネットラジオ受信と遠隔操作」
https://deviceplus.jp/hobby/raspberrypi_entry_013/

Node-redだけで簡易Alexaアプリを作ってみる「アレクサ、雨雲きてる?」
https://dream-soft.mydns.jp/blog/developper/smarthome/2019/11/466/

IoTビジネスの現場で学んだNode-RED活用術
https://qiita.com/a-yoshino/items/0900a4fffc7caf0a0c02

Node-REDの作品例
https://uepon.hatenadiary.com/archive/category/Node-RED

【完成編】Raspberry Piで作ろう!手作りスマートミラー
https://www.indetail.co.jp/blog/11421/


ACパワーコントローラー電流計付き

2020-03-13 09:33:22 | 電子工作
久々のブログで思い出しながらやってます。
だいぶ前に半田ごてのパワーをコントロールするために作ったのですが、
最近温度調節機能付きの半田ごてを買ったので使わなくなりました。
そこで、今でも未熟ですが当時の部品配置、配線があまりにも汚かったのでやりかえついでにAC100V実験用電源として保護回路、電流計、電源のON、OFFとパワーを変えることのできる物に改造しました。
電圧も測定してやれば電力、力率なども表示出来たのですが、
キャラクター液晶にいっぱい表示させても見えにくいと思い、今回はこれでよしとします。
マイコンはATmega88 Arduinoでやってみました。
今まで、アセンブラでほとんど書いていたので、特に32bitの計算とか拍子抜けするほど簡単でした。
ただ、A/D変換周りの処理は遅いなぁと思いましたが、今回は我慢します。

マイコンの電源5Vととは別に、バックライト用の降圧回路、4.1Vを供給するために+ー電源から取っています。
後で、共通でも良かったと思いました。w
(いつもと逆ですが、右から左に電気が流れます。)
・回路図

・配線図

・電流センサーはこれを使用しました。

・差動増幅で受けて、2.5Vを加算してマイコンのA/Dで取り込み、中点からの値を積分して電流を出しています。
 ピークからルート2で割るとかではないので、精度的にちょっとマシかな。参考程度にしてます。


換気扇をつないでパワーコントロールして見ましたが、結構いい感じです。
電流もパワーに合わせて増減して満足しています。

おかえり検出器

2019-02-16 17:25:46 | 電子工作
大阪のイベントに出品したものです。(2018年)
発信器を持った人が電波の届く所まで近くに寄るとIDから誰が帰ってきたのかを音声で知らせる機械です。
また、リレーが動くので照明などをつけたりもできます。
子供のランドセルの中に発信器を入れているので、帰ってくる前に玄関を開ける事ができます。
実際に使っています。