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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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..
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!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
Not that I am aware of.
But, that is a retired/EOL product.
Others may be able to advise an alternative.
Is it possible to convert that code to GCBasic?
https://gist.github.com/enukane/cd687c06f99090789fae
any alternative similar for MMA8452?
Yes, you should be able to port this with ease. There is nothing complicated above the MMA7452.
Is there a tool to convert above code to GCBasic? any example code about that ?
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.
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.
hi Basil
@mmotte Very nice - great job!
A new demo added.. I just changed the layout. :-)
https://github.com/GreatCowBASIC/Demonstration_Sources/blob/main/Accelerometer_Solutions/MMA8452_basic_operationsgcb.gcb
Last edit: Anobium 2023-01-10
Many thanks Anobium , mmote for your help!
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
Updated demo @ https://github.com/GreatCowBASIC/Demonstration_Sources/blob/main/Accelerometer_Solutions/MMA8452_basic_operationsgcb.gcb
I have added the missing END SUB. I am interested to see your ASM file for MMA8452_V0_2.gcb I want to understand how the missing END SUB compiled.
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.
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.
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..
Does the ZIP in the device .h files? and the device .cpp files? They are required to aid any potential work,
https://github.com/oxullo/Arduino-MAX30100/find/master
@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!
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
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.
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.
Returns
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
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....
Last edit: 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.
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
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.