Tower Crane: Electronic Scales

Difficult to know what category to select. Also, do I stick this in the Crane thread or start a new one?
This is a stand alone part of the crane for now, so A stand alone problem it is.
Problem. It Doesn't work.

Some pics, hope they help.





The wiring diagram.

Hi,
A circuit diagram will help.
What doesn't work?
And some code.

Thanks.. Tom... :smiley: :+1: :coffee: :australia:

Working on it. I'm new at everything.

[code]
        
#include <LiquidCrystal.h>

const int rs = 12, en = 11, d4 = 4, d5 = 5, d6 = 6, d7 = 7;

LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
#define DT A2
#define SCK A3
#define sw 3

long sample=0;
float val=0;
long count=0;

unsigned long readCount(void)
{
  unsigned long Count;
  unsigned char i;
  pinMode(DT, OUTPUT);
  digitalWrite(DT,HIGH);
  digitalWrite(SCK,LOW);
  Count=0;
  pinMode(DT, INPUT);
  while(digitalRead(DT));
  for (i=0;i<24;i++)
  {
    digitalWrite(SCK,HIGH);
    Count=Count<<1;
    digitalWrite(SCK,LOW);
    if(digitalRead(DT)) 
    Count++;
  }
  digitalWrite(SCK,HIGH);
  Count=Count^0x800000;
  digitalWrite(SCK,LOW);
  return(Count);
}

void setup()
{
  pinMode(SCK, OUTPUT);
  pinMode(sw, INPUT_PULLUP);
  lcd.begin(16, 2);
  lcd.print("    Weight ");
  lcd.setCursor(0,1);
  lcd.print(" Measurement ");
  delay(1000);
  lcd.clear();
  calibrate();
}

void loop()
{
  count= readCount();
  int w=(((count-sample)/val)-2*((count-sample)/val));
  lcd.setCursor(0,0);
  lcd.print("Measured Weight");
  lcd.setCursor(0,1);
  lcd.print(w);
  lcd.print("g             ");

  if(digitalRead(sw)==0)
  {
    val=0;
    sample=0;
    w=0;
    count=0;
    calibrate();
  }
}

void calibrate()
{
    lcd.clear();
  lcd.print("Calibrating...");
  lcd.setCursor(0,1);
  lcd.print("Please Wait...");
  for(int i=0;i<100;i++)
  {
    count=readCount();
    sample+=count;
  }
  sample/=100;
  lcd.clear();
  lcd.print("Put 100g & wait");
  count=0;
  while(count<1000)
  {
    count=readCount();
    count=sample-count;
  }
  lcd.clear();
  lcd.print("Please Wait....");
  delay(2000);
  for(int i=0;i<100;i++)
  {
    count=readCount();
    val+=sample-count;
  }
  val=val/100.0;
  val=val/100.0;        // put here your calibrating weight
  lcd.clear();
}

    
//Testing the System
//After uploading the code, put the 100g weight and wait for calibration. After calibration, weight measurement should proceed normally.
[/code]

Give me ten minutes and I'll post a little vid.

You should say what doesn't work

Hi,
It might be worth looking, googling

arduino hx711 weight scale

There is a library for the HX711 and many examples to look at.

It will save all the bit banging you are doing to extract data from the HX711.

Tom... :smiley: :+1: :coffee: :australia:

You should say what doesn't work

They did: "it" :rofl:

Here is a little vid which might nhelp.

Hi,
Have you adjusted the pot to see if you have anything on the display?

Your code needs some debugging serial.prints.

Tom... :smiley: :+1: :coffee: :australia:

Hi,
Have you got some code that tests your display?

Tom... :smiley: :+1: :coffee: :australia:

Yes , I’d test the display on its own first , with an example in the IDE .
I’d then also try the scale using the library for it .
Then you’ll know the parts and wiring are correct and you can turn your attention to the code .
( the pot is essential and alters the contrast) .

Always best to do the small steps, otherwise very hard to fault find ( eg nothing in the display ? Is it code or wiring or display ?? ) - good luck !

1 Like

Hi,
Try this code.
I have commented out the major parts and just written to the LCD, open the monitor at 9600 baud and it should tell you what it is doing.

        
#include <LiquidCrystal.h>

const int rs = 12, en = 11, d4 = 4, d5 = 5, d6 = 6, d7 = 7;

LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
#define DT A2
#define SCK A3
#define sw 3

long sample=0;
float val=0;
long count=0;

unsigned long readCount(void)
{
  unsigned long Count;
  unsigned char i;
  pinMode(DT, OUTPUT);
  digitalWrite(DT,HIGH);
  digitalWrite(SCK,LOW);
  Count=0;
  pinMode(DT, INPUT);
  while(digitalRead(DT));
  for (i=0;i<24;i++)
  {
    digitalWrite(SCK,HIGH);
    Count=Count<<1;
    digitalWrite(SCK,LOW);
    if(digitalRead(DT)) 
    Count++;
  }
  digitalWrite(SCK,HIGH);
  Count=Count^0x800000;
  digitalWrite(SCK,LOW);
  return(Count);
}

void setup()
{
  Serial.begin(9600);
  Serial.println("Test code 1");
  pinMode(SCK, OUTPUT);
  pinMode(sw, INPUT_PULLUP);
  lcd.begin(16, 2);
  lcd.print("    Weight ");
  lcd.setCursor(0,1);
  lcd.print(" Measurement ");
  delay(1000);
  lcd.clear();
//  calibrate();
}

void loop()
{
/*  count= readCount();
  int w=(((count-sample)/val)-2*((count-sample)/val));
  lcd.setCursor(0,0);
  lcd.print("Measured Weight");
  lcd.setCursor(0,1);
  lcd.print(w);
  lcd.print("g             ");

  if(digitalRead(sw)==0)
  {
    val=0;
    sample=0;
    w=0;
    count=0;
    calibrate();
  }
  */
  lcd.setCursor(0,0);
  lcd.print("Hello World");
  Serial.println("LCD should say Hello World ");
}

void calibrate()
{
    lcd.clear();
  lcd.print("Calibrating...");
  lcd.setCursor(0,1);
  lcd.print("Please Wait...");
  for(int i=0;i<100;i++)
  {
    count=readCount();
    sample+=count;
  }
  sample/=100;
  lcd.clear();
  lcd.print("Put 100g & wait");
  count=0;
  while(count<1000)
  {
    count=readCount();
    count=sample-count;
  }
  lcd.clear();
  lcd.print("Please Wait....");
  delay(2000);
  for(int i=0;i<100;i++)
  {
    count=readCount();
    val+=sample-count;
  }
  val=val/100.0;
  val=val/100.0;        // put here your calibrating weight
  lcd.clear();
}

    
//Testing the System
//After uploading the code, put the 100g weight and wait for calibration. After calibration, weight measurement should proceed normally.

Tom... :smiley: :+1: :coffee: :australia:

I pressed the button and turned the pot up and down then pressed the button again, repeat with the pot. No result.

No.

I'll do that tomorrow but you guys are presuming that I know what I am doing.

Hi, mate.
Pot adjust the contrast of the display.

Tom... :smiley: :+1: :coffee: :australia:

who is "they" ?