• 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 or print
    to transmit my data?

    should i initialize a serial port?

    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


    let laser;
    function lis(){
      let somme=0;
      var dist = laser.performSingleMeasurement().distanc­e;
      //console.log("distance: ",dist," lissée:",somme/table.length);
      analogWrite(LED1, (300-dist)/300, { soft:true, freq:200 });
    function onInit() {
      laser = require("VL53L1X").connect(I2C2);
      digitalWrite(B4,1); // set XSDN -> turn the sensor on
      setInterval(lis, 80);

    and the processing sketch

    import processing.serial.*;
    Serial myPort;  // Create object from Serial class
    int val;      // Data received from the serial port
    void setup() 
      size(200, 200);
      // le port de l'espruino sur mon mac est en 3
      String portName = Serial.list()[3];
      myPort = new Serial(this, portName, 115200);
    void draw(){
      while (myPort.available() > 0) {
        String inBuffer = myPort.readStringUntil('\r');
        if (inBuffer != null) {
          String[] q = splitTokens(inBuffer, "[J");
          if (q.length > 1) {
            val = int(float(q[1]));
  • 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, not Serial1 and you don't need to setup speed for USB

  • USB object is an instance of Serial

    There is no exemple! to initiate the USB

    have you one?

    should i use this?

    E.on('init', function() {

    Or USB.setConsole(true); ?



  • 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 from USB so better something like Serial1.setConsole() or LoopbackA.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

  • I had a switchto switch on/off setConsole on USB or on an other Serial
    I use print non console.log

    i've tried this

    let laser;
    function lis(){
      let somme=0;
      var dist = laser.performSingleMeasurement().distanc­e;
      //console.log("distance: ",dist," lissée:",somme/table.length);
      analogWrite(LED1, (1000-dist)/1000, { soft:true, freq:200 });
    function onInit() {
      laser = require("VL53L1X").connect(I2C2);
      digitalWrite(B4,1); // set XSDN -> turn the sensor on
      setInterval(lis, 150);
      pinMode(A6, 'input_pulldown');
      setWatch( function (e) {
        if (e.state) {
        } else {
      }, 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


    1587 is my number


    Any idea

  • print is basically same as console.log both write to console
    try stuff mentioned in post #2

  • 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

  • @Gordon Thanks
    i'll try tomorrow
    I'm able to clean the output, but i was looking for a way to have a clean output (easer to explain the code to beginners)


  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview

connecting a pico to a computer and Processing.org with serial

Posted by Avatar for Mrbbp @Mrbbp