Coder Social home page Coder Social logo

raspberrypimouse's Introduction

RaspberryPiMouse

CI

This repository has the source code and kernel objects for the Raspberry Pi Mouse.

Installation

Run the installation script (./utils/build_install.bash).

インストール用のシェルスクリプト(./utils/build_install.bash)を実行します。

for Raspbian

$ git clone https://github.com/rt-net/RaspberryPiMouse.git
$ cd RaspberryPiMouse/utils
$ sudo apt install raspberrypi-kernel-headers build-essential
$ ./build_install.bash

for Ubuntu

$ git clone https://github.com/rt-net/RaspberryPiMouse.git
$ cd RaspberryPiMouse/utils
$ sudo apt install linux-headers-$(uname -r) build-essential
$ ./build_install.bash

Manual installation

$ git clone https://github.com/rt-net/RaspberryPiMouse.git
$ cd RaspberryPiMouse/src/drivers
$ make
$ sudo insmod rtmouse.ko

Notes for the installation (ドライバの導入の際の注意)

for Raspbian

Enable SPI and I2C functions via raspi-config command.

以下の設定を確認ください。 raspi-config コマンドで設定します。

  • SPI機能を「入」にする。
  • I2C機能を「入」にする。

2017年1月現在、以下の設定は不要です。
rtmouseをインストールして不具合が出た場合のみ以下の設定を追加で行ってください。

  • Device Tree機能を「切」にする。

for Raspberry Pi 4

Edit rtmouse.c to change the defined value RASPBERRYPI from '2' to '4'.

