SlideShare una empresa de Scribd logo
1 de 19
Descargar para leer sin conexión
パイプでバイブを動かそう
シェル芸 × Arduino
@grethlen
$ whoami
• HN —ぐれさん
• ぐれっぷが大好きだからです

見た目がグレてるからではない
• Twitter — @grethlen
• Notes
• ソフトウェアエンジニア
• 危険シェル芸戦犯者の一人
• 罰としてシェル芸本に

無断掲載されている
※「シェルプログラミング実用テクニック」82ページ
$ cd /home
• 家のドアを電子錠に改造
• 自宅 のSSHで

コマンド叩けば開閉
• スマホで開閉
$ echo 電子工作は楽しい | wall
• サーバばかりいじってる人にも

はんだごて握って欲しい
• 電子工作を食わず嫌いしてる人も多いはず

「興味あるけどこわい。」「むずそう。」
• 電子工作でもみんな大好きシェル芸が活かせます

→「シェル芸バイブ」を作ろう!
$ man シェル芸バイブ
• シェル芸で動作する次世代型ハードウェア
• シェル芸でパイプをつなげると

Arduinoとつながったバイブが動く!
• USB接続 + バスパワーで動作
• 結構簡単に作れる
• システム保守用途で活躍

アラートメールは古い!

時代はアラートバイブ!
• サーバーだけでなく

パートナーのメンテナンスにも(危険シェル芸)
$ man シェル芸バイブ
• バイブ起動
• バイブ停止
• 初心者でも半日∼一日かければできる
$ vib 1
$ vib 0
作り方
• 材料(一人分)
• PC (Linux or Mac)
• Arduino UNO × 1
• 1KΩくらいの抵抗器 × 1
• ちっちゃいトランジスタ× 1

(2SC1815GRを使用)
• よくあるバイブ × 1
• ブレッドボードに挿せる形のリード線数本
• ブレッドボード 

(代わりに基板 + はんだなら更にGood)
• PC以外全部で5000円くらい?
肩こりに効くピンクローター*1
秋葉原で30分で うよ
*1 http://www.amazon.co.jp/ARMS-07643-%E3%82%B9%E3%82%B1%E3%83%AB
%E3%83%88%E3%83%B3%E3%83%AD%E3%83%BC%E3%82%BF%E3%83%BC-
%E3%83%94%E3%83%B3%E3%82%AF/dp/B00LEA3FIY/
回路図
とてもシンプルです。こわくないです。
※バイブのコントローラーは

ちょん切る
Arduino側のコード
• 0を受信したらLow — (0V)
• 1を受信したらHigh — (5V)
• コピペでOKです
たった17行です。
こわくないです。ソースはココ:

https://gist.github.com/greymd/78a4c6dbf35611e84220
PCからArduinoに命令を送る
• 本来ならば……
1. 専用のIDEを使う?
• 他のツールとの連携が面倒
2. Cとかでコードをガリガリ書く?
• 細かいことできるけど結構面倒
• 通信用バッファの操作とか色々
PCからArduinoに命令を送る
• 面倒なことはやめてscreenコマンド使って簡単にシリアル通信!
1. ArduinoをUSBに挿す
2. Macでは「/dev/tty.usbmodem1421」こんなデバイスが出現

(Linuxでは「/dev/ttyACM(数字)」)
3. screenでこのデバイスを読むと

よしなにシリアル通信してくれる。
• screenのセッションで 0 or 1キー を打つ

→バイブが動く
$	
  screen	
  /dev/tty.usbmodem1421	
  9600
PCからArduinoに命令を送る
• USB接続→下記のコマンドを実行することで

screenをバックグラウンドでアタッチ状態にできる

もっとスマートなやり方あるみたいだけど上手く行かなかった……
• 既存のscreenセッションにデータを送信する
• 0を送る
• 1を送る

$	
  nohup	
  screen	
  -­‐S	
  arduino	
  /dev/tty.usbmodem1421	
  9600	
  &
$ screen -S arduino -X stuff 0
$ screen -S arduino -X stuff 1
念願のバイブコマンドが完成!
#!/bin/bash	
  
screen	
  -­‐S	
  arduino	
  -­‐X	
  stuff	
  $1
$	
  vib	
  1
$	
  vib	
  0
/usr/local/bin/vib
バイブ起動
バイブ停止
シェル芸による応用例(1)
• 遠隔に居る

