About Ardpy

연구/Ardpy 2016. 10. 23. 09:34

Ardpy : Arduino controlled by python


 The ardpy is a python and Arduino library that makes it easy to control Arduino board using python via i2c communication. This package contains Ardpy library for Arduino that automates i2c communication.


 If the Raspberry Pi is set to enable i2c and is wired to the Arduino through i2c pins (SCL/SDL), you can call the Arduino function using python method in ardpy package. The following figure illustrates how to wire Raspberry Pi and Arduino nano through voltage level converter. (refer setup page)


 For example, you can call the analogRead() function of the Adruino in the python shell as:


python3 shell in Raspberry Pi

Arduino program

>>> from ardpy import *

>>> ard = Ardpy(0x10) # 0x10 is i2c addr

>>> ard._set_byte(0)  # set port as A0

>>> ret = ard._exec_func(0) # call aread()

#include <Wire.h>

#include <Ardpy.h>


void aread() {

   byte pin = Ardpy.get_byte();

   int ret = analogRead(pin);

   Ardpy.set_ret(ret);

}


void setup() {

   Ardpy.add_func(aread);// func 0

   Ardpy.begin(0x10); // 0x10 is i2c addr

}


void loop() {

}


 As seen in this example, you can make your own arduino application board controllable by python very easily using Ardpy.


c{ardpy001}



'연구 > Ardpy' 카테고리의 다른 글

Ardpy API reference  (0) 2016.10.23
Ardpy examples  (0) 2016.10.23
Ardpy setup  (0) 2016.10.23
About Ardpy  (0) 2016.10.23
ardpy 개발 동기  (0) 2016.05.02
파이썬의 smbus 패키지를 이용하여 i2c 통신하기  (0) 2015.11.25
Posted by 살레시오

댓글을 달아 주세요