RE: UDP Receive funny outputs from arduino numeric input

Hi,

sorry for not posting in the correct format previously, so I am going to try again.

As I was saying, I’ve been working on an arduino project where the sensor from arduino will broadcast input to the ethernet thru UDP and the computer will receives the UDP packets on the other end. The connection is fine and I can receive the data well using normal analogread method.

However, I would like to try this oversampling method from ElectricRCAircraftGuy; but when i did so, i started to receiving wierd symbol on the receiving side (C#) whereas the arduino serial monitor still shows numeric inputs.

Here are a few pictures to help better understand the situation

This is the arduino code I am using;

#include <Ethernet2.h>
#include <EthernetUdp2.h>
#include <eRCaGuy_analogReadXXbit.h>

#include <SPI.h>      

EthernetUDP Udp;

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address

//the IP address is dependent on your network
IPAddress localIp(192, 168, 0, 192);
IPAddress destIp(192, 168, 0, 186);
unsigned int Port = 5555;

float val[9];
int counter = 0;
eRCaGuy_analogReadXXbit adc;
uint8_t bits_of_precision; //bits of precision for the ADC (Analog to Digital Converter)
float analog_reading; //the ADC reading
float V; //Voltage calculated on the analog pin
unsigned long num_samples;
const uint8_t pin = A0; //analogRead pin
const float MAX_READING_10_bit = 1023.0;

void setup() {
  // start the Ethernet and UDP:
  Ethernet.begin(mac, localIp);
  Udp.begin(Port);
  Serial.begin(115200);
}

void loop() 
{
    num_samples = 100; //Averaging for Increased Accuracy
    do_a_bunch_of_samples(num_samples);
}

void do_a_bunch_of_samples(unsigned long num_samples)
{
  //10-bit ADC reading
  bits_of_precision = 10; //bits of precision for the ADC (Analog to Digital Converter)
    for (int x=0; x <10; x++){
    analog_reading = adc.analogReadXXbit(pin,bits_of_precision,num_samples); //get the avg. of [num_samples] 10-bit readings
    val[x]= analog_reading*100;
    counter=counter+1;
    }
    
  //Print the results
  if (counter>9){  
    for(int i = 0; i < 10; i++)
    {
      delay(1000);
    Serial.println(char(val[i]));
    Udp.beginPacket(destIp, Port);
    Udp.write(float(val[i]));
    Udp.endPacket();
    }
  counter=0;
  }
}


As you can see, the serial monitor displays normal numerical digits.


However, on the C# side, the outputs are gibberish, i tried listening to the UDP packets with other pragrams like SocketTest too, but the out are the same.


I did some testing and found some clue on why it is printing random symbols when I edited my data type for serial print to char, however I still can’t find a way to fix it.

Any help is deeply appreciated thank you!