Type conversion not working? ESP32 Wroom

For general Flowcode discussion that does not belong in the other sections.
chipfryer27
Valued Contributor
Posts: 1110
http://meble-kuchenne.info.pl
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 278 times
Been thanked: 397 times

Re: Type conversion not working? ESP32 Wroom

Post by chipfryer27 »

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

BenR
Matrix Staff
Posts: 1707
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 435 times
Been thanked: 598 times

Re: Type conversion not working? ESP32 Wroom

Post by BenR »

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.

MJU20
Posts: 237
Joined: Tue Dec 08, 2020 5:11 pm
Has thanked: 75 times
Been thanked: 50 times

Re: Type conversion not working? ESP32 Wroom

Post by MJU20 »

BenR wrote:
Wed Jul 27, 2022 3:45 pm
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.
This seems great news!
Is the update already available? I just did an update but the problem stays..
After many nightly hours I really want this to work.

medelec35
Matrix Staff
Posts: 1432
Joined: Wed Dec 02, 2020 11:07 pm
Has thanked: 506 times
Been thanked: 469 times

Re: Type conversion not working? ESP32 Wroom

Post by medelec35 »

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.
Martin

MJU20
Posts: 237
Joined: Tue Dec 08, 2020 5:11 pm
Has thanked: 75 times
Been thanked: 50 times

Re: Type conversion not working? ESP32 Wroom

Post by MJU20 »

@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!!

BenR
Matrix Staff
Posts: 1707
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 435 times
Been thanked: 598 times

Re: Type conversion not working? ESP32 Wroom

Post by BenR »

Ok I'll look intot he WriteInt function thanks for letting us know you've got some progress.

Post Reply