Skip to content
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

Various updates and corrections #15

Merged
merged 4 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ In order to flash and run these programs on an STM32 device, you will need, in a

* 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)
* 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.
* 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).
* 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).
* The [st-flash](https://github.com/texane/stlink) flashing tool.
* 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).
* (Recommended) A serial console program, such as [`minicom`](https://en.wikipedia.org/wiki/Minicom).
Expand Down
2 changes: 1 addition & 1 deletion demos/morse_server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Your ESP can be reached with a web browser on port 8080 by its IP address or DHC

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

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

## Supported Platforms

Expand Down
16 changes: 10 additions & 6 deletions elixir/Blinky/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

Welcome to the `Blinky` AtomVM application.

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

> Note. This example program only runs on the `esp32` and `stm32` platforms.
> Note. This example program only runs on the `esp32`,`stm32`, and `pico` platforms.

To run this example, connect a 1k ohm resistor in series with a 3.3v LED between IO pin 2 and GND.
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.

+-----------+
| | 1k ohm
| | 330 ohm
| IO2 o--- \/\/\/\ ---+
| | resistor |
| | |
Expand All @@ -19,8 +19,12 @@ To run this example, connect a 1k ohm resistor in series with a 3.3v LED between
+-----------+ LED
ESP32

> Note. Many ESP32 development boards already attach pin 2 to an on-board LED.
> ESP32 Note. Many ESP32 development boards already attach pin 2 to an on-board LED.

For more information about programming on the AtomVM platform, see the [AtomVM Programmers Guide](https://doc.atomvm.net/programmers-guide.html).
> STM32 Note. The Nucleo line of boards all have three leds on `{:b, [0, 7, 14]}`.

> 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}`.

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

For general information about building and executing Elixir AtomVM example programs, see the Elixir example program [README](../README.md).
34 changes: 32 additions & 2 deletions elixir/Blinky/lib/Blinky.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@
#

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

def start() do
GPIO.set_pin_mode(@pin, :output)
loop(@pin, :low)
platform_gpio_setup()
loop(pin(), :low)
end

defp loop(pin, level) do
Expand All @@ -40,4 +43,31 @@ defmodule Blinky do
defp toggle(:low) do
:high
end

defp pin() do
case :atomvm.platform() do
:esp32 -> 2
:pico -> @pin
:stm32 -> {:b, [0]}
unsupported -> :erlang.exit({:unsupported_platform, unsupported})
end
end

defp platform_gpio_setup() do
case :atomvm.platform() do
:esp32 -> GPIO.set_pin_mode(pin(), :output)
:stm32 -> GPIO.set_pin_mode(pin(), :output)
:pico ->
case @pin do
{:wl, 0} -> :ok
pin ->
GPIO.init(pin)
GPIO.set_pin_mode(pin, :output)
end
unsupported ->
:io.format("Platform ~p is not supported.~n", [unsupported])
:erlang.exit({:error, {:unsupported_platform, unsupported}})
end
end

end
2 changes: 1 addition & 1 deletion elixir/HelloWorld/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ Welcome to the `HelloWorld` AtomVM application.

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

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

For general information about building and executing Elixir AtomVM example programs, see the Elixir example program [README](../README.md).
2 changes: 1 addition & 1 deletion elixir/LEDC_Example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ The `LEDC_Example` AtomVM application illustrates use of the AtomVM `LEDC` inter
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
for the GPIO pins in the example if necessary. See the Blinky example for wiring if you are unsure.

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

For general information about building and executing Erlang AtomVM example programs, see the Erlang example program [README](../README.md).
4 changes: 3 additions & 1 deletion elixir/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ Some example programs can only run on specific platform. The following table su

| Example Program | esp32 | stm32 | Pico | Pico W | generic_unix |
|-----------------|-------|-------|------|--------|--------------|
| Blinky | ✅ | ✅ | | | ❌ |
| Blinky | ✅ | ✅ | | | ❌ |
| HelloWorld | ✅ | ✅ | ✅ | ✅ | ✅ |
| LEDC_Example | ✅ | ❌ | ❌ | ❌ | ❌ |

✦ Works, but requires editing to use onboard LED, see the README in the examples directory.

To build and run an example in this directory, change your working directory to the corresponding example program, and execute the generic instructions below.

> WARNING! The Elixir examples in this repository are currently under construction. They may not run or even compile. Stay tuned for updates!
Expand Down
6 changes: 4 additions & 2 deletions erlang/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ Some example programs can only run on specific platform. The following table su
| Example Program | esp32 | stm32 | Pico | Pico W | generic_unix |
|-----------------|-------|-------|----------------|------------------|--------------|
| arepl_example | ✅ | ❌ | ❌ | ❌ | ✅ |
| blinky | ✅ | | ✅ | | ❌ |
| blinky | ✅ | | ✅ | | ❌ |
| deep_sleep | ✅ | ❌ | ❌ | ❌ | ❌ |
| esp_nvs | ✅ | ❌ | ❌ | ❌ | ❌ |
| gpio_interrupt | ✅ | | ❌ | ❌ | ❌ |
| gpio_interrupt | ✅ | | ❌ | ❌ | ❌ |
| hello_world | ✅ | ✅ | ✅ | ✅ | ✅ |
| http_server_example | ✅ | ❌ | ❌ | ❌ | ✅ |
| i2c_example | ✅ | ❌ | ❌ | ❌ | ❌ |
Expand All @@ -28,6 +28,8 @@ Some example programs can only run on specific platform. The following table su
| udp_server | ✅ | ❌ | ❌ | ❌ | ✅ |
| wifi | ✅ | ❌ | ❌ | ❌ | ❌ |

✦ Works, but requires editing to use onboard LED, see the README in the examples directory.

To build and run an example in this directory, change your working directory to the corresponding example program, and execute the generic instructions below.

## Generic Instructions
Expand Down
2 changes: 1 addition & 1 deletion erlang/arepl_example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Welcome to the `arepl_example` AtomVM application.

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

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

## Build and Run Instructions

Expand Down
16 changes: 10 additions & 6 deletions erlang/blinky/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

Welcome to the `blinky` AtomVM application.

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

> Note. This example program only runs on the `esp32` and `stm32` platforms.
> Note. This example program only runs on the `esp32`, `stm32`, and `pico` platforms.

To run this example, connect a 1k ohm resistor in series with a 3.3v LED between IO pin 2 and GND.
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.

+-----------+
| | 1k ohm
| | 330 ohm
| IO2 o--- \/\/\/\ ---+
| | resistor |
| | |
Expand All @@ -19,8 +19,12 @@ To run this example, connect a 1k ohm resistor in series with a 3.3v LED between
+-----------+ LED
ESP32

> Note. Many ESP32 development boards already attach pin 2 to an on-board LED.
> ESP32 Note. Many ESP32 development boards already attach pin 2 to an on-board LED.

For more information about programming on the AtomVM platform, see the [AtomVM Programmers Guide](https://doc.atomvm.net/programmers-guide.html).
> STM32 Note. The Nucleo line of boards all have three LEDs on {b, [0, 7, 14]}.

> 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}).`

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

For general information about building and executing Erlang AtomVM example programs, see the Erlang example program [README](../README.md).
37 changes: 35 additions & 2 deletions erlang/blinky/src/blinky.erl
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@
-module(blinky).
-export([start/0]).

% External LED on pin 2 will work with all pico devices.
-define(PIN, 2).
% Comment out above and uncomment the following line to use pico-w onboard LED.
% -define(PIN, {wl, 0}).

start() ->
gpio:set_pin_mode(?PIN, output),
loop(?PIN, low).
platform_gpio_setup(atomvm:platform()),
loop(pin(), low).

loop(Pin, Level) ->
io:format("Setting pin ~p ~p~n", [Pin, Level]),
Expand All @@ -37,3 +40,33 @@ toggle(high) ->
low;
toggle(low) ->
high.

pin() ->
case atomvm:platform() of
esp32 ->
2;
pico ->
?PIN;
stm32 ->
{b, 0};
Platform ->
erlang:exit({unsupported_platform, Platform})
end.

platform_gpio_setup(esp32) ->
gpio:set_pin_mode(pin(), output);
platform_gpio_setup(stm32) ->
gpio:set_pin_mode(pin(), output);
platform_gpio_setup(pico) ->
case ?PIN of
{wl, 0} ->
% Pico-W needs no setup for extra "WL" pins
ok;
Pin ->
% Setup for Pico GPIO pins
gpio:init(Pin),
gpio:set_pin_mode(Pin, output)
end;
platform_gpio_setup(Platform) ->
io:format("Platform ~p is not supported.~n", [Platform]),
erlang:exit({error, {unsupported_platform, Platform}}).
2 changes: 1 addition & 1 deletion erlang/deep_sleep/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ Welcome to the `deep_sleep` AtomVM application.

The `deep_sleep` AtomVM application will put the ESP32 device into low-power deep sleep for 10 seconds, wake up, and report the reset reason. In most cases this will be `esp_rst_deepsleep`, but the initial reset reason will be `esp_rst_poweron`, or if you reset the device manually during sleep.

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

For general information about building and executing Erlang AtomVM example programs, see the Erlang example program [README](../README.md).
2 changes: 1 addition & 1 deletion erlang/esp_nvs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ Welcome to the `esp_nvs` AtomVM application.

The `esp_nvs` AtomVM application uses the ESP non-volatile storage to record the number of times the device has restarted. If the NVS storage has not been set for this application, it will be intialized with a count of 0. The device will then sleep for 10 seconds, and restart. After each restart, the number of restarts is incremented and stored in non-volatile storage.

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

For general information about building and executing Erlang AtomVM example programs, see the Erlang example program [README](../README.md).
2 changes: 1 addition & 1 deletion erlang/gpio_interrupt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ This application will wait in a loop for interrupt signals when GPIO pin 2 is ri
Waiting for interrupt ... Interrupt on pin 2
Waiting for interrupt ...

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

For general information about building and executing Erlang AtomVM example programs, see the Erlang example program [README](../README.md).
79 changes: 14 additions & 65 deletions erlang/gpio_interrupt/src/gpio_interrupt.erl
Original file line number Diff line number Diff line change
Expand Up @@ -22,66 +22,12 @@

-export([start/0]).

% -define(OUTPUT_PIN, 2).
% -define(INPUT_PIN, 22).

% start() ->
% case verify_platform(atomvm:platform()) of
% ok ->

% gpio:set_pin_mode(?INPUT_PIN, input),
% gpio:set_pin_pull(?INPUT_PIN, down),
% GPIO = gpio:start(),
% gpio:set_int(GPIO, ?INPUT_PIN, rising),
% spawn(fun receive_interrupt/0),

% gpio:set_pin_mode(?OUTPUT_PIN, output),
% loop(?OUTPUT_PIN, low);
% Error ->
% Error
% end.

% loop(Pin, Level) ->
% io:format("Setting pin ~p ~p~n", [Pin, Level]),
% gpio:digital_write(Pin, Level),
% timer:sleep(1000),
% loop(
% Pin,
% case Level of
% low -> high;
% high -> low
% end
% ).

% receive_interrupt() ->
% io:format("Waiting for interrupt ... "),
% receive
% {gpio_interrupt, Pin} ->
% io:format("Interrupt on pin ~p~n", [Pin]);
% X -> erlang:display(X)
% end,
% receive_interrupt().

% verify_platform(esp32) ->
% ok;
% verify_platform(stm32) ->
% ok;
% verify_platform(Platform) ->
% {error, {unsupported_platform, Platform}}.

-define(PIN, 2).

start() ->
case verify_platform(atomvm:platform()) of
ok ->
gpio:set_pin_mode(?PIN, input),
gpio:set_pin_pull(?PIN, down),
GPIO = gpio:start(),
gpio:set_int(GPIO, ?PIN, rising),
loop();
Error ->
Error
end.
io:format("Testing gpio interrupt on pin ~p.~n", pin()),
GPIO = gpio:start(),
gpio:set_pin_mode(pin(), input),
gpio:set_int(GPIO, pin(), rising),
loop().

loop() ->
io:format("Waiting for interrupt ... "),
Expand All @@ -91,9 +37,12 @@ loop() ->
end,
loop().

verify_platform(esp32) ->
ok;
verify_platform(stm32) ->
ok;
verify_platform(Platform) ->
{error, {unsupported_platform, Platform}}.
pin() ->
case atomvm:platform() of
esp32 ->
0;
stm32 ->
{c, 13};
Platform ->
erlang:exit({unsupported_platform, Platform})
end.
2 changes: 1 addition & 1 deletion erlang/hello_world/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ Welcome to the `hello_world` AtomVM application.

The `hello_world` AtomVM application prints "Hello World" to the console and then terminates.

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

For general information about building and executing Erlang AtomVM example programs, see the Erlang example program [README](../README.md).
2 changes: 1 addition & 1 deletion erlang/i2c_example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ Welcome to the `i2c_example` AtomVM application.

The `i2c_example` AtomVM application demonstrates use of the `i2c` interface using the popular SHT3x temperature sensor.

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

For general information about building and executing Erlang AtomVM example programs, see the Erlang example program [README](../README.md).
2 changes: 1 addition & 1 deletion erlang/ledc_example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ Welcome to the `ledc_example` AtomVM application.

The `ledc_example` AtomVM application illustrates use of the AtomVM `ledc` interface.

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

For general information about building and executing Erlang AtomVM example programs, see the Erlang example program [README](../README.md).
2 changes: 1 addition & 1 deletion erlang/read_priv/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ For this test, note the presence of the `favicon-32x32.png` in the `priv` direct

<<-119,80,78,71,13,10,26,10,0,0,0,...>>

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

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