(ODD) question about A4/A5 pins

I currently have no direction myself right now, so I need to post to see if I'm just glazing over something? or..., what?

Long story/short. I have a project that send serial data to the Arduino. Arduino parse it, calls whatever functions are called to action. this all works fine.

This function toggles 1-8 relays, which toggles 1-8 pumps..etc (hardware wise, everything is 100% correct/working)

Had to implement a 'scale' in my project to weigh things. I only had pins A4/A5 open, and that are used as digital pins I believe (I am using the HX711_ADC library).

//JX711 pins:
const int HX711_dout = A4; //mcu > HX711 dout pin
const int HX711_sck = A5; //mcu > HX711 sck pin

//HX711 constructor:
HX711_ADC LoadCell(HX711_dout, HX711_sck);

everything is working fine/great.. UNTIL, I use pump #7? all actions are called the same:
(example of actions sent)

<v=1:1.00>
<v=2:1.00>
<v=3:1.00>
<v=4:1.00>
<v=5:1.00>
<v=6:1.00>
<v=7:1.00> // - if this is sent, scale weights/returns....nothing? everything else works fine.
<v=8:1.00>

I dont believe it to be a code issue as every other combination and output works as expected..

I ran a separate 'scale' test... works fine.
I ran a separate 'pump' text on D12.. works fine.

