Skip to content

Commit

Permalink
Completed docs for examples
Browse files Browse the repository at this point in the history
  • Loading branch information
VedantParanjape committed Aug 17, 2020
1 parent e9f7991 commit 0ca1fa9
Show file tree
Hide file tree
Showing 17 changed files with 424 additions and 16 deletions.
33 changes: 32 additions & 1 deletion docs/examples/button_click_rpmsg.md
Original file line number Diff line number Diff line change
@@ -1 +1,32 @@
# Sending state of button using RPMSG
# Sending state of button using RPMSG

!!! info "Schematic"
=== "Pocket Beagle"
![](images/led_button_pocket_beagle.png)

=== "BeagleBone Black / Beagle Bone Black Wireless"
![](images/led_button_beagle_bone_black.png)

## Code

```python
init_message_channel();

while : true {
if : digital_read(P1_29) {
send_message(1);
}
else {
send_message(0);
}
delay(100);
}
```

* Following code works on PocketBeagle, to use on other boards, please change the pins accordingly.

## Explaination

`init_message_channel` is needed to setup communication channel between ARM<->PRU. It only needs to be called once, before using RPMSG functions.

`while : true` loop runs endlessly, inside this, we check for value of header pin P1_29, if it reads HIGH, 1 is sent to the ARM core using `send_message` and if it is LOW, 0 is sent to ARM core using `send_message`. Then PRU waits for 100ms, and repeats the steps again and again.
19 changes: 18 additions & 1 deletion docs/examples/delay.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,21 @@
![](images/led_pocket_beagle.png)

=== "BeagleBone Black / Beagle Bone Black Wireless"
![](images/led_beagle_bone_black.png)
![](images/led_beagle_bone_black.png)

## Code

```python
digital_write(P1_31, true);
delay(2000);
digital_write(P1_31, false);
delay(5000);
digital_write(P1_31, true);
```

* Following code works on PocketBeagle, to use on other boards, please change the pins accordingly.

## Explaination

This code snippet writes HIGH to header pin P1_31, then waits for 2000ms using the `delay` call, after that it writes LOW to header pin P1_31, then again waits for 5000ms using the `delay` call, and finally writes HIGH to header pin P1_31.

24 changes: 23 additions & 1 deletion docs/examples/digital_read.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,26 @@
![](images/led_button_pocket_beagle.png)

=== "BeagleBone Black / Beagle Bone Black Wireless"
![](images/led_button_beagle_bone_black.png)
![](images/led_button_beagle_bone_black.png)

## Code

```python
while : true {
if : digital_read(P1_29) {
digital_write(P1_31, false);
}
else {
digital_write(P1_31, true);
}
}
```

* Following code works on PocketBeagle, to use on other boards, please change the pins accordingly.

## Explaination

This code runs a never ending loop, since it is `while : true`. Inside `while` it checks if header pin P1_29 is HIGH or LOW.
If header pin P1_29 is HIGH, header pin P1_31 is set to LOW, and if header pin P1_29 is LOW, header pin P1_31 is set to HIGH.


17 changes: 16 additions & 1 deletion docs/examples/digital_write.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,19 @@
![](images/led_pocket_beagle.png)

