Notifications
Clear all

Widget Weight Counter using HX711 and LED Display – Feasibility Study

42 Posts
6 Users
19 Reactions
798 Views
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2542
 

Posted by: @billinfl

One last thing: I have noticed, for the first time just before I'm writing this, that the numbers ARE going in sequence, but the segments that are dark are the ones that are supposed to be lit for each number. (Please see the post I'm about to make to Dave for more details.

As a fast (but low probability of success) attempt to 'reverse' the reverse, try changing the setup from COMMON_ANODE to COMMON_CATHODE to see if that makes a difference.

 

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 4 years ago
Posts: 7140
 

@billinfl Just an observation or two. Your comment says display 0 to 9 but your code says 0 to 10. The for loop is wrong, it should be I < 10, NOT I <= 10.

Now remove lines 22 to 26 inclusive (see pic).

Screenshot 2024 04 20 at 15.01.39

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2542
 

@zander

Posted by: @zander

@billinfl Just an observation or two. Your comment says display 0 to 9 but your code says 0 to 10. The for loop is wrong, it should be I < 10, NOT I <= 10.

Good point. To extend that a bit farther, it should be changed to look like this ... (without the gaps, of course; I just edited the picture of the sketch).

adjusted

 

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 4 years ago
Posts: 7140
 

@will YEP, that's what I was trying to say.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2542
 

Posted by: @zander

@will YEP, that's what I was trying to say.

Yeah, it's awkward trying to edit a photo of a sketch 🙂

 

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 4 years ago
Posts: 7140
 

@billinfl CC @will Since the OP has more than hinted that his programming level is in the beginner class, I thought I might try to explain to him why we changed the code the way we did.

For programming micro controllers we are given two functions to fill in, the setup function that is executed only once each time the board is booted (reset) and the loop function that loops until power is removed or the reset button is pressed.

That is why we removed the lines where you tried to reset your display loop. Something like that would be needed in normal programming, but not for things like Arduino or ESPs etc.

What now happens is you loop through the display code from 0 to 9 inclusive then fall out of the loop when I is greater than 9, BUT now you hit the end of the loop function and start over from the top where the first part of the for loop is i=0.

Does that make sense?

Here is what you will see in the IDE when you select New Sketch. The comments are NOT mine, the IDE inserts all the following lines.

void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}

Now we can add your code to the new sketch

void setup() {
  // put your setup code here, to run once:

  // the code you have in setup is ok with possible correction for reverse image oe a wiring change

}

void loop() {
  // put your main code here, to run repeatedly:
  // Display numbers 0 to 9 with 1 seconds delay
  for (int i = 0; i < 10; i++){
    sevseg.setNumber(i);
    sevseg.refreshDisplay();
    delay(1000);
  }

}

 

 

 

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
(@billinfl)
Member
Joined: 4 months ago
Posts: 34
 

