Getting weight datapoints from an analytical scale through Arduino

Goodmorning,

I am running another little project and I am looking for any insight or suggestion, please.

MY GOAL: I want to gather data from a scale (Adam Equipments W-series, WA210 rev B) and made them available on an SD card through Arduino UNO or better online (web server or whatever) so they are fully accessible from my Android or PC (in remote).

WHERE I AM: At the moment I was able to connect the scale (through a null serial-to-USB adaptor cable) to my laptop. I am gathering the data through Putty and logging them in a .csv file. (If anyone needs any help on how to do this I am available to help).

So, I know that I can get data from the scale through its COM port (serial) but I would not like to keep my laptop busy/connected all the time, you know :slight_smile: I would like to use my Arduino and achieve what I explained in "MY GOAL" above.

This is a fresh project and any help that will make me have a go will be greatly appreciated.

P.S. My lab from Oxygen sensor, to T/RH and now this is becoming really "intresting" :slight_smile: :slight_smile: :slight_smile:

M.

Nice idea! Should be a fun, reasonably easy project too I think, especially as you're already reading the data with something as simple as PuTTY (rather than the special ADAM data acquisition software).

First thing I think you need to address: Arduino serial isn't proper RS232 - the signals have the same form but the voltages are different. So you'll need something like a MAX232 to translate the voltages.

Then I think the famous Serial Input Basics thread will probably be a good place to go next.

Let me know how you get on. We've got quite a few RS232 scales in the lab I run here. :slight_smile:

GypsumFantastic:
Nice idea! Should be a fun, reasonably easy project too I think, especially as you're already reading the data with something as simple as PuTTY (rather than the special ADAM data acquisition software).

First thing I think you need to address: Arduino serial isn't proper RS232 - the signals have the same form but the voltages are different. So you'll need something like a MAX232 to translate the voltages.

Then I think the famous Serial Input Basics thread will probably be a good place to go next.

Let me know how you get on. We've got quite a few RS232 scales in the lab I run here. :slight_smile:

Dear GypsumFantastic,

thanks a lot for your suggestions/insights and future availability.

I studied the MAX232 chip and I understood ( hopefully :slight_smile: ) what is doing. Here my plan:

  1. buy the following item that use the MAX232 and makes a rs232 port available (very convenient I would say):
    http://www.gearbest.com/development-boards/pp_139898.html?currency=GBP&vip=760169&gclid=CjwKEAiAz4XFBRCW87vj6-28uFMSJAAHeGZbvOmLUTwwnAmHTiSAIDapAwwrzIB9tmRZ54RCTLtiYhoCN1rw_wcB
    What do you think?

  2. Wire it up with the Arduino, studying the pins that will enable the serial communication: I am suggesting digital pins 0 and 1. Hopefully I am not wrong here. But I can read further.

  3. Once Arduino is able to read the same values as Putty on the serial screen, I believe is pretty straightforward - using the knowledge acquired in the other 2 projects I am running (the T/RH project through the DHT22 and the Oxygen project Oxygen content inside a sealed SMALL space - Project Guidance - Arduino Forum) - to write the readings on the SD card.

Any further suggestion will be helpful.

Hi, I am finally back.

So I bought that item in the previous post RS232 Serial Port To TTL Converter Module.
I read this thread Serial basics updated (Hopefully I understood something :))

My connections are:

Vcc --> 5V
Gnd --> GND
RX --> D0
TX --> D1

My first code is (no errors while compiling):

// Code for receiving the data from my analytical scale through RS232

// Libraries
#include <LiquidCrystal.h>; // Includes the libraries for the LCD
#include <SPI.h>; // Includes the libraries for the Serial Peripheral Interface that allows the Master (Arduino) to control a slave device
#include <SD.h>; // Includes the libraries for the SD card

// Interface and Objects definitions
LiquidCrystal lcd(8, 9, 4, 5, 6, 7); // Creates a LCD LiquidCrystal object
const int chipSelect = 10; // Assigns the pin for the SPI-SD chip selection
boolean newData = false;
char receivedData;

void setup()
{
  Serial.begin(9600);
  boolean newData = false;
  pinMode(chipSelect, OUTPUT); // Ensures that the SPI-SD selection pin is an output
  lcd.begin(16, 2); // Initialises the interface to the LCD screen, and specifies the dimensions
  // Initialising sensor and SD card:
  lcd.clear(); // // Clears the LCD screen and positions the cursor in the upper-left corner
  if (!SD.begin(chipSelect)) // Checks if the SD card is working
  {
    lcd.println("SD failed!");
    delay(6000);
    return;
  }
}

void loop() 
{
  recvData();
  showData();
  saveData();
}

