Avatar for Mrbbp

Mrbbp

Member since Mar 2017 • Last active May 2022
  • 31 conversations
  • 173 comments

I'm newb with espruino, not with arduino, not with js...
But i'm not a coding ninja

Most recent activity

  • in Interfacing
    Avatar for Mrbbp

    @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)

    regards

  • in Interfacing
    Avatar for Mrbbp

    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;
      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

  • in Interfacing
    Avatar for Mrbbp

    USB object is an instance of Serial
    https://www.espruino.com/Reference#l__gl­obal_USB

    There 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

    é.

  • in Interfacing
    Avatar for Mrbbp

    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?
    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

    let laser;
    
    function lis(){
      let somme=0;
      var dist = laser.performSingleMeasurement().distanc­e;
      //print(dist);
      console.log(dist);
      //console.log("distance: ",dist," lissée:",somme/table.length);
      analogWrite(LED1, (300-dist)/300, { soft:true, freq:200 });
    }
    
    function onInit() {
      Serial1.setup(115200);
      I2C2.setup({sda:B3,scl:B10});
      laser = require("VL53L1X").connect(I2C2);
      console.log("init");
      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]));
            println(val);
          }
        }
      }
    }
    
  • in Pico / Wifi / Original Espruino
    Avatar for Mrbbp

    Thanks @Robin,
    I started with the same example, but i missed the ‘toString()’ to convert my counter in String in my attempt.

    It works now...

    thanks again.

    Regards

  • in Pico / Wifi / Original Espruino
    Avatar for Mrbbp

    Hello,

    I'm looking for to store a var in a permanent way (power off) and load at start (power on)
    i saw that @Gordon implement a way to store data since 2v05, but the example code is for log datas (implementative way) and it seems a beat complex just for store a counter var.

    have you a simple example to implement a counter (with a long type) storage over power-down?

    I've tried

    var memoire = require("Storage");
    [...]
    let NumPoemeEncours = memoire.read("num"); // numero encours
      if (NumPoemeEncours == null || NumPoemeEncours == undefined  || NumPoemeEncours == "") {
          NumPoemeEncours = 1;
          console.log("numero du poeme inconnu", memoire.read("num"));
          memoire.write("num",NumPoemeEncours);
          console.log("numero du poeme connu", memoire.read("num"));
      }
    console.log("NumPoemeEncours:",NumPoemeE­ncours);
    

    but it does not works!

    what i'm doing wrong?

    thanks for your time.

  • in Pico / Wifi / Original Espruino
    Avatar for Mrbbp

    Do you need this at the same time? Because it would potentially be really bad news to attach power to the USB power input and then plug it into your PC as well.

    Not at the same time of course, but the possibility to scratch the paint and uncover the mini usb pads and sold 2 wires seem to be a bit dangerous if i need to plug the usb in my computer to update code.

    there is a samsung travel charger with slim wire in black or white, and is cute and strong enough to power a simple led matrix.

    sorry instagram link to see picture
    https://www.instagram.com/p/COrzei-h9uH/­

Actions