Skip to content

Commit 010af8b

Browse files
Update giga-r1-wifi.md
1 parent ca182f3 commit 010af8b

File tree

1 file changed

+206
-1
lines changed
  • content/micropython/03.micropython/04.board-examples/giga-r1-wifi

1 file changed

+206
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,209 @@
11
---
22
title: GIGA R1 WiFi
33
description: Learn how to use specific features on the GIGA R1 WiFi using MicroPython
4-
---
4+
---
5+
![GIGA R1 WiFi](./assets/giga-r1-wifi.png)
6+
7+
In this guide, you will find information specific to the [GIGA R1 WiFi board](https://store.arduino.cc/products/giga-r1-wifi), such as supported serial protocols, built-in peripherals, and how to access the wireless features.
8+
9+
For installation instructions, please visit the link below:
10+
- [Installing MicroPython](https://labs.arduino.cc/en/labs/micropython-installer)
11+
12+
## Pinout
13+
14+
The pinout for the GIGA R1 WiFi can be found in the image below.
15+
16+
![GIGA R1 WiFi Pinout](./assets/giga-r1-wifi-pinout.png)
17+
18+
***For more details on this product, visit the [hardware product page](/hardware/giga-r1-wifi/).***
19+
20+
## Board-Specific Features
21+
22+
The GIGA R1 WiFi has several board-specific features that we can access through MicroPython:
23+
24+
- **Dual-core STM32H7**: Leverage the power of two cores (Cortex-M7 and Cortex-M4) and RPC for advanced multitasking applications.
25+
- **RGB LED**: A built-in RGB LED that can be controlled by setting `r`, `g`, and `b` values.
26+
- **Wireless Connectivity**: Supports both **Wi-Fi®** and **Bluetooth®** using the integrated Murata 1DX module.
27+
- **High-speed Connectivity**: Includes a USB-C® connector, high-speed UART, and CAN bus support.
28+
29+
30+
## Wireless Connectivity
31+
32+
The GIGA R1 WiFi features a Murata 1DX module that provides both **Wi-Fi®** and **Bluetooth®** connectivity. To find examples, please visit the links below:
33+
34+
- **[MicroPython - Bluetooth® documentation]()**
35+
- **[MicroPython - Wi-Fi® documentation]()**
36+
37+
38+
39+
### Dual-Core Programming
40+
41+
The GIGA R1 WiFi supports dual-core programming, where the Cortex-M7 and Cortex-M4 cores can execute separate tasks simultaneously. Below is an example of how to run MicroPython on one core while offloading specific tasks to the other:
42+
43+
**Example:** Running MicroPython on Cortex-M7 and using the M4 for auxiliary tasks.
44+
45+
```python
46+
from machine import freq
47+
import _thread
48+
49+
# Function to run on Cortex-M4 core
50+
def auxiliary_task():
51+
while True:
52+
print("Running auxiliary task on M4")
53+
time.sleep(1)
54+
55+
# Run main task on M7 core
56+
def main_task():
57+
print("Main task on M7 core")
58+
_thread.start_new_thread("Aux", auxiliary_task, ())
59+
60+
main_task()
61+
```
62+
63+
> **Note**: Dual-core programming is an advanced topic and requires proper synchronization to avoid resource conflicts.
64+
65+
66+
67+
### RGB LED
68+
69+
The GIGA R1 WiFi has a built-in RGB LED that can be easily controlled to turn on each color individually. The following example shows how to cycle through red, green, and blue, waiting a second between each, and then turning off all colors before looping back.
70+
71+
```python
72+
from machine import Pin
73+
import time
74+
75+
# Initialize pins for the RGB LED
76+
red = Pin("LED_RED", Pin.OUT) # LED_RED GPIO
77+
green = Pin("LED_GREEN", Pin.OUT) # LED_GREEN GPIO
78+
blue = Pin("LED_BLUE", Pin.OUT) # LED_BLUE GPIO
79+
80+
# Function to turn off all colors
81+
def turn_off_all():
82+
red.value(0)
83+
green.value(0)
84+
blue.value(0)
85+
86+
# Cycle through colors
87+
while True:
88+
red.value(1) # Turn on Red
89+
time.sleep(1) # Wait for 1 second
90+
red.value(0) # Turn off Red
91+
92+
green.value(1) # Turn on Green
93+
time.sleep(1) # Wait for 1 second
94+
green.value(0) # Turn off Green
95+
96+
blue.value(1) # Turn on Blue
97+
time.sleep(1) # Wait for 1 second
98+
blue.value(0) # Turn off Blue
99+
100+
turn_off_all() # Ensure all colors are off
101+
```
102+
103+
104+
### PWM on the GIGA R1 WiFi
105+
106+
On STM32 boards like the Arduino GIGA R1 WiFi, PWM is handled differently than on typical MicroPython boards. Instead of directly using the `PWM` class, you need to use the `Timer` class in combination with the `Pin` class from the `pyb` module.
107+
108+
Below is an example of how to set up PWM on the GIGA R1 WiFi:
109+
110+
```python
111+
from pyb import Pin, Timer
112+
113+
# Set up the PWM pin
114+
p = Pin('A13') # Replace 'A13' with your desired PWM-capable pin
115+
116+
# Initialize a timer for PWM
117+
tim = Timer(2, freq=1000) # Timer 2 with a frequency of 1 kHz
118+
119+
# Create a PWM channel on the timer
120+
ch = tim.channel(1, Timer.PWM, pin=p)
121+
122+
# Set the duty cycle
123+
ch.pulse_width_percent(25) # 25% duty cycle
124+
```
125+
126+
- **Pin Setup**:
127+
`p = Pin('A13')` initializes the pin `A13` for PWM output. Replace `'A13'` with another PWM-capable pin if needed. Note that on the GIGA R1 WiFi, `A13` is marked as **DAC1** on the pinout.
128+
129+
- **Timer Initialization**:
130+
`tim = Timer(2, freq=1000)` initializes **Timer 2** with a frequency of 1000 Hz.
131+
132+
- **Channel Setup**:
133+
`ch = tim.channel(1, Timer.PWM, pin=p)` creates a PWM channel on Timer 2, Channel 1, and associates it with pin `p`.
134+
135+
- **Set Duty Cycle**:
136+
`ch.pulse_width_percent(25)` sets the duty cycle of the PWM signal to 25%. You can adjust this value between `0` and `100` to control the signal's ON time.
137+
138+
139+
### Using the RPC Library with MicroPython
140+
141+
The **msgpackrpc** library provides the same functionality as the Arduino RPC library for MicroPython, allowing seamless communication between the two cores (M7 and M4) on the GIGA R1 WiFi. This library enables binding of local functions or objects, starting the M4 core, and invoking remote calls from Python scripts.
142+
143+
#### Key Features:
144+
- **Dual-Core Support**: Execute tasks on the M4 core while the main MicroPython code runs on the M7 core.
145+
- **Ease of Use**: The library is built-in and enabled by default in compatible Arduino boards, starting with MicroPython release v1.23.
146+
- **No External Dependencies**: The library is included in the MicroPython firmware and does not require additional installations.
147+
148+
149+
#### Restrictions:
150+
While powerful, the **msgpackrpc** library has some limitations:
151+
1. Arduino sketches can only run on the **M4 core**.
152+
2. **SDRAM-based firmware** is not supported.
153+
3. **Flash-based firmware** must use a 1.5MB M7 + 0.5MB M4 flash partitioning scheme.
154+
155+
156+
157+
#### Example
158+
159+
Here’s how to bind a function on the M7 core and call it from the M4 core:
160+
161+
**On the M7 Core:**
162+
163+
```python
164+
from rpc import RPCServer
165+
166+
# Define a function to bind
167+
def hello_world():
168+
return "Hello from M7!"
169+
170+
# Start the RPC server
171+
rpc_server = RPCServer()
172+
rpc_server.bind_function("hello_world", hello_world)
173+
174+
# Keep the server running
175+
rpc_server.run()
176+
```
177+
178+
**On the M4 Core:**
179+
180+
```python
181+
from rpc import RPCClient
182+
183+
# Connect to the M7 core
184+
rpc_client = RPCClient()
185+
186+
# Call the bound function on the M7 core
187+
result = rpc_client.call_function("hello_world")
188+
print(result) # Outputs: Hello from M7!
189+
```
190+
191+
For a detailed explanation of the RPC library, including advanced use cases and configuration, visit the [RPC Library with MicroPython guide](https://docs.arduino.cc/tutorials/giga-r1-wifi/giga-dual-core/#using-the-rpc-library-with-micropython).
192+
193+
194+
195+
!Needs testing for CANBUS!
196+
197+
## Additional Features
198+
199+
The GIGA R1 WiFi includes other features that can be explored:
200+
201+
- **Analog Pins**: Use `ADC` to read analog values from sensors.
202+
- **PWM**: Use `PWM` for pulse-width modulation to control motors or LEDs.
203+
204+
205+
## Summary
206+
207+
The GIGA R1 WiFi is a robust microcontroller packed with advanced features for embedded programming with MicroPython. From dual-core programming to high-speed connectivity and wireless communication, this guide provides the essentials to get started with this powerful board.
208+
209+
For more advanced projects and examples, visit the [Arduino Docs - MicroPython](https://docs.arduino.cc/micropython/).

0 commit comments

Comments
 (0)