0

I just get an MCP23017 circuit and wired it to my raspberry pi like in datasheet. I am able to set pins for hight/low (tested with leds) using this code:

import wiringpi as wiringpi
from time import sleep

pin_base = 65       # lowest available starting number is 65
i2c_addr = 0x20     # A0, A1, A2 pins all wired to GND

wiringpi.wiringPiSetup()                    # initialise wiringpi
wiringpi.mcp23017Setup(pin_base,i2c_addr)   # set up the pins and i2c address

wiringpi.pinMode(65, 1)         # sets GPA0 to output
wiringpi.pinMode(66, 1)         # sets GPA1 to output
wiringpi.pinMode(67, 1)         # sets GPA2 to output
wiringpi.pinMode(68, 1)         # sets GPA3 to output
wiringpi.pinMode(69, 1)         # sets GPA4 to output


wiringpi.digitalWrite(65, 1)

sleep(0.5)

wiringpi.digitalWrite(66, 1)
wiringpi.digitalWrite(65, 0)

sleep(0.5)

wiringpi.digitalWrite(67, 1)
wiringpi.digitalWrite(66, 0)

sleep(0.5)

wiringpi.digitalWrite(68, 1)
wiringpi.digitalWrite(67, 0)

sleep(0.5)

wiringpi.digitalWrite(69, 1)
wiringpi.digitalWrite(68, 0)

sleep(0.5)

wiringpi.digitalWrite(69, 0)

My question is how can i use these pins for connect a hx711 module to it. If i use hx711 directly to raspberry pi i am using this code:

 s = HX711.sensor(pi, DATA=27, CLOCK=22, mode=CH_B_GAIN_32, callback=cbf)

So i don t know what to put instead 27 and 22 in my code to use GPA0 and GPA1 as data pins for hx711

Thank you

  • Have you read the datasheet for the HX711? I really don't understand how you will meet the required microsecond timing control by switching GPIO over an I2C bus connected to a standard operating system. – joan Feb 27 '17 at 14:32
  • Do you think I can use a MCP23s17 chip which use SPI instead I2C? – user3036295 Feb 28 '17 at 13:57
  • Possibly, as SPI can go much faster. However it still won't be particularly reliable as you will hit problems with rescheduling every now and then. Have you run out of GPIO? Why do you need a port expander? – joan Feb 28 '17 at 14:11
  • yes, i need to read 12 x hx711 , read 2 hall sensors and control 7 relays and unfortunately raspi does not have all these ports. – user3036295 Mar 1 '17 at 7:55
0

The underlying problem appears to be the need to read 12 HX711.

The HX711 have tight timing requirements. From memory they don't like a clock stuck either high or low (can't remember which) for more than 60 µs.

The (pigpio) solution you are currently using for one HX711 avoids the problem by using uninterruptible waves to transmit the clock bits.

If you do not need to read the HX711 simultaneously I would propose you use one or more multiplexor chips.

Use these to map the Pi's clock and data GPIO to multiple HX711. That will allow you to read each HX711 in turn.

The GPIO count would be 4 for the multiplexor (assuming you can find a 16 in to each switch 2 out) and 2 for the clock and data GPIO for a total of 6 GPIO.

  • But what about wire load cells in parallel ? will that work? in this way i will have few less pins to use on raspi – user3036295 Mar 1 '17 at 9:05
  • . I use 4 wires lead cells. 2 wires for power and 2 wires for read – user3036295 Mar 1 '17 at 9:11
  • I don't know if that will work or not. I assume you mean one clock and individual data lines for 13 GPIO. That might well work if you sample at say half the nominal update rate. So if they are set to generate 80 samples per second try sampling 40 times per second. The low sampling rate should hopefully mean that all the HX711 are ready to return the result. – joan Mar 1 '17 at 9:11
  • I've just read your second comment. I'm sorry, I don't understand what you are suggesting. – joan Mar 1 '17 at 9:12
  • no it does not work with common clock pin i already tried that. what i mean was to try to wire somehow in parallel 4 load cells (corners of one weight scale) and read only using one hx711, like i read only one cell....not sure i was clearly – user3036295 Mar 1 '17 at 9:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.