void recvData()
{
  if (Serial.available() > 0)
{
  receivedData = Serial.read();
  newData = true;
}
}

void saveData()
{
  if (newData == true)
  {
    File readings = SD.open("readings.csv", FILE_WRITE); // Opens the file on the SD card
    if (readings) // If the file opened OK, write to it on SD card
    {
      readings.println(receivedData); // Saves the data on the SD card
      readings.close(); // Closes the file to save the data on the SD card
    }
    else // If the file didn't open, print an error
    {
      lcd.println("FILE NOT OPEN");
      delay(6000);
      newData = false;
    }
  }
}

void showData()
{
  lcd.print(receivedData);  // Prints the data on the LCD screen
}

I am trying to get the data transmitted from my scale and save them on an SD card. If I connect the scale to a PC with Putty I have a flow of data on the screen (I set up the scale to send them already), so I would like to save THAT flow on a file on an SD card.
I left the LCD screen from a previous project to just double check for error e.g. SD card not read or file not opened. Also, I am trying to show the flow of the data on the LCD (but at this stage is not fundamental).

Please, forgive me, I cannot try the scale because it will be "busy" for 2 days, but please help me anyway.

I just connected the Arduino with the RS232 converter to my PC with Putty:

  1. If I transmit something like "Serial.print('Hi');" or another string it shows on Putty a series of weird symbols and then after 5-6 lines it stops writing. I do not know what is going on, but I believe it is transmitting, so the connection Arduino - Putty is there, right? :slight_smile:

After this, I tried to make the Arduino receiving something so I started typing some character (just pushing keyboard randomly) expecting to have something on my LCD screen (on Putty I did not have anything of course) and on the SD card CSV file. BUT no luck.

Any help from GypsumFantastic, Robin2, or any other experts in the field will be really appreciated. To start with just to know if I am going in the right direction :slight_smile:

Thanks a lot, really thanks.

Mario

