Avatar for stephaneAG


Member since Jun 2014 • Last active Jun 2018
  • 11 conversations

'love hackety trick

Most recent activity

  • in Interfacing
    Avatar for stephaneAG

    all right, if anyone needs more or less the same hack for servo.move, I have the following code ( not yet tested but worked flawlessly within a browser ;p )

    var interval, currentPos;
    var offs = 1, mul = 1;
    var options = {};
    //var options = { range: 3};
    if (options && options.range) {
      mul = options.range;
      offs = 1.5-(mul/2);
    // helpers
    // replacement for E.clip when not in Espruino env
    var clip = function(val, min, max){
      if(val < min) val = min;
      if(val > max) val = max;
      return val;
    // the good-ol' Ar map() !
    var map = function(x, in_min, in_max, out_min, out_max){
      //return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
      var mapped = (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
      return mapped.toFixed(3);
    var move = function(pos, time, callback) {
      if (time===undefined) time = 1000; // T: if no time is set as duration for the move, set 1 sec
      var amt = 0;
      if (currentPos===undefined) currentPos = pos; // T: if no currentPos is defined, set it to the goal position
      if (interval) // T: if already existing interval, cancel it
      var initial = currentPos; // T: set initial position for the move
      interval = setInterval(function() { // T: schedule re-calls
        if (amt>1) {  // T: move fully executed ( & maybe a little farther ? )
          clearInterval(interval); // T: no more re-calls
          interval = undefined; // T:  reset interval
          amt = 1; // T: set move to fully executed
          if (callback) callback(); // T: move ended callback
        currentPos = pos*amt + initial*(1-amt); // T: calculate currentPos from initialPos, pos & current amount ( steps already took )
        //digitalPulse(pin, 1, offs+E.clip(currentPos,0,1)*mul); // T: function digitalPulse(pin, value_highOrLow, time_duration), clip to min & max
        //digitalPulse(pin, 1, offs+clip(currentPos,0,1)*mul); // T: function digitalPulse(pin, value_highOrLow, time_duration), clip to min & max
        console.log('HIGH pulse width: ' + ( offs+clip(currentPos,0,1)*mul ) );
        console.log('amt: ' + amt);
        // IDEA: clip/map to 0.03..0.115 ?
        console.log('hacky analogWrite value:' + map(amt, 0, 1, 0.03, 0.15) );
        amt += 1000.0 / (20*time); // T: next step
      }, 20);
    // test-drive ..
    move(1, 500, function(){
      console.log('movement done !');

    I'll test the above as soon as I can, although not that efficient, it should hopefully do the trick :)

    On the "web side of things", still no success using the attached code ( "kinda" works .. sometimes .. for some values .. so actually more random that working ;p ), and the tests I could run using Audacity to generate tones were no that concluant :/ ..

    nb: on a quick try, I also didn't get any signal using the sound card from the pin driven by Espruino "analogWrite" command, even driving it repeatedly ( maybe it needs some amplification ? )

    ps: I'm doing stuff on a macbookpro 2K11 ( don't know yet if it means some specific stuff on audio input/output ( .. ) )

  • in Interfacing
    Avatar for stephaneAG

    Hi !

    I'm currently trying to get some servos working nicely with an original Espruino board ( and also within a chrome browser ).

    The overall goal is to have a video & synchronized servo movements ( controlled, if can do so, by the audio channel within the video, or within a "tied" audio file, or on-the-fly-generated signals )

    I solved the "45° mystery" thanks to http://forum.espruino.com/conversations/­316585/, which now allows me to move each of the servos I have using the following:

       micro servo SG90 on C8:
       Position "0" ( 1.5 ms pulse ) is middle,
               "90" (~2 ms pulse) is all the way to the right,
               "-90" (~1 ms pulse) is all the way to the left.
       //var s2 = require("servo").connect(C9);
       // servo.move() doesn't work for my microservo ( SG90 ): here's what works
       analogWrite(C9, 0.03, {freq:50}); // -> full left ( -90deg )
       analogWrite(C9, 0.07, {freq:50}); // -> middle ( 0deg )
       analogWrite(C9, 0.115, {freq:50}); // -> full right ( 90deg )

    Now, I'm looking for a replacement for the servo.move() fcn ( or a tweak of it ) that'd allow me to go to a certain position & taking some time to do so - not sure of what to change, one of my guesses is tweaking the following part ?

    digitalPulse(pin, 1, offs+E.clip(currentPos,0,1)*mul);
    // IDEA: clip to 0.03..0.115 ?

    On a close subject, I'm also trying to get the same servos to move:

    • using an audio file ( or an audio channel of a video ) with "recorded" movements from the servos ( when controlled from an Espruino running some code to generate the signals )
    • using the WebAudioAPI to generate the necessary signals

    I stumbled on 2 related posts ( http://www.massmind.org/techref/io/servo­/wav.htm & https://github.com/pendragon-andyh/WebAu­dio-PulseOscillator ) which led me to messing around & try stuff, but I didn't achieve ( yet :/ ) my goal of controlling the said servos using purely on-th-fly-generated signals from the WebAudioAPI

    Last but not least, I'm aware of the 'ontimeupdate' evt that's available when a video is playing ( & yup, I plan to use it to trigger generating on-the-fly signals sync-ed with the video content )

    This being said, here's the code I have so far, I'll be hacking around with it today & the coming days, hopefully coming to a success .. ( .. thanks to hints from here ? ;p )

    Thanks in advance for reading this,
    Looking forward to reading anything on the subject

    ps: test files attached ;)

  • in ESP8266
    Avatar for stephaneAG


    Nb: other point, but I think my above drawing is completely wrong ( .. )
    'this being said",

    From what I could read, 38kHz is a far reach for the esp8266, if its said max is actually 100Hz ( & I'm not talking about code taking too much time to exec & disrupting the WiFi part .. )
    From the post linked above, it seems using 'gpio_write(pin, 1)' & 'os_delay_us(13)' for HIGH & then for LOW could do the trick on the esp8266 platform - maybe as a tiny module or tweak to the build ?

    I'm also wondering which of the following could best suit the need ( & work as intended, if working at all, on most of the platforms .. ):

    // way A
    var arr38kHz = [0.013,0.013,0.013,0.013, ..]; // huuge array ?
    function sendSig(sigArr){
      digitalPulse(irLed_anodePin, 1, arr38kHz); // start 38kHz
      digitalPulse(irLed_cathodePin, 1, sigArr); // send signal
      digitalPulse(irLed_cathodePin, 1, 0); // wait until signal finished before further code execution
      digitalRead(irLed_anodePin); // stop 38kHz
      // or digitalWrite(irLed_anodePin, 0); // if I'm not wrong ;)
      // or digitalPulse(irLed_anodePin, 0, 0); // as well as above  ;)
    // way B
    var interval
    function sendSig(sigArr){
      interval = setInterval(function(){
        digitalPulse(irLed_anodePin, 1, 0.013);
        digitalPulse(irLed_anodePin, 0, 0.013);
      }, 0.026); // start 38kHz
      digitalPulse(irLed_cathodePin, 1, sigArr); // send signal
      digitalPulse(irLed_cathodePin, 1, 0); // wait until signal finished before further code execution
      clearInterval(interval); // stop 38kHz
      digitalRead(irLed_anodePin); // make sure it's off
    // way C
    var signal = [.., ..];
    for(var i=0; i< signal.length; i++){
      if( i.isEven() ){ // we need a HIGH
        digitalWrite(irLed_cathodePin, 1);
        for(var j=0; j < signal[i]/2; j++){
          digitalPulse(irLed_anodePin, 1, 0.013);
          digitalPulse(irLed_anodePin, 0, 0.013);
      } else { // we need a LOW
        digitalPulse(irLed_cathodePin, 0, signal[i]); // stay Low for a while
        /* or, but not mandatory since we're LOW anyway ?
        digitalWrite(irLed_cathodePin, 0);
        for(var j=0; j < signal[i]/2; j++){
          digitalPulse(irLed_anodePin, 1, 0.013);
          digitalPulse(irLed_anodePin, 0, 0.013);
    // way D - using only one leg of the IR LED & the other to Gnd ?
    var signal = [.., ..];
    for(var i=0; i< signal.length; i++){
      if( i.isEven() ){ // we need a HIGH
        for(var j=0; j < signal[i]/2; j++){
          digitalPulse(irLed_cathodePin, 1, 0.013);
          digitalPulse(irLed_cathodePin, 0, 0.013);
      } else { // we need a LOW
        digitalPulse(irLed_cathodePin, 0, signal[i]); // stay Low for a while

    I'll test as soon as I can, but sadly I'm surely not as confident in tweaking the esp build or writing a quick module for it for now :/ ..

  • in ESP8266
    Avatar for stephaneAG

    little update:

    • as an cheap alternative to transmitting the actual IR signals, it seems I can use the learn mode to learn other IR signals ( if those are both supported & long enough - like holding a btn on an actual remote until hearing a buzzing sound as confirmation that some IR signal was learned successfully ): after some quick tries, it doesn't seem to be working all the time ( more like 33% ), even using a code that used to work ( one sniffed from the device, not one learned )

    • since the IR signals can be learned, I suppose it'd be a good idea to look for custom IR signals that could be easily transmitted from whatever board ( I plan to test on original Espruino, Pico, EspruinoWiFi, & esp8266 esp-01, esp-12 & Wemos D1 Mini Pro ), although it 'd be awesome to easily support the actual signals of some device :)

    • I gotta digg the following link to experiment with the signals I already have & custom ones - any hint welcome ;) https://internetofhomethings.com/homethi­ngs/?p=899

    • on a related subject, it seems someone has ported /is porting Ken Shirriff's IR remote lib for the esp8266 https://github.com/markszabo/IRremoteESP­8266

    Aside from this, it seems I have troubles with an EspruinoWiFi: "NetworkJS" & 'http' modules not found ? ( though, it seems it can connect but I can't for ex call 'wifi.getIP()' for some reason :/ ).
    The WeMos is ok ( wifi & hosting the UI ) but doesn't yet support sending IR signals, so pretty much useless for now .. ( .I didn't try again using the original Espruino board + esp8266 esp-01 for WiFi, I'll do & hope it works on 1st try ;p )

    Last but not least, I also have to check if the IR signals learnt can be / are reset when plugging off the tv support power supply ( .. )

    On the html/UI side, the code used 'll be published on the github repo later tonight, & I also plan to try using some jsonp to get an html page bigger than can be hosted as is on the Espruino ( nb: my 1st try on the WeMos ran out of memory :/ .. ) - I'll be posting the logic here as well

    "onto the next update " ..

  • in Interfacing
    Avatar for stephaneAG

    @ClearMemory041063 -> nice work !
    I plan to use a LSM9DS0 9-DOF ( from adafruit ) for another project & I wonder how much work it'd be ( & how close it is to the LSM9DS1 ) to adapt you nearly-module-code to handle it ? ( also I'd be willing to help/do so if it's not "too advanced" for me for now ;) )

    this being said, kudos ++ ;)

  • in ESP8266
    Avatar for stephaneAG

    Hi there ! :)

    Now back, I was glad to receive 2 Espruino WiFI boards :D ( @Gordon #keepUpTheGoodWork #supportingEspruino ;P )

    While I didn't have time yet to test my code on the Espruino Wifi or try the external oscillator way, I did a quick visual recap of the idea ( feel free to correct me if I'm wrong - I really may be so :/ .. ) - the attached .pdf file.

    On that a question: when setting a pin to oscillate, it jump-starts HIGH, right ?
    ( since the logic - if I'm not false - is: "when oscillating pin goes LOW & signal pin is HIGH, IR LED is lit", I try that guess using "visual cues" ;) ( .. ) )

    If so, then I'll only have to write code that actually mixes some signal[] to some passed freq of oscillation & return the "mixed" signal ( I guess it'd be better to pre-process the existing one instead of doing so "on the fly" ( .. ) ), then test it out :)

    I plan to test out the aboves in few days & really hope the esp8266-emitted signals 'll do the trick, but now that I have the said Espruino WiFi, I'd really consider pushing the project further, adding*:

    • accel/gyro/mag detection ( LSM9DS0 9-DOF )
    • ble support ( HC-05 )
    • rgb LED ==> to be added anyway ;)
      & maybe opening up the actual tv support to directly interface with its motors ? => 'de be GREAT ( to learn stuff as well as to bypass some limitations of the "available range of positions" to which the tv can be set to ( .. ) )

    Last but not least, if the signals can be sent correctly for the esp8266 while its also handling changing the rgb led colors & the WiFi stuff, I still have to figure out where the troubles came from in my "quick svg ui" for the tv support ( I'll post that as well as an updated version soon ;) ), but I guess this should be the least of the troubles ..

    This being said, whishing any reader a very nice day :)

    *I guess now I'll also have to try interfacing these with the WeMos D1 as well as do so on the Espruino WiFi ( .. ) ;p

  • in ESP8266
    Avatar for stephaneAG

    hi !

    yup, I think it may work ( although I'd have to workout the resulting Float32Array from the signals[] array + 38kHz pulses ) ;)

    For the second option, maybe connecting a 555 'd work ? ( but I'd truly prefer the 1st option .. )

    As said above, I'll investigate more as I get back home ( where all my uCs are .. )
    Nevertheless, thanks for the quick answer ;)

  • in ESP8266
    Avatar for stephaneAG

    reading the above, I see I'm not the only one with such troubles ( .. )
    I just ordered 2 Espruino WiFi to support the Espruino project, meanwhile I still wanna figure out a way to make this work on the ESP8266 platforms ( see my latest post: http://forum.espruino.com/conversations/­303540/ )