=== "BeagleBone Black / Beagle Bone Black Wireless"
![](images/led_beagle_bone_black.png)
![](images/

## Code

```python
while : true {
digital_write(P1_31, true);
}
```

* Following code works on PocketBeagle, to use on other boards, please change the pins accordingly.

## Explaination

This code runs a never ending loop, since it is `while : true`. Inside `while` it sets header pin P1_31 to HIGH.
64 changes: 64 additions & 0 deletions docs/examples/hcsr04_example_rpmsg.md
Original file line number Diff line number Diff line change
@@ -1 +1,65 @@
# HCSR04 Distance Sensor example (sending distance data to ARM using RPMSG)

!!! info "Schematic"
=== "Pocket Beagle"
![](images/hcsr04_pocket_beagle.png)

=== "BeagleBone Black / Beagle Bone Black Wireless"
![](images/hcsr04_beagle_bone_black.png)

## Code

```python
def measure : int : {
bool timeout := false;
int echo := -1;

start_counter();

while : read_counter() <= 2000 {
digital_write(5, true);
}
digital_write(5, false);
stop_counter();

start_counter();
while : not (digital_read(6)) and true {
if : read_counter() > 200000000 {
timeout := true;
break;
}
}
stop_counter();

if : not(timeout) and true {
start_counter();
while : digital_read(6) and true {
if : read_counter() > 200000000 {
timeout := true;
break;
}
echo := read_counter();
}
stop_counter();
}

if : timeout and true {
echo := 0;
}

return echo;
}

init_message_channel();

while : true {
int ping:= measure();

send_message(ping);
delay(1000);
}
```

* Following code works on PocketBeagle, to use on other boards, please change the pins accordingly.

## Explaination
63 changes: 62 additions & 1 deletion docs/examples/hcsr04_sensor.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,65 @@
![](images/hcsr04_pocket_beagle.png)

=== "BeagleBone Black / Beagle Bone Black Wireless"
![](images/hcsr04_beagle_bone_black.png)
![](images/hcsr04_beagle_bone_black.png)

## Code

```python
def measure : int : {
bool timeout := false;
int echo := 0;

start_counter();

while : read_counter() <= 2000 {
digital_write(7, true);
}
digital_write(7, false);
stop_counter();

start_counter();
while : not (digital_read(1)) and true {
if : read_counter() > 200000000 {
timeout := true;
break;
}
}
stop_counter();

if : not(timeout) and true {
start_counter();
while : digital_read(1) and true {
if : read_counter() > 200000000 {
timeout := true;
break;
}
echo := read_counter();
}
stop_counter();
}

if : timeout and true {
echo := 0;
}

return echo;
}

while : true {
int ping:= measure()*1000;

if : ping > 292200 {
digital_write(4, false);
}
else
{
digital_write(4, true);
}
delay(1000);
}
```

* Following code works on PocketBeagle, to use on other boards, please change the pins accordingly.

## Explaination
19 changes: 18 additions & 1 deletion docs/examples/led_blink.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,21 @@
![](images/led_pocket_beagle.png)

=== "BeagleBone Black / Beagle Bone Black Wireless"
![](images/led_beagle_bone_black.png)
![](images/led_beagle_bone_black.png)

## Code

```python
while : 1 == 1 {
digital_write(P1_31, true);
delay(1000);
digital_write(P1_31, false);
delay(1000);
}
```

* Following code works on PocketBeagle, to use on other boards, please change the pins accordingly.

## Explaination

This code runs a never ending loop, since it is `while : true`. Inside `while` it sets header pin P1_31 to HIGH, waits for 1000ms, then sets header pin P1_31 to LOW, then again it waits for 1000ms. This loop runs endlessly, so we get a Blinking output if one connects a LED
21 changes: 20 additions & 1 deletion docs/examples/led_blink_button.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,23 @@
![](images/led_button_pocket_beagle.png)

=== "BeagleBone Black / Beagle Bone Black Wireless"
![](images/led_button_beagle_bone_black.png)
![](images/led_button_beagle_bone_black.png)

## Code

```python
while : true {
if : digital_read(P1_29) {
digital_write(P1_31, false);
}
else {
digital_write(P1_31, true);
}
}
```

* Following code works on PocketBeagle, to use on other boards, please change the pins accordingly.

## Explaination

This code runs a never ending loop, since it is `while : true`. Inside `while` if header pin P1_29 is HIGH, then header pin P1_31 is set to HIGH, waits for 1000ms, then sets header pin P1_31 to LOW, then again it waits for 1000ms. This loop runs endlessly as long as header pin P1_29 is HIGH, so we get a Blinking output if one connects a LED to output pin.
30 changes: 29 additions & 1 deletion docs/examples/led_blink_counter.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,32 @@
![](images/led_pocket_beagle.png)

=== "BeagleBone Black / Beagle Bone Black Wireless"
![](images/led_beagle_bone_black.png)
![](images/led_beagle_bone_black.png)

## Code

```python
while : true {
start_counter();
while : read_counter() < 200000000 {
digital_write(P1_31, true);
}
stop_counter();

start_counter();
while : read_counter() < 200000000 {
digital_write(P1_31, false);
}
stop_counter();
}
```

* Following code works on PocketBeagle, to use on other boards, please change the pins accordingly.

## Explaination

This code runs a never ending while loop, since it is `while : true`. Inside `while` it starts the counter, then in a nested while loop, which runs as long as `read_counter` returns values less than 200000000, so for 200000000 cycles, HIGH is written to header pin P1_31, and after the while loop ends, the counter is stopped.

Similarly counter is started again, which runs as long as `read_counter` returns a value less than 200000000, so for 200000000 cycles, LOW is written to header pin P1_31, and after the while loop ends, the counter is stopped.

This process goes on endlessly as it is inside a never ending while loop. Here, we check if `read_counter` is less than 200000000, as counter takes exactly 1 second to count this much cycles, so basically the LED is turned on for 1 second, and then turned off for 1 second. Thus if a LED is connected to the pin, we get a endlessly blinking LED.
21 changes: 20 additions & 1 deletion docs/examples/led_blink_for.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,23 @@
![](images/led_pocket_beagle.png)

=== "BeagleBone Black / Beagle Bone Black Wireless"
![](images/led_beagle_bone_black.png)
![](images/led_beagle_bone_bl

## Code

```python
for : l in 0:10 {
digital_write(P1_31, true);
delay(1000);
digital_write(P1_31, false);
delay(1000);
}
```

* Following code works on PocketBeagle, to use on other boards, please change the pins accordingly.

## Explaination

This code runs for loop with 10 iterations, Inside `for` it sets header pin P1_31 to HIGH, waits for 1000ms, then sets header pin P1_31 to LOW, then again it waits for 1000ms. This loop runs endlessly, so we get a Blinking output if one connects a LED. So LED will blink 10 times with this code.

19 changes: 18 additions & 1 deletion docs/examples/led_blink_while.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,21 @@
![](images/led_pocket_beagle.png)

=== "BeagleBone Black / Beagle Bone Black Wireless"
![](images/led_beagle_bone_black.png)
![](images/led_beagle_bone_black.png)

## Code

```python
while : true {
digital_write(P1_31, true);
delay(1000);
digital_write(P1_31, false);
delay(1000);
}
```

* Following code works on PocketBeagle, to use on other boards, please change the pins accordingly.

## Explaination

This code runs a never ending while loop, since it is `while : true`. Inside `while` it sets header pin P1_31 to HIGH, waits for 1000ms, then sets header pin P1_31 to LOW, then again it waits for 1000ms. This loop runs endlessly, so we get a Blinking output if one connects a LED
Loading

0 comments on commit 0ca1fa9

Please sign in to comment.