Avatar for ClearMemory041063

ClearMemory041063

Member since Apr 2016 • Last active Feb 2017
  • 43 conversations
  • 276 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 General
    Avatar for ClearMemory041063

    A suggestion:
    Using two way communication.
    A sends a 16 byte random number to B
    B receives random number and uses secret key and the AES block encryption to encrypt the random number. B sends the encrypted results to A.
    A uses original random number and secret key to calculate the encrypted value to compare with the message from B.

  • in Electronics
    Avatar for ClearMemory041063

    Attached is a start on the translation of the Adafruit C code.
    Since I don't have the chip it is untested.
    It should give you an idea of what is involved.

  • in Electronics
    Avatar for ClearMemory041063

    A Google search produces at least one path for a driver in C.
    A bit of translation would produce the code that you need. ( a week to a month estimate)
    github.com/adafruit/Adafruit_INA­219

    This link is a good discussion of the chip
    cdwilson.us/articles/understandin­g-the-INA219/

    A NODEjs version of the code
    github.com/brettmarl/node-ina219­
    and another
    libraries.io/npm/ina219

    Have fun sorting it all out.

  • in Puck.js
    Avatar for ClearMemory041063

    Try this as the datasheet mentions that setup has to come before enable
    accel.interrupts(0,0);
    accel.interrupts(4,0);

  • in Puck.js
    Avatar for ClearMemory041063

    Here are some things to try.

    page 26
    Register 0x28—THRESH_FF (Read/Write)
    The THRESH_FF register is eight bits and holds the threshold
    value, in unsigned format, for free-fall detection. The acceleration on
    all axes is compared with the value in THRESH_FF to determine if
    a free-fall event occurred. The scale factor is 62.5 mg/LSB. Note
    that a value of 0 mg may result in undesirable behavior if the freefall
    interrupt is enabled. Values between 300 mg and 600 mg
    (0x05 to 0x09) are recommended.
    Register 0x29—TIME_FF (Read/Write)
    The TIME_FF register is eight bits and stores an unsigned time
    value representing the minimum time that the value of all axes
    must be less than THRESH_FF to generate a free-fall interrupt.
    The scale factor is 5 ms/LSB. A value of 0 may result in undesirable
    behavior if the free-fall interrupt is enabled. Values between 100 ms
    and 350 ms (0x14 to 0x46) are recommended.

    • The interrupt polarity could be flipped.
      Register 0x31 bit D5
      INT_INVERT Bit
      A value of 0 in the INT_INVERT bit sets the interrupts to active
      high, and a value of 1 sets the interrupts to active low.
  • in Interfacing
    Avatar for ClearMemory041063

    Now you have me a bit worried. The oriental specifications for this device are sketchy at best.
    It seems to contain 3 switches, 3 resistors and have 8 pins.
    Connecting both ground and 3.3V from the Pico to this device without a proper diagram runs the risk of shorting 3.3 to ground and popping the fuse on the Pico, A Bad thing :(
    If you have an ohmmeter that would provide a way to probe the device safely and figure out how it is wired. Short of that connect ground only and not the 3.3V. use the pin setup with pull up. The code that reads a Pico pin to light the LED can then be used as a test probe to puzzle out a proper wiring sequence.

  • in Interfacing
    Avatar for ClearMemory041063

    Translating C to Espruino Javascript
    #define CHECK_BIT(var,pos) ((var) & (1<<(pos)))
    So my guess is it becomes this:
    function CHECK_BIT (val, pos) { return ((val) & (1<<(pos))); }
    And the init_i2c function is puzzling to me. Looks like init_i2c("/dev/i2c-1"); is akin to calling I2C1.setup().
    Some #define statements have to become functions.
    Having done this for the LSM9DS1 IMU these snippets may help.
    The other gotchas are handling the bytes read as unsigned or signed values, big or little endian and two’s compliment math. C programmers seem to grab a datasheet for a chip and #define everything in sight, at the end there tends to be a lot of unused stuff defined in the C code. I usually resort to commenting out blocks of stuff to see what complains and uncomment the complaints.

    void LSM9DS1::initI2C()
    {
        Wire.begin();   // Initialize I2C library
    }
    Becomes
    //Configuration
    //The I2C pins that the LSM9D01 is connected to
    //PICO I2C pins
    //IC1  sda=B7  scl=B6
    //IC1  sda=B9  scl=B8  shim pins
    //IC3  sda=B4  scl=A8
    //IC2  sda=B3  scl=B10
    var W;
    function start(){
    //  console.log("start");
     I2C3.setup({ scl :A8, sda: B4} );
    //console.log(I2C3);
    var xgAddress= 0x6B;// Would be 0x1C if SDO_M is LOW
    var mAddress= 0x1e;// Would be 0x6A if SDO_AG is LOW 
     W =require("slimLSM9DS1").connect(I2C3,xgA­ddress,mAddress);
    W.run();//Get it started
    
    uint8_t LSM9DS1::I2CreadByte(uint8_t address, uint8_t subAddress)
    {
        int timeout = LSM9DS1_COMMUNICATION_TIMEOUT;
        uint8_t data; // `data` will store the register data    
        
        Wire.beginTransmission(address);         // Initialize the Tx buffer
        Wire.write(subAddress);                  // Put slave register address in Tx buffer
        Wire.endTransmission(true);             // Send the Tx buffer, but send a restart to keep connection alive
        Wire.requestFrom(address, (uint8_t) 1);  // Read one byte from slave register address 
        while ((Wire.available() < 1) && (timeout-- > 0))
            delay(1);
        
        if (timeout <= 0)
            return 255; //! Bad! 255 will be misinterpreted as a good value.
        
        data = Wire.read();                      // Fill Rx buffer with result
        return data;                             // Return data read from slave register
    }
    Becomes
    /** 'mReadByte(subAddress) read a byte from the magnetometer at subaddress'*/
    LSM9DS1.prototype.mReadByte=function(sub­Address){
     var x=this.mAddress;
     var data=Uint8Array(1);
     this.i2c.writeTo(x, subAddress);
     data=this.i2c.readFrom(x, 1);
     return data[0];
    };//end mReadByte
    
    uint8_t LSM9DS1::I2CreadBytes(uint8_t address, uint8_t subAddress, uint8_t * dest, uint8_t count)
    {  
        int timeout = LSM9DS1_COMMUNICATION_TIMEOUT;
        Wire.beginTransmission(address);   // Initialize the Tx buffer
        // Next send the register to be read. OR with 0x80 to indicate multi-read.
        Wire.write(subAddress | 0x80);     // Put slave register address in Tx buffer
    
        Wire.endTransmission(true);             // Send the Tx buffer, but send a restart to keep connection alive
        uint8_t i = 0;
        Wire.requestFrom(address, count);  // Read bytes from slave register address 
        while ((Wire.available() < count) && (timeout-- > 0))
            delay(1);
        if (timeout <= 0)
            return -1;
        
        for (int i=0; i<count;)
        {
            if (Wire.available())
            {
                dest[i++] = Wire.read();
            }
        }
        return count;
    }
    
    Becomes
    /** 'mReadBytes(subAddress,count) read count bytes from magnetometer at subAddress'*/
    LSM9DS1.prototype.mReadBytes=function(su­bAddress,count){
     var x=this.mAddress;
     var dest=new Uint8Array(count);
     this.i2c.writeTo(x, subAddress|0x80);
     dest=this.i2c.readFrom(x, count);
     return dest;
    };//end mReadBytes
    
    
    // Wire.h read and write protocols
    void LSM9DS1::I2CwriteByte(uint8_t address, uint8_t subAddress, uint8_t data)
    {
        Wire.beginTransmission(address);  // Initialize the Tx buffer
        Wire.write(subAddress);           // Put slave register address in Tx buffer
        Wire.write(data);                 // Put data in Tx buffer
        Wire.endTransmission();           // Send the Tx buffer
    }
    Becomes
    LSM9DS1.prototype.mWriteByte=function(su­bAddress,data){ 
      //console.log("mWriteByte ",this.mAddress, subAddress, data);
      var x=this.mAddress;
      this.i2c.writeTo(x, subAddress,data);
      return 0;
    };//end mWriteByte
    

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

  • in Interfacing
    Avatar for ClearMemory041063

    This code looks like it could be of use to you. It at least helps to sort out the various sequences of bytes that are needed to converse with the fuel gauge chip. Translating from C to JavaScript would need to be done. A starting point is to replace the #define variable 0xvalue with var variable= 0xvalue. For example
    #define BQ27441_CONTROL_STATUS 0x0000
    becomes
    var BQ27441_CONTROL_STATUS= 0x0000;

    then functions need to be redefined
    void init_i2c(char *DeviceName)
    {
    }
    rewrite as
    function init_i2c(DeviceName){
    }
    Lots of work from there to get it all working.

    github.com/chintanp/i2c-charger/­blob/master/BQ-27441-Gauge/c/gauge.c

  • in Interfacing
    Avatar for ClearMemory041063

    So does that work ?

Actions