-
• #2
In my opinion console is for entering commands and logging errors, data like this can better go directly to the right Serial object while the real console is switched away - that would give you clean output without any surprises.
see also http://www.espruino.com/Reference#Serial - methods print,println,write
USB port serial is
USB
object, notSerial1
and you don't need to setup speed forUSB
-
• #3
USB object is an instance of Serial
https://www.espruino.com/Reference#l__global_USBThere is no exemple! to initiate the USB
have you one?
should i use this?
E.on('init', function() { USB.setConsole(); });
Or
USB.setConsole(true);
?regards
é.
-
• #4
there is no need to initialize
USB
, just attach device to computer and it should be automatically enabled. And the idea I mentioned was to actually switch console away fromUSB
so better something likeSerial1.setConsole()
orLoopbackA.setConsole()
Of course after running this you cannot connect over USB via Espruino IDE, this is for final state when the project runs as designed. However you can make this conditional on something (button or some other pin high/low). Also I think when you hold button while inserting pico to USB it may avoid starting your code at all so that can be the way to connect IDE and change stuff
-
• #5
I had a switchto switch on/off setConsole on USB or on an other Serial
I useprint
nonconsole.log
i've tried this
let laser; function lis(){ let somme=0; var dist = laser.performSingleMeasurement().distance; print(dist); //console.log(dist); //console.log("distance: ",dist," lissée:",somme/table.length); analogWrite(LED1, (1000-dist)/1000, { soft:true, freq:200 }); } function onInit() { //Serial1.setup(115200); I2C2.setup({sda:B3,scl:B10}); laser = require("VL53L1X").connect(I2C2); print("init"); digitalWrite(B4,1); // set XSDN -> turn the sensor on setInterval(lis, 150); pinMode(A6, 'input_pulldown'); setWatch( function (e) { console.log(e.state); if (e.state) { Serial1.setConsole(); } else { USB.setConsole(true); } }, A6, { repeat:true, edge:"both", debounce: 100 }); }
if i move the console to another Serial...
nothing come in Processing
otherwise my output is always crippy> [J1587
1587
is my number:v
Any idea
-
• #6
print is basically same as console.log both write to console
https://www.espruino.com/Reference#l__global_print
try stuff mentioned in post #2 -
• #7
should i use console.log or print
These write to the console, but they also have to add extra chars to remove the
>
prompt, add a newline, print what you want and then put>
back after.If you want to write direct, use
USB.println(...)
and you'll avoid all the extra stuff getting written
I know this certainly a stupid question.
i'm prototyping something for my students
i use a V53L1X connected to my pico.
i would like to transfer the datas to Processing.
i connect the Pico on the usb plug.
should i use
console.log
orprint
to transmit my data?
should i initialize a serial port?
Serial1.setup(115200);
some time the console send error from the program (i2c init);
i'm really confuse, it should be simple, but it's not.
sometime nothing arrive to Processing.
i've got an other problem, the string received start with an invisible char and
[J
How should i do to have a clean string with distance value?
Could i use midi thru usb to send datas?
i should split my value [0-4000] in 2 set of 7bits (midi value)
thanks for your help
éric
and the processing sketch