micropython通过单总线控制Arduino

MicroPython相关代码、库、工具
回复
头像
shaoziyang
帖子: 1508
注册时间: 2019年 10月 21日 13:48

micropython通过单总线控制Arduino

#1

帖子 shaoziyang » 2019年 11月 26日 12:46

这是一个通过单总线协议,使用micropython设备控制Arduino设备的库,目前它可以支持下面几个命令:
  • pinMode
  • digitalWrite
  • digitalRead
  • analogWrite
  • analogRead
通信使用了crc校验,防止通信错误。

项目网站

demo

代码: 全选

from arduinoGPIO.arduinoControl import ArduinoControl
import machine
import time

arduinoControl = ArduinoControl(machine.Pin(19)) # 19: pin number of the 1-wire connection

roms=arduinoControl.scanSafely() # .scan() can be used too, this is just safer as it scans multiple times
available_digital_pins=arduinoControl.digitalPins(roms[0])
available_analog_pins=arduinoControl.analogPins(roms[0])
arduinoControl.digitalWrite(roms[0], 13, 1) # led on
time.sleep(2)
arduinoControl.digitalWrite(roms[0], 13, 0) # led off

代码: 全选

from arduinoGPIO.arduinoControl import ArduinoControl
from arduinoGPIO.arduino import Arduino
import machine
import time

arduinoControl = ArduinoControl(machine.Pin(19)) # 19: pin number of the 1-wire connection
roms=arduinoControl.scanSafely() # .scan() can be used too, this is just safer as it scans multiple times

arduino = Arduino(arduinoControl, roms[0])

adc=arduino.ADC(0,vcc=3.3) # Analog pin 0. optional argument vcc used for calculating voltages
print(adc.read())
print(adc.readVoltage())

led=arduinoControl.Pin(roms[0],13)
led.on()
time.sleep(1)
led.off()
Arduino

代码: 全选

#include "OneWireHub.h"
#include "Control.h"

constexpr uint8_t pin_led {13};
constexpr uint8_t pin_onewire {2};

auto hub = OneWireHub(pin_onewire);

#define UNIT_ID 0x03 //change this to be unique for every device in your 1-wire network

auto arduino = Control(Control::family_code, 0x00,0x00,0xB2,0x18,0xDA,UNIT_ID);
 

回复

  • 随机主题
    回复总数
    阅读次数
    最新文章