Go Down

Topic: Arduino Due using Native USB to communicate with Mettler Toledo scale (Read 98 times) previous topic - next topic

Hi all,

I am working on a conceptually very simple project involving connecting an Arduino Due to a Mettler Toledo precision scale.  The Arduino would receive instructions and then send back information on the programming USB port to the controlling computer.  It would send tare and weighing instructions to the scale on the native USB port, and then read weights.  The Arduino would open and close solenoids in a certain sequence based on parameters sent from the computer, and weight information sent from the scale.  This is all dirt slow by computer standards - 9600 baud is certainly fast enough.

The scale has a USB (slave) connector.

The computer and relay system sides are solved.  I've even built a cute little "bridge" circuit board with 2n2222 transistors to drive a SainSmart 12V 16 relay board.

However, connecting the Arduino to the scale through the native port, as simple as it would seem, has been a stopper.  One would think that all one would need to do is use SerialUSB commands (begin println, available, readString, etc.)  to send a simple command to the scale and wait for the 20-or-so byte return text.  However, it appears that the instructions to the scale are not going through.
 
I have checked out the scale communications side by using a terminal program from the PC directly to the scale via USB.  This works very well at 9600 baud.  So the problem appears to be getting the communications straight between the Arduino native USB port and the scale.

I have tried hundreds of combinations and settings with no result with the scale apparently not getting the communication from the Arduino.  If you offer suggestions I'll either try and confirm or advise that I had already tried your suggestion.

Here is some simple typical Arduino test code that I used to test the communication issue.

Code: [Select]


String strCommand;
String strReturn;
unsigned long sCount;

void setup()
  {   
  Serial.begin(9600);
  SerialUSB.begin(9600);
  sCount=0
  }

void loop()
  {
  Serial.println("Enter command: "); //Prompt User for input from Arduino terminal
  while (Serial.available()==0)  {}
  strCommand=Serial.readString();
  Serial.println(strCommand);              //Check to make sure string was received

//  Okay to here
//  Problem appears to start here

  while(SerialUSB.available())
    { 
    SerialUSB.println(strCommand); //Native USB LEDs don't flash
    }
  if (SerialUSB.available() > 0
    {
    strReturn = SerialUSB.readString();
    sCount=0;
    }
  else
    {
    delay(500);      //If no return, create a timeout
    sCount=sCount+1;
    if (sCount == 10)
      {
      strReturn = "No Return";
      break;
      sCount=0;
      }
    }
  Serial.println(strReturn);
  }



This should be very simple problem to solve.  I sincerely appreciate any feedback.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy