Hi Martin
In a previous example my chart documented a conversion from float to 4 x bytes, then took those bytes and converted back into a float. There doesn't appear to be any issue with the conversion. However if when I tried to convert say three bytes and an integer (as defined in variable properties) then the conversion failed.
Following on from your post saying that it shouldn't matter, I revisited the chart and discovered that with the integer initial value set at "zero" the conversion didn't seem to work. However, and in a "Doh...! moment" I'd replaced the MSB with the integer (x=0) meaning that the conversion did work, just returning a very small value indeed, which was subsequently decimal placed "out". Replacing LSB with "x" worked fine.
Regards
Type conversion not working? ESP32 Wroom
-
- Valued Contributor
- Posts: 1528
- http://meble-kuchenne.info.pl
- Joined: Thu Dec 03, 2020 10:57 am
- Has thanked: 353 times
- Been thanked: 549 times
-
- Matrix Staff
- Posts: 1926
- Joined: Mon Dec 07, 2020 10:06 am
- Has thanked: 503 times
- Been thanked: 686 times
Re: Type conversion not working? ESP32 Wroom
Hello,
Me and Medelec35 have been exploring the TypeConversion problem with Float variables on the ESP hardware and there was indeed a problem. But hopefully with the latest library updates this should solve things. At least it's now working correctly for us.
We were defining the float variable as a double and so the variable was 64-bits instead of 32-bits and hence not mapping correctly with the 32-bit type converter union. Hopefully float calculations are faster now too.
Me and Medelec35 have been exploring the TypeConversion problem with Float variables on the ESP hardware and there was indeed a problem. But hopefully with the latest library updates this should solve things. At least it's now working correctly for us.
We were defining the float variable as a double and so the variable was 64-bits instead of 32-bits and hence not mapping correctly with the 32-bit type converter union. Hopefully float calculations are faster now too.
Regards Ben Rowland - MatrixTSL
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel
Re: Type conversion not working? ESP32 Wroom
This seems great news!BenR wrote: ↑Wed Jul 27, 2022 3:45 pmHello,
Me and Medelec35 have been exploring the TypeConversion problem with Float variables on the ESP hardware and there was indeed a problem. But hopefully with the latest library updates this should solve things. At least it's now working correctly for us.
We were defining the float variable as a double and so the variable was 64-bits instead of 32-bits and hence not mapping correctly with the 32-bit type converter union. Hopefully float calculations are faster now too.
Is the update already available? I just did an update but the problem stays..
After many nightly hours I really want this to work.
-
- Matrix Staff
- Posts: 1923
- Joined: Wed Dec 02, 2020 11:07 pm
- Has thanked: 623 times
- Been thanked: 645 times
Re: Type conversion not working? ESP32 Wroom
Hello.
You can tell if you have had the update.
If you check for updates and have Full database selected and Show up-to date files ticked, then within the Core System files section, scroll down until you see ESP\ESP_CAL_TypeDefs.c
You should be on revision 3.
As you could have made changes to your project, if you post it then I will take a look at it for you.
I can confirm that the ESP32 device I was using does convert from float to UInt and from UInt to float OK.
You need to remember that each EEPROM address is 16bits wide and not 8bits
For example, if you save at address 0, then two bytes are used, whereas if you save on an 8bit pic then only one byte will be used.
For that reason use UInt to move from EEPROM to a float variable and vice versa and not bytes.
You can tell if you have had the update.
If you check for updates and have Full database selected and Show up-to date files ticked, then within the Core System files section, scroll down until you see ESP\ESP_CAL_TypeDefs.c
You should be on revision 3.
As you could have made changes to your project, if you post it then I will take a look at it for you.
I can confirm that the ESP32 device I was using does convert from float to UInt and from UInt to float OK.
You need to remember that each EEPROM address is 16bits wide and not 8bits
For example, if you save at address 0, then two bytes are used, whereas if you save on an 8bit pic then only one byte will be used.
For that reason use UInt to move from EEPROM to a float variable and vice versa and not bytes.
Martin
Re: Type conversion not working? ESP32 Wroom
@Matrix Staff,
Medelec35 helped me behind the scenes to get this working.
I don't know if he already informed you, but the "WriteInt" from the EEprom macro was the problem.
By using just the normal "Write" it worked.
The ReadInt works, but only the WriteInt has a problem?
Thanks to anyone that helped!!
Medelec35 helped me behind the scenes to get this working.
I don't know if he already informed you, but the "WriteInt" from the EEprom macro was the problem.
By using just the normal "Write" it worked.
The ReadInt works, but only the WriteInt has a problem?
Thanks to anyone that helped!!
-
- Matrix Staff
- Posts: 1926
- Joined: Mon Dec 07, 2020 10:06 am
- Has thanked: 503 times
- Been thanked: 686 times
Re: Type conversion not working? ESP32 Wroom
Ok I'll look intot he WriteInt function thanks for letting us know you've got some progress.
Regards Ben Rowland - MatrixTSL
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel