I'm trying to communicate with my Arduiono UNO via USB serial port, more precisely I'm trying to read a string like 125,0, I know it's full of article out there about this, but belive me I've tryied more or less everything, now I got a NODEJS server on a Raspberry Pi that looks like:
var express = require('express');
app = express();
server = require('http').createServer(app);
io = require('socket.io').listen(server);
var SerialPort = require("serialport")
var serialPort = new SerialPort("/dev/ttyACM1", { baudrate: 115200 });
server.listen(8080);
app.use(express.static('public'));
var brightness1 = 0;
var brightness2 = 0;
var string;
io.sockets.on('connection', function (socket) {
socket.on('led', function (data) {
brightness1 = data.value1;
brightness2 = data.value2;
string = brightness1 +","+brightness2;
var buf = new Buffer(1);
buf.write(string);
serialPort.write(buf);
console.log(buf);
console.log(string);
io.sockets.emit('led', {value1: brightness1, value2: brightness2});
});
So based on that, I'm sending a string over the serial and the console log showed above gives me that:
<Buffer 32> //console.log(buf);
23,0 //console.log(string);
Wich I think it should be ok because I'm sending what I need a 32 and a 0, also if i don't know what it means the
Arduino side I used the sketch provided here and retouch it a bit based on my needs:
void setup()
{
Serial.begin(115200);
}
void loop()
{
while(!Serial.available()); //wait until a byte was received
Serial.println(Serial.read());
int a = Serial.parseInt();
int b = Serial.parseInt();
Serial.println(a);
Serial.println(b);
//analogWrite(3, a);
}
but the result of my Serial.print() are really incongruents, something like: 5--2224, which is totally nosense, my question so is WHY? Where I'm getting wrong? I read a lot around, am I missing something?
<Buffer 32>
.