Skip to content

Commit aa3b77a

Browse files
authored
Merge pull request #15 from UncleGrumpy/blinky
Various updates and corrections
2 parents de8b648 + 1b40652 commit aa3b77a

File tree

27 files changed

+128
-104
lines changed

27 files changed

+128
-104
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ In order to flash and run these programs on an STM32 device, you will need, in a
4747

4848
* An STM32 device with support for USB connectivity via UART, such as the [STMicroelectronics](https://www.st.com) [Nucleo-F429ZI](https://www.st.com/en/evaluation-tools/nucleo-f429zi.html). (Some STM32 boards require an external adapter for UART connectivity)
4949
* Installation of the release of the AtomVM virtual machine image on the STM32 device. For information about how to install a release of the AtomVM virtual machine image on an STM32 device, see the AtomVM [Getting Started Guide](https://doc.atomvm.net/getting-started-guide.html) documentation.
50-
* A USB cable to connect to UART and.or JTAG. (The [STM32F4Discovery](https://www.st.com/en/evaluation-tools/stm32f4discovery.html) needs two cables -- one for built in JTAG, and one for external UART, where as on the [Nucleo-F429ZI](https://www.st.com/en/evaluation-tools/nucleo-f429zi.html) board both UART and JTAG are presented on the one on-board usb connection).
50+
* A USB cable to connect to UART and/or JTAG. (The [STM32F4Discovery](https://www.st.com/en/evaluation-tools/stm32f4discovery.html) needs two cables -- one for built in JTAG, and one for external UART, where as on the [Nucleo-F429ZI](https://www.st.com/en/evaluation-tools/nucleo-f429zi.html) board both UART and JTAG are presented on the one on-board usb connection).
5151
* The [st-flash](https://github.com/texane/stlink) flashing tool.
5252
* To use JTAG for flashing and console output debugging, you will need a [st-link v2](https://www.st.com/en/development-tools/st-link-v2.html) or [st-link v3](https://www.st.com/en/development-tools/stlink-v3set.html) device (typically already included on Nucleo and Discovery boards).
5353
* (Recommended) A serial console program, such as [`minicom`](https://en.wikipedia.org/wiki/Minicom).

demos/morse_server/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Your ESP can be reached with a web browser on port 8080 by its IP address or DHC
3535

3636
"http://192.168.0.32:8080" or "http://atomvm-240ac458d278:8080"
3737

38-
For more information about programming on the AtomVM platform, see the [AtomVM Programmers Guide](https://doc.atomvm.net/programmers-guide.html).
38+
For more information about programming on the AtomVM platform, see the [AtomVM Programmers Guide](https://www.atomvm.net/doc/master/programmers-guide.html).
3939

4040
## Supported Platforms
4141

elixir/Blinky/README.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
Welcome to the `Blinky` AtomVM application.
44

5-
The `Blinky` AtomVM application will blink an LED attached to pin 2 on and off once every second.
5+
The `Blinky` AtomVM application will blink an LED attached to pin 2 (`stm32` pin `{:b, 0}`) on and off once every second.
66

7-
> Note. This example program only runs on the `esp32` and `stm32` platforms.
7+
> Note. This example program only runs on the `esp32`,`stm32`, and `pico` platforms.
88
9-
To run this example, connect a 1k ohm resistor in series with a 3.3v LED between IO pin 2 and GND.
9+
To run this example, depending on how bright you want your led, connect a 220 ohm to 1k ohm resistor in series with a 3.3v LED between IO pin 2 and GND.
1010

1111
+-----------+
12-
| | 1k ohm
12+
| | 330 ohm
1313
| IO2 o--- \/\/\/\ ---+
1414
| | resistor |
1515
| | |
@@ -19,8 +19,12 @@ To run this example, connect a 1k ohm resistor in series with a 3.3v LED between
1919
+-----------+ LED
2020
ESP32
2121

22-
> Note. Many ESP32 development boards already attach pin 2 to an on-board LED.
22+
> ESP32 Note. Many ESP32 development boards already attach pin 2 to an on-board LED.
2323
24-
For more information about programming on the AtomVM platform, see the [AtomVM Programmers Guide](https://doc.atomvm.net/programmers-guide.html).
24+
> STM32 Note. The Nucleo line of boards all have three leds on `{:b, [0, 7, 14]}`.
25+
26+
> Pico-W Note. To use the onboard LED on a `picow` edit lib/Blinky.ex and comment out the current `@pin` definition (change to: `# @pin 2`), and uncomment the definition for the picow onboard LED `@pin` definition: `@pin {:wl, 0}`.
27+
28+
For more information about programming on the AtomVM platform, see the [AtomVM Programmers Guide](https://www.atomvm.net/doc/master/programmers-guide.html).
2529

2630
For general information about building and executing Elixir AtomVM example programs, see the Elixir example program [README](../README.md).

elixir/Blinky/lib/Blinky.ex

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,14 @@
1919
#
2020

2121
defmodule Blinky do
22+
# Pin 2 works on any pico device with an external LED
2223
@pin 2
24+
# Comment out above and uncomment below to use Pico W onboard LED
25+
# @pin {:wl, 0}
2326

2427
def start() do
25-
GPIO.set_pin_mode(@pin, :output)
26-
loop(@pin, :low)
28+
platform_gpio_setup()
29+
loop(pin(), :low)
2730
end
2831

2932
defp loop(pin, level) do
@@ -40,4 +43,31 @@ defmodule Blinky do
4043
defp toggle(:low) do
4144
:high
4245
end
46+
47+
defp pin() do
48+
case :atomvm.platform() do
49+
:esp32 -> 2
50+
:pico -> @pin
51+
:stm32 -> {:b, [0]}
52+
unsupported -> :erlang.exit({:unsupported_platform, unsupported})
53+
end
54+
end
55+
56+
defp platform_gpio_setup() do
57+
case :atomvm.platform() do
58+
:esp32 -> GPIO.set_pin_mode(pin(), :output)
59+
:stm32 -> GPIO.set_pin_mode(pin(), :output)
60+
:pico ->
61+
case @pin do
62+
{:wl, 0} -> :ok
63+
pin ->
64+
GPIO.init(pin)
65+
GPIO.set_pin_mode(pin, :output)
66+
end
67+
unsupported ->
68+
:io.format("Platform ~p is not supported.~n", [unsupported])
69+
:erlang.exit({:error, {:unsupported_platform, unsupported}})
70+
end
71+
end
72+
4373
end

elixir/HelloWorld/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ Welcome to the `HelloWorld` AtomVM application.
44

55
The `HelloWorld` AtomVM application prints "Hello World" to the console and then terminates.
66

7-
For more information about programming on the AtomVM platform, see the [AtomVM Programmers Guide](https://doc.atomvm.net/programmers-guide.html).
7+
For more information about programming on the AtomVM platform, see the [AtomVM Programmers Guide](https://www.atomvm.net/doc/master/programmers-guide.html).
88

99
For general information about building and executing Elixir AtomVM example programs, see the Elixir example program [README](../README.md).

elixir/LEDC_Example/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ The `LEDC_Example` AtomVM application illustrates use of the AtomVM `LEDC` inter
77
LEDs are wired to GPIO pins 4, 5, 18, and 19 and should use a resistor (minimum 100 Ohm up to 1K, 220 Ohm is a good choice). Change the number
88
for the GPIO pins in the example if necessary. See the Blinky example for wiring if you are unsure.
99

10-
For more information about programming on the AtomVM platform, see the [AtomVM Programmers Guide](https://doc.atomvm.net/programmers-guide.html).
10+
For more information about programming on the AtomVM platform, see the [AtomVM Programmers Guide](https://www.atomvm.net/doc/master/programmers-guide.html).
1111

1212
For general information about building and executing Erlang AtomVM example programs, see the Erlang example program [README](../README.md).

elixir/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ Some example programs can only run on specific platform. The following table su
99

1010
| Example Program | esp32 | stm32 | Pico | Pico W | generic_unix |
1111
|-----------------|-------|-------|------|--------|--------------|
12-
| Blinky ||| | ||
12+
| Blinky ||| | ||
1313
| HelloWorld ||||||
1414
| LEDC_Example ||||||
1515

16+
✦ Works, but requires editing to use onboard LED, see the README in the examples directory.
17+
1618
To build and run an example in this directory, change your working directory to the corresponding example program, and execute the generic instructions below.
1719

1820
> WARNING! The Elixir examples in this repository are currently under construction. They may not run or even compile. Stay tuned for updates!

erlang/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ Some example programs can only run on specific platform. The following table su
1010
| Example Program | esp32 | stm32 | Pico | Pico W | generic_unix |
1111
|-----------------|-------|-------|----------------|------------------|--------------|
1212
| arepl_example ||||||
13-
| blinky || || ||
13+
| blinky || || ||
1414
| deep_sleep ||||||
1515
| esp_nvs ||||||
16-
| gpio_interrupt || ||||
16+
| gpio_interrupt || ||||
1717
| hello_world ||||||
1818
| http_server_example ||||||
1919
| i2c_example ||||||
@@ -28,6 +28,8 @@ Some example programs can only run on specific platform. The following table su
2828
| udp_server ||||||
2929
| wifi ||||||
3030

31+
✦ Works, but requires editing to use onboard LED, see the README in the examples directory.
32+
3133
To build and run an example in this directory, change your working directory to the corresponding example program, and execute the generic instructions below.
3234

3335
## Generic Instructions

erlang/arepl_example/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Welcome to the `arepl_example` AtomVM application.
44

55
The `arepl_example` AtomVM application demonstrates the use of the `arepl` LISP interpreter.
66

7-
For more information about programming on the AtomVM platform, see the [AtomVM Programmers Guide](https://doc.atomvm.net/programmers-guide.html).
7+
For more information about programming on the AtomVM platform, see the [AtomVM Programmers Guide](https://www.atomvm.net/doc/master/programmers-guide.html).
88

99
## Build and Run Instructions
1010

erlang/blinky/README.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
Welcome to the `blinky` AtomVM application.
44

5-
The `blinky` AtomVM application will blink an LED attached to pin 2 on and off once every second.
5+
The `blinky` AtomVM application will blink an LED attached to pin 2 (`stm32` pin `{b, 0}`) on and off once every second.
66

7-
> Note. This example program only runs on the `esp32` and `stm32` platforms.
7+
> Note. This example program only runs on the `esp32`, `stm32`, and `pico` platforms.
88
9-
To run this example, connect a 1k ohm resistor in series with a 3.3v LED between IO pin 2 and GND.
9+
To run this example, depending on how bright you want your led, connect a 220 ohm to 1k ohm resistor in series with a 3.3v LED between IO pin 2 and GND.
1010

1111
+-----------+
12-
| | 1k ohm
12+
| | 330 ohm
1313
| IO2 o--- \/\/\/\ ---+
1414
| | resistor |
1515
| | |
@@ -19,8 +19,12 @@ To run this example, connect a 1k ohm resistor in series with a 3.3v LED between
1919
+-----------+ LED
2020
ESP32
2121

22-
> Note. Many ESP32 development boards already attach pin 2 to an on-board LED.
22+
> ESP32 Note. Many ESP32 development boards already attach pin 2 to an on-board LED.
2323
24-
For more information about programming on the AtomVM platform, see the [AtomVM Programmers Guide](https://doc.atomvm.net/programmers-guide.html).
24+
> STM32 Note. The Nucleo line of boards all have three LEDs on {b, [0, 7, 14]}.
25+
26+
> Pico W Note. To use the onboard LED on a `picow` edit src/blinky.erl and comment out the current `PIN` definition (change to: `% -define(PIN, 2).`), and uncomment the definition for the `picow` onboard LED definition: `-define(PIN, {wl, 0}).`
27+
28+
For more information about programming on the AtomVM platform, see the [AtomVM Programmers Guide](https://www.atomvm.net/doc/master/programmers-guide.html).
2529

2630
For general information about building and executing Erlang AtomVM example programs, see the Erlang example program [README](../README.md).

0 commit comments

Comments
 (0)