Converting byte array or String value to float in P5.js (javascript based)

I have been successful in getting serial data in P5.js sketch using this – GitHub – p5-serial/p5.serialport: Serial Port API and Server for p5.js library as either byte array or string values.

When I tried converting string to float type using float() – I get a lot of NaN values which shouldn’t be coming since data is numerical.

Alternatively, I then tried getting data from serial port as byte array. I can’t find a way to convert this array to my original float value in P5.js.

Any ideas on how to convert byte array to float or avoid getting NaN when converting string to float?

Appreciate your time and help. Thanks.

Codes I have tried for conversion:

  1. From String to float, I used

    let incomingData;
    let dataValue;
    incomingData = serial.readStringUntil('\n');
    dataValue = float(incomingData);  //standard method in P5.js -- returns NaN values

I also tried parseFloat() —

  dataValue = parseFloat(incomingData);
  //again returns maximum values as NaN
  1. From byte array to float

    let incomingBytes = [];
    let dataValue;
    incomingBytes = serial.readBytesUntil('\n');
    dataValue = dataView.getFloat64(bytebuffer); 
    // This javascript method is not supported by P5.js it seems

original data in arduino
string data in P5.js
NaN after converting to float
array of converted values - a lot of NaN
array of string data without conversion

171 thoughts on “Converting byte array or String value to float in P5.js (javascript based)”

  1. Unquestionably believe that which you stated.
    Your favourite justification seemed to be at the internet the easiest thing
    to remember of. I say to you, I certainly get irked while people think about concerns that they just do not recognize about.

    You controlled to hit the nail upon the top and defined out the entire thing without
    having side effect , folks can take a signal.
    Will probably be back to get more. Thanks

  2. Pingback: buy ivermectin
  3. Pingback: deltasone 40mg