Tower Crane: Electronic Scales

Serial monitor says "LCD should say hello world"

Hi,
Did the LCD display anything?
Turn the pot control slowly to see if it comes up in the display.

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

OMG, it says "Hello World" Upside down though, I'll have to turn LCD around. Wow amazing, thank you very much. How should I proceed?

Hi,
That is great, so your display is working.
Run this, its your full code with some serial.prints in to see if it completes the "calibration" function.

        
#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.

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

Awesome. In a nutshell, it works. The pot turns the LCD brightness up and down and pressing the button puts it back to calibrating. I placed a 100 g weight on the scales, waited as instructed and took it off. I then put it back on and it measured 90g ish so there must be a bit of tweaking needed. My engineering approach would be to add 10g to the top of the scales but if it could be tweaked in the sketch I would love to know how to do that.
Do I need to run through that process every time or can I disconnect the computer, plug in 9 volts and see what happens?

Hi, @doonie
Great mate :+1: :+1: :+1: :+1:
I will be interested to see it integrated into the crane project.

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

You and me both. :astonished:

1 Like

That calibration code looks odd - there doesn't seem to be anything to indicate to the system when the 100g weight was added, just a prompt to do it. Maybe it's cleverer than it appears though.

Ah thanks for that. It's driving me nuts at the moment. Right now it is skipping the bit about put 100g & wait.
Also it returns a wrong answer when I put a known weight on it ie a tin of beans weighing 162 g returns 300 odd but not clear.
I have uploaded a different sketch hoping to clear it's brains out then reloaded a pure version of the sketch but it still skips the put 100g thing. Is there a different but similar sketch I can use to try to find the problem? Remember that I don't know anything, I'm just floundering around using my particular brand of weird logic.