Avatar for ClearMemory041063

ClearMemory041063

Member since Apr 2016 • Last active Jun 2017
  • 47 conversations
  • 333 comments

Retired. Just having fun now.
I'm running an Espruino Board connected to ESP8266 via serial port.

Working on a program derived from the SD card file server example.
When you request a file from the displayed list, it looks at the file extension and modifies the MIME header field.
This causes files with the extension .HTML to load the Web page.
Files with the extension .js allow an .HTML file to include scripts.
Files with the extension .csv cause Excel to load the file into a spreadsheet, which can be saved on your hard drive.

I'm having problems with another part that accepts POSTs from a client.

Most recent activity

  • in Interfacing
    Avatar for ClearMemory041063
    3DMouse8adrainB.js

    This version uses the update BNO055.js module from the WebIDE sandbox.
    It requires BNO055.js (sandbox), FlashEEPROM, and ESP8266WiFi_0v25 (Espruino modules).
    It runs on a PICO with an ESP8266 connected via a shim.
    The BNO055 module is connected as before.
    // define the I2C connection I2C3.setup({ scl :A8, sda: B4} );
    A normally open pushbutton is connected to ground and pin B7. Once the calibration status read 3333 the button is pressed to write the calibrations to the PICO EEROM
    The calibration offsets and radiae are saved in PICO EEROM page var CalPage=89;
    The html page is divided into two portions page1 and page2 to avoid out of memory errors
    The web address uses port 8000. Given a router assigned IP address 192.168.1.6 use
    "http//192.168.1.6:8000" in the browser. (Note older browsers may noe support the WebSockets used in this program. ( My old Android Tablet loads the page but doesn't support the websockets)
    The drain command is used to serve the two pages.

    function onPageRequest(req, res) {
      res.writeHead(200, {'Content-Type': 'text/html'});
     res.on('drain',function(){
      res.write(page2);
      res.end();//Page);
     });
      res.write(page1);
    }
    

    Some sample left pane output:

    A
    {"st":333,"yaw":341.125,"roll":16.625,"p­itch":101.3125}
    Usage= 4369
    A
    {"st":333,"yaw":341.0625,"roll":16.4375,­"pitch":101.5}
    Usage= 4369
    

    The BNO055.js module and savCalBNO055.js can be found at:
    http://forum.espruino.com/conversations/­305928/

  • in Interfacing
    Avatar for ClearMemory041063

    BNO055 Module Improvements
    24Jun2017

    BNO055 Module Improvements 24Jun2017

    The BNO055.js module was used to implement an application as described here:
    Using an IMU to control an airplane image

    http://forum.espruino.com/conversations/­306319/

    It was discovered that the Pitch data values from the module were changing for a fixed position of the sensor. The BNO055.js module was updated to correct this problem, the reset function and external clock functions were also added.
    The attached program savCalBNO055.js is setup for a PICO connected to a BNO055 board. A normally open pushbutton connected from ground to pin B7 is used to save the calibration data to EEROM on the PICO. When all four of the calibration status indications equal 3, save the calibrations.
    Once a calibration has been saved, the program has to be restarted. The presence of calibration in the EEROM is detected and they are read, displayed and loaded into the BNO055 chip. Here is and example:

    sysstatus= 0
    syscal= 0 Gyrcal= 0 Acccal= 0 Magcal= 0
    sysstatus= 0
    Calibration is defined
    Aoffset=,-6,3,8,Moffset=,-14,90,-142,Gof­fset=,0,0,0,Aradius=,1000,Mradius=,816
    

    Here is a data example.

    sysstatus= 5
    A=,0.47,-9.54,-1.62,m/s^2
    M=,20.1875,-7,11.1875,uT
    G=,-0.25,-0.3125,0.375,deg/s
    Heading=,359.9375,Roll,2.6875,Pitch,99.7­5deg
    Q=(,5276.5,-6259,-47.5,2.5,)E-14
    Lin=,-0.01,0.1,-0.06,m/s^2
    Grav=,0.46,-1.97,-1.66,m/s^2
    Temperature= 64 F
    syscal= 0 Gyrcal= 3 Acccal= 3 Magcal= 3
    Aoffset=,-6,3,8,Moffset=,-14,90,-142,Gof­fset=,0,0,0,Aradius=,1000,Mradius=,816
    
  • in Interfacing
    Avatar for ClearMemory041063
    Found the fix to gotcha 1

    Recall that glitch1 produces Pitch values that fluctuate for a steady position of the IMU chip.
    The BNO055.js has been changed to fix this problem and the median filter has been removed from the 3dMouse8aDrain.js.
    The original approach was to read a series of BNO055 registers in one big scoop.

    BNO055.prototype.getIMU=function(){
     var IMU=new Int16Array(13);
     this.selectPage(0);
     IMU=this.ReadBytes(this.Page0Regs.EUL_He­ading_LSB,26);
     this.Head[0]=IMU[0]/this.EULscale;
     this.Head[1]=IMU[1]/this.EULscale;
     this.Head[2]=IMU[2]/this.EULscale;
     this.Quant[0]=IMU[3]/2;
     this.Quant[1]=IMU[4]/2;
     this.Quant[2]=IMU[5]/2;
     this.Quant[3]=IMU[6]/2;
     this.Lin[0]=IMU[7]/this.ACCscale;
     this.Lin[1]=IMU[8]/this.ACCscale;
     this.Lin[2]=IMU[9]/this.ACCscale;
     this.Grav[0]=IMU[10]/this.ACCscale;
     this.Grav[1]=IMU[11]/this.ACCscale;
     this.Grav[2]=IMU[12]/this.ACCscale;
    };//end getIMU
    

    By changing the way the data are read from the BNO055 the data value flutter issue has been resolved.
    (The Art of Computer Programming)

    BNO055.prototype.getIMU=function(){
     var IMU=[];
     this.selectPage(0);
     var R=this.Page0Regs.EUL_Heading_LSB;
     for(var i=0;i<13;i++){
      IMU.push(this.ReadBytes(R,2));
      R=R+2;
     }//next i
     this.Head[0]=IMU[0]/this.EULscale;
     this.Head[1]=IMU[1]/this.EULscale;
     this.Head[2]=IMU[2]/this.EULscale;
     this.Quant[0]=IMU[3]/2;
     this.Quant[1]=IMU[4]/2;
     this.Quant[2]=IMU[5]/2;
     this.Quant[3]=IMU[6]/2;
     this.Lin[0]=IMU[7]/this.ACCscale;
     this.Lin[1]=IMU[8]/this.ACCscale;
     this.Lin[2]=IMU[9]/this.ACCscale;
     this.Grav[0]=IMU[10]/this.ACCscale;
     this.Grav[1]=IMU[11]/this.ACCscale;
     this.Grav[2]=IMU[12]/this.ACCscale;
    };//end getIMU
    
    

    The module will be further updated to extend this discovery to other block reads of data.

  • in Interfacing
    Avatar for ClearMemory041063

    From the BNO055 datasheet

    The output data format is based on the following convention regarding the rotation angles
    for roll, pitch and heading / yaw (compare also section 3.4):

    Table 3-13: Rotation angle conventions

    Rotation angle Range (Android format) Range (Windows format)
    Pitch +180° to -180° -180° to +180°
    Roll -90° to +90° -90° to +90°
    Heading / Yaw 0° to 360° 0° to 360°
  • in Interfacing
    Avatar for ClearMemory041063

    Gotcha 1 Glitches in the data from the BNO055.

    Examine the pitch values which should be around 180 degrees but on occasion read near 0.

    Cal= 3033
    {"st":3033,"yaw":181.6875,"roll":18.5625­,"pitch":-179.3125}
    Cal= 3033
    {"st":3033,"yaw":181.9375,"roll":16.875,­"pitch":177.0625}
    Cal= 3033
    {"st":3033,"yaw":180.875,"roll":6.875,"p­itch":178.25}
    Cal= 3033
    {"st":3033,"yaw":179.8125,"roll":3.375,"­pitch":178.9375}
    Cal= 3033
    {"st":3033,"yaw":181.3125,"roll":3.1875,­"pitch":179.9375}
    Cal= 3033
    {"st":3033,"yaw":181.75,"roll":2.3125,"p­itch":-0.0625}
    Cal= 3033
    {"st":3033,"yaw":181.25,"roll":3.8125,"p­itch":-0.0625}
    Cal= 3033
    {"st":3033,"yaw":182.625,"roll":5.1875,"­pitch":-179.6875}
    Cal= 3033
    {"st":3033,"yaw":183.0625,"roll":6,"pitc­h":-0.0625}
    Cal= 3033
    {"st":3033,"yaw":183.375,"roll":7,"pitch­":-177.75}
    Cal= 3033
    {"st":3033,"yaw":183.125,"roll":7.25,"pi­tch":-177.625}
    Cal= 3033
    {"st":3033,"yaw":183.9375,"roll":7.875,"­pitch":-176.8125}
    Cal= 3033
    {"st":3033,"yaw":184.3125,"roll":-0.0625­,"pitch":-0.0625}
    Cal= 3033
    {"st":3033,"yaw":185.0625,"roll":9.25,"p­itch":-175.75}
    
    Try using a median filter on the Yaw, Roll and Pitch data.

    See attached file medianFilter.js and 3Dmouse8b.js

    var MM=new xyzMF(7); //global
    …
      W.getIMU();
      MMM=MM.getMF(W.Head);
      Msg.yaw=MMM[0];
      Msg.roll=MMM[1];
      Msg.pitch=MMM[2];
      console.log(JSON.stringify(Msg));
    

    And the output:

    Cal= 3003
    {"st":3003,"yaw":178.625,"roll":2.875,"p­itch":179.75}
    Cal= 3003
    {"st":3003,"yaw":178.6875,"roll":2.8125,­"pitch":179.75}
    Cal= 3003
    {"st":3003,"yaw":178.6875,"roll":2.8125,­"pitch":179.75}
    Cal= 3003
    {"st":3003,"yaw":178.625,"roll":2.75,"pi­tch":179.625}
    Cal= 3003
    {"st":3003,"yaw":178.5625,"roll":2.6875,­"pitch":179.5625}
    Cal= 3003
    {"st":3003,"yaw":178.625,"roll":2.625,"p­itch":179.6875}
    Cal= 3003
    {"st":3003,"yaw":178.6875,"roll":2.625,"­pitch":179.75}
    Cal= 3003
    {"st":3003,"yaw":178.625,"roll":2.75,"pi­tch":179.75}
    Cal= 3003
    {"st":3003,"yaw":178.8125,"roll":2.625,"­pitch":179.8125}
    Cal= 3003
    {"st":3003,"yaw":178.875,"roll":2.75,"pi­tch":179.875}
    Cal= 3003
    {"st":3003,"yaw":179.0625,"roll":2.75,"p­itch":179.9375}
    Cal= 3003
    {"st":3003,"yaw":179.0625,"roll":2.8125,­"pitch":179.875}
    Cal= 3003
    {"st":3003,"yaw":179.125,"roll":2.875,"p­itch":179.875}
    
    3DMouse8c.js reconnects the web interface and uses the median filter

    This version eliminates the image radically changing positions on the screen.
    I still wonder if I missed a data ready status in the BNO055 module that might be causing the problem.
    The hypothesis BNO055 is updating values at the same time the PICO is trying to read them. I’ll have to revisit this issue.

    Other gotchas relating to the position of the screen image and the position of the chip still remain to be resolved.

    testws7a.js allows one to type yaw=23; roll=45; or pitch=-179 (supply your value) into the left pane of the WebIde and have the position of the airplane change on the web page.

  • in Interfacing
    Avatar for ClearMemory041063

    Success

    Combined two programs with some editing and the resulting program connects to the BNO055 IMU, then is connects to the local WiFi to serve the display page. As you move the BNO055 chip around the airplane on the screen seems to follow. (Just got it working so there are likely some gotchas, but I feel pretty good for now).
    Put the BNO055.js in the modules directory of the WebIDE project (sandbox)
    The WiFi is an ESP8266 on a Pico shim
    The BNO055 is I2C. See code for pins.

  • in Interfacing
    Avatar for ClearMemory041063

    I reworked the communications link last night. Removed the timer approach and went to the approach that the client sends a character, the server replies with the JSON string, on receipt by the client, but before the JSON parse, the client sends another character, then does the JSON parse within a try/catch framework. The results run much faster and much longer without errors

    The port used in the browser is 8000 not 8080. (you can edit it if you like). So the IP address line of the browser reads:
    http//192.168.1.6:8000
    The latest are attached.

  • in Interfacing
    Avatar for ClearMemory041063

    The HTML POST problem

    If you try to post and then process the reply too fast, the header information winds up in the message from the client to the server.

    Are Websockets faster?

    To find out I went to the Espruino site to try a Websocket example
    https://www.espruino.com/ws
    In the Websocket server example code:

    var page = '<html><body><script>var ws;setTimeout(function(){';
    page += 'ws = new WebSocket("ws://" + location.host + "/my_websocket", "protocolOne");';
    page += 'ws.onmessage = function (event) { console.log("MSG:"+event.data); };';
    page += 'setTimeout(function() { ws.send("Hello to Espruino!"); }, 1000);';
    page += '},1000);</script></body></html>';
    

    This is the HTML code sent to the client. Note the line page += 'ws.onmessage = function (event) { console.log("MSG:"+event.data); };';
    Console.log is not a valid way to display a message in HTML/javascript.
    The example works but nothing appears on the client screen.
    A better example is in the attached file websockserve1a.js

    Websockets seem to be faster

    Reworked the HTML file into the attached file flight5a.html to use Websockets. It is incorporated into the server code as a string using the file converter site at
    https://www.espruino.com/File+Converter
    The attached file websocketserver2.js contains the server code using Websockets.

    Bugs

    The airplane flies and flies but eventually stops communicating.
    Using the debugger on the client side the following two errors were occurring

    ws.onmessage=function(event){
       var S=JSON.parse(event.data);
    (index):1 Uncaught SyntaxError: Unexpected end of JSON input
        at JSON.parse (<anonymous>)
        at WebSocket.ws.onmessage ((index):214)
    
    
    VM44:37 WebSocket connection to 'ws://192.168.1.6:8000/my_websocket' failed: A server must not mask any frames that it sends to the client
    
    The JSON.parse bug has been fixed.

    The file trycatch.js shows how this was done in the client code. The messages sometime come in garbled and the JSONparse throws an error. The code catches the error and discards the message.

    ws.onmessage=function(event){
    try{
       var S=JSON.parse(event.data);
    }
    catch(e){return;}
       CalStat=S.st;
    
    
    The other bug I have no clue. Helpful suggestions are welcome.

    Is this project the start of a 3D mouse?
    The POST method fails with 500 ms sample intervals.
    The Websockets method works well at 300ms and maybe 200ms.

Actions