(wanted to make sure I didnt have any line/circuit issues..... was just reaching, since every other pump/combo works, and the scale out is there..... but with pump #7,.. no scale output)

So I was starting to second guess.. is there any issues between I/O pin D12 and A4/A5?

Should I use/code it as D18 / D19 or something?? instead? (even though it works with everything else, as-is..without issues?)

Summary:

Q: Any hardware pin conflict issues maybe in play here ? (reaching)

Q: Why does the scale/serial output return NOTHING (like the scale is NOT connected more or less) -ONLY- when pump 7 is used in the commands/output? Pump turns on... but does -not- turn off because no scale input/return data given (so only turns off due to a timer default/catch-all in place)

What am I missing here? LOL :slight_smile:
Thanks

Your code and a schematic.
At least.

1 Like

Post an annotated schematic as you have wired it. Include links to technical information on each of the hardware devices.

Full code would be too much.. here is the function that is called though. (again.. works every time, without issue... but scales returns nothing -only- when D12/pump7 is being used) Its like somehow the A4/A5 pins no longer work when pin D12 is being used?

//add mixer (pump output/on-time) output
void addMixer(byte targetMixer, float targetWeight) {

  Serial.print(F("Target Pump: "));
  Serial.println(targetMixer);  
  
  Serial.print(F("Target Weight: "));
  Serial.println(targetWeight);  
  
  //set target mixer value/relay
  int targetMixerRelay = mixPos[targetMixer - 1];

  //move stepper to correct bottle position   
  long targetPos = mixerPos; 
  stepper.runToNewPosition(targetPos); 
  //^Serial.println(F("Reached mixer dispenser position (mixer-location/home)"));

 
  //NEW scale approach  

  //tare() scale to zero
  //LoadCell.tareNoDelay(); //non-blocking
  LoadCell.tare(); //blocking

  // check if last tare operation is complete:
  if (LoadCell.getTareStatus() == true) {
    Serial.println("Tare complete");
  }
  
  LoadCell.update();
  float i = LoadCell.getData();  
  Serial.print(F("Current Scale Read/Data: (should be zero after trace() call) - "));
  Serial.println(i);

  //small delay once you reach bottle position
  delay(500); 
  
  //start pump output
  digitalWrite(targetMixerRelay, LOW);
  Serial.println(F("Pump: ON"));


  //SCALE LOOPING SNIPPET [CHECK] START
  
  //initial weight check (should be zero when starting/after tare() function)
  bool doMeasureWeight = true;
  float last_i = 0;
  unsigned long lastPumpOnMs = millis();
  unsigned long lastPumpOffMs = lastPumpOnMs + 20000; //how does 2000 adjustment effect?
  bool pumpOn = true;
  
  while (doMeasureWeight) {
    unsigned long now = millis();
    if (LoadCell.update()) {
      // get smoothed value from the dataset:
      //log/update current weight/data
      i = LoadCell.getData();
      Serial.print(F("ms:"));
      Serial.print(now);
      Serial.print(F(" Output Weight:"));
      Serial.print(i);
      Serial.print(F("  Target Weight:"));
      Serial.println(targetWeight);
      
      if (i >= targetWeight) {        
        if ((last_i < targetWeight) && pumpOn) { // crossed initial threshold
          
          pumpOn = false;
          digitalWrite(targetMixerRelay, HIGH);
          Serial.println(F("Pump: OFF"));
          lastPumpOffMs = now;
          
          Serial.print(F("Output weight has met target weight:"));
          Serial.print(i);
          Serial.print(" in ");
          Serial.print(lastPumpOffMs - lastPumpOnMs);
          Serial.print(" ms.\n");

          Serial.println();
          Serial.println(F("-- Any Weight Ouput Ater This Point Is Checking (SHOULD BE) After Pump Is Off? --")); 
          
        }
      }
      last_i = i; // update for edge detection
           
    }
    // timeout: (catch-all back-up listener to auto shut pump off)
    if ((signed long)(now - lastPumpOffMs) > 1000 || now - lastPumpOnMs > 16000) { 
   //if (now - lastPumpOffMs > 1000 || now - lastPumpOnMs > 5000) { // timeouts
      doMeasureWeight = false; 
      digitalWrite(targetMixerRelay, HIGH);  // ensure off
      Serial.println(F("Pump: OFF [back-up call]"));
      
      Serial.print(F("Weight After Pump Is OFF: "));
      Serial.println(i);
    }
  }
  
  //SCALE LOOPING SNIPPET END


  Serial.println(F("function end"));
   
  delay(1000); //drip catcher delay
  //return to packet parsing routine above
  //^Serial.println(F("..back to next packet parsing"));
}

Never getting this output either:

Serial.println(F("Pump: OFF"));
lastPumpOffMs = now;
Serial.print(F("Output weight has met target weight:"));
 Serial.print(i);
Serial.print(" in ");
Serial.print(lastPumpOffMs - lastPumpOnMs);
Serial.print(" ms.\n");

very odd.. because the scale seems to be working with all other pumps being toggled.

Maybe that's the problem.

Hope you find it

Good luck.

2 Likes

Do you have anything connected to the I2C bus (SCL and SDA pins)?

1 Like

A4/A5 are used for SDA/SCL I2C comms. This is legacy compatibility. Like D0/D1 are reserved for serial

Anything.... 'else'? No.

Just the 'scale pins' If there was anything else connected, why would it work when any other pump (all exact same set-up.. just different I/O pins) gets prompted/toggled?

Everything works as expected, -except- the scale seems to stop/not respond when pump#7/D12 is being used.

12 is MISO. Could the HX711 library be trying to mess with hardware SPI? Maybe there's a configuration thing in there? I know nothing of the library, it just strikes me that HX711 seem like the kind of thing you could use a SPI bus to read and the library might be touching that pin somewhere.

I'm not sure to be honest either. First time using this library myself.

From what I have read and all examples posted/I went through.. didnt seem like any pin type mattered. (You could just use..any?)

Here is git link:

States:

" HX711 is a precision 24-bit analog-to-digital converter (ADC) that is designed for weighing scales and industrial control applications to interface directly with a bridge sensor. It is specially made for amplifying signals from cells and reporting them to another microcontroller."

Also.. I'm using a NANO clone by the way.. (sorry forgot to provide that earlier if that matters somehow??)

This old post also seems to show someone using A4/A5??

Again... using these A4/A5 pins... have NO ISSUES.. when I have ran each and every scale example/test sketches.. and works 100% of the time in my project.. EXCEPT when D12 is currently in use?? HOW? WHY? :slight_smile:

Thats for the response... I'm not clear what you mean?

I understand that A5/A5 -can- be used for I2C comm... but that is (in this instance) just being used as digitial pins I believe?? (I guess I'm not 100% clear how the library interacts with them tbh.. but if you are allowed to -any- pins.. then I would assume digital?)

Says the pins are: DOUT & SCK? (not sure what type of protocol that is?.. or why it would interfere with PIN D12?)

The reason I asked is because I thought you might have been using an UNO, where there is a separate set of SCL/SDA header pins connected to A4/A5. Not knowing your level of experience, it is not uncommon for someone to be unaware that those are connected together, and any use of I2C would likely interfere with the HX711.

I do not see any use of D12 in the HX711_ADC library.

When you compile the sketch, how much memory usage is shown? Are you using String type variables?

1 Like

That's why I asked about MOSI and SPI, cause it looks like that. But I just looked at the library and yea it aught to work with any pin. It does turn off interrupts for a while when it transfers. I think think I might get a couple of these and play with putting them on the SPI bus and letting hardware do that so interrupts don't have to be off.

But I don't see what any of that code has to do with pin 12.

A4/A5 pins are connected to nothing -but- the scale itself. (they just happened to be the ONLY open/last 2 I/O pins I had available).

From the lib examples... it doesnt seem that it matters what I/O pins are declared for usage.

  • so pins were chosen on purpose based on anything I2C related (only ones that were available)
  • nothing else is running/connected to A4/A5 pins
  • scale and -everything- runs as expected/coded (expect when the actions involves pump#7 [connected to D12])

D12 is not used in the HX711 lib that I saw either.... but 'something' is turning off the scale/killing it (only returns '0.00' when D12 is being used... when any of the other I/O pins that the other pumps are connected to.. no issues?)

-- completely stumped?

Thats a good question actually... (although I have no clue how that would effect only D12/pump#7?) and not pump#8 or 1-6 pumps even..

but yes.. checking I now see:

Sketch uses 16606 bytes (54%) of program storage space. Maximum is 30720 bytes.
Global variables use 1633 bytes (79%) of dynamic memory, leaving 415 bytes for local variables. Maximum is 2048 bytes.
Low memory available, stability problems may occur.

I am using character arrays only.. not unstable String stuff here. I send a serial 'packet' with 1 to many 'actions' in it..

<v=1:1.00,v=2:1.00,v=3:1.00,v=4:1.00,v=5:1.00,v=6:1.00,v=7:1.00,v=8:1.00>

or just:

<v=2:1.00>

for example.. int/value prior to : is the pump#.. float value after the : in the dosage amount.
sends that data to the above posted function..

  • and toggles the correct relay/pump..
  • starts scale/weight checking
  • once target weight is met in checking loop().. toggles pump off

again.. it works fine.. every since time.. EXCEPT when pump#7 is being using.
sample/test:

<v=7:1.00>

Pump does start.... but scale returns 'nothing' (just 0.00 like its off.. or pin not connected).. and pumps only turns off if I catch it.. and power down Arduino.. or the 'timer' catch-all/loop powers off the pump (back off off setting)

I might try to swap out the pins from pump7 with say pump6.. and see if that new pump (now on D12) also kills the scale feedback/output?

I 10000% agree.. NOTHING has to do with pin D12.. AT ALL.

BUT.. that is what pin pump #7 is.. and ANY time pump#7 is part of the recipe/commands.. the scale will not return any data/reads.. everything is 0.00 (so never hits target weight, and hence never toggles of)..

without re-starting.. touching anything.. I can send a same code/action but just with a different pump#, and it will fine.. and actually VERY precise/accurate

Completely lost as to how D12 being 'on' has any bearing on what the HX711_ADC class does when using the A4/A5 pins for communication. (unfortunately.. those -are- the only 2 open pins I have really)

The ram usage may be a concern, 415 is getting fairly low. See if there are any Serial.print() statements that are not using the F() macro, freeing up some ram may help.

If you swap the pin assignments for pump #7 and another of the pumps, does the problem remain on D12 or does it remain with pump #7?

read this in github:

Disable interrupts when sck pin is high. This could be required to avoid "power down mode" if you have some other time consuming (>60µs) interrupt routines running (default: interrupts enabled)

Possibly have any bearing on this? Maybe try to disable interrupts in the lib itself.. to see what results if any?

In the end.. there will be 'no' Serial.print() commands going on...

Wait... sorry, I take that back, once all packets in the incoming serial data are parsed and acted upon.. a Serial.print() action that sends 'c' will fire (which is sent back to the connected RPi/touched screen interface..etc..etc.. nothing to do with anything here, but wanted to be clarify that no serial data will be sent anyways in the end.

Also to challenge the theory a bit... then 'why' doesnt this effect ANY of the other pumps if it was a memory issue? :slight_smile:

I will try to swap the pins now on pump 7 vs 6 to see if running

<v=6:1.00> (ie: pump 6, and 1.00oz dosage being sent)
vs
<v=7:1.00>
.. still kills the scale output/feedback.

update:

//if you have some other time consuming (>60μs) interrupt routines that trigger while the sck pin is high, this could unintentionally set the HX711 into "power down" mode
//if required you can change the value to '1' to disable interrupts when writing to the sck pin.
//default 
#define SCK_DISABLE_INTERRUPTS		0		//default value: 0
//test
//#define SCK_DISABLE_INTERRUPTS		1		//default value: 0

didnt seem to have any impact.. FYI.

update 2:

ok.. I now have switched the wires..

so D12 (aka: pump 7 pin).. is now physically connected to pump 6.

So the same line of code (<v=7:1.00>) should toggle pump 6 now.. and in theory.. pump 6 should not turn off.. there should be no scale output/return... *because it uses D12 still to toggle things.

if I send <v=6:1.00> command.. then physically pump 7 should turn on .. and scale info SHOULD be there.. because 'pump #6 pin' is set to pin 11

const int mixer6 = 11;

and D11 never had any scale output issue previously.

(testing)

results:

I think we may be on to something here now (finally).. thank you all for letting me talk through this! lol..

ok.. so after running the above (after switch the wires)

<v=1:1.00> = worked fine!
<v=7:1.00> = also worked fine this time.. which I believe is still D12 I/O pin on NANO... but -now- connected to RELAY/PUMP#6 physically.
<v=6:1.00> = same results as before. (no scale returned/displayed data).. and I believe this NANO I/O pin is still pin D11, and is now physically connected to RELAY/PUMP#7


Here is the PIN set-up:

const int mixer6 = 11;
const int mixer7 = 12;

I changed no code, just swapped the wire that was on mixer6/D11 with the wire that was on mixer7/D12.

So.. this is related specifically to RELAY/PUMP # 7 ...somehow? (not the I/O pin on the NANO toggling it). hmmmmmm


@noiasca
"make a demo sketch which reads the hx711 and let it control the relay at pin 12."

thats what I'm doing now. I also made separate sketches.. to ensure there were no mistaken connections between the tween.. and things worked.

Seems like the test results above lead to something.. else? relay7/pump7 specifically now? (but not sure exactly what yet)

pic of my set-up for the 8-channel relay board (each one has its own fly-back DIODE as well)

no different set-up than any other relay/pump in the project. what would be allowing relay7/pump7 to somehow kill the scale pin/output? but everything else works fine?

hmmmm

make a demo sketch which reads the hx711 and let it control the relay at pin 12.
Does that work?
If not

  • what happens exactly?
  • post a schematic
  • post a pictures of your real so we can see each module/wire
  • post a full compileable sketch which causes the problem.

Is VCC to the board coming directly off the Ardunio? Could it be a power issue? Could the relay board get it's own power?