# Modbus IEE754 Float convert from Arduino

**URL:** <https://discourse.processing.org/t/modbus-iee754-float-convert-from-arduino/38971>\
**Category:** Electronics (Arduino, etc.)\
**Created:** [September 25, 2022, 7:47am UTC](https://discourse.processing.org/t/modbus-iee754-float-convert-from-arduino/38971 "2022-09-25T07:47:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Holle](https://avatars.discourse-cdn.com/v4/letter/h/50afbb/32.png) [@Holle](https://discourse.processing.org/u/Holle)\
**Post date:** [September 25, 2022, 7:47am UTC](https://discourse.processing.org/t/modbus-iee754-float-convert-from-arduino/38971/1 "2022-09-25T07:47:49Z")

</div>

Hello, I’m new here.

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

> **[SDM630Register1-5.pdf](https://bg-etech.de/download/manual/SDM630Register1-5.pdf)**
>
> 512.87 KB

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.

```auto

//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

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [September 25, 2022, 1:01pm UTC](https://discourse.processing.org/t/modbus-iee754-float-convert-from-arduino/38971/2 "2022-09-25T13:01:45Z")

</div>

Hello @Holle ,

**Processing (JAVA)**

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

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/1/b/1bf6e78db55350cb40c1844b82b40dde50bf3abc.png)

**Arduino (C++)**

This may help to understand that snippet of code:

[C in a Nutshell Chapter 4. Type Conversions In C](https://www.oreilly.com/library/view/c-in-a/0596006977/ch04.html)

See section on _Implicit Pointer Conversions_.

Some code I dabbled with:

> **Arduino Code \< Click to open!**
>
> ```auto
> 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() 
> {
> }
> 
> ```

`:)`

---

<div class="post-metadata">

**Author:** ![Holle](https://avatars.discourse-cdn.com/v4/letter/h/50afbb/32.png) [@Holle](https://discourse.processing.org/u/Holle)\
**Post date:** [September 26, 2022, 7:34am UTC](https://discourse.processing.org/t/modbus-iee754-float-convert-from-arduino/38971/3 "2022-09-26T07:34:40Z")

</div>

Hallo glv  
Thats works 🙂  
Many thank for this.  
Greating Holle

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

```
