Member Avatar for Yamil_1

I have to do a project based on the Internet of Things. It's a project that seems simple. But I need to control multiple devices through software and need help in the control part of of RS232.

I have a board with Linux Mint and is the ttyUSB0 port I use to connect a high precision scale. Since Linux with Minicom I can open the port and read activity weighs smoothly. The communication channel and port work perfectly.

I am using Python and PySerial library, as I also use PyCharm IDE. The scale sends information through the serial port when it is inactive 00.00 and value in Kilograms (25,310) when there is activity. I need to know how to capture the non-zero value, print it on the screen in real time and store it on a database.

I have some ideas of how to treat the data, but need help. I need to capture the weight from the scale, display it and store it next to a date. Any information on how to program this device will be very useful. Thank you very much.

Recommended Answers

All 3 Replies

What have you done so far? Are you able to read anything off of the serial port? That would be step one.

The second step would be deciding when to "capture" a value. I dout you want to capture all non-zero values (although you might). The scale will probably fluxtuate for a bit when a load is put on. A simple method would be to display the weight in realtime, and let the user confirm when the full load is on and it stable. You might also want to think about tare and callibration (ie, are you sure 00.00 means inactive?).

Member Avatar for Yamil_1

The scale when not placed anything always sends 00.00. With Minicom I can read the ttyUSB0 port (/ dev/ttyUSB0) 9600 b. What I want is to capture the weight value when an object is placed on the scale. I use the library PySerial, but I'm a little lost.

Maybe I should create a loop that always listen to the serial port and when changing from zero to a large value, then process the information that is sending the scale. When the value back to zero, then return to the loop.

I need examples of how to manipulate the data, whether as a string way or another and then store them at DB. Thks!

Again, the problem is that the value will fluxtuate - and I don't think you want to capture each fluxuation, do you? You might want to wait until a second has passed and the scale is still reporting the same value. I'm suprized that the scale will never have a tare problem - it might be for some big weights.

Say you've writtin a getScaleWeight() function. You would problably want something like (written without testing and half-asleep, you've been warned):

import time

weight = 0.0
new_weight = 0.0
catpured = False

while True:
    new_weight = getScaleWeight()

    if new_weight == 0.0:
        captured = False
    elif new_weight == weight and not captured:
        print "Weight is " + str(new_weight)
        captured = True

    weight = new_weight

    time.sleep(1)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.