void recvData()
{
  if (Serial.available() > 0)
{
  receivedData = Serial.read();
  newData = true;
}

That code reads one byte, only, not the entire message. How is the message from the scale formatted? Is there a terminating character (like a carriage return and/or line feed)?

I am suggesting digital pins 0 and 1. Hopefully I am not wrong here. But I can read further.

If you want to read from the scale and use the serial monitor to troubleshoot the sketch you can't use pins 0 and 1 (the hardware serial port) for the scale. Only 1 device can use a serial port. You could use one of the software serial libraries for the scale if you have an Uno or a different hardware serial if using a Mega or one of the other boards with multiple hardware serial ports.

Dear groundfungus, thanks for your contribution.

groundfungus:
That code reads one byte, only, not the entire message. How is the message from the scale formatted? Is there a terminating character (like a carriage return and/or line feed)?

Without Arduino UNO, I am able to show the data flow on Putty session screen. I am then able to log them through Putty "log all session output" option to obtain a CSV file as below (G is for "gram" and the "OK" is because the scale display shows on "OK" once it reaches equilibrium):


animated gif hosting

In order to show the data flow on Putty session screen, I just followed the scale user manual, setting up the parameters such as continuous reading, time step, etc. etc.

Something like (please refer to user manual attached for better understanding, but not fundamental, it is just to get an idea):

031517 ENTER 100 STORE (date)
150320 ENTER 101 STORE (time)
0 ENTER 79 STORE (date/time printed out)
30 ENTER 89 STORE (time step, here 30sec)

Just for reference the serial parameter of Putty - scale communication are:

Baud rate: 9600
Data bit: 7
Parity bit: NONE
Stop bit: 1

Of course, I would like to read the whole message (the whole data flow). How could I do that?

I did not put any terminating character, the scale was sending the data with date, time, reading with that format ALREADY.

groundfungus:
If you want to read from the scale and use the serial monitor to troubleshoot the sketch you can't use pins 0 and 1 (the hardware serial port) for the scale. Only 1 device can use a serial port. You could use one of the software serial libraries for the scale if you have an Uno or a different hardware serial if using a Mega or one of the other boards with multiple hardware serial ports.

To avoid confusion: at the moment I cannot connect the scale to Arduino UNO, I just connected the Arduino through the TLL converter to my PC to try to understand if I could build any sort of TX/RX that I will use once I plug in the scale. I thought that typing something on Putty will act as a flow of data that Arduino would log into the CSV file...perhaps I am wrong with this approach.

What I will expect once I connect the Arduino to the scale is to have the data flow logged on the CSV file on the SD card.

To give as much information as possible please also find attached my scale user manual.

Thanks.

W SERIES RS232 user manual.pdf (251 KB)

I connected to my scale the Arduino UNO with the TLL converter etc.

RED LED (DS1) with RX on D0 and TX on D1 (as indicated on the side of Arduino UNO).
I swapped RX with TX and GREEN LED (DS2)!

The file was not created on the SD card, though. I am suggesting that the condition serial.available > 0 is not activated...and from there everything fails. :frowning:

I then changed the line on serial.begin putting more parameters because the default is 8 data bits while my scale transfer at 7 data bits (as per user manual):

Serial.begin(9600, SERIAL_7N1);

So the new code will be:

// Code for receiving the data from my analytical scale through RS232

// Libraries
#include <LiquidCrystal.h>; // Includes the libraries for the LCD
#include <SPI.h>; // Includes the libraries for the Serial Peripheral Interface that allows the Master (Arduino) to control a slave device
#include <SD.h>; // Includes the libraries for the SD card

// Interface and Objects definitions
LiquidCrystal lcd(8, 9, 4, 5, 6, 7); // Creates a LCD LiquidCrystal object
const int chipSelect = 10; // Assigns the pin for the SPI-SD chip selection
boolean newData = false;
char receivedData;

void setup()
{
  Serial.begin(9600, SERIAL_7N1);
  boolean newData = false;
  pinMode(chipSelect, OUTPUT); // Ensures that the SPI-SD selection pin is an output
  lcd.begin(16, 2); // Initialises the interface to the LCD screen, and specifies the dimensions
  // Initialising sensor and SD card:
  lcd.clear(); // // Clears the LCD screen and positions the cursor in the upper-left corner
  if (!SD.begin(chipSelect)) // Checks if the SD card is working
  {
    lcd.println("SD failed!");
    delay(6000);
    return;
  }
}

void loop() 
{
  recvData();
  showData();
  saveData();
  //Serial.println('2');
}

void recvData()
{
  if (Serial.available() > 0)
{
  receivedData = Serial.read();
  newData = true;
}
}

void saveData()
{
  if (newData == true)
  {
    File readings = SD.open("readings.csv", FILE_WRITE); // Opens the file on the SD card
    if (readings) // If the file opened OK, write to it on SD card
    {
      readings.println(receivedData); // Saves the data on the SD card
      readings.close(); // Closes the file to save the data on the SD card
    }
    else // If the file didn't open, print an error
    {
      lcd.println("FILE NOT OPEN");
      delay(6000);
      newData = false;
    }
  }
}

void showData()
{
  lcd.print(receivedData);  // Prints the data on the LCD screen
}

Now bothe the LEDs are OFF completely :frowning:
I tried another TLL converter, LEDs OFF as well!!!

I do not know what is happening, any suggestion will be really great guys :slight_smile:

Thanks a lot.

M.

My TLL converter is this one:

My TLL converter

You can see the DS1 and DS2 LEDs light up during uploading of the code (together, then just DS1 red, then both go OFF) but this is what is happening more precisely in the conditions I described in the previous posts (I will try to edit the previous posts too, sorry).

  1. CODE1 (the one with serial.begin(9600) without specifying further parameters):
    With RX on D0 and TX on D1 the red led on DS1 was lighting up, DS2 was OFF.
    When I swapped RX with TX then the green led DS2 was lighting up and the red led DS1 was OFF.

  2. I then uploaded the CODE2 (the one with Serial.begin(9600, SERIAL_7N1)):
    At this point both the LEDs are OFF. (even if I swap TX with RX), they do not light up at all.

  3. Doubting that the issue was caused by the Code2 ( :o ), I uploaded back again the CODE1 and the LEDs remain OFF as well. :o

  4. I tried another TLL converter and the reactions from point 2) and 3) is THE SAME! :confused:

Someone can please give me some suggestions? Because this is getting too complicated for me as newbie :frowning:

P.S. I am also trying to understand the meaning of DS1 and DS2 (it seems they are dip switch but I did not get the real meaning/usage of them and most of all HOW they should behave in "working condition")

Thanks a lot.

Mario

Can you post a photo or diagram of how you have the RS-232 - TTL adapter connected up?

GypsumFantastic:
Can you post a photo or diagram of how you have the RS-232 - TTL adapter connected up?

of course:

the GND (brown jumper) is connected to the "-" or "GND" on my breadboard
the VCC (red jumper) is connected to the "+" or 5V on my breadboard
the yellow jumper (RX) is connected to Digital 0 on Arduino UNO
the orange jumper (TX) is connected to Digital 1 on Arduino UNO.

The breadboard +/- is connected to the 5V/GND of Arduino UNO. I am using it because I have other components (RTC, SD card).

Hope this helps mate

Thanks.

I also introduced a "checking point" inside the recvData function:

void recvData()
{
  if (Serial.available() > 0)
{
  receivedData = Serial.read();
  newData = true;
}
  else
{
  lcd.print("SERIAL FAILED");  // Serial not available message
  delay(6000);
  lcd.clear();
}
}

