-
Using hubSerial.available() - rather than hubSerial.data('on') - to chunk the input stream seems to make some difference (fewer errors) at 4800 baud. But no difference at 2400 (mostly good) or 9600 (bad transmission). See code below (both .available and .on('data') fragments are included:
var d0 = console.log; var debug = console.log; var hubSerial = new Serial(); var usbSerial = new Serial(); function onInit() { hubSerial.setup(4800, { // problematic when baud rate=9600 rx: NodeMCU.D5, tx: NodeMCU.D6 }); usbSerial.setup(9600, { rx: NodeMCU.D9, tx: NodeMCU.D10 }); usbSerial.on('data', function (data) { try { hubSerial.print(data); } catch (e) { d0("failed to send on hub's data"); } }); //* hubSerial.on('framing', function (data) { d0("framing error"); }); setInterval(() => { let n = hubSerial.available(); if (n > 0) { //d0(n); let d = hubSerial.read(0); usbSerial.print(d); } }, 200); //*/ /* hubSerial.on('data', function (data) { try { // d0(data.length); usbSerial.print(data); } catch (e) { d0("failed to send on usb's data"); } }); //*/ }
-
I am using two soft serials, taking input from one UART and passing it to the USB UART.
var hubSerial = new Serial(); hubSerial.setup(2400, { // problematic when baud rate=9600 rx: NodeMCU.D5, tx: NodeMCU.D6 }); var usbSerial = new Serial(); usbSerial.setup(9600, { rx: NodeMCU.D9, tx: NodeMCU.D10 }); usbSerial.on('data', function (data) { try { hubSerial.print(data); } catch (e) { d0("failed to send on hub's data"); } }); hubSerial.on('data', function (data) { try { usbSerial.print(data); } catch (e) { d0("failed to send on usb's data"); } });
d0() is essentially console.log over port 23.
The PIN assignment cannot be changed hence the use of soft serial. I think the issue is that .on('data',..) is coming back 1 or 2 bytes at a time. I will experiment using .available().
-
From http://www.espruino.com/USART
"As software serial doesn't use dedicated hardware there are some compromises:
Baud rates significantly above 9600 baud are unlikely to be reliable
Sending more than one or two characters will block execution of other JavaScript code until completion (hardware serial ports have a ~100 byte transmit buffer)
Software serial reception will become increasingly unreliable the higher the CPU load."In my application, I use soft serial (rx=D5, tx=D6). I get bursts of 60+ bytes (5x a second) from an external source. I find that anything beyond 2400 baud increases errors in the data received. What's the experience of others?
Using an Amica 8266 board.
-
-
-
Your first line (D25,D26) produces result but not (D26,D26)!
var cmds = { // main menu top left - select mainSelect: [ 9.0, 4.4, 0.6, 0.5, 0.6, 1.6, 0.6, 1.6, 0.6, 0.5, 0.6, 0.5, 0.6, 0.5, 0.6, 0.5, 0.6, 1.6, 0.6, 1.6, 0.6, 0.5, 0.6, 1.6, 0.6, 0.5, 0.6, 0.5, 0.6, 0.5, 0.6, 0.5, 0.6, 0.5, 0.6, 0.5, 0.6, 0.5, 0.6, 0.5, 0.6, 0.5, 0.6, 1.6, 0.6, 0.5, 0.6, 1.6, 0.6, 0.5, 0.6, 1.6, 0.6, 1.6, 0.6, 1.6, 0.6, 1.6, 0.6, 0.5, 0.6, 1.6, 0.6, 0.5, 0.6, 1.6, 0.6, 42.9, 9.0, 2.2, 0.6, 95.9, 9.0, 2.2, 0.6, 95.9, 9.0, 2.2, 0.6, 95.9, 9.0, 2.2, 0.6, 95.9, 9.0, 2.2, 0.6, 95.9, 9.0, 2.2, 0.6, 95.9, 9.0, 2.2, 0.6, 95.9, 9.0, 2.2, 0.6 ]}; /* received on the other end (D25,D26): 4.4,0.5,0.6,0.5,1.6,0.5,1.6,0.6,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.6,1.6,0.6,1.6,0.6,0.5,0.6,1.6,0.6,0.5,0.6,0.5,0.6,0.5,0.6,0.5,0.6,0.5,0.6,0.5,0.6,0.5,0.6,0.5,0.6,0.5,0.5,1.6,0.6,0.5,0.6,1.6,0.6,0.5,0.6,1.6,0.5,1.6,0.6,1.6,0.6,1.6,0.5,0.5,0.6,1.6,0.6,0.5,0.6,1.6,0.6,42.9,8.9,2.3,0.5,95.9,8.9,2.3,0.5,95.9,8.9,2.2,0.7,95.9,8.9,2.2,0.7,95.9,8.9,2.2,0.6,95.9,9.0,2.2,0.6,95.9,9.0,2.2,0.6,95.9,8.9,2.2 0.2 */
I guess I will use D25,26 for transmission.
A query: not sure why the first value is consistently missing (i.e. 9.0).
Am I in fact transmitting the inverse pattern or am I just not understanding the IR protocol? (The definition file was captured (transmitted from a physical remote) using the same Receiver code, i.e. (from you!)
function onInit() { digitalWrite(D2, 0); pinMode(D1, "input_pullup"); var d = []; setWatch(function (e) { d.push(1000 * (e.time - e.lastTime)); }, D1, { edge: "both", repeat: true }); var lastLen = 0; setInterval(function () { if (d.length && d.length == lastLen) { d.shift(); // remove first element console.log(d.map(a => a.toFixed(1)).toString()); d = []; } lastLen = d.length; }, 200); setInterval(() => LED3.toggle(), 500); }
-
Thanks - I am using v2.05 firmware (Sep 2019 vintage PuckJS). The onboard IR LED transmits in the ~940nm (same as mine) so it's odd that the same receiver does not see it.
I have now inverted the roles of the two PuckJS. Again the same phenomenon (second Puck sees the IR signal from my own LED but not Puck's). It is unlikely that the transmitter on both Pucks are faulty. But I don't have anything else to test them with. Any idea?
-
Hi @Gordon,
I am looking for the spec for the IR transmitter on the PuckJS. I have been able to use your demo code to transmit and receive IR signals using a pair of PuckJS and 940nm transmitter and https://www.vishay.com/docs/82491/tsop382.pdf receiver using the following code to test:
setWatch(() => { Puck.IR(cmds.mainSelect); // line 1 Puck.IR(cmds.mainSelect, D31, D30); // line 2 LED2.toggle(); }, BTN1, true);
Line 2 works as advertised.
When I use line 1 only, I cannot get any reading. I doubt the onboard transmitter is busted so it could be an incompatibility issue somewhere else?
-
-
I have made sure that other bluetooth devices are no connected to it.
I've reflashed the Puck with v2.05 using nRFTool. I also powered up while holding the button (until beyond the 5 red blinks).
On the desktop, I reset its bluetooth module so that it has no memories of prior pairings (I had to re-pair my keyboard and mousepad).
In this fresh start, the other Puck appears quickly in web IDE and is re-paired.
The web IDE still cannot seem to find this Puck during 're-scan'.
-
I have two puck.js, received a few months ago. I had paired both in IDE and everything worked. Then they went in the drawer somewhere.
I got them out today. Upgraded both to v2.05. One paired with the IDE and works well. The other does not seem to show up at all during BLE Select. I have hard reset it a few times. The self-test seems to pass. It seems functional, just does not connect/pair.
How do we forget a Puck that was paired before but does not now show up?
-
Thanks @Gordon!
I am curious about the relationship between Serial1 and console. I still have an issue about getting some leading chars from console.log http://forum.espruino.com/conversations/345448.
Also, with Serial1.on('data' ...) I will only get data from the USB port IF the IDE is connected to port 23.
Nothing comes out when the IDE is disconnected.
Yet when I send from 8266 by console.log(), the IDE needs to be off or the data are collected there rather than going to the USB. Using print() or Serial1.print() does not change things.
Please elucidate.
-
-
I would like to act on the output from the Espruino by listening to the Espruino's port on node-red.
I am getting 7 leading bytes for a one-byte payload ('1') i.e. (decimal) 62,13,27,91,74,21,16,49,13,10.
Same result for print("1") as for console.log("1").
Is this because the console is 'Telnet' (from process.env.CONSOLE)?
Is it possible to eliminate the leading chars?
Thanks.
-
-
This is JSON as parsed by node.js on a desktop:
{ week_number: 50, utc_offset: '-05:00', utc_datetime: '2019-12-15T18:10:33.811491+00:00', unixtime: 1576433433, timezone: 'America/Toronto', raw_offset: -18000, dst_until: null, dst_offset: 0, dst_from: null, dst: false, day_of_year: 349, day_of_week: 0, datetime: '2019-12-15T13:10:33.811491-05:00', client_ip: '174.114.161.151', abbreviation: 'EST' }
The actual text string comes from https://worldtimeapi.org/api/timezone/America/New_York
-
I use the following code on a desktop computer as well as on an ESP8266 (2v04).
function getTime() { require("http").get("http://worldtimeapi.org/api/timezone/America/Toronto", function (res) { res.on('data', function (data) { console.log(data); console.log(JSON.parse(data).datetime); }); res.on('close', function (data) { console.log("Connection closed"); }); }); } getTime();
node.js on the desktop could parse the output just fine :
<Buffer 7b 22 77 65 65 6b 5f 6e 75 6d 62 65 72 22 3a 35 30 2c 22 75 74 63 5f 6f 66 66 73 65 74 22 3a 22 2d 30 35 3a 30 30 22 2c 22 75 74 63 5f 64 61 74 65 74 ... > 2019-12-15T12:50:08.336992-05:00
ESP8266 shows the following:
-
-
-
Thanks - I am now running the Chrome app. When I try to connect, both "TCP/IP" and serial ports show up.
When I tried to connect to /dev/wcusbserial, I could see the Espruino respond but the "Select a port ..." panel does not go away.
(In the Console, it still shows No navigator.serial even though the IDE could see the serial ports now.)
I also tried unsuccessfully to connect over Wifi. The 'port' is available but the IDE cannot connect to it.
I have been able to use the standard module to get readings. I'm interested in exploring the true capabilities of the sensor.
Has anyone been able to change the speed/accuracy parameter on the VL53L0X lidar?
Any experience to share on its calibration? Variability between one unit and the next?