Hi - Serial is a built-in object, so by setting it to Serial1 you're probably causing yourself a lot of trouble. Try the following:
var serial=Serial1
USB.setConsole(true);
serial.setup(9600);
serial.on('data', function (data) {
console.log(data);
if (data==='1'){
LED1.write(1);
serial.print("test\n");
}
if (data==='0'){
LED1.write(0);
}
if (data==='d'){
LED2.write(1);
serial.print("sensor: t="+temp_act+", p="+press_act+", h="+hum_act);
LED2.write(0);
}
});
Using Serial2.setConsole should work, but I'd set Serial2 up first or it'll use the default pins. Personally I'd use USB.setConsole(true) (as above) because then the console is still available on USB for updating code.
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Hi -
Serial
is a built-in object, so by setting it toSerial1
you're probably causing yourself a lot of trouble. Try the following:Using
Serial2.setConsole
should work, but I'd setSerial2
up first or it'll use the default pins. Personally I'd useUSB.setConsole(true)
(as above) because then the console is still available on USB for updating code.