Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 01:27 27 Nov 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : PicoMite and HX711 Load cell

Author Message
Skipo
Newbie

Joined: 12/10/2023
Location: Australia
Posts: 2
Posted: 05:12am 14 Oct 2023
Copy link to clipboard 
Print this post

Hi All

I'm wanting to use a PicoMite to read a HX711 load cell arrangement to measure weight with not much sucsess.
I'm ok with basic (just) and love Picomite, C on the other hand I'm rubbish.

Any help would be greatly appreciated.
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 6792
Posted: 07:40am 14 Oct 2023
Copy link to clipboard 
Print this post

Welcome to the 'Shed, Skipo. :)

The HX711 has a clock line and a data line but it's not I2C. It's a non-standard serial interface with it's own protocol. TBH I think I'd use a Arduino Nano to read it and convert the readings into something sensible like I2C! C is all foreign to me too. lol

A bit of information here.
Edited 2023-10-14 17:44 by Mixtel90
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6098
Posted: 08:03am 14 Oct 2023
Copy link to clipboard 
Print this post

Something like this.
Tested on a picomite running at 250MHz

 ' hx711 load cell
 OPTION EXPLICIT
 OPTION DEFAULT INTEGER
 CONST clk = 22
 CONST dta = 21
 
 DIM databit, raw_reading, n
 SETPIN dta, DIN
 SETPIN clk,DOUT
 
 PIN(clk) = 1 ' force reset
 PAUSE 10
 DO
   raw_reading = 0
   PIN(clk)= 0 ' start conversion
   DO
   LOOP UNTIL PIN(dta) = 0 ' data is ready
   FOR n = 1 TO 25 ' send 25 clock pulses
     PIN(clk) = 1
     'pause 0.002
     databit = PIN(dta)
     PAUSE 0.002
     PIN(clk) = 0
     raw_reading = (raw_reading << 1) + databit
     ' pause 0.001
   NEXT n
   
   raw_reading = raw_reading >> 1 ' get rid of the 25th bit.
   
   PRINT HEX$(raw_reading,6), raw_reading ', str$((raw_reading-95000)/3000000,3,2)
   PAUSE 500
 LOOP



You will have to calibrate it yourself.
The timing is a bit rubbery. The pulses are not really needed but that is something I haven't looked too closely at yet.

Jim
VK7JH
MMedit   MMBasic Help
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 6792
Posted: 08:33am 14 Oct 2023
Copy link to clipboard 
Print this post

This module appears to do the same job but has a proper I2C interface. I think I'd prefer that one. :)
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
Skipo
Newbie

Joined: 12/10/2023
Location: Australia
Posts: 2
Posted: 11:51am 14 Oct 2023
Copy link to clipboard 
Print this post

Thanks for taking the time to reply

I'll take all your advice and dive in.

Thanks again

