-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added basic wireless module examples
- Loading branch information
1 parent
5d976a7
commit 816228e
Showing
5 changed files
with
108 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# RM2 Wireless Module - Micropython Examples <!-- omit in toc --> | ||
|
||
<img src="https://shop.pimoroni.com/cdn/shop/files/wireless-1_1500x1500_crop_center.jpg" width="500"> | ||
|
||
These are micropython examples for the [RM2 Wireless Module for Yukon](https://shop.pimoroni.com/products/rm2-wireless-module-for-yukon). | ||
|
||
- [Examples](#examples) | ||
- [Detect Module](#detect-module) | ||
- [WiFi Scan](#wifi-scan) | ||
- [Cheerlights](#cheerlights) | ||
|
||
|
||
## Examples | ||
|
||
### Detect Module | ||
[detect_module.py](detect_module.py) | ||
|
||
A boilerplate example showing how to detect if the RM2 Wireless Module is attached to Yukon prior to performing any wireless operations. | ||
|
||
|
||
### WiFi Scan | ||
[wifi_scan.py](wifi_scan.py) | ||
|
||
Periodically scan for available WiFi networks using a RM2 Wireless Module connected to Slot 5, and print out their details. | ||
|
||
|
||
### Cheerlights | ||
|
||
[cheerlights.py](cheerlights.py) | ||
|
||
Obtain the current CheerLights colour from the internet and show it on an LED Strip connected to Yukon. For more information about CheerLights, visit: https://cheerlights.com/ | ||
|
||
This example requires a secrets.py file to be on your board's file system with the credentials of your WiFi network. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from pimoroni_yukon import Yukon | ||
from pimoroni_yukon import SLOT5 as SLOT | ||
from pimoroni_yukon.modules import WirelessModule | ||
|
||
""" | ||
A boilerplate example showing how to detect if the RM2 Wireless Module | ||
is attached to Yukon prior to performing any wireless operations. | ||
""" | ||
|
||
# Variables | ||
yukon = Yukon() # Create a new Yukon object, with a lower voltage limit set | ||
module = WirelessModule() # Create a WirelessModule object | ||
|
||
# Wrap the code in a try block, to catch any exceptions (including KeyboardInterrupt) | ||
try: | ||
yukon.register_with_slot(module, SLOT) # Register the WirelessModule object with the slot | ||
yukon.verify_and_initialise() # Verify that a WirelessModule is attached to Yukon, and initialise it | ||
|
||
# Do wireless things here | ||
|
||
finally: | ||
# Put the board back into a safe state, regardless of how the program may have ended | ||
yukon.reset() | ||
|
||
# Disconnect from wireless here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import network | ||
import binascii | ||
from pimoroni_yukon import Yukon | ||
from pimoroni_yukon import SLOT5 as SLOT | ||
from pimoroni_yukon.modules import WirelessModule | ||
|
||
""" | ||
Periodically scan for available WiFi networks using a RM2 Wireless Module connected to Slot 5, | ||
and print out their details. | ||
Hold "Boot" to exit the program (can take up to 5 seconds). | ||
""" | ||
|
||
# Constants | ||
SCAN_INTERVAL = 5.0 # The time to sleep between each network scan | ||
|
||
# Variables | ||
yukon = Yukon() # Create a new Yukon object, with a lower voltage limit set | ||
module = WirelessModule() # Create a WirelessModule object | ||
|
||
|
||
# Wrap the code in a try block, to catch any exceptions (including KeyboardInterrupt) | ||
try: | ||
yukon.register_with_slot(module, SLOT) # Register the WirelessModule object with the slot | ||
yukon.verify_and_initialise() # Verify that a WirelessModule is attached to Yukon, and initialise it | ||
|
||
wlan = network.WLAN(network.STA_IF) # Create a new network object for interacting with WiFi | ||
wlan.active(True) # Turn on WLAN communications | ||
|
||
while not yukon.is_boot_pressed(): | ||
# Scan for nearby networks and print them out | ||
networks = wlan.scan() # Returns a list of tuples with 6 fields: ssid, bssid, channel, RSSI, security, hidden | ||
for i, w in enumerate(networks): | ||
print(i, w[0].decode(), binascii.hexlify(w[1]).decode(), | ||
w[2], w[3], w[4], w[5]) | ||
print() | ||
|
||
# Monitor sensors for a number of seconds, recording the min, max, and average for each | ||
yukon.monitored_sleep(SCAN_INTERVAL) | ||
|
||
finally: | ||
# Put the board back into a safe state, regardless of how the program may have ended | ||
yukon.reset() | ||
|
||
# Attempt to disconnect from WiFi | ||
try: | ||
wlan.disconnect() | ||
except Exception: | ||
pass |
This file was deleted.
Oops, something went wrong.