{"id":13802381,"url":"https://github.com/IDWizard/uln2003","last_synced_at":"2025-05-13T13:30:50.764Z","repository":{"id":215170626,"uuid":"98753203","full_name":"IDWizard/uln2003","owner":"IDWizard","description":"Micropython code to drive stepper motors via ULN2003","archived":false,"fork":false,"pushed_at":"2017-07-29T19:35:48.000Z","size":4,"stargazers_count":43,"open_issues_count":1,"forks_count":16,"subscribers_count":0,"default_branch":"master","last_synced_at":"2024-04-22T12:35:37.881Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/IDWizard.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2017-07-29T19:00:22.000Z","updated_at":"2024-04-22T12:35:37.882Z","dependencies_parsed_at":"2024-01-07T21:53:30.455Z","dependency_job_id":null,"html_url":"https://github.com/IDWizard/uln2003","commit_stats":null,"previous_names":["idwizard/uln2003"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IDWizard%2Fuln2003","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IDWizard%2Fuln2003/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IDWizard%2Fuln2003/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IDWizard%2Fuln2003/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/IDWizard","download_url":"https://codeload.github.com/IDWizard/uln2003/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225218036,"owners_count":17439712,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-04T00:01:43.164Z","updated_at":"2024-11-18T17:31:20.369Z","avatar_url":"https://github.com/IDWizard.png","language":"Python","readme":"# uln2003\nMicropython code to drive stepper motors via ULN2003\n\nThis is the ongoing work of my experiments with the BBC micro:bit and some ULN2003 stepper motors connected to 5V 28BYJ-48 Stepper Motors.\n\n## Materials\n\nYou will need:\n\n1. A micro:bit with USB cable (and a computer to connect it to!)\n1. A 5V DC power source\n1. One or more 28BYJ-48 stepper motors with matching ULN2003 driver boards\n1. Wires, lots of wires.\n1. (Optional but handy) A breakout board to make accessing the bit's IO pins easier\n\n## Wiring / Connecting\n\n1. Plug the stepper motor into the ULN2003\n1. Connect the 4 pins from the ULN2003 into 4 separate I/O pins of the bit\n1. Connect the 5v input +/- on the ULN2003 to a 5v source +/- terminals\n1. Connect the bit to the computer\n1. Load up the library and push to the bit (i.e. compile the program and upload to the bit)\n\n## Using the library\n\nCode example:\n\n```python\n# Create a stepper using the HALF_STEP command sequence \n# to a stepper which is connected:\n#                     micro:bit    ULN2003\n#                     pin16     -\u003e INP1 \n#                     pin15     -\u003e INP2\n#                     pin14     -\u003e INP3\n#                     pin13     -\u003e INP4\n# Set the delay between steps to 5 microseconds\n\ns1 = Stepper(HALF_STEP, microbit.pin16, microbit.pin15, microbit.pin14, microbit.pin13, delay=5)  \ns1.step(100)     # Rotate 100 steps clockwise\n\ns1.step(100, -1) # Rotate 100 steps anti-clockwise\n```\n\nA delay of less than 5 microseconds may cause the motor to simply buzz and not move at all. Try and see what works for you and your motors.\n\nBecause of the gearing of this motor a full rotation isn't very exact. It is somewhere between 508 and 509 steps. The constant FULL_ROTATION has a value of int(4075.7728395061727 / 8) = ~509 steps.\n\n## Advanced Usage (Driving more than 1 stepper motor)\n\nBeing able to drive a stepper is cool but the bit has a lot more IO pins. It's possible to drive two steppers:\n\n```python\ns1 = Stepper(HALF_STEP, microbit.pin16, microbit.pin15, microbit.pin14, microbit.pin13, delay=5)    \ns2 = Stepper(HALF_STEP, microbit.pin6, microbit.pin5, microbit.pin4, microbit.pin3, delay=5)   \ns1.step(FULL_ROTATION)\ns2.step(FULL_ROTATION)\n```\n\nBut you will notice that this makes stepper1 move a full circle (or a teensy bit more than a full circle) and then stepper2 will move a full circle. \n\nIf you want to move both motors at the same time then you need to interleave the commands to do that so that stepper1 moves a step, then stepper2 moves a step, then stepper1 moves a step and so on.\n\nThe library provides a way to do that:\n\n```python\ns1 = Stepper(HALF_STEP, microbit.pin16, microbit.pin15, microbit.pin14, microbit.pin13, delay=5)    \ns2 = Stepper(HALF_STEP, microbit.pin6, microbit.pin5, microbit.pin4, microbit.pin3, delay=5)   \n\nc1 = Command(s1, FULL_ROTATION)         # Go all the way round\nc2 = Command(s2, FULL_ROTATION/2, -1)   # Go halfway round, backwards\n\nrunner = Driver()\nrunner.run([c1, c2])\n```\n\nThe Driver class will run 1 step from each command until there are no more commands to run which will make the two motors move (apparently) simultaneously.\n\n\n\n","funding_links":[],"categories":["Libraries","编程","🐍 Python"],"sub_categories":["Motion","Python","🐍 MicroPython Libraries"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FIDWizard%2Fuln2003","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FIDWizard%2Fuln2003","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FIDWizard%2Fuln2003/lists"}