Interfacing via Lua

So. I want to communicate with my Arduino.

I have the Arduino IDE istalled 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 jups to full brightness. And if you type "0", the LED goes off!

This is what I wanted the recreate via Lua. I downloaded rs232 and then I tried to run the following:

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()[/code

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

I use Linux CentOS 7 and a Arduino UNO

Please Help

(deleted)

(deleted)

(deleted)

spycatcher2k:
And this is a LUA question, NOT an arduino one.

Yes. I'm fully aware of that. I also posted it on reddit and on Stackexchange. But I also wanted to post it here. It has after all to do with the Arduino!

P.S: What was the second ignored rule??

(deleted)

Okaghana:
Yes. I'm fully aware of that. I also posted it on reddit and on Stackexchange. But I also wanted to post it here. It has after all to do with the Arduino!

Some people come here to nurture a grievance and others come here to get help. :slight_smile: :slight_smile:

...R