パートナーのバイブを

動かす(危険シェル芸)
• 念には念の運用改善 

バッチ落ちたらバイブ
• cronで目覚まし
$	
  ssh	
  root@partner.com	
  ‘vib	
  1’
$	
  command	
  ...	
  ||	
  vib	
  1
0	
  8	
  *	
  *	
  *	
  vib	
  1
シェル芸による応用例(2)
$	
  while	
  true	
  ;	
  do	
  vib	
  1	
  &&	
  sleep	
  0.5	
  &&	
  	
  
vib	
  0	
  &&	
  sleep	
  0.5	
  ;	
  done
そこそこ激しく
$ while	
  true	
  ;	
  do	
  vib	
  1	
  &&	
  sleep	
  0.1	
  &&	
  	
  
vib	
  0	
  &&	
  sleep	
  0.1	
  ;	
  done
弱モード
パワー調整に可変抵抗なんて必要ないぞ!
シェル芸による応用例(3)
• おまかせモード(みだれる数)
$	
  cat	
  /dev/urandom	
  |	
  tr	
  -­‐dc	
  '01'	
  |	
  fold	
  -­‐w	
  1	
  |	
  xargs	
  -­‐n	
  1	
  vib
※MacではGNU版 tr (gtr)を使って下さい
素数の神秘
1. どんなに数が大きくても、

素数が極端な偏りなく分布する確率が
常に存在する
• http://www.47news.jp/CN/201402/
CN2014022601001180.html
2. ラウムの螺旋(右図)
• https://ja.wikipedia.org/wiki/
%E3%82%A6%E3%83%A9%E3%8
3%A0%E3%81%AE%E8%9E%BA
%E6%97%8B
• 身体で感じよう!
• 素数を渦巻き状にプロットすると

模様が出現する
シェル芸による応用例(4)
• 素数の神秘を身体で感じる
$	
  yes	
  |	
  awk	
  '$0=NR'	
  |	
  factor	
  |	
  
awk	
  'NF!=2{print	
  0}	
  NF==2{print	
  1}'	
  |	
  xargs	
  -­‐n	
  1	
  vib
• #シェル芸 ハッシュタグ付きで

資料をTweetするので試してみてください><
おわり

Más contenido relacionado

Último

研究紹介スライド: オフライン強化学習に基づくロボティックスワームの制御器の設計
研究紹介スライド: オフライン強化学習に基づくロボティックスワームの制御器の設計研究紹介スライド: オフライン強化学習に基づくロボティックスワームの制御器の設計
研究紹介スライド: オフライン強化学習に基づくロボティックスワームの制御器の設計
atsushi061452
 

Último (16)

5/22 第23回 Customer系エンジニア座談会のスライド 公開用 西口瑛一
5/22 第23回 Customer系エンジニア座談会のスライド 公開用 西口瑛一5/22 第23回 Customer系エンジニア座談会のスライド 公開用 西口瑛一
5/22 第23回 Customer系エンジニア座談会のスライド 公開用 西口瑛一
 
情報を表現するときのポイント
情報を表現するときのポイント情報を表現するときのポイント
情報を表現するときのポイント
 
Hyperledger Fabricコミュニティ活動体験& Hyperledger Fabric最新状況ご紹介
Hyperledger Fabricコミュニティ活動体験& Hyperledger Fabric最新状況ご紹介Hyperledger Fabricコミュニティ活動体験& Hyperledger Fabric最新状況ご紹介
Hyperledger Fabricコミュニティ活動体験& Hyperledger Fabric最新状況ご紹介
 
部内勉強会(IT用語ざっくり学習) 実施日:2024年5月17日(金) 対象者:営業部社員
部内勉強会(IT用語ざっくり学習) 実施日:2024年5月17日(金) 対象者:営業部社員部内勉強会(IT用語ざっくり学習) 実施日:2024年5月17日(金) 対象者:営業部社員
部内勉強会(IT用語ざっくり学習) 実施日:2024年5月17日(金) 対象者:営業部社員
 
ネットワーク可視化 振る舞い検知(NDR)ご紹介_キンドリル202405.pdf
ネットワーク可視化 振る舞い検知(NDR)ご紹介_キンドリル202405.pdfネットワーク可視化 振る舞い検知(NDR)ご紹介_キンドリル202405.pdf
ネットワーク可視化 振る舞い検知(NDR)ご紹介_キンドリル202405.pdf
 
