Send anlog input into 6 bytes overs I2C

Hello everyone !

I would like to use a specific option of Lascar SGD24M ,where we can use I2C bus (or SPI) to send multi informations.

The protocol need 6 bytes data in ASCII form .

I realized simple static informations, which appear on the display .

Now I 'm trying to send analog value read on input ,but after long search :

How can I sent for example my result "sensorValue" from an analog potentiometer into 6 ascii bytes ?

I join my little sketch and the specific protocol

With a uart reply , My display have "+4.321" write on display .

Thanks for any help

v1.3.ino (943 Bytes)

Multidigit.pdf (417 KB)

When you do a println with a floating point number, you can specify the number of decimal places.
If that doesn't work, there is always sprintf() which has more options.

Hi BLH64 !

Thanks in advance from your help!

With remainder "%" I found a sketch which use it and realized 4 cut ,from thousand to unit of my analog input

The serial monitor display the 4 cut of 0 to 1023 into 1 0 2 3 ( four bytes) .

And can display my four bytes into HEX byte with the function HEX with the code :

"Serial.print(analogInput, HEX);"

But

This is with the I2C communication where I have some problem ,in particularly to convert the value into HEX value

Like Serial.print ,I tryed that :

"Wire.write(analogInput, HEX);"

Without any success > Error code

I'm tested different code to convert directly a decimal value from my analog into hex value on I2C ,but I'm so stopped now .

If you have any idea ,thanks in advance

A second reply from me ,

I found my solution after lots of long hours ,and many hairs pulled !

I thought ,that my solution could be mathematical ...

I explain :

For working my display must receive 6 bytes data in ascii format ,

My error were ,I would always want to sent my bytes in hexadecimal format ,where this format specific need to be converted before ,be sent .

After reflexion and a view on the ascii table , 0x32 in hexadecimal is like 2 in ascii
But 50 in decimal is like 2 in ascii too !

This is more easy to join the fixed value 48 + the variable value from my analog ,to obtain a decimal code ,which can be read by my display .

Before

//

int m=(valeur-valeur%1000)/1000);
int c=(valeur%1000-valeur%100)/100);
int d=(valeur%100-valeur%10)/10);
int u=(valeur%10);

//

After

//

int m=(48+(valeur-valeur%1000)/1000);
int c=(48+(valeur%1000-valeur%100)/100);
int d=(48+(valeur%100-valeur%10)/10);
int u=(48+(valeur%10));
//

(Sorry for the comment missing, this is a quick code)

When a 0 value is obtained with the variable "m"
0+48 = 48 decimal ,in ascii 48 is 0

When a 5 value is obtained
5+48 = 53 decimal ,in ascii 53 is 5

I'm so happy !!!!

Now I can pass to another part of my project

Thank you Arduino !