I`m trying to read a weigh value from a scale with the code above and using the this library https://github.com/bogde/HX711

arduino = DeviceOpen["Arduino", "COM3"]
DeviceConfigure[arduino, "Upload" -> {"Libraries" -> 
Initialization -> "HX711 scale(A1,A0);
 void setupScale()
"Functions" -> <|
  "Scale" -> 
   ArduinoCode[<|"ArgumentTypes" -> {}, "ReturnType" -> Real, 
     "Code" -> "
      float medicao()
      return scale.get_units(10);

I know that Arduino code works because I tested in Arduino IDE before and works, but when I use in Mathematica an it just shows me the output below -[Infinity].

[enter image description [1]

I wanna know what is causing this and how I fix it.


Difficult question to answer, because it's impossible to verify any proposed solution. I can merely guess what the problem is:

  1. I don't think that BaudRate should be specified in the Arduino code. I'd write: DeviceOpen["Arduino", {"COM3", "BaudRate" -> 38400}]

  2. Your setupScale()-function is in fact never executed. It's prepended to the Arduino sketch but never executed. You need to call it too! The standard way of doing this would be to add byte initScale = 0; in the initialization code, and then in the Scale-function add:

    if (!initScale) { initScale = 1; setupScale(); }

That way, the setup function will be run the first time you call the function.

Try these things and see if it works.

(For some example code, look here: Direct Pressure Data Acquisition with Mathematica and Arduino)

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.