Sony's Developer World forum

    • Home
    • Forum guidelines

    Upcoming maintenance 

     

    Dear Customers and Partners.

    This website will be undergoing scheduled maintenance on June 14, 2023. Please be aware there may be disruption to the developer portal website and associated services during the scheduled maintenance period.

    This upgrade is essential to ensure the continued performance, reliability, and security of Developer World.

    We apologize for any inconvenience.

     

     

    Using a load cell with the extension board and HX711

    Spresense
    hx711 load nan
    2
    6
    1435
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    This topic has been deleted. Only users with topic management privileges can see it.
    • MezmerizeR
      MezmerizeR last edited by

      Hey guys,

      hope you can help me out here.

      I'm trying to connect a load cell via the HX711 module and using it all with Arduino IDE.

      Pin connections are:

      HX7111 Ext. board
      GND GND
      DT PIN_D02
      SCK PIN_D03
      VCC Vout

      It is nothing special since I use a basic example ("HX_kitchen_scale") of the Arduino lib "HX711". Using the same pins for the Arduino UNO (also DUE) is working just fine.
      I have measured the signal of the clock with an ocsilloscope and it differs from the Arduino to the Spresense of course.' Maybe that is the culprit', I thought because the HX711 expects the clock frequency to be lower (see https://cdn.sparkfun.com/datasheets/Sensors/ForceFlex/hx711_english.pdf).
      So I actually copied the source of the header/source file of the HX711 lib and the example sketch to a new sketch to play around with it. I noticed the lines

      v.data[2] = shiftIn(_dataPin, _clockPin, MSBFIRST);
      v.data[1] = shiftIn(_dataPin, _clockPin, MSBFIRST);
      v.data[0] = shiftIn(_dataPin, _clockPin, MSBFIRST);
      

      in the read() method of the lib. I copied the code of the shiftIn function again and changed the commented lines

      uint8_t shiftInMod(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint32_t myDelay) // myDelay is new
      {
          uint8_t value = 0;
          uint8_t i;
      
          for (i = 0; i < 8; ++i)
          {
              digitalWrite(clockPin, HIGH);
              if (bitOrder == LSBFIRST)
                  value |= digitalRead(dataPin) << i;
              else
                  value |= digitalRead(dataPin) << (7 - i);
              delayMicroseconds(myDelay); // this is new
              digitalWrite(clockPin, LOW);
              delayMicroseconds(myDelay); // this is new
          }
          return value;
      }
      

      A delay of 5 µs makes the clock of the Spresense almost look like the clock of the UNO.

      Still the problem is that I just get readings of nan only.
      I also changed the data pin and clock pin to other pins but nothing works.

      As a voltage I use the 5 V from the extension board and I tried to level up the current with a transistor but took it out again since it did not work, either. So actually I don't really know if it is a software or a hardware problem.

      I just hope that somebody has an idea or even used a load cell with the HX711 module.

      Wish you all a nice day,
      MezmerizeR

      1 Reply Last reply Reply Quote
      • K
        KamilTomaszewski DeveloperWorld last edited by

        Hi @MezmerizeR

        I don't know what library you use but I guess this one: https://github.com/bogde/HX711

        They support fast CPU boards here: https://github.com/bogde/HX711/blob/bc5a7e5a0d518a0f384bd30105cdce0773e20028/src/HX711.cpp#L24, but unfortunately Spresense is not added there.

        Could you please try adding || defined(ARDUINO_ARCH_SPRESENSE) here in your local library?

        Best Regards,
        Kamil Tomaszewski

        1 Reply Last reply Reply Quote
        • MezmerizeR
          MezmerizeR last edited by

          Hey Kamil,

          thank you for your answer. I used another HX711 lib before. I switched to the one that you have mentioned and put the define in there. But still I did not get the load cell to output values - just zeros. As in the other lib, I pulled the pins for clock and data to LOW in the beginning since the reading will not start if they are on HIGH.

          I don't know. The clock looks actually pretty good. Nice amplitude and regular. Maybe it is something with the amplifier board?
          My idea is now to use the analog pins as input without the amplifier board. The ADC from the Spresense analog pins is only 16 bit instead of 24 bit with the amp but maybe I get it to give me some useful output with some other circuit I have not thought about yet.

          Thanks for your help anyways! If you have another suggestion for me, I'd still be open for that. It bothers me a little that it works right away on the UNO. Still I want to use the Spresense because of the multiple cores ;).

          Best,
          MezmerizeR

          1 Reply Last reply Reply Quote
          • MezmerizeR
            MezmerizeR last edited by

            Hey guys,

            I have a new guess why it is not working:

            The Spresense never hits 0 V. After pulsing the clock the voltage stays around 0.2 V which is probably not 'LOW' for some applications and therefore the lib that I'm using will never go into 'ready state'. Do you have a hint for me how to handle the offset? As I mentioned, the UNO does not have the problem. The UNO is almost at 0 V after pulsing.

            Best,
            MezmerizeR

            1 Reply Last reply Reply Quote
            • K
              KamilTomaszewski DeveloperWorld last edited by

              Hi @MezmerizeR

              Have you tried to use an operating voltage of 3.3V on the GPIO pins?
              https://developer.sony.com/develop/spresense/docs/hw_docs_en.html#_setting_operating_voltage

              If you change it then you also need to connect VCC to 3.3V and not to Vout.

              Best Regards,
              Kamil Tomaszewski

              MezmerizeR 1 Reply Last reply Reply Quote
              • MezmerizeR
                MezmerizeR @KamilTomaszewski last edited by

                Hi @kamiltomaszewski,

                sorry for the late reply.
                Yes, I've tried it and still there is an offset in Voltage which seems to be not LOW for the load cell.

                Still the load cell is not working on the Spresense.

                Best,
                MezmerizeR

                1 Reply Last reply Reply Quote
                • First post
                  Last post
                Developer World
                Copyright © 2021 Sony Group Corporation. All rights reserved.
                • Contact us
                • Legal