研究紹介スライド: オフライン強化学習に基づくロボティックスワームの制御器の設計
研究紹介スライド: オフライン強化学習に基づくロボティックスワームの制御器の設計研究紹介スライド: オフライン強化学習に基づくロボティックスワームの制御器の設計
研究紹介スライド: オフライン強化学習に基づくロボティックスワームの制御器の設計
 
ロボットマニピュレーションの作業・動作計画 / rosjp_planning_for_robotic_manipulation_20240521
ロボットマニピュレーションの作業・動作計画 / rosjp_planning_for_robotic_manipulation_20240521ロボットマニピュレーションの作業・動作計画 / rosjp_planning_for_robotic_manipulation_20240521
ロボットマニピュレーションの作業・動作計画 / rosjp_planning_for_robotic_manipulation_20240521
 
2024年5月17日 先駆的科学計算フォーラム2024 機械学習を用いた新たなゲーム体験の創出の応用
2024年5月17日 先駆的科学計算フォーラム2024 機械学習を用いた新たなゲーム体験の創出の応用2024年5月17日 先駆的科学計算フォーラム2024 機械学習を用いた新たなゲーム体験の創出の応用
2024年5月17日 先駆的科学計算フォーラム2024 機械学習を用いた新たなゲーム体験の創出の応用
 
論文紹介:ViTPose: Simple Vision Transformer Baselines for Human Pose Estimation
論文紹介:ViTPose: Simple Vision Transformer Baselines for Human Pose Estimation論文紹介:ViTPose: Simple Vision Transformer Baselines for Human Pose Estimation
論文紹介:ViTPose: Simple Vision Transformer Baselines for Human Pose Estimation
 
20240523_IoTLT_vol111_kitazaki_v1___.pdf
20240523_IoTLT_vol111_kitazaki_v1___.pdf20240523_IoTLT_vol111_kitazaki_v1___.pdf
20240523_IoTLT_vol111_kitazaki_v1___.pdf
 
Intranet Development v1.0 (TSG LIVE! 12 LT )
Intranet Development v1.0 (TSG LIVE! 12 LT )Intranet Development v1.0 (TSG LIVE! 12 LT )
Intranet Development v1.0 (TSG LIVE! 12 LT )
 
クラウド時代におけるSREとUPWARDの取組ーUPWARD株式会社 CTO門畑
クラウド時代におけるSREとUPWARDの取組ーUPWARD株式会社 CTO門畑クラウド時代におけるSREとUPWARDの取組ーUPWARD株式会社 CTO門畑
クラウド時代におけるSREとUPWARDの取組ーUPWARD株式会社 CTO門畑
 
LoRaWAN無位置ロープ型水漏れセンサー WL03A-LB/LSカタログ ファイル
LoRaWAN無位置ロープ型水漏れセンサー WL03A-LB/LSカタログ ファイルLoRaWAN無位置ロープ型水漏れセンサー WL03A-LB/LSカタログ ファイル
LoRaWAN無位置ロープ型水漏れセンサー WL03A-LB/LSカタログ ファイル
 
Keywordmap overview material/CINC.co.ltd
Keywordmap overview material/CINC.co.ltdKeywordmap overview material/CINC.co.ltd
Keywordmap overview material/CINC.co.ltd
 
Amazon Cognitoで実装するパスキー (Security-JAWS【第33回】 勉強会)
Amazon Cognitoで実装するパスキー (Security-JAWS【第33回】 勉強会)Amazon Cognitoで実装するパスキー (Security-JAWS【第33回】 勉強会)
Amazon Cognitoで実装するパスキー (Security-JAWS【第33回】 勉強会)
 
MPAなWebフレームワーク、Astroの紹介 (その1) 2024/05/17の勉強会で発表されたものです。
MPAなWebフレームワーク、Astroの紹介 (その1) 2024/05/17の勉強会で発表されたものです。MPAなWebフレームワーク、Astroの紹介 (その1) 2024/05/17の勉強会で発表されたものです。
MPAなWebフレームワーク、Astroの紹介 (その1) 2024/05/17の勉強会で発表されたものです。
 

Destacado

Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

Destacado (20)

AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 

パイプでバイブを動かそう シェル芸 × Arduino