Arduino code
Code: Select all
#include <SoftwareSerial.h>
#define px A0
#define py A1
float x;
float y;
String pos;
SoftwareSerial BT(10, 11);
void setup() {
pinMode(px,INPUT);
pinMode(py,INPUT);
Serial.begin(9600);
BT.begin(9600);
}
void loop() {
x=analogRead(px);
y=analogRead(py);
Serial.print(x);
Serial.print(" , ");
Serial.println(y);
pos=String(x)+","+String(y);
BT.println(pos);
}
Code: Select all
local cadena="a"--this get BT.println(pos)
function love.load()
end
function love.update(dt)
end
function love.draw()
love.graphics.print(cadena,100,100)
end
Code: Select all
local rs232 = require "luars232"
function love.load()
local p, e = rs232.port('COM6',{
baud = '_9600';
data_bits = '_8';
parity = 'NONE';
stop_bits = '_1';
flow_control = 'OFF';
rts = 'ON';
})
p:open()
print(p:write('AT\r\n'))
print(p:read(64, 5000))
p:close()
end
PD2: Error with 'luars232 expected, got userdata''
Code: Select all
local rs232 = require "luars232"
function love.load( )
port_name = "COM6"
local out = io.stderr
-- open port
local e, p = rs232.open(port_name)
if e ~= rs232.RS232_ERR_NOERROR then
-- handle error
out:write(string.format("can't open serial port '%s', error: '%s'\n",
port_name, rs232.error_tostring(e)))
return
end
-- set port settings
assert(p:set_baud_rate(rs232.RS232_BAUD_115200) == rs232.RS232_ERR_NOERROR)
assert(p:set_data_bits(rs232.RS232_DATA_8) == rs232.RS232_ERR_NOERROR)
assert(p:set_parity(rs232.RS232_PARITY_NONE) == rs232.RS232_ERR_NOERROR)
assert(p:set_stop_bits(rs232.RS232_STOP_1) == rs232.RS232_ERR_NOERROR)
assert(p:set_flow_control(rs232.RS232_FLOW_OFF) == rs232.RS232_ERR_NOERROR)
out:write(string.format("OK, port open with values '%s'\n", tostring(p)))
-- read with timeout
local read_len = 20 -- read one byte
local timeout = 100 -- in miliseconds
for i=1,10000,1 do
local err, data_read, size = p:read(read_len, timeout)
print(data_read)
end
assert(e == rs232.RS232_ERR_NOERROR)
-- close
assert(p:close() == rs232.RS232_ERR_NOERROR)
end