Code Monkey home page Code Monkey logo

koshian.py's Introduction

koshian.py (こしあんパイ)

これはなに

koshianをPCからArduinoのようにPythonから制御する ライブラリです。現時点では Linuxでしか動きません。Ubuntu14.04 で動作確認をしています。

インストール

koshian,pyのインストールの前に pygattlib を インストールしてください。インストール方法はリンク先を参照のこと。しかるのちに下記でインストールできます。

python ./setup.py install

ハードウェアの準備

konashi.jsアプリを使ってkoshianのファームをkonashi2.0にアップデートしておきます。

使用例

Lチカ

from koshian import *

class myKoshian(Koshian):
    def setup(self):    
        self.pinMode(PIO5, OUTPUT)
    def loop(self):
        self.digitalWrite(PIO5, HIGH)
        delay(1000)
        self.digitalWrite(PIO5, LOW)
        delay(1000)

k= myKoshian()
k.run()

サーボ

from koshian import *

class myKoshian(Koshian):
    def setup(self):    
        self.s=Servo(self)
        self.s.attach(PIO2)
    def loop(self):
        self.s.write(30)
        delay(1000)
        self.s.write(90)
        delay(1000)

k= myKoshian()
k.run()

自動検出とMACアドレス指定

引数を付けずに呼び出すとkoshianを自動検出します。

from koshian import *
k= Koshian()

ただし、自動検出にはsudoでスクリプトを実行する必要があります。

MACアドレスを直接指定する場合は下記のようにします。

from koshian import *
mac = "00:00:00:00:00:00"
k= Koshian(mac)

MAC アドレスは下記のコマンドでスキャンできます。

sudo hcitool lescan

もしhcitoolが見つからなければ、blueZをインストールしてください。

非Arduino風コーディング

from koshian import *
k= Koshian()
k.pinMode(PIO5,OUTPUT)
k.digitalWrite(PIO5,HIGH)
from koshian import *
k= Koshian()
s= Servo(k)
s.attach(PIO2)
s.write(30)

こちらのほうがself地獄にならなくてスッキリするかもしれません。

I2Cの例

I2Cはまだデバッグ中です。。

UARTの例

UARTはまだデバッグ中です。。

License

koshian.py is licensed under MIT License.

koshian.py's People

Contributors

ashitani avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

gandarla

koshian.py's Issues

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.