Error reading uint8 values while trying to read serial information from a scale for mass-based flow calculation

This could make sense, we will check this out.

Absolutely! Arduino (MCUs in general) is actually intended for such low level tasks.

1 Like

yes - the arduino can play the middle man interpreting each sensor's specifics and build a payload to send all the meaningful data to MATLAB.

1 Like

Yes

The Arduino can run all the time. You can start matlab whenever you want; the only problem might be the synchronisation. You can study Robin's updated serial input basics to get ideas how to solve that problem.

1 Like

This makes much more sense. Do you anticipate that refining all of our signal data on the Arduino before we send it to MATLAB would also make our code faster on MATLAB, since less interpretation is required in our main script?

This is extremely helpful. Thank you.

and note the fact that the MEGA will reboot when MATLAB opens the serial connection

How difficult do you anticipate synchronizing to be? If we have the baudrates of the Arduino and the PC set the same, they should sync up, right? Or am I being naive.

What exactly occurs upon rebooting? Is it a simple restart or does it clear the Arduino code that we have uploaded? We will want the code that we write and upload to the Arduino to always be on the Arduino, no matter what we do to the MATLAB program.

OK, think about it this way

Your Mega is continuously sending data like 123g, 456g, 33g etc.
Now you start your matlab program; it drops in the middle of the conversation and it received 56g, 33g etc. So you're first data that matlab sees is wrong as it should have been 456g.

But @J-M-L has a point about the reset (I forgot about that) so the risk is a little smaller that it goes wrong because the Mega anyway restarts. However, it's anyway a good idea to add hardening/synchronisation to the communication protocol.

Notes:

  1. A reset of the Arduino will not wipe the code.
  2. You will have a problem when connecting 5 scales. There are only 3 spare UARTs available; you can add a single SoftwareSerial but you're still one short.

Can you post the user manual / protocol specification of the scale; if you can query the scale on command, you can use multiple SoftwareSerial instances.

Oh yes, forgot to touch on that part. We are planning on utilizing two separate Arduinos to expand the number of ports we have available. From preliminary research, we believe this is possible; would it be?

Yes, for sure. It is hard to do such low-level data manipulations with Matlab, and the code is messy. Easy with Arduino.

Post a link to the scale user manual and people can help with the Arduino code to interpret the data.

Communication between two boards usually makes life more complicated but it can be done. I'm not familiar with matlab but see if you can open two serial ports in matlab, one for your one Arduino and one for your other one.

Yes. Here is the link to the scale manual.

Unfortunately the second board is still in the mail, but we will try as soon as we can.

The scale manual linked in post #34 doesn't seem to describe the serial data protocol, or the options. Please check for a separate Application Note or User Guide.

Will do

Is this not the serial information, or am I mistaken? On page 207

You will have to look at your settings of the scale. By default it has Xon/Xoff; this can result in the Xon and Xoff characters being send confusing you and your matlab. Maybe switch that off for testing.

And there is continuous mode; the name implies that it might be possible to only get data from the scale on request (you send a command, the scale gives the data back.

Yes, Matlab can handle multiple serial communication ports open at the same time

so basically MEGA #1 handles 3 scales, MEGA #2 handles the two others

just need to secure the protocol so that communication include the scale number. May be the payload can still be ascii but with some additional info like "<1,234>" which would say scale#1 read 234 g. The '<' and '>' would serve as start and end markers to sync the Matlab code with the Serial streams.