Modbus IEE754 Float convert from Arduino

Hello, I’m new here.

I am trying to read an Eastron smart meter with Modbus IEE754

I sent the modbus string to Smartmeter and received the bytes.

But this is the IEE75 with floating point. I found an Arduino code that works well, but I don’t understand it and therefore can’t implement it in processing.


//uint32_t VAL = 0x4368DBD9; //232.86
  uint32_t VAL = 0xc3663334; //-230.2
//uint32_t VAL = 0x43663334; //230.2

float X = *(float*) & VAL;

Serial.println(X) ;

It would be nice if someone could help me there.

Greeting Holger

Hello @Holle ,

Processing (JAVA)

I gleaned some insight from here:
https://www.baeldung.com/java-convert-float-to-byte-array

Arduino (C++)

This may help to understand that snippet of code:

C in a Nutshell Chapter 4. Type Conversions In C

See section on Implicit Pointer Conversions.

Some code I dabbled with:

Arduino Code < Click to open!
uint32_t v0 = 0xc3663334; // This has an address in memory

void setup()
  {  
  Serial.begin(9600);
  uint32_t x0 = v0;
 
  int address = &v0;        // address of v0
  Serial.println(address);  // prints address

  Serial.println(x0) ;      // prints integer value
  
  uint32_t *p1 = &v0;       // pointer to v0
  float x1 = *p1;           // This won't work! 
  Serial.print("x1: ");
  Serial.println(x1);

  uint32_t *p2 = &v0;       // pointer to v0
  uint32_t x2 = *p2;        
  Serial.print("x2: ");
  Serial.println(x2);

  uint32_t *p3 = &v0;
  float x3 = *(float*)p3 ;  // Implicit conversion to float works!
  Serial.print("x3: ");
  Serial.println(x3); 
  }

void loop() 
  {
  }

:)

2 Likes

Hallo glv
Thats works :slight_smile:
Many thank for this.
Greating Holle

float f = Float.intBitsToFloat( inBuffer[3]<<24 | inBuffer[4]<<16 | inBuffer[5]<<8 | inBuffer[6] );
println(f);
1 Like