@will Will, Send me the bill! You nailed it. It was the first thing I did today, and the LED is now happily flashing 1-0, and purring like a kitten.Thanks! I say 1-0, because unlike before, when it was starting off by showing an "8" right after pressing the reset button, (which I thought was like a "test" of all segments, but now I'm not sure), it now just starts with "1" after hitting reset, and happily counts up to "0", and then repeats. I will now slowly back out of the room...... Actually, I will probably now just move on to Step 3 of Dave's development strategy from his post of March 26th. Question, would you still make the changes that you and Ron (thanks Ron)  recommended, or just forge ahead with the main project? Thanks again. Bill


   
ReplyQuote
(@billinfl)
Member
Joined: 4 months ago
Posts: 34
 

@zander Thanks Ron. I now see that it's ok to add my own text to a sketch, and that the computer will ignore it.( at least I hope it does). That will be handy for me, since my memory is pretty well shot, so reminders of changes I make to a code, as well as why I made them, will come in handy going forward. Bill


   
Ron reacted
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2542
 

Posted by: @billinfl

Actually, I will probably now just move on to Step 3 of Dave's development strategy from his post of March 26th. Question, would you still make the changes that you and Ron (thanks Ron)  recommended, or just forge ahead with the main project? Thanks again. Bill

I'm glad it was that easy (it rarely happens that way) 🙂

The reason that it worked is because the ULN2003 has an inverter on each pin and that's why everything was reversed (on & offwise). Because of that the sevseg display device received the signals backwards. It was therefore necessary to reverse the voltage on the MCU side and 'pretend' that it was a common cathode device.

Secondly, the reason it works without any pin in the array as I mentioned above is that I assume that you've connected the + line to the display's common pin(s). So the display is always on, there's no need for a pin to turn it on and off.

However, that indicates an error in your 'wiring diagram' which does not seem to indicate any connection ifrom the + and display common; hence the apparent need for a control pin. This originally confused us because the circuit as shown couldn't have lit any of the LED arms. It was only after you continued to assert that it worked that it was possible to hypothecate a permanent and direct connection to power. And then, it was only after you specified that the LED arms were inverted that the final explanation was possible.

Since this is only an incremental step towards your goal and this code won't appear in the final sketch, it's not important to change the existing sketch.

On the other hand, it's important that you understand WHY Ron (@zander) and I suggested those changes, so you should take that knowledge with you towards the final goal.

 

Anything seems possible when you don't know what you're talking about.


   
DaveE and Ron reacted
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 4 years ago
Posts: 7140
 

@billinfl I assume you are talking about adding comments. You should know there are two kinds of comments, those that start with // for single line comments, and the /* Block comments  */ style for a large block of text generally at the start of a sketch or at preceding a significant piece of code or function.

p.s. When talking about code, it is always and only 'code'. There is no plural as some try with codes nor is there any such thing as 'a code'. You will fit in much better if you follow the language rules of the veterans.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
(@billinfl)
Member
Joined: 4 months ago
Posts: 34
 

@will Will, Thanks for the clarification(s), and I'm glad you thought of "pretending", cause I certainly wasn't going to. My confusion over not even being able to get the LED to count to ten after a couple hours of trying had me nearing the "throw it out the window" frustration level.

Yes, my diagram is pretty crude, and I'm not surprised that it was confusing. (I guess when the person making the drawing is right there with the components in front of them, it's easy to assume that the reader will understand everything, so that's my bad). In this case, I now see that the red line from the 12 volt power supply (at bottom left) doesn't actually connect to anything, except the side of the breadboard, so it doesn't touch  the "+" "bus" of the BB. Additionally, when the same positive (red) lead crosses the resistor BB over to the LED,  it doesn't actually connect to the common pin (pins 1 and 5 are the "+" common pins), but instead connects to a nothing pin that I created in my mind, and then just threw in there. Details matter, and I will tighten up these types of errors in the future, or better yet, do what others do, and learn to let the computer make it neat and understandable. Sorry if it created a time waste for you.

Lastly, I now understand the reversal was caused by the inverters, so more good info to know for the future.

Thanks again, Bill 

 


   
ReplyQuote
(@billinfl)
Member
Joined: 4 months ago
Posts: 34
 

@zander Hi Ron. Yes, your assumption was correct. I was talking about "comments" added to a sketch, (but after re-reading my post, I now see that since my terminology needs work, it was hard to tell what I was talking about)! Thanks for the explanation of the difference between the two types. Bill

 


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2542
 

Posted by: @billinfl

Yes, my diagram is pretty crude, and I'm not surprised that it was confusing. (I guess when the person making the drawing is right there with the components in front of them, it's easy to assume that the reader will understand everything, so that's my bad).

Anther lesson to learn is that when you are looking at your own diagrams, wiring and sketches, your mind tends to see what you MEANT as oppose to what you PUT TOGETHER. We've all been there looking time and again at a glaring error unable to see the problem because our brain 'fixes' it to be what we meant.

 

Anything seems possible when you don't know what you're talking about.


   
Ron reacted
ReplyQuote
(@billinfl)
Member
Joined: 4 months ago
Posts: 34
 

@will So True! BTW, I just now noticed the little saying you have at the bottom of each of your posts. It's pretty funny, and I think it's classic, and I will probably steal it for when I'm among my friends, but I now have a sneaking suspicion that you have added it only since I joined this board! (Just messing with you!). Have a good one. Bill


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2542
 

Posted by: @billinfl

I just now noticed the little saying you have at the bottom of each of your posts. It's pretty funny, and I think it's classic, and I will probably steal it for when I'm among my friends, but I now have a sneaking suspicion that you have added it only since I joined this board!

No, I changed it a couple of months ago. My previous signature was "I had a psychic girlfriend but she left me before we met."

 

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
Page 2 / 3