-
Notifications
You must be signed in to change notification settings - Fork 120
Add a MicroPython course #544
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 1 commit
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
c34737c
Micropython materials in separated files per topic and/or HW
frenzymadness ce0894f
Fix bug - Pin imported from machine
frenzymadness 7f60f51
Remove unneeded import
frenzymadness 943298b
Unify salutations
frenzymadness 223d118
Fix typo in file name: rgb%leds.md -> rgb_leds.md
frenzymadness f1515e2
Remove note about `sudo picocom`
frenzymadness c6f1e03
Move MicroPython pages to their own lessons
encukou 734dcad
Put MicroPython installation instructions in subpages
encukou b5292a6
Reword MicroPython materials, switch to MCUv2, remove external USB/TT…
encukou 3a816aa
Correct button name in Windows instructions for PuTTY
encukou b4df9af
Add several advanced MicroPython topics
encukou 1b9636a
Clarify L293D connections
encukou 9610c94
Add course for MicroPython
encukou cf667b0
Apply review suggestions
encukou File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
# Motorky | ||
|
||
Pojďme ovládat stejnosměrné motory! | ||
|
||
Motory potřebují, na rozdíl od počítače a LED světýlek, celkem hodně elektrické | ||
energie, a navíc můžou dokonce energii vyrábět (fungují jako dynamo). | ||
Kdybys je připojil{{a}} přímo k destičce, která na tolik proudu není | ||
připravená, mohla by se destička zničit. | ||
|
||
Představ si náramkové hodninky a traktor: obě zařízení něčím točí (ručičkami | ||
nebo koly), ale kdybys připojil{{a}} motor z traktoru na mechanismus hodinek, | ||
moc dlouho by správný čas neukazovaly. | ||
A motůrek z hodinek by zase nepohohl při orání pole. | ||
|
||
Proto použijeme čip s názvem L293D, který elektřinu potřebnou pro “hrubou sílu” | ||
motorku odstínit od logických signálů z destičky. | ||
encukou marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Potřebnou energii dodáme z baterií. | ||
|
||
Čip je černá krabička, která na sobě má trochu textu, ale ne dost na to, | ||
abys poznal{{a}} co dělá. | ||
To je deteilně popsáno v takzvaném *datasheetu* – PDF, které vypadne když | ||
encukou marked this conversation as resolved.
Show resolved
Hide resolved
|
||
zadáš „L293D“ do vyhledávače. | ||
Tam lze najít kompletní popis této součástky včetně diagramy, který ukazuje | ||
encukou marked this conversation as resolved.
Show resolved
Hide resolved
|
||
kde najít kterou nožičku: | ||
|
||
{{ figure(img=static('l293d.svg'), alt="L293D pinout") }} | ||
|
||
Všimni si, že nahoře je znázorněné „vykousnutí“ (zde oranžově), | ||
které najdeš i na součástce. | ||
Je důležité mít čip správně otočený, jinak nebudeš zapojovat správné nožičky. | ||
|
||
Čip posílá do své nožičky `1Y` energii z_`Vpower`, pokud je signál na | ||
`1A` i `1,2EN` současně. Jinak nožičku `1Y` spojí se zemí (`GND`). | ||
Podobně pro `2Y` (`2A` i `1,2EN`), `3Y` (`3A` i `3,4EN`), `4Y` (`4A` i `3,4EN`). | ||
Co to pro nás znamená, je vysvětleno níže.) | ||
|
||
|
||
# Zapojení | ||
|
||
Čip a motorky zapoj následovně: | ||
|
||
* Napájení | ||
* V<sub>logic</sub> k 5V – `Vin` na destičce | ||
* V<sub>power</sub> k `+` na baterii | ||
* GND (jedno který) k `GND` na destičce | ||
* GND (jedno který) k `-` na baterii | ||
* První motorek: | ||
* `1A` na `D1` | ||
* `2A` na `D2` | ||
* `1,2EN` na `D3` | ||
* `1Y` a `2Y` k dvěma kontaktům motorku | ||
* Druhý motorek: | ||
* `3A` na `D6` | ||
* `4A` na `D7` | ||
* `3,4EN` na `D8` | ||
* `3Y` a `4Y` k dvěma kontaktům motorku | ||
|
||
{{ figure(img=static('motors_bb.svg'), alt="L293D pinout") }} | ||
|
||
|
||
# Ovládání | ||
|
||
Motorek se točí, pokud je na jeho kontaktech rozdíl napětí: pro první motorek | ||
musí být na `1Y` jiná hodnota než na `2Y`. | ||
Pro obě musí být aktivní nožička `1,2EN`, a pak `1A` ovládá `1Y` a | ||
`2A` ovládá `2Y`. | ||
|
||
``` | ||
from machine import Pin | ||
|
||
pin_1a = Pin(5, Pin.OUT) # D1 na destičce, 1A na čipu | ||
pin_2a = Pin(4, Pin.OUT) # D2 na destičce, 2A na čipu | ||
pin_12en = Pin(0, Pin.OUT) # D3 na destičce, 1,2EN na čipu | ||
|
||
pin_1a.value(1) | ||
pin_2a.value(0) | ||
pin_12en.value(1) | ||
``` | ||
|
||
Když prohodíš hodnoty `pin_1a` a `pin_2a`, motorek se začne točit opačným | ||
směrem. | ||
|
||
Pro nastavení rychlosti otáčení se hodí použít obdélníkovou vlnu, PWM, | ||
nastavenou na nožičce `1,2EN`: | ||
|
||
``` | ||
from machine import Pin | ||
|
||
pwm_1 = PWM(pin_12en, freq=100, duty=512) | ||
... | ||
pwm_1.duty(1024) | ||
... | ||
pwm_1.duty(256) | ||
``` | ||
|
||
Druhý motorek se dá ovládat podobně, jen s jinými čísly pinů. | ||
Tady jsou: | ||
|
||
``` | ||
pin_3a = Pin(12, Pin.OUT) # D6 na destičce, 3A na čipu | ||
pin_4a = Pin(13, Pin.OUT) # D7 na destičce, 4A na čipu | ||
pin_34en = Pin(15, Pin.OUT) # D8 na destičce, 3,4EN na čipu | ||
``` | ||
|
||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
title: Motorky | ||
style: md | ||
attribution: | ||
- Pro PyLadies CZ napsal Petr Viktorin 2019. | ||
- Diagramy s LED vytvořeny pomocí [Fritzing](http://fritzing.org). | ||
- NodeMCU © 2015 [Daniel Eichhorn z blog.squix.org](https://blog.squix.org/2015/05/esp8266-nodemcu-v10-part-created-for.html) pod licencí MIT | ||
license: cc-by-sa-40 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.