Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

183
Views
No puedo enviar datos a través de serialPort

Me gustaría controlar mi robot Arduino con Node.js y un joystick, pero serialport.write no envía ningún dato a Arduino. He intentado usar código sin joystick y funciona pero solo con un serial.write .

¿Hay un error en mi código?

codigo arduino:

 String data = Serial.readString(); Serial.println(data); if(data=="2") { //motor1 }

Nodo.js

 var hid = require('node-hid'); var SerialPort = require("serialport").SerialPort var serialPort = new SerialPort('COM3', { baudrate: 9600 }); serialPort.on("open", function() { console.log('open'); function sentData(data) { console.log(data); if (data == 0) setTimeout(function() { serialPort.write('1') }, 2000); else if (data > 999) setTimeout(function() { serialPort.write('2') }, 2000); } var device = new hid.HID(1133, 49685); device.on('data', function(buf) { var ch = buf.toString('hex').match(/.{1,2}/g).map(function(c) { return parseInt(c, 16); }); var position = ((ch[2] & 0x0f) << 6) + ((ch[1] & 0xfc) >> 2); position = parseInt(position);sentData(position); }); });
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

El código de arduino debería verse así:

 String data = ''; while(Serial.available() > 0) { data = data + Serial.read(); } Serial.println(data); if(data == "2") { //code }

Pero, lo siento, no puedo ver si hay un problema en tu node.js

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!