Reply to topic  [ 4 posts ] 
HX711 Bridge Sensor Digital Interface Module (HCMODU0073) 
Author Message
Site Admin

Joined: Sun Aug 05, 2012 4:02 pm
Posts: 633
Post HX711 Bridge Sensor Digital Interface Module (HCMODU0073)
Image

A very low cost module incorporating with a very high precision 24 ADC and differential high gain inputs designed to be interfaced with many common types of bridge sensors. E.g. pressure, strain, weight sensors.

Based on Avia Semiconductor’s patented technology, HX711 is a precision 24-bit analogue to-digital converter (ADC) designed for weigh scales and industrial control applications to interface directly with a bridge sensor. The input multiplexer selects either Channel A or B differential input to the low-noise programmable gain amplifier (PGA). Channel A can be programmed with a gain of 128 or 64, corresponding to a full-scale differential input voltage of ±20mV or ±40mV respectively, when a 5V supply is connected to AVDD analogue power supply pin. Channel B has a fixed gain of 32. On-chip power supply regulator eliminates the need for an external supply regulator to provide analogue power for the ADC and the sensor. There is no programming needed for the internal registers. All controls to the HX711 are through the pins.


Features:

• Two selectable differential input channels
• On-chip active low noise PGA with selectable gain of 32, 64 and 128
• On-chip power supply regulator for load-cell and ADC analogue power supply
• On-chip oscillator requiring no external component with optional external crystal
• On-chip power-on-reset
• Simple digital control and serial interface: pin-driven controls, no programming needed
• Simultaneous 50 and 60Hz supply rejection
• Current consumption including on-chip analogue power supply regulator: normal operation < 1.5mA, power down < 1uA
• Operation supply voltage range: 2.6 ~ 5.5V
• Operation temperature range: -40 ~ +85oC


Example:
Image


Schematic:
Image


Example Arduino Sketch:

Code:
/* FILE:    HX711_Bridge_Sensor_Digital_Interface_Module
   DATE:    28/08/14
   VERSION: 0.1
   AUTHOR:  Andrew Davies

This is a basic example of how to use the HX711 dual channel bridge sensor interface
module (HCMODU0073). By default the sketch will configure the module to take
measurements from the channel A input with a gain of 64. These measurements will be
repeatedly triggered at its maximum rate and the result output to a serial terminal.

PINOUT:

Module.....Uno/Nano
GND........GND
DT.........D9
SCK........D8
VCC........+5V


You may copy, alter and reuse this code in any way you like, but please leave
reference to HobbyComponents.com in your comments if you redistribute any part of
this code. This software may not be used for the purpose of promoting products
that directly compete with Hobby Components Ltd's own range of products.

THIS SOFTWARE IS PROVIDED "AS IS". HOBBY COMPONENTS MAKES NO WARRANTIES, WHETHER
EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ACCURACY OR LACK OF NEGLIGENCE.
HOBBY COMPONENTS SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR ANY DAMAGES,
INCLUDING, BUT NOT LIMITED TO, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY
REASON WHATSOEVER.
*/


/* Define digital pins used for the clock and data signals. */
#define PD_SCK 8
#define DOUT 9

/* Define the various gain and input options */
#define CHAN_A_GAIN_128 1
#define CHAN_B_GAIN_32 2
#define CHAN_A_GAIN_64 3


void setup()
{
  Serial.begin(9600);
 
  /* Set the clock pin to and output and the digital pin to an input */
  pinMode(PD_SCK, OUTPUT);
  pinMode(DOUT, INPUT);
 
   /* Take the device out of power down mode (clock pin low) */
  digitalWrite(PD_SCK, LOW);
 
  /* Trigger a conversion so that the module is in the correct mode for
     the next measurement */
  ReadConversion(CHAN_A_GAIN_64);
}

/* Main program loop */
void loop()
{
  /* Read in the last measurement and output to the serial port */
  Serial.println(ReadConversion(CHAN_A_GAIN_64));
}


/* Function to read a measurement from the module.
   The result is returned as a 32 bit signed integer */
long ReadConversion(byte ConversionMode)
{
  byte index;
  long ConversionData = 0L;
 
  /* Read in the 24 bit conversion data */
  while(digitalRead(DOUT));
  for (index = 0; index < 24; index++)
  {
    digitalWrite(PD_SCK, HIGH);
    ConversionData =  (ConversionData << 1) | digitalRead(DOUT);
    digitalWrite(PD_SCK, LOW);
  }
 
  /* Output some extra clock cycles to set the gain and input options */
  for (index = 0; index < ConversionMode; index++)
  {
    digitalWrite(PD_SCK, HIGH);
    digitalWrite(PD_SCK, LOW);
  }
 
  /* Number is returned as a 24bit 2's compliment but we need to
     convert it to convert to 32 bit singed integer */
  if (ConversionData >= 0x800000)
    ConversionData = ConversionData | 0xFF000000L;
 
  return ConversionData ;
}



Datasheet:
Attachment:
HX711_AD_HCMODU0073_Datasheet.pdf


You do not have the required permissions to view the files attached to this post.


Mon Nov 17, 2014 2:50 pm
Profile