Raspberry Pi 4ではCPUのレジスタがそれまでのRaspberry Piとは異なります(issues#21)。
Raspberry Pi 4で本ドライバを使用する際にはrtmouse.cの以下の行(2020年4月13日現在の最新版のv2.1.0では54行目)をRASPBERRYPI 4に書き換えて手動でビルドする必要があります。

// define the Raspberry Pi version here
// Raspberry Pi 1 B/A/B+/A+: 1
// Raspberry Pi 2 B        : 2
// Raspberry Pi 3 B/A+/B+  : 2
// Raspberry Pi 4 B        : 4
#define RASPBERRYPI 2

パルスカウンタについて

パルスカウンタは値の読み取りにI2Cを使用しています。仕様上は400kHzまでbaudrateを上げることができます(※1)。
I2Cのbaudrateを上げると通信に失敗する場合がある(issues#13)ので、基本的にはI2Cのbaudrateはデフォルト値(※2)から変更して62.5kHzに固定してください。

According to issues#13, it may be necessary to set the I2C baudrate lower than the default value. Add a following new line in /boot/firmware/config.txt to change the i2c_baudrate to 62.5 kHz.

/boot/firmware/config.txtに以下の1行を追加することでI2Cのbaudrateを62.5kHzに固定することができます。

dtparam=i2c_baudrate=62500

※1 Raspberry Pi 4 Model B(Ubuntu 18.04とUbuntu 20.04)を搭載して400kHzで通信できることを確認しています。
※2 現在設定されているI2Cのbaudrateは以下のコマンドを実行することで確認できます。

$ printf "%d\n" 0x$(xxd -ps /sys/class/i2c-adapter/i2c-1/of_node/clock-frequency)

Device files

For example code of device files, please refer to SampleProgram.

デバイスファイルの使用例はサンプルプログラムを参考にしてください。

Light sensor x4 (Input)

Read /dev/rtlightsensor0 to get proximity (0:far ~ 4095:close) of objects detected by light sensors.

/dev/rtlightsensor0を読み取り、光センサで検出された物体の近接度 (0:遠い ~ 4095:近い)を取得します。

# cat /dev/rtlightsensor0
# Return value: [front right] [right] [left] [front left]
$ cat /dev/rtlightsensor0
9 2 13 3

Switch x3 (Input)

Read /dev/rtswitch0 ~ /dev/rtswitch2 to get the switches on/off state.

/dev/rtswitch0 ~ /dev/rtswitch2 を読み取りスイッチのON/OFF状態を取得します。

# cat /dev/rtswitch[0,1]
# Return value: 1(Open), 0(Pressed)
$ cat /dev/rtswitch0

Buzzer (Output)

Write 0 ~ 20000 to /dev/rtbuzzer0 to beep the buzzer.

/dev/rtbuzzer0 に0 ~ 20000を書き込みブザーを鳴らします。

# echo 0 ~ 20000(Hz) > /dev/rtbuzzer0
$ echo 440 > /dev/rtbuzzer0
$ echo 0 > /dev/rtbuzzer0

LED x4 (Output)

Write 1/0 to /dev/rtled0 ~ /dev/rtled3 to turn on/off the LEDs.

/dev/rtled0 ~ /dev/rtled3 に1/0を書き込みLEDを点灯/消灯します。

# echo 0(OFF) or 1(ON) > /dev/rtled[0,1,2,3]
$ echo 1 > /dev/rtled0
$ echo 0 > /dev/rtled1

Motor enable (Output)

Write 1/0 to /dev/rtmotoren0 to enable/disable motors control.

/dev/rtmotoren0 に 1/0 を書き込みモータ操作を有効/無効にします。

# echo 0(disable) or 1(enable) > /dev/rtmotoren0
$ echo 1 > /dev/rtmotoren0

PWM frequency for left/right motor driver (Output)

Write 0 ~ 10000 to /dev/rtmotor_raw_l0 or /dev/rtmotor_raw_r0 to set PWM frequency for motor drivers.

/dev/rtmotor_raw_l0 または /dev/rtmotor_raw_r0 に 0 ~ 10000 を書き込み、モータドライバへのPWM周波数を設定します。

# echo 0 ~ 10000(Hz) > /dev/rtmotor_raw_[l0, r0]
$ echo 1 > /dev/rtmotoren0
$ echo 400 > /dev/rtmotor_raw_l0

PWM frequencies and drive duration (Output)

Write left and right PWM frequencies and drive duration to /dev/rtmotor0 to drive both motors.

/dev/rtmotor0に左右のPWM周波数と動作時間を書き込み、左右のモータを回します。

# echo [left_freq Hz] [right_freq Hz] [duration ms] > /dev/rtmotor0
$ echo 1 > /dev/rtmotoren0
$ echo 400 800 1000 > /dev/rtmotor0

Pulse counter x2 (Input/Output)

Read /dev/rtcounter_* to get pulse counts of PWM for motor drivers or write values to reset counts.

/dev/rtcounter_*を読み取りモータドライバへのPWMパルス数を取得します。また、値を書き込みカウントをリセットします。

  • unsigned counters : /dev/rtcounter_l0, /dev/rtcounter_r0
  • signed counters : /dev/rtcounter_l1, /dev/rtcounter_r1
# cat /dev/rtcounter_[l0, r0]
# Return value: 0 ~ 65565 (counts of PWM pulse)
# cat /dev/rtcounter_[l1, r1]
# Return value: -32767 ~ 32767 (counts of PWM pulse)
$ cat /dev/rtcounter_l0
1104
$ echo 0 > /dev/rtcounter_l0
$ cat /dev/rtcounter_l0
0

その他

その他のよくある質問についてはwikiにまとめています。

日経Linux連載

連載(Raspberry Piで始めるかんたんロボット製作)で上田氏が書いた シェルスクリプトは下記にあります。

https://github.com/ryuichiueda/RPiM

License

This repository except for SampleProgram directory is licensed under the GPL-2.0-only License, see LICENSE.

SampleProgram directory is licensed under the Apache 2.0 License, see SampleProgram / LICENSE.

このリポジトリはSampleProgramディレクトリを除きGPL-2.0-onlyライセンスで公開されています。詳細はLICENSEを確認してください。

SampleProgramディレクトリはApache-2.0ライセンスで公開されています。詳細はSampleProgram / LICENSEを確認してください。

Includings

This repository contains the code of the repository shown below.

このリポジトリは以下に示すリポジトリのコードを一部含みます。

raspberrypimouse's People

Contributors

rt-corp avatar ryuichiueda avatar tiryoh avatar shotaak avatar aoki-rt avatar atsushisaito avatar shu-13 avatar tabe avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.