Arduino通过Lua接口

时间:2017-12-17 19:02:42

标签: linux lua arduino arduino-uno interfacing

我想和我的Arduino沟通。我安装了Arduino IDE,如果我使用它,一切都很好。这是我的草图:

const int ledPin = 11; // the pin that the LED is attached to

void setup() {
  // initialize the serial communication:
  Serial.begin(9600);
  // initialize the ledPin as an output:
  pinMode(ledPin, OUTPUT);
}

void loop() {
  byte brightness;
  // check if data has been sent from the computer:
  if (Serial.available()) {
    // read the most recent byte (which will be from 0 to 255):
    brightness = (Serial.read()-48)*28;
    // set the brightness of the LED:
    analogWrite(ledPin, brightness);
    Serial.println(brightness);
  }
}

如果我现在启动串行监视器并输入“9”,我会返回252并且LED跳到全亮度。如果输入“0”,LED熄灭!

这就是我想在Lua中重新创建的内容。我下载了rs232,然后我写了这个脚本:

local rs232 = require "rs232"

local e, p = rs232.open('/dev/ttyACM0',{
  baud         = '_9600';
  data_bits    = '_8';
  parity       = 'NONE';
  stop_bits    = '_1';
  flow_control = 'OFF';
  rts          = 'ON';
})

input=io.read()
p:write(input)
print(p:read(1))
p:close()

但没有任何反应。即使没有p.read()部分。

请帮忙。

PS:我的系统是Linux CentOS 7,主板是Uno

0 个答案:

没有答案
相关问题