As expected, on the LCD screen I can now read "SERIAL FAILED" all the time...

OK I see you've tried swapping TX and RX.

I can see in your photo you're using a null modem cable. How about trying a straight-through modem cable?

GypsumFantastic:
OK I see you've tried swapping TX and RX.

I can see in your photo you're using a null modem cable. How about trying a straight-through modem cable?

I am actually waiting for its delivery :slight_smile:

I was using the NULL cable because I needed to connect the scale to Putty and the PC.

In the meanwhile, I would like to be sure that I did not mess around with the code or something else...

:slight_smile:

As far as the code goes, I recommend writing a very simple serial test program.

Maybe just echo whatever it receives to the LCD.

I will try this:

// Sample code to echo anything from SERIAL to an LCD

int incomingByte = 0; // for incoming serial data
#include <LiquidCrystal.h> // Includes the libraries for the LCD
LiquidCrystal lcd(8, 9, 4, 5, 6, 7); // Creates a LCD LiquidCrystal object

void setup()
{
  lcd.begin(16, 2);
  Serial.begin(9600);
}

void loop() 
{
  if (Serial.available() > 0)
  {
    incomingByte = Serial.read();
    lcd.print((char)incomingByte);
    delay(5000);
    lcd.clear();
  }
  else
  {
    lcd.print("SERIAL FAIL");
    delay(5000);
    lcd.clear();
  }
}

I hope I am following in the right way the thread guys. As soon as I have the straight cable I will give a feedback from that too.

Thanks a lot.

Good news guys:

I am using the straight cable instead of the NULL one. Also, I needed to swap TX and RX (I do not know why...).

I am running this code:

// Code for receiving the data from my analytical scale through RS232 (V5)

// Libraries
#include <LiquidCrystal.h>; // Includes the libraries for the LCD
#include <SPI.h>; // Includes the libraries for the Serial Peripheral Interface that allows the Master (Arduino) to control a slave device
#include <SD.h>; // Includes the libraries for the SD card

// Interface and Objects definitions
LiquidCrystal lcd(8, 9, 4, 5, 6, 7); // Creates a LCD LiquidCrystal object
const int chipSelect = 10; // Assigns the pin for the SPI-SD chip selection
boolean newData = false;
int receivedData; // Receives an integer in ASCII to transform in CHAR to be visualised/printed

void setup()
{
  Serial.begin(9600, SERIAL_7N1); // Includes the scale parameters
  boolean newData = false;
  pinMode(chipSelect, OUTPUT); // Ensures that the SPI-SD selection pin is an output
  lcd.begin(16, 2); // Initialises the interface to the LCD screen, and specifies the dimensions
  // Initialising sensor and SD card:
  lcd.clear(); // // Clears the LCD screen and positions the cursor in the upper-left corner
  if (!SD.begin(chipSelect)) // Checks if the SD card is working
  {
    lcd.println("SD failed!");
    delay(2000);
    return;
  }
}

void loop()
{
  recvData();
  showData();
  saveData();
}

void recvData()
{
  if (Serial.available() > 0)
{
  receivedData = Serial.read();
  newData = true;
}
  else
{
  lcd.print("SERIAL FAILED");  // Serial not available message
  delay(2000);
  lcd.clear();
}
}

void saveData()
{
  if (newData == true)
  {
    File readings = SD.open("readings.csv", FILE_WRITE); // Opens the file on the SD card
    if (readings) // If the file opened OK, write to it on SD card
    {
      readings.println((char)receivedData); // Saves the data on the SD card
      readings.close(); // Closes the file to save the data on the SD card
    }
    else // If the file didn't open, print an error
    {
      lcd.println("FILE NOT OPEN");
      delay(2000);
      lcd.clear();
      newData = false;
    }
  }
}

void showData()
{
  lcd.print((char)receivedData);  // Prints the data on the LCD screen
  delay(2000);
  lcd.clear();  
}

and I am able to receive the data and to save them on the SD.

The only thing at the moment it is the format (I have every char in different lines). I know that this is due to the println command but if I use the normal print then I will have them in a raw :frowning:
I would like to have every char in a different raw BUT UNTIL the new reading (after the "OK") :slight_smile:

Please find below a screenshot of the CSV file:


cloud based image processing

Any further help and contribution will be really appreciated. Thanks.

Guys, thanks a lot for all your help. It has been really appreciated.

I believe now I should move this project towards the next topic because it is not anymore about "feasibility".

I obtained the data from the scale, I just need to put them in the format I want.

I posted the subject here for your interest, please:

http://forum.arduino.cc/index.php?topic=464164.0

Thanks a lot.

Mario