Menu

READ ACCELEROMETER MMA8452

Help
2023-01-08
2023-02-14
1 2 > >> (Page 1 of 2)
  • BASIL HATZILAIOS

    Hello to all!
    I would like to get data from an MMA8452 3axis accelerometer. The sensor connected to I2C port of a PIC18F46K22. Is there an example code for that sensor or similar 3axis (LIS3LV02DQ) ? Thanks.
    Basil

     
  • Anobium

    Anobium - 2023-01-08

    Not that I am aware of.

    But, that is a retired/EOL product.

    Others may be able to advise an alternative.

     
  • BASIL HATZILAIOS

    Is it possible to convert that code to GCBasic?
    https://gist.github.com/enukane/cd687c06f99090789fae
    any alternative similar for MMA8452?

     
    • Anobium

      Anobium - 2023-01-09

      Yes, you should be able to port this with ease. There is nothing complicated above the MMA7452.

       
  • BASIL HATZILAIOS

    Is there a tool to convert above code to GCBasic? any example code about that ?

     
    • Anobium

      Anobium - 2023-01-09

      No converter exists. One could be written but this would take longer that the port by hand.

      It is a case of porting by hand. Relatively easy to port as the source program is very small.

       
  • BASIL HATZILAIOS

    ok. I'll try to make a block diagram of command blocks according to c code.
    1.initialise
    2. collect data from local accelerometer buffers
    3. reads a set of data values from sequential registers of accelerometer
    4. reads a value from a register on the accelerometer
    5. reads from the accelerometer and updates the local x , y , z variables
    6. writes a set of data to sequential registers of accelerometer
    7. writes a data value to a specific register on the accelerometer
    in your opinion what of above blocks must be used and in what sequence?
    thanks.

     
  • BASIL HATZILAIOS

    Many thanks Anobium , mmote for your help!

     
  • mmotte

    mmotte - 2023-01-10

    It was late. I did not finish the initialization. I do not have that chip to test but the pdf says it comes up in "standby".

     
  • mmotte

    mmotte - 2023-01-11

    Great Cow BASIC (0.99.01 2022-01-27 (Linux 64 bit) : Build 1073)

    That's what was on the PC next to my chair watching nothing on TV. I was thinking how hard it would be to build a converter to change code from arduino to GCB. Basil needed some inspiration, so i wrote those few lines of code thinking what it would take. Maybe ChatGPT could do it? It was too busy to let me in yesterday.

     
    • Anobium

      Anobium - 2023-01-11

      The date tells me all.. and, the build number. We have published a newer version for Linux last month.


      Re a converter. I do think we can do this. I would a great addition. Written in JavaScript and then executed in a Browser? I see a compiled EXE for any language as a real problem. I have written Language converters in AWK - this was the best approach for me.

       
  • BASIL HATZILAIOS

    I think that a converter arduino code to GCBasic would be very useful..
    MMA8452_V0_2.gcb would help me to get sensor data.
    below are two codes for the other sensor for that I need to get data MAX30100
    one is from arduino, the other is for PIC18F46K22 that I'll use. Would be very useful to convert one of two to GCBasic..

     
    • Anobium

      Anobium - 2023-01-11

      Does the ZIP in the device .h files? and the device .cpp files? They are required to aid any potential work,

       
  • Anobium

    Anobium - 2023-01-12

    @mmotte

    Do you have a plan for a convertor?

    My idea would still to use AWK as it is interpreted and anyone can hack it. Do the following steps:
    1. Extract the constants from the .H
    2. Extract the methods from the .CPP - this would then show up any missing constants and variables.
    3. Create a patch file of constants and variables based on the output of step 2.
    4. Convert the methods using the output of step 1 to 3.
    5. Convert any application using the methods from the output of step 4.

    Sorted and party!

     
  • mmotte

    mmotte - 2023-01-12

    Anobium , You are very optimistic! I think we need the beer before we start!

    AWK is not a one of my languages. I kind of understand how it works but there is a lot of hidden stuff.

    When I convert .ino's and .lib's ,I usually use a editor and do search and replace OR search and destroy.
    'void's and 'bool' are usually sub or function starts.
    Serial.print is replaced with HSerPrint
    Also in HSerIn we need it buffered without additional setup, uses a define to turn off for smaller chips
    If's need the "then " added and an "end If"
    '{' and '}' and ';' need to be destroyed
    '==' compares are '='
    But the hardest ones are 'floats' because ours don't work.
    Another they always flaunt is 'enum'
    Other edits are discovered as you go!
    Then it takes a bunch of hole filling and glue to make it work.

    BR
    Mike

     
    • Anobium

      Anobium - 2023-01-12

      Beer in the hand.

      I use the same process as you.

      So, this is just about digitising what we do in code.
      Totally, agree on the 'gotchas' the trick will be to do as much as practical with a tool and then to hilite what is not converted.

      You list of 'knowledge' is what we do with some ease. Digitising will be hard but fun.

       
  • Anobium

    Anobium - 2023-01-12

    15 mins work - seriously. My starter.

    This extracts the constants. I got the .H files from GitHub.

    You should have awk or gawk somewhere. GSTOOLS in the Windows installer has it.

    Command line. Passes two files, but, all the ,h could be passed.

    gawk -f ctogcb.awk  MAX30100_Registers.h  max30100.h
    

    Returns

    C:\Users\admin\OneDrive\Desktop>gawk -f ctogcb.awk  MAX30100_Registers.h  max30100.h
    #DEFINE MAX30100_I2C_ADDRESS                    0X57
    #DEFINE MAX30100_REG_INTERRUPT_STATUS           0X00
    #DEFINE MAX30100_IS_PWR_RDY                     (1 << 0)
    #DEFINE MAX30100_IS_SPO2_RDY                    (1 << 4)
    #DEFINE MAX30100_IS_HR_RDY                      (1 << 5)
    #DEFINE MAX30100_IS_TEMP_RDY                    (1 << 6)
    #DEFINE MAX30100_IS_A_FULL                      (1 << 7)
    #DEFINE MAX30100_REG_INTERRUPT_ENABLE           0X01
    #DEFINE MAX30100_IE_ENB_SPO2_RDY                (1 << 4)
    #DEFINE MAX30100_IE_ENB_HR_RDY                  (1 << 5)
    #DEFINE MAX30100_IE_ENB_TEMP_RDY                (1 << 6)
    #DEFINE MAX30100_IE_ENB_A_FULL                  (1 << 7)
    #DEFINE MAX30100_REG_FIFO_WRITE_POINTER         0X02
    #DEFINE MAX30100_REG_FIFO_OVERFLOW_COUNTER      0X03
    #DEFINE MAX30100_REG_FIFO_READ_POINTER          0X04
    #DEFINE MAX30100_REG_FIFO_DATA                  0X05  // BURST READ DOES NOT AUTOINCREMENT ADDR
    #DEFINE MAX30100_REG_MODE_CONFIGURATION         0X06
    #DEFINE MAX30100_MC_TEMP_EN                     (1 << 3)
    #DEFINE MAX30100_MC_RESET                       (1 << 6)
    #DEFINE MAX30100_MC_SHDN                        (1 << 7)
    #DEFINE MAX30100_REG_SPO2_CONFIGURATION         0X07
    #DEFINE MAX30100_SPC_SPO2_HI_RES_EN             (1 << 6)
    #DEFINE MAX30100_REG_LED_CONFIGURATION          0X09
    #DEFINE MAX30100_REG_TEMPERATURE_DATA_INT       0X16
    #DEFINE MAX30100_REG_TEMPERATURE_DATA_FRAC      0X17
    #DEFINE MAX30100_REG_REVISION_ID                0XFE
    #DEFINE MAX30100_REG_PART_ID                    0XFF
    #DEFINE MAX30100_FIFO_DEPTH                     0X10
    #DEFINE DEFAULT_MODE                MAX30100_MODE_HRONLY
    #DEFINE DEFAULT_SAMPLING_RATE       MAX30100_SAMPRATE_100HZ
    #DEFINE DEFAULT_PULSE_WIDTH         MAX30100_SPC_PW_1600US_16BITS
    #DEFINE DEFAULT_RED_LED_CURRENT     MAX30100_LED_CURR_50MA
    #DEFINE DEFAULT_IR_LED_CURRENT      MAX30100_LED_CURR_50MA
    #DEFINE EXPECTED_PART_ID            0X11
    #DEFINE RINGBUFFER_SIZE             16
    #DEFINE I2C_BUS_SPEED               400000UL
    

    So, we have the constants. Clearly, the next step is to resolve the ( 1 << 3 ) type constants.

    The awk program reads all lines into a multiline dimension array. for all files.
    Then, in the END{} routine it loops through the array examining each element for a valid line.

    Enjoy.

     

    Last edit: Anobium 2023-01-12
  • Anobium

    Anobium - 2023-01-13

    Update processor. This now expands enums. Same source now gives expand emun to constants.

    Just also added comments handler.

    My assessment - that .H files converted. Next the CPP files....

    #DEFINE DEFAULT_MODE                MAX30100_MODE_HRONLY
    #DEFINE DEFAULT_SAMPLING_RATE       MAX30100_SAMPRATE_100HZ
    #DEFINE DEFAULT_PULSE_WIDTH         MAX30100_SPC_PW_1600US_16BITS
    #DEFINE DEFAULT_RED_LED_CURRENT     MAX30100_LED_CURR_50MA
    #DEFINE DEFAULT_IR_LED_CURRENT      MAX30100_LED_CURR_50MA
    #DEFINE EXPECTED_PART_ID            0X11
    #DEFINE RINGBUFFER_SIZE             16
    #DEFINE I2C_BUS_SPEED               400000UL
    #DEFINE MAX30100_I2C_ADDRESS                    0X57
    // INTERRUPT STATUS REGISTER (RO)
    #DEFINE MAX30100_REG_INTERRUPT_STATUS           0X00
    #DEFINE MAX30100_IS_PWR_RDY                     1       // BITADDRESS. WAS ( 1 << 0 )
    #DEFINE MAX30100_IS_SPO2_RDY                    16      // BITADDRESS. WAS ( 1 << 4 )
    #DEFINE MAX30100_IS_HR_RDY                      32      // BITADDRESS. WAS ( 1 << 5 )
    #DEFINE MAX30100_IS_TEMP_RDY                    64      // BITADDRESS. WAS ( 1 << 6 )
    #DEFINE MAX30100_IS_A_FULL                      128     // BITADDRESS .WAS ( 1 << 7 )
    // INTERRUPT ENABLE REGISTER
    #DEFINE MAX30100_REG_INTERRUPT_ENABLE           0X01
    #DEFINE MAX30100_IE_ENB_SPO2_RDY                16      // BITADDRESS. WAS ( 1 << 4 )
    #DEFINE MAX30100_IE_ENB_HR_RDY                  32      // BITADDRESS. WAS ( 1 << 5 )
    #DEFINE MAX30100_IE_ENB_TEMP_RDY                64      // BITADDRESS. WAS ( 1 << 6 )
    #DEFINE MAX30100_IE_ENB_A_FULL                  128     // BITADDRESS .WAS ( 1 << 7 )
    // FIFO CONTROL AND DATA REGISTERS
    #DEFINE MAX30100_REG_FIFO_WRITE_POINTER         0X02
    #DEFINE MAX30100_REG_FIFO_OVERFLOW_COUNTER      0X03
    #DEFINE MAX30100_REG_FIFO_READ_POINTER          0X04
    #DEFINE MAX30100_REG_FIFO_DATA                  0X05  // BURST READ DOES NOT AUTOINCREMENT ADDR
    // MODE CONFIGURATION REGISTER
    #DEFINE MAX30100_REG_MODE_CONFIGURATION         0X06
    #DEFINE MAX30100_MC_TEMP_EN                     8       // BITADDRESS. WAS ( 1 << 3 )
    #DEFINE MAX30100_MC_RESET                       64      // BITADDRESS. WAS ( 1 << 6 )
    #DEFINE MAX30100_MC_SHDN                        128     // BITADDRESS .WAS ( 1 << 7 )
    
    // Enum expansion to Constants for MODE
    #DEFINE MAX30100_MODE_HRONLY     0X02
    #DEFINE MAX30100_MODE_SPO2_HR    0X03
    
    // SPO2 CONFIGURATION REGISTER
    // CHECK TABLES 8 AND 9, P19 OF THE MAX30100 DATASHEET TO SEE THE PERMISSIBLE
    // COMBINATIONS OF SAMPLING RATES AND PULSE WIDTHS
    #DEFINE MAX30100_REG_SPO2_CONFIGURATION         0X07
    #DEFINE MAX30100_SPC_SPO2_HI_RES_EN             64      // BITADDRESS. WAS ( 1 << 6 )
    
    // Enum expansion to Constants for SAMPLINGRATE
    #DEFINE MAX30100_SAMPRATE_50HZ       0X00
    #DEFINE MAX30100_SAMPRATE_100HZ      0X01
    #DEFINE MAX30100_SAMPRATE_167HZ      0X02
    #DEFINE MAX30100_SAMPRATE_200HZ      0X03
    #DEFINE MAX30100_SAMPRATE_400HZ      0X04
    #DEFINE MAX30100_SAMPRATE_600HZ      0X05
    #DEFINE MAX30100_SAMPRATE_800HZ      0X06
    #DEFINE MAX30100_SAMPRATE_1000HZ     0X07
    
    
    // Enum expansion to Constants for LEDPULSEWIDTH
    #DEFINE MAX30100_SPC_PW_200US_13BITS     0X00
    #DEFINE MAX30100_SPC_PW_400US_14BITS     0X01
    #DEFINE MAX30100_SPC_PW_800US_15BITS     0X02
    #DEFINE MAX30100_SPC_PW_1600US_16BITS    0X03
    
    // LED CONFIGURATION REGISTER
    #DEFINE MAX30100_REG_LED_CONFIGURATION          0X09
    
    // Enum expansion to Constants for LEDCURRENT
    #DEFINE MAX30100_LED_CURR_0MA       0X00
    #DEFINE MAX30100_LED_CURR_4_4MA     0X01
    #DEFINE MAX30100_LED_CURR_7_6MA     0X02
    #DEFINE MAX30100_LED_CURR_11MA      0X03
    #DEFINE MAX30100_LED_CURR_14_2MA    0X04
    #DEFINE MAX30100_LED_CURR_17_4MA    0X05
    #DEFINE MAX30100_LED_CURR_20_8MA    0X06
    #DEFINE MAX30100_LED_CURR_24MA      0X07
    #DEFINE MAX30100_LED_CURR_27_1MA    0X08
    #DEFINE MAX30100_LED_CURR_30_6MA    0X09
    #DEFINE MAX30100_LED_CURR_33_8MA    0X0A
    #DEFINE MAX30100_LED_CURR_37MA      0X0B
    #DEFINE MAX30100_LED_CURR_40_2MA    0X0C
    #DEFINE MAX30100_LED_CURR_43_6MA    0X0D
    #DEFINE MAX30100_LED_CURR_46_8MA    0X0E
    #DEFINE MAX30100_LED_CURR_50MA      0X0F
    
    // TEMPERATURE INTEGER PART REGISTER
    #DEFINE MAX30100_REG_TEMPERATURE_DATA_INT       0X16
    // TEMPERATURE FRACTIONAL PART REGISTER
    #DEFINE MAX30100_REG_TEMPERATURE_DATA_FRAC      0X17
    // REVISION ID REGISTER (RO)
    #DEFINE MAX30100_REG_REVISION_ID                0XFE
    // PART ID REGISTER
    #DEFINE MAX30100_REG_PART_ID                    0XFF
    #DEFINE MAX30100_FIFO_DEPTH                     0X10
    
     

    Last edit: Anobium 2023-01-13
  • Anobium

    Anobium - 2023-01-13

    Next, CPP conversion will be a tad harder. I am thinking.

    Examination of each type of method will be required. BOOL, VOID, uint8_t (BYTE), FLOAT and uint16_t (WORD). For each type of method the conversion will be processed independently.

    Parameters will be determined, including type or pointer. Then, process the internal code for the method.

    This convert will never handle every piece of code. But, if is gets 50% there... it will be better then nothing. And, the conversion program can be improved as others use it for more and more conversions.

     
  • mmotte

    mmotte - 2023-01-13

    Anobium got me GAWKing!

    Very good! I just ran your awk script and got the same output. Always one more programming language to learn.

    On the web they only give 2 liners. This much better example. And you gave the command line!

    Thanks
    Mike

     
    • Anobium

      Anobium - 2023-01-13

      Let me add one method handler. I designed a compilation method that will process the routines a few time. 1) Indentify the methods masking off all the code in the methods 2) Go back through identifying the parameter types 3) Go back thru handling all the code. This was all the methods are 'known' and the parameters 'known'. This step will expand the C code into GCBASIC.

      Actually, should work and be pretty easy to maintain.

       
1 2 > >> (Page 1 of 2)

Log in to post a comment.