Joined: Fri Sep 09, 2016 12:24 pm
Posts: 2
Location: Wokingham
Post Re: HX711 Bridge Sensor Digital Interface Module (HCMODU0073
Hi there,

Thanks for this code very helpfull to have an alternative to the HX711 lib's, I am having problems with the code my Teensy-LC seems to fail at the while loop

"while(digitalRead(DOUT));"

To me this seems wrong as the are no {} to encase the contents of the while loop and nothing to to compare DOUT to, or it my be the way Teensy handles the code?

I would have expected
while(digitalRead(DOUT) == something)
{
//do this, do that
}

It might just be me not understanding, as I am not very experienced with C!!


Fri Sep 09, 2016 12:36 pm
Profile
Site Admin

Joined: Sun Aug 05, 2012 4:15 pm
Posts: 629
Post Re: HX711 Bridge Sensor Digital Interface Module (HCMODU0073
Quote:
To me this seems wrong as the are no {} to encase the contents of the while loop and nothing to to compare DOUT to, or it my be the way Teensy handles the code?


There are lots of little coding tricks that can be done in C++ that can sometimes confuse a beginner or even an experienced programmer! The while statement is actually correct and is acting as a 'wait until the HX711 is ready' command.

Before reading a conversion out of the HX711 the sketch needs to wait for the current conversion to complete. The HX711 signifies this by holding the data output pin high whilst it is doing a conversion and then pulling it low once the conversion has completed.

Each time the while function is executed is runs the the digitalRead() function contained within its brackets. The digitalRead() function then returns the state of the pin as either True (high) or False (low). The while function will keep executing until the contents within its brackets equate to a false. Although you are correct in that you could write the line as while(digitalRead(DOUT) == true); the statement between the brackets will still get evaluated as true or false, it's just adding an extra step.

Also as there is no additional code to run whilst the while function is being executed then there is nothing to put in between a set of {} brackets so they can be omitted.


Quote:
I am having problems with the code my Teensy-LC seems to fail at the while loop


What do you mean by fail? Are you getting an error message or is the code just not getting past this point. If its getting stuck how have you determined this?

_________________
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.


Fri Sep 09, 2016 2:57 pm
Profile

Joined: Fri Sep 09, 2016 12:24 pm
Posts: 2
Location: Wokingham
Post Re: HX711 Bridge Sensor Digital Interface Module (HCMODU0073
Hi Andrew,

Thanks for the reply, I think I have just solved this :) my circuit included a mux chip to switch between two HX711 boards (im using 4 x pressure sensors) switching between the two IC's it seems they were going to sleep, the code ran "while(digitalRead(DOUT));" this was never satisfied (or maybe in the for loop) as there is no timeout (nore should there be) so the program stopped waiting to be satisfied (i just put serial.println's everywhere to find where it was stopping :roll: ). I have solved this by adding the wake up line after the mux logic to force the chip to wake every time, unfortunatly this probably means a time penalty for multiple readings.

Also had to call the reading twice to be able to change the PGA to use the other channel. I tried to call the gain options first but this did not work, I will hopefully make this more elegant and clean it up somewhat, but its working hurray!

Code:
//**********************************************************************

/* Function to read a measurement from the module.
   The result is returned as a 32 bit signed integer */
long ReadPressure(int input, int channel)
{
  int index;
  long ConversionData = 0L;
Serial.print("*");
 if(channel == 1){                                                //checks to see if 2nd hx711 is selected
  digitalWrite(muxAPin, HIGH);
  digitalWrite(PD_SCK, LOW);                            //Take the device out of power down mode
 }
 else{
  digitalWrite(muxAPin, LOW);
  digitalWrite(PD_SCK, LOW);                            //Take the device out of power down mode
 }
  //delay(1);
  while(digitalRead(DOUT));                                       // Read in the 24 bit conversion data
  //Serial.println("while");
  for (index = 0; index < 24; index++){
    //Serial.println("for loop");
    digitalWrite(PD_SCK, HIGH);
    ConversionData =  (ConversionData << 1) | digitalRead(DOUT);
    digitalWrite(PD_SCK, LOW);
  }

   for (index = 0; index < input; index++)                         //Output some extra clock cycles to set the gain and input options
  {
    digitalWrite(PD_SCK, HIGH);
    digitalWrite(PD_SCK, LOW);
  }
 
  ConversionData = 0;
 
  while(digitalRead(DOUT));                                       // Read in the 24 bit conversion data
  //Serial.println("while");
  for (index = 0; index < 24; index++){
    //Serial.println("for loop");
    digitalWrite(PD_SCK, HIGH);
    ConversionData =  (ConversionData << 1) | digitalRead(DOUT);
    digitalWrite(PD_SCK, LOW);
  }
  for (index = 0; index < input; index++)                         //Output some extra clock cycles to set the gain and input options
  {
    digitalWrite(PD_SCK, HIGH);
    digitalWrite(PD_SCK, LOW);
  }
 
  if (ConversionData >= 0x800000)                               //24bit 2's compliment but we need to convert it to convert to 32 bit singed integer
    ConversionData = ConversionData | 0xFF000000L;
 
  return ConversionData ;
 
}


Anyway thanks, problem solved for now just in time for the weekend! :D :D


Fri Sep 09, 2016 4:31 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 4 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Thank you to phpBB.com & phpBB.ro.
Design created by Florea Cosmin Ionut.
© 2011 All contents of this site are © Hobby Components LTD