WEB IDE and COM issues in Windows

Posted on
  • I have Windows 7 installed and I originally tried to install the USB CDC drivers by downloading and install this: http://www.st.com/web/en/catalog/tools/P­F257938

    After installing the CDC drivers I unplugged the Espruino from the USB port and plugged in the Espruino back into the USB port. The Device Manager failed to find the Espruino even though I installed the CDC drivers. I then, completely removed the CDC drivers by using the installer. I then decided to using Windows Update to find and install the CDC drivers. A couple minutes later the installation of the CDC drivers successfully installed and now the Device Manager successfully finds the CDC driver.

    However, multiple new issues arose. The Web IDE has a hard time connecting to the Espruino. Most of the time when I connect to the Espruino in the console I would receive Connect and nothing more instead of the console outputting the double =undefined. When that happens, I noticed when I click the upload code button I would get the upload status bar but the code doesn't actually upload.

    To trouble shoot these issues, I tried multiple usb cables and usb ports and I would still get the issues stated above. I then went into the Device Manager and uninstalled the CDC driver, removed the Espruino from the USB cable and plugged the Espruino back in. I now can successfully connect to the Espruino and upload code. My test code outputs the array values to the console a few times and then stops responding. I have absolutely no idea why these issues happen on Windows. I can't seem to reproduce the issues on my Ubuntu machine.

    Complete test code:

    I2C1.setup({scl:b6, sda:b7});
    
    setInterval(function (e) {
      var tempQuery = 0;
    
      I2C1.writeTo(99, "T,19.5");
      setTimeout(function (e) {
        I2C1.writeTo(99, "T,?");
        setTimeout(function (e) {
          tempQuery = I2C1.readFrom(99, 7);
          console.log(tempQuery);
        }, 300 );
      }, 300 );
    }, 5000);
    
  • Hmm, I'm not really sure what could be the issue there. What happens if you:

    • plug the Espruino board in
    • leave it for a while
    • connect with the Web IDE
    • Use up-arrow to step through the previous commands sent to the Espruino

    Are there any AT... commands there? If so, it could be Windows is trying to connect to your Espruino as if it were a modem - it'd explain why it suddenly stops responsing if Windows just grabs control of the serial device.

  • The Web IDE has a hard time connecting to the Espruino. Most of the time when I connect to the > Espruino in the console I would receive Connect and nothing more instead of the
    console outputting the double =undefined. When that happens, I noticed
    when I click the upload code button I would get the upload status bar
    but the code doesn't actually upload.

    I have been struggling with similar issues when I am trying to connect through HC-05 Bluetooth from a Win 7 (64bit) machine with a USB Bluetooth dongle. there will be two COM ports created and they behave exactly as described above. If I manage to create a third COM port with outgoing connection it usually works fine. But not always. It can happen that I manage to create a third COM port that is outgoing but it does not work. I am thinking that the problem is related to the Bluetooth drivers on my Win 7 not really working with the HC-05, but I have no clue. I am following this discussion in hope of finding a clue to my Bluetooth connection issue.

    I use Blutetooth settings to Add Device, HC-05 appears, then I get to type in the four digit code, I open the Web IDE and there are two COM ports, both incoming. I can connect but all I get is
    Connected
    then after a while I get
    Disconnected

  • The bluetooth one may not be related - but if it is I'd imagine it points to some issue with the Web IDE and Chrome.

    What happens if you try and connect with Putty instead? Does it always work?

  • @Gordon I tried pressing the up and down arrows; however, sometimes the IDE is completely unresponsive.

    I tried the 'press rst button then immediately press btn1(hold for 2 seconds) then release' The IDE seems to be responding as expected now. Putty seems to always connect even when the IDE locks up. I would send an arbitrary character to Putty and Espruino would respond back with '=undefined'. So, i'm assuming the issue lies primarily in the way Chrome handles serial connections.

  • Well I spoke too soon. The IDE stopped responding. Putty can connect, but I can't type anything into the terminal. This is really frustrating.

    I use multiple timeouts in my code.... I wonder if that causes the IDE to stop responding to the Espruino?

    Is there anything I can do? Such as create a function that waits for bnt1 press? Then once bnt1 is press execute some sort of halt() function?

  • It could be you are (or have) uploaded some code to Espruino that causes it to crash - it's all I can think that would cause Putty to stop responding. Definitely I2C can block for a few seconds if the device on the end isn't responding.

    The BTN+RST thing you did only works temporarily - so if you unplugged/replugged or reset Espruino then it'd spring back up exactly as it was before. To fix that, I'd do the BTN+RST thing, connect with Putty/Web IDE and type save().

    Of course maybe the simplest solution is just to re-flash the firmware? On the Espruino board (at least as long as you're not using @DrAzzy's BigRam builds) that'll clear out any saved code.

    Also, it might be worth trying another USB cable. Sounds crazy but so many people have had problems with them that it wouldn't surprise me.

  • Hi @Gordon I have been meaning to update this post. It seems to be my code. In order for me to send code or save() I need to execute clearInterval(Interval). Also typing clearInterval into the terminal lags. One letter after another appears. After clearInterval is executed the lagging stops and the IDE becomes reaponsive. I have a feeling my temperature code is the culprit. My temperature code: http://forum.espruino.com/comments/11973­561/

  • IDE is (still) responsive, and so so is Espruino. But:

    It looks like that your code makes Espruino so busy, that only little is left to answer your terminal input. Try to time a single run. It will tell you whether 3 seconds are enough to take the readings, process them, and display the consolidated value on your display. Just for the sake of this theory, choose 10 seconds (10000 ms), and watch the terminal interaction behavior then.

    You can visualize how busy Espruino is by putting LED3.set() as your first expression in your MedianRead() function, and LED3.reset() as your last. If the LED3 is on (for you eye) all the time, 3 seconds is not enough to go through with all your code.

  • Hi @allObjects I tested your theory (10000ms) and that gives me plenty of time to type in the terminal. I will use your visualization to time how long i will need to set the setInterval. Again, like always, thank you for your help and explanations.

  • setBusyIndicator(LED1); //might be useful for this

  • To make it easier to upload your code, it might be an idea to put all the calls to setInterval or setTimeout into an onInit function. They'll then only be called after you've typed save().

    You could also really speed up your median code I reckon. For starters you could use Float32Array (which is a bit more memory efficient too), and you could then use the 'views' and built-in sum - also the default compare function for sorting does what you want I think, so you can just call sort with no arguments:

    function MedianRead(n,Pin) {
      var myarr = new Float32Array(n);
      for(i=0; i<n; i++) myarr[i] = analogRead(Pin);
      myarr.sort();
      // cut off first and last 2 elements
      var view = new Float32Array(myarr.buffer, 4/*sizeof(float32)*/*2, n-4);
      console.log(E.sum(view)/view.length);
    }
    

    I've not tested it though...

    As a way to make Espruino respond a lot faster, you might also want to look at Waveforms.

    You could do something like:

    var w = new Waveform(128/* your buffer size */,{doubleBuffer:true, bits:16});
    w.on("buffer", function(myarr) { 
       myarr.sort();
       // cut off first and last 2 elements
       var view = new Uint16Array(myarr.buffer, 2/*sizeof(uint16)*/*2, n-4);
       console.log(E.sum(view)/(view.length*655­36));
    });
    w.startInput(Pin,2000 /* Samples per second */,{repeat:true});
    

    Waveforms allow you to do analog readings at a fixed frequency in the background - it'll then only call your JavaScript code when it has filled up a buffer full of data. All the rest of the time it'll be able to do other things.

    Only thing to note is it puts the data into a 16 bit value, so you can do exactly the same stuff but you have to divide by 2^16 (65536) at the end.

  • @Gordon the Waveform that you recommended will come in handy. I was looking for away to trigger the other sensor readings once the espruino receives the temp. The temp is needed first before I request the other sensor readings.

    I will respond back hopefully in a couple days with my results/issues.

  • @Gordon I'm a little confused about how the sampling works in the StartInput. If i create a buffersize of 128 does the StartInput average out the 2000 samples then store the averaged sample into the buffer and do that 128 times?

  • Ahh, nope... Basically:

    • You've got two 128-word buffers
    • startInput will start it sampling at 2000 samples per second
    • When one buffer is full (in 128 / 2000 = 0.064 of a second) it'll call your code with that buffer, while it's busy reading samples into the second buffer
    • It calls you again when the second buffer is full (and it starts writing to the first)
    • And so on... You need to be finished with each buffer within 0.064 of a second or it'll start writing to the buffer as you're working on it
  • #waveforms #sampling

    Cool mechanism this double buffering to take advantage of internal speed and 'external' coding simplicity!...

    Lowering the sampling rate to give enough time to do the (filter/average) calculations would be the point. For example, a sampling rate of 128[samples] / 3[secs] = 43 [samples/sec] would deliver enough time - 3 seconds - to do the work. Depending how 'fast' temperature is changing though, only a segment of the 128 samples should then be taken... If this does not deliver enough samples, buffer size and sampling rate can to be increased proportionally.

    Another solution - with high(er) sampling rate / samplings over a shorter period - for example, 0.5[secs], but allowing a longer period - for example, 5[secs] - can be achieved by option repeat:false. After processing the samples, issueing a .startInput() with a timeout will for sure prevent overruns. A third option is to put start with no-repeat into a function and invoke it on the desired interval. For example:

    Every ... milliseconds, take 128 samples over a period of 0.5 seconds and average over 124 :

    var samplingInterval = null;
    var wf = new Waveform(128,{doubleBuffer:false, bits:16});
    wf.on("buffer", function(arr) { 
       arr.sort();
       var view = new Uint16Array(arr.buffer, 4, 128 - 4);
       console.log((E.sum(view)/65536)/view.len­gth);
    });
    var startSampling = function(interval) {
      var si = isNaN(interval) ? 5000 : (interval < 1000) ? 1000 : interval;
      samplingInterval = setInterval(function(){ 
          wf.startInput(pin,256) ,{repeat:false});
        },si);
    };
    var stopSampling = function() {
      if (samplingInterval) { clearInterval(samplingInterval); }
      samplingInterval = null;
    };
    

    To start the sampling, issue:

    startSampling(5000);
    

    To stop the sampling, issue:

    stopSampling();
    
  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

WEB IDE and COM issues in Windows

Posted by Avatar for d0773d @d0773d

Actions