Skip to content

Commit bbec0d5

Browse files
dbg
1 parent c02c9d0 commit bbec0d5

File tree

4 files changed

+255
-7
lines changed

4 files changed

+255
-7
lines changed
Lines changed: 248 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,248 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "f3918b49-9476-4415-a7e9-68539c202181",
6+
"metadata": {},
7+
"source": [
8+
"# Project 0 - Jupyter Notebook Tutorial\n",
9+
"\n",
10+
"Welcome to the SparkFun MicroPython SIK! This guide contains a Jupyter Notebook for each."
11+
]
12+
},
13+
{
14+
"cell_type": "code",
15+
"execution_count": null,
16+
"id": "f346d560",
17+
"metadata": {},
18+
"outputs": [],
19+
"source": []
20+
},
21+
{
22+
"cell_type": "markdown",
23+
"id": "1bd52930-d783-460a-923b-41a3c37d2f2b",
24+
"metadata": {},
25+
"source": [
26+
"## Blinking the LED\n",
27+
"\n",
28+
"Now that your circuit is build, it's time to blink the LED. This is done using MicroPython, which is running on the RedBoard.\n",
29+
"\n",
30+
"The first step is to connect your RedBoard to a USB port on this computer.\n",
31+
"\n",
32+
"Select the \"Connect\" button at the bottom right of this screen and a panel is displayed\n",
33+
"\n",
34+
"Select the \"Connect Device\" Button, and when the selection dialog appears, select the port that displays ***Board in FS mode (...)*** or ***Board CDC (...)***\n",
35+
"\n",
36+
"![Select a Port](images/sik-demo-select-port.png)\n",
37+
"\n",
38+
"With the RedBoard connected, use the following MicroPython commands to blink the LED. \n",
39+
"\n",
40+
"### Using MicroPython\n",
41+
"\n",
42+
"The following MicroPython commands are entered to blink the LED on your board. \n",
43+
"\n",
44+
"**REMEMBER** To enter a MicroPython command, hold down either the Control (on Windows) or Command (on Mac) key when pressing *Enter*.\n",
45+
"\n",
46+
"**Make sure for each notebook you run EVERY code cell presented and you run them in order.**\n",
47+
"\n",
48+
"An alternative is to click the \"Restart kernel and run all cells\" button at the top of the page (⏩). If you are connected to your board, this should automatically run every cell in order.\n",
49+
"\n",
50+
"#### Step 1 - Setup\n",
51+
"\n",
52+
"To blink the LED, we need to enable the board pin **34** (the pin that the LED is connected to in the circuit). \n",
53+
"\n",
54+
"To do this we **load the Pin definition for the board**\n",
55+
"\n"
56+
]
57+
},
58+
{
59+
"cell_type": "code",
60+
"execution_count": null,
61+
"id": "4494b462-505b-4a23-8ebc-28b54152bd88",
62+
"metadata": {},
63+
"outputs": [],
64+
"source": [
65+
"from machine import Pin"
66+
]
67+
},
68+
{
69+
"cell_type": "markdown",
70+
"id": "2d94be96-a8c9-4932-8111-58d10a8622a9",
71+
"metadata": {},
72+
"source": [
73+
"Now **create a Pin variable for the LED pin, number 34**. Also define it as an **output pin**, so we can turn it on and off"
74+
]
75+
},
76+
{
77+
"cell_type": "code",
78+
"execution_count": null,
79+
"id": "432bb00a-9160-4e56-a08e-716ab922f60c",
80+
"metadata": {},
81+
"outputs": [],
82+
"source": [
83+
"led_pin = Pin(34, Pin.OUT)"
84+
]
85+
},
86+
{
87+
"cell_type": "markdown",
88+
"id": "27ad33ac-2e51-409c-8a12-753da4384740",
89+
"metadata": {},
90+
"source": [
91+
"We turn the LED on by setting the pin value to **high** or on"
92+
]
93+
},
94+
{
95+
"cell_type": "code",
96+
"execution_count": null,
97+
"id": "cd2ae013-674c-4f33-8827-8c3d672d07a5",
98+
"metadata": {},
99+
"outputs": [],
100+
"source": [
101+
"led_pin.high()"
102+
]
103+
},
104+
{
105+
"cell_type": "markdown",
106+
"id": "f8c6243c-33b8-4eb1-8065-e22e5e6d3814",
107+
"metadata": {},
108+
"source": [
109+
"And to turn the LED off, we set the pin to **low**"
110+
]
111+
},
112+
{
113+
"cell_type": "code",
114+
"execution_count": null,
115+
"id": "52a875da-ccd3-437d-b310-e2ce58de53bd",
116+
"metadata": {},
117+
"outputs": [],
118+
"source": [
119+
"led_pin.low()"
120+
]
121+
},
122+
{
123+
"cell_type": "markdown",
124+
"id": "3cb0f029-afa4-4a0b-9846-cc874d67879a",
125+
"metadata": {},
126+
"source": [
127+
"To *blink* the LED, we can turn it on, wait a period of time and then turn it off. This is done by sleeping between the **on** and **off** commands. \n",
128+
"\n",
129+
"To do this in MicroPython, we need a sleep function. Let's load the **sleep** function, which will sleep for a number of seconds.."
130+
]
131+
},
132+
{
133+
"cell_type": "code",
134+
"execution_count": null,
135+
"id": "73457bed-1444-4300-ba58-4809bf9068f8",
136+
"metadata": {},
137+
"outputs": [],
138+
"source": [
139+
"from time import sleep"
140+
]
141+
},
142+
{
143+
"cell_type": "markdown",
144+
"id": "1ea7c7a6-7dfb-4bbd-bab5-da4b52af14bf",
145+
"metadata": {},
146+
"source": [
147+
"Now lets blink the LED - sleeping for 1 second between turning the LED on and off"
148+
]
149+
},
150+
{
151+
"cell_type": "code",
152+
"execution_count": null,
153+
"id": "95e90c57-57d0-4e26-b8f8-0d4f0720b46a",
154+
"metadata": {},
155+
"outputs": [],
156+
"source": [
157+
"led_pin.high()\n",
158+
"sleep(1)\n",
159+
"led_pin.low()\n",
160+
"sleep(1)\n",
161+
"led_pin.high()\n",
162+
"sleep(1)\n",
163+
"led_pin.low()"
164+
]
165+
},
166+
{
167+
"cell_type": "markdown",
168+
"id": "54d14da9-3d4f-4493-98a5-3dd0c025733f",
169+
"metadata": {},
170+
"source": [
171+
"Now we have blinked the LED! \n",
172+
"\n",
173+
"Now we'll present the idea of a **for loop**. A loop repeats a statement for a number of specified times. \n",
174+
"\n",
175+
"To blink our LED 10 times, use the following command:"
176+
]
177+
},
178+
{
179+
"cell_type": "code",
180+
"execution_count": null,
181+
"id": "73237269-9f49-4145-b03d-7ba0f6bc8664",
182+
"metadata": {},
183+
"outputs": [],
184+
"source": [
185+
"for i in range(10):\n",
186+
" led_pin.high()\n",
187+
" sleep(1)\n",
188+
" led_pin.low()\n",
189+
" sleep(1)"
190+
]
191+
},
192+
{
193+
"cell_type": "markdown",
194+
"id": "d91669fb-aea7-411c-927b-99724540a33c",
195+
"metadata": {},
196+
"source": [
197+
"## What You Should See\n",
198+
"\n",
199+
"When this command runs, it blinks the LED 10 times by setting the LED high, then low and sleeping in between each step. "
200+
]
201+
},
202+
{
203+
"cell_type": "markdown",
204+
"id": "67d5c010",
205+
"metadata": {},
206+
"source": [
207+
"## Coding Challenges\n",
208+
"\n",
209+
"| Challenge | Description |\n",
210+
"|------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n",
211+
"| Persistence of Vision | Computer screens, movies and the lights in your house all flicker so quickly that they appear to be on all of the time but are actually blinking faster than the human eye can detect. See how much you can decrease the delay time in your program before the light appears to be on all the time but is still blinking. |\n",
212+
"| Morse Code | Try changing the delays and adding more `led_pin.high()` and `led_pin.low()` commands to make your program blink a message in Morse code. |\n",
213+
"\n",
214+
"## Troubleshooting\n",
215+
"\n",
216+
"| Problem | Solution |\n",
217+
"|-----------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n",
218+
"| I get an error when uploading my code | Make sure you are connected to the correct serial port and have run all of the code cells in order in this Notebook. You can also try clicking the \"Restart kernel and run all cells\" button at the top of the page (⏩). This will make sure to run every cell and run them in order. Which Serial Port is the right one? Depending on how many devices you have plugged into your computer, you may have several active Serial Ports. A simple way to determine the correct one is to look at your list of Serial Ports. Unplug your RedBoard from your computer. Look at the list again. Whichever Serial Port has disappeared from the list is the one you want to select once you plug your board back in to your computer. |\n",
219+
"| My code uploads, but my LED won’t turn on | LEDs will only work in one direction. Try taking it out of your breadboard, turning it 180 degrees, and reinserting it. |\n",
220+
"| Still not working? | Jumper wires unfortunately can go \"bad\" from getting bent too much. The copper wire inside can break, leaving an open connection in your circuit. If you are certain that your circuit is wired correctly and that your code is error-free and uploaded but you are still encountering issues, try replacing one or more of the jumper wires for the component that is not working. |\n",
221+
"\n",
222+
"## You've Completed Circuit 1A!\n",
223+
"\n",
224+
"Continue to circuit 1B to learn about analog signals and potentiometers\n",
225+
"\n",
226+
"![Next - Circuit B](images/sik-demo-prj1-ca-next.png)\n",
227+
"\n",
228+
"[![Next Project](images/next-circuit.png)](./SIK_Project1_CircuitB_Full.ipynb)"
229+
]
230+
}
231+
],
232+
"metadata": {
233+
"kernelspec": {
234+
"display_name": "MicroPython upydevice kernel",
235+
"language": "python",
236+
"name": "micropython-upydevice"
237+
},
238+
"language_info": {
239+
"codemirror_mode": "python",
240+
"file_extension": ".py",
241+
"mimetype": "text/x-python",
242+
"name": "python",
243+
"pygments_lexer": "python"
244+
}
245+
},
246+
"nbformat": 4,
247+
"nbformat_minor": 5
248+
}

