Arduino Interfacing via Lua

628 views Asked by At

I want to communicate with my Arduino. I have the Arduino IDE installed and if I use it, everything works perfectly fine. Here is my sketch:

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);
  }
}

If I start the Serial Monitor now and type in "9", I get back an 252 and the LED jumps to full brightness. And if you type "0", the LED goes off!

This is what I wanted to recreate in Lua. I downloaded rs232 and then I wrote this script:

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()

But nothing happens. Even without the p.read() part.

Please help.

PS: My system is Linux CentOS 7 and the board is a Uno

0

There are 0 answers