(I've ordered a Module and will try the code)
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6098
Posted: 06:29am 15 Oct 2023
Copy link to clipboard 
Print this post

I had a bit more of a play.
This code results in about 1.6mS for a read.
 ' hx711 load cell
 OPTION EXPLICIT
 OPTION DEFAULT INTEGER
 CONST clk = 22
 CONST dta = 21
 
 DIM raw_reading, n

 SETPIN dta, DIN
 SETPIN clk,DOUT

 PRINT CHR$(27)+"[2J" ' CLS
 PIN(clk) = 1 ' force reset
 PAUSE 10
 DO
   raw_reading = 0
   PIN(clk)= 0 ' start conversion
   DO
   LOOP UNTIL PIN(dta) = 0 ' data is ready
   FOR n = 1 TO 25 ' send 25 clock pulses
     PULSE clk, 0.002
     raw_reading = (raw_reading << 1) + PIN(dta)
   NEXT n
   
   raw_reading = raw_reading >> 1 ' get rid of the 25th bit.
   PRINT CHR$(27)+"[0;0H"
   PRINT HEX$(raw_reading,6), STR$(raw_reading,10)
   PAUSE 500
 LOOP



The main thing is to keep the clock 'high' time well below 60uS or the device will go into sleep mode.
Using a 2uS pulse is reliable and easy to do.

Yellow trace is the 2uS clock pulses and green is the data



I purchased my module for a project 2 years ago but life matters got in the way. I changed the plans so weren't going to use this method but I might give it a try anyway.


Jim
VK7JH
MMedit   MMBasic Help
 
Bowden_P
Senior Member

Joined: 20/03/2019
Location: United Kingdom
Posts: 162
Posted: 10:20pm 21 Oct 2023
Copy link to clipboard 
Print this post

Hi Skipo,
The HX711 chip needs up to 3 trailing clock pulses after clocking out the present conversion, to select the channel and gain for the NEXT conversion.

Also some sort of digital filtering is advisable to remove some "noise" from the 24-bit value.

I am using an HX711 successfully in a project, and can post my code if you're interested. I rely on the Data pin going LOW to trigger an MMBasic interrupt to do a Read of the data, so get a new value about every 100ms.

With best regards, Paul.
Nothing so constant as change.
 
SteveIzett
Newbie

Joined: 04/05/2023
Location: Australia
Posts: 24
Posted: 12:45pm 16 Dec 2023
Copy link to clipboard 
Print this post

Hi Paul
I would very much appreciate seeing your HX711  code.

Cheers

Steve
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6098
Posted: 07:49pm 16 Dec 2023
Copy link to clipboard 
Print this post

Repeat of earlier post!
Edited 2023-12-17 05:50 by TassyJim
VK7JH
MMedit   MMBasic Help
 
SteveIzett
Newbie

Joined: 04/05/2023
Location: Australia
Posts: 24
Posted: 10:23pm 16 Dec 2023
Copy link to clipboard 
Print this post

Hi Jim

Have I missed something here. Paul had offered to post his code - I was interested in how he used an interrupt and the code to setup the next data tx.

Cheers

Steve
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6098
Posted: 11:00pm 16 Dec 2023
Copy link to clipboard 
Print this post

No problem Steve,
I was going to post my code but realised that it wasn't much different to my earlier post so deleted it.

Jim
VK7JH
MMedit   MMBasic Help
 
Bowden_P
Senior Member

Joined: 20/03/2019
Location: United Kingdom
Posts: 162
Posted: 11:30pm 16 Dec 2023
Copy link to clipboard 
Print this post

Hi Steve,
Here are the subroutines I use for the HX711 Load Cell chip. I "liberated" the Load Cell from a cheap kitchen scales. It has a load capacity of 10Kg, and will zero to +/-1g with very little drift. I must confess that some of my code isn't as elegant as examples posted here, but works well never-the-less for my application.

This code is running on an MM Explore 28 running at 48MHz, but was originally intended to run on a MM+ Explore 100 until I ran too low on Flash, and had to split the Measurement side of the project from the Control side, with a serial link between. DISCO4NOW's clever #REPLACE extension for MMEdit has pulled this project from the fire of failure many times by significantly reducing the Flash and RAM usage!

See the attached for the subroutines I have written for the HX711.

With best regards, Paul.

HX711 Code.zip
Nothing so constant as change.
 
SteveIzett
Newbie

Joined: 04/05/2023
Location: Australia
Posts: 24
Posted: 04:20am 18 Dec 2023
Copy link to clipboard 
Print this post

Thanks very much Paul.
Steve
 
aFox
Regular Member

Joined: 28/02/2023
Location: Germany
Posts: 76
Posted: 04:17pm 18 Dec 2023
Copy link to clipboard 
Print this post

  Mixtel90 said  This module appears to do the same job but has a proper I2C interface. I think I'd prefer that one. :)


If time is money it is an alternative, if you get the parcel in time.

Gregor
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024