content/SIK_Project2_CircuitA_Full.ipynb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -262,18 +262,18 @@
262262
"\n",
263263
"## Coding Challenges\n",
264264
"\n",
265-
"| Challenge | Description |\n",
266-
"|----------------------------|----------------------------------------------------------------------------------------------|\n",
267-
"| Change the tempo of the song | Experiment with the `beatLength` variable to change the tempo of the song. |\n",
268-
"| Make your own song | Try changing the notes to make a different song. Spaces `\" \"` can be used for rests in the song. |\n",
265+
"Challenge | Description\n",
266+
"--- | ---\n",
267+
"Change the tempo of the song | Experiment with the `beatLength` variable to change the tempo of the song.\n",
268+
"Make your own song | Try changing the notes to make a different song. Spaces `\" \"` can be used for rests in the song.\n",
269269
"\n",
270-
"## Troubleshooting\n",
271270
"\n",
271+
"## Troubleshooting\n",
272272
"\n",
273273
"| Problem | Solution |\n",
274274
"|------------------------------- |--------------------------------------------------------------------------------------------|\n",
275275
"| The song is too quiet or too loud | Turn the potentiometer to adjust the volume. |\n",
276-
"| No sound is playing | Try pressing the reset button on the RedBoard. If that doesn’t work, check your wiring of the buzzer. It's easy to misalign a pin with a jumper wire. |\n",
276+
"| No sound is playing | Try pressing the reset button on the RedBoard. If that doesn’t work, check your wiring of the buzzer. It's easy to misalign a pin with a jumper wire. |\n",
277277
"\n",
278278
"## You've Completed Circuit 2A!\n",
279279
"\n",

content/images/save-to-redboard.png

2.99 KB
Loading

kernel/src/kernel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export class EmbeddedKernel extends BaseKernel {
8383
this.outputResponse(`Save command detected, saving code...`);
8484
const codeToSave = code.split(saveString)[1].trim();
8585
// pass the "stream" to the saveCodeToDevice method
86-
const result = await this.serviceContainer.saveCodeToDevice(codeToSave, this.outputResponse.bind(this));
86+
const result = await this.serviceContainer.saveCodeToDevice(codeToSave, this.stream.bind(this));
8787
if (result && result.status === 'ok') {
8888
return {
8989
status: 'ok',

0 commit comments

Comments
 (0)