Ghostchips Posted July 11, 2019 Share Posted July 11, 2019 14 hours ago, Ned said: why are you still dicking around with this? just buy a speeduino board, and start writing code... those ignition drivers all work etc as well as give you lots of other inputs you're going to need... or you doing it purely as an exercise on how to drive coils/learn something? I dont understand why you are using a fet to drive an IGBT to drive a coil, when you can just use a fet to drive the coil Doing it to prove i can. And i've driven the coils from mosfets many times & burnt up every one of them. 1 Quote Link to comment Share on other sites More sharing options...
h4nd Posted July 11, 2019 Share Posted July 11, 2019 LTspice Quote Link to comment Share on other sites More sharing options...
Roman Posted July 12, 2019 Share Posted July 12, 2019 Just bought some STM32H7 dual core processors. Now all that's left to figure out is... Everything 1 Quote Link to comment Share on other sites More sharing options...
flyingbrick Posted July 12, 2019 Author Share Posted July 12, 2019 18 hours ago, Ghostchips said: Doing it to prove oldschool can. And i've driven the coils from mosfets many times & burnt up every one of them. Quote Link to comment Share on other sites More sharing options...
ajg193 Posted July 12, 2019 Share Posted July 12, 2019 Ordered an arduino due off of ali today. Not sure what I will use it for, but the extra speed may outweigh the lack of 5V capability for some applications (32 bit, 84 MHz ARM cpu) 1 Quote Link to comment Share on other sites More sharing options...
rusty360 Posted July 12, 2019 Share Posted July 12, 2019 On 13/06/2019 at 22:19, Ned said: mechanical switches bounce, thats just the nature of them. Add SW debouncing by checking the signal is valid for 30mS or something, or do hardware debouncing with a 100nF capacitor across the switch and a weak pullup? 10k or bigger maybe? i dont usually do HW debouncing as it costs more than a few lines of code so might pay to google a bit.... So I tried adding a resistor to put the pin down to ground but still had triggering issues from the machinery running around it. How does a pull up work?. If I posted the code on here could ya point me in the right direction? Cheers!!! Quote Link to comment Share on other sites More sharing options...
Roman Posted July 12, 2019 Share Posted July 12, 2019 4 hours ago, ajg193 said: Ordered an arduino due off of ali today. Not sure what I will use it for, but the extra speed may outweigh the lack of 5V capability for some applications (32 bit, 84 MHz ARM cpu) Teensy range is bloody good too, and as the name would suggest, uhhh... teensy. for if you need something with a smaller footprint than the Due.https://www.pjrc.com/teensy/ Quote Link to comment Share on other sites More sharing options...
flyingbrick Posted July 12, 2019 Author Share Posted July 12, 2019 15 hours ago, rusty360 said: So I tried adding a resistor to put the pin down to ground but still had triggering issues from the machinery running around it. How does a pull up work?. If I posted the code on here could ya point me in the right direction? Cheers!!! You need to do some of the basic arduino tutorials on this, makes heaps of sense after 1 Quote Link to comment Share on other sites More sharing options...
h4nd Posted July 31, 2019 Share Posted July 31, 2019 Should I design up a board to slap an arduino in that has a 12V reg, inputs and will drive ignition / relays / whatever? (Carduino) Also, many of the cheap Chinese arduino clones use the CH340 usb-serial interface chip. Unfortunately the drivers for this are a bit shit. My main desktop was having power/sleep mode troubles, and ended up rebooting everynight (resetting my workspaces, and long running jobs). Tracked it down to a WeMOS board, so all is well if I unplug it last thing. HTH / H4nd 2 Quote Link to comment Share on other sites More sharing options...
rusty360 Posted August 1, 2019 Share Posted August 1, 2019 On 13/06/2019 at 22:19, Ned said: mechanical switches bounce, thats just the nature of them. Add SW debouncing by checking the signal is valid for 30mS or something, or do hardware debouncing with a 100nF capacitor across the switch and a weak pullup? 10k or bigger maybe? i dont usually do HW debouncing as it costs more than a few lines of code so might pay to google a bit.... Hi Ned, I've been googling this up a fair bit and cant quite work it out. I'm still getting a large amount of static affecting the pins. I found this online but cant quite work out the diagram, I read it as the green line will go to the GPIO pin, both the triangles are to ground? But this would mean the 3.3v would go straight to ground. Any help would be awesome! This is the last bit of the puzzle. 1 Quote Link to comment Share on other sites More sharing options...
Ned Posted August 1, 2019 Share Posted August 1, 2019 hey man. 3v3 does not go directly to ground, it goes to a resistor, which goes to a cap to ground, and to another resistor to ground. It doesnt go directly to ground. You understand what a resistor does right? thats a pretty simple circuit and should work just fine...? i think i'd prefer it without the 1k resistor myself, so when you press the switch the cap instantly discharges, and keeps the pin low during bouncing while the cap charges? but thats just a feeling without trying any of it myself with a scope to see if that actually works that way. that way will remove some weird noise and false triggering, and will do a bit for debouncing. It really just slows down the button press, which works as debouncing 3 Quote Link to comment Share on other sites More sharing options...
rusty360 Posted August 2, 2019 Share Posted August 2, 2019 4 hours ago, Ned said: hey man. 3v3 does not go directly to ground, it goes to a resistor, which goes to a cap to ground, and to another resistor to ground. It doesnt go directly to ground. You understand what a resistor does right? thats a pretty simple circuit and should work just fine...? i think i'd prefer it without the 1k resistor myself, so when you press the switch the cap instantly discharges, and keeps the pin low during bouncing while the cap charges? but thats just a feeling without trying any of it myself with a scope to see if that actually works that way. that way will remove some weird noise and false triggering, and will do a bit for debouncing. It really just slows down the button press, which works as debouncing Hey ned, yep understand how a resistor reduces the current. I did have the system looking for a pull down but the electrical noise generated from the packing gear just made it trigger like crazy. That's why I thought I would try a pull up. This is what I have for the wiring circuit. Look ok ? 1 Quote Link to comment Share on other sites More sharing options...
rusty360 Posted August 5, 2019 Share Posted August 5, 2019 Righto so had some success today, I had another look at my circuit and realised I'd farrked up on the bread board. So I got the program running today but the debounce time needed to be set quite high 1500m/s for the program only to register one button push. I'm wondering if this is due to the closing relay being the trigger? Heres a pic of the circult now. White and grey wires go to the switch (relay) there is a cap in parallel with these. Red is 3.3v. Orange is GPIO pin. Green is ground. Quote Link to comment Share on other sites More sharing options...
h4nd Posted August 5, 2019 Share Posted August 5, 2019 What kind of relay? Mechanical or electronic? I see it says 24ac, is it ac driving it? Quote Link to comment Share on other sites More sharing options...
rusty360 Posted August 5, 2019 Share Posted August 5, 2019 1 hour ago, h4nd said: What kind of relay? Mechanical or electronic? I see it says 24ac, is it ac driving it? Just a simple mechanical one. Yep 24v ac as that's the control system on the machine. Quote Link to comment Share on other sites More sharing options...
h4nd Posted August 5, 2019 Share Posted August 5, 2019 Good-o, so it's probably staying pulled in, and not oscillating at 100Hz during the transition. How's the code for reading the pin look? Quote Link to comment Share on other sites More sharing options...
rusty360 Posted August 5, 2019 Share Posted August 5, 2019 13 minutes ago, h4nd said: Good-o, so it's probably staying pulled in, and not oscillating at 100Hz during the transition. How's the code for reading the pin look? Yep definitely stays in for very short time based on the led coming on. Hold the phone caller I'll try and post the code. Quote Link to comment Share on other sites More sharing options...
rusty360 Posted August 5, 2019 Share Posted August 5, 2019 20 minutes ago, h4nd said: Good-o, so it's probably staying pulled in, and not oscillating at 100Hz during the transition. How's the code for reading the pin look? Current Code - import constantimport datetimeimport RPi.GPIO as GPIO## global variable to count bags processed in current minutegBagsInMinuteCount = 0## function to realise if bag has been processeddef button_callback(channel):print("Button was pushed!")global gBagsInMinuteCountgBagsInMinuteCount+= 1## write to log file every time the button is pushed# roll log every daynow = datetime.datetime.now()logFilename = constant.LOG_DIR + now.strftime("%Y%m%d") + ".log"## write to log filef = open(logFilename, "a")f.write(constant.PROCESS_ID + "," + now.strftime("%d/%b/%Y %H:%M:%S") + ",1")f.close()## main program# initialisetry:## setup some stuffGPIO.setwarnings(False) # Ignore warning for nowGPIO.setmode(GPIO.BOARD) # set up BCM GPIO numbering## set pin 7 to be an inputGPIO.setup(7, GPIO.IN)## setup eventGPIO.add_event_detect(7,GPIO.RISING,callback=button_callback,bouncetime=1500)## main loopcurrentMinute = datetime.datetime.now().minutewhile True:## if have moved to the next minute then update the process status filenow = datetime.datetime.now()if(now.minute != currentMinute): ## write html file for current countf = open(constant.HTML_FILE, "w")f.write("<html>\n")f.write(" <head>\n")f.write(" <title>Bag Counter</title>\n")f.write(" <meta http-equiv='refresh' content='5'>\n")f.write(" </head>\n")f.write(" <body>\n")f.write(" <table style='width:100%'>\n")f.write(" <tr>\n")f.write(" <td style='text-align:center; font-size: 4000%'>{}</td>\n".format(gBagsInMinuteCount))f.write(" </tr>\n")f.write(" <tr>\n")f.write(" <td style='text-align:center'><img src='https://www.wilcoxgoodness.co.nz/images/logo@2x.png' alt='wilcox'></td>\n")f.write(" </tr>\n")f.write(" <tr>\n")f.write(" <td style='text-align:center'>updated: " + now.strftime("%Y-%m-%dT %H:%M:%S") + "</td>\n")f.write(" </tr>\n")f.write(" </table>\n")f.write(" </body>\n")f.write("</html>\n")f.close()## and reset the counter as is a new minutegBagsInMinuteCount = 0currentMinute = now.minutefinally:## clean upGPIO.cleanup() and help or info would be great as its all very very new to me! Quote Link to comment Share on other sites More sharing options...
h4nd Posted August 6, 2019 Share Posted August 6, 2019 Looks OK, can you re-post as quote text please? Indent and spaces matter for python. Quote Link to comment Share on other sites More sharing options...
rusty360 Posted August 6, 2019 Share Posted August 6, 2019 Yep i can try. I've learnt that indents and spaces matter for python alright!! Hope that helps, the bit i wasn't 100% sure about is this - GPIO.add_event_detect(7,GPIO.RISING,callback=button_callback,bouncetime=1500) The whole rising, falling, leading edge, trailing edge confuses me a bit. The bounce time needed to be above 1100 to no register 2 button pushes as one. This is prob to do with the relay holding on for a while. Code - import constant import datetime import RPi.GPIO as GPIO # # global variable to count bags processed in current minute gBagsInMinuteCount = 0 # # function to realise if bag has been processed def button_callback(channel): print("Button was pushed!") global gBagsInMinuteCount gBagsInMinuteCount+= 1 # # write to log file every time the button is pushed # roll log every day now = datetime.datetime.now() logFilename = constant.LOG_DIR + now.strftime("%Y%m%d") + ".log" # # write to log file f = open(logFilename, "a") f.write(constant.PROCESS_ID + "," + now.strftime("%d/%b/%Y %H:%M:%S") + ",1") f.close() # # main program # initialise try: # # setup some stuff GPIO.setwarnings(False) # Ignore warning for now GPIO.setmode(GPIO.BOARD) # set up BCM GPIO numbering # # set pin 7 to be an input GPIO.setup(7, GPIO.IN) # # setup event GPIO.add_event_detect(7,GPIO.RISING,callback=button_callback,bouncetime=1500) # # main loop currentMinute = datetime.datetime.now().minute while True: # # if have moved to the next minute then update the process status file now = datetime.datetime.now() if(now.minute != currentMinute): # # write html file for current count f = open(constant.HTML_FILE, "w") f.write("<html>\n") f.write(" <head>\n") f.write(" <title>Bag Counter</title>\n") f.write(" <meta http-equiv='refresh' content='5'>\n") f.write(" </head>\n") f.write(" <body>\n") f.write(" <table style='width:100%'>\n") f.write(" <tr>\n") f.write(" <td style='text-align:center; font-size: 4000%'>{}</td>\n".format(gBagsInMinuteCount)) f.write(" </tr>\n") f.write(" <tr>\n") f.write(" <td style='text-align:center'><img src='https://www.wilcoxgoodness.co.nz/images/logo@2x.png' alt='wilcox'></td>\n") f.write(" </tr>\n") f.write(" <tr>\n") f.write(" <td style='text-align:center'>updated: " + now.strftime("%Y-%m-%dT %H:%M:%S") + "</td>\n") f.write(" </tr>\n") f.write(" </table>\n") f.write(" </body>\n") f.write("</html>\n") f.close() # # and reset the counter as is a new minute gBagsInMinuteCount = 0 currentMinute = now.minute finally: # # clean up GPIO.cleanup() 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.