diff --git a/config.toml b/config.toml index ea3b4e7b..064b61d7 100644 --- a/config.toml +++ b/config.toml @@ -421,46 +421,34 @@ theme = "doc-theme" parent = "tutorials" weight = 50 [[menu.main]] - name = "Pygate" - url = "/tutorials/expansionboards/pygate/" - identifier = "tutorials@expansionboards@pygate" + name = "Tracking" + url = "/tutorials/expansionboards/tracking/" + identifier = "tutorials@expansionboards@tracking" parent = "tutorials@expansionboards" weight = 10 [[menu.main]] - name = "pysense" - url = "/tutorials/expansionboards/pysense/" - identifier = "tutorials@expansionboards@pysense" + name = "Sensing" + url = "/tutorials/expansionboards/sensing/" + identifier = "tutorials@expansionboards@sensing" parent = "tutorials@expansionboards" weight = 20 [[menu.main]] - name = "pysense 2.0 X" - url = "/tutorials/expansionboards/pysense2/" - identifier = "tutorials@expansionboards@pysense2" + name = "Scanning" + url = "/tutorials/expansionboards/scanning/" + identifier = "tutorials@expansionboards@scanning" parent = "tutorials@expansionboards" weight = 30 [[menu.main]] - name = "pytrack" - url = "/tutorials/expansionboards/pytrack/" - identifier = "tutorials@expansionboards@pytrack" + name = "Pysleep" + url = "/tutorials/expansionboards/sleep/" + identifier = "tutorials@expansionboards@sleep" parent = "tutorials@expansionboards" weight = 40 -[[menu.main]] - name = "pytrack 2.0 X" - url = "/tutorials/expansionboards/pytrack2/" - identifier = "tutorials@expansionboards@pytrack2" - parent = "tutorials@expansionboards" - weight = 50 -[[menu.main]] - name = "pyscan" - url = "/tutorials/expansionboards/pyscan/" - identifier = "tutorials@expansionboards@pyscan" - parent = "tutorials@expansionboards" - weight = 60 [[menu.main]] name = "Sleep" url = "/tutorials/expansionboards/sleep/" identifier = "tutorials@expansionboards@sleep" - parent = "tutorials@basic" + parent = "tutorials@expansionboards" weight = 20 [[menu.main]] name = "Advanced" @@ -1062,7 +1050,7 @@ theme = "doc-theme" weight = 60 [[menu.main]] - name = "Expansion Boards and Shields" + name = "Shields" url = "/datasheets/expansionboards/" identifier = "datasheets@boards" parent = "datasheets" diff --git a/content/datasheets/expansionboards/pygate.md b/content/datasheets/expansionboards/pygate.md index e6504e0d..5cf0361a 100644 --- a/content/datasheets/expansionboards/pygate.md +++ b/content/datasheets/expansionboards/pygate.md @@ -8,7 +8,15 @@ aliases: --- **Store**: [Buy Here](https://pycom.io/product/pygate/) -## ![](/gitbook/assets/pygate.png) +The Pygate is an 8-channel LoRa Gateway + +## Getting started +1. Upload the latest stable `pygate` firmware release using the [firmware updater](/updatefirmware/device/). +1. Follow the [tutorial](/tutorials/expansionboards/pygate/) to get your Pygate up and connected to The Things Network. + +## Features + +![](/gitbook/assets/pygate.png) ## Datasheet diff --git a/content/datasheets/expansionboards/pyscan.md b/content/datasheets/expansionboards/pyscan.md index baf2a500..5027a377 100644 --- a/content/datasheets/expansionboards/pyscan.md +++ b/content/datasheets/expansionboards/pyscan.md @@ -8,8 +8,21 @@ aliases: --- **Store**: [Buy Here](https://pycom.io/product/pyscan/) -![](/gitbook/assets/pyscan-new.png) +The Pyscan shield allows you to scan RFID and NFC tags and includes an accelerometer and light sensor. +## Getting started +1. Find the libraries for the Pyscan in the [Pycom libraries](https://github.com/pycom/pycom-libraries/releases/) repository on Github. +1. Download the files and extract them into the project folder in Pymakr +1. Click the `upload project to device` button. This will store all necessary files on the device and allow you to import them in the example `main.py`. +1. Check the REPL. If you have Pybytes activated, the example will send the sensor data to Pybytes automatically. Note that the Pyscan will return command to the REPL while it scans for NFC cards in the background. Note that the example also allows the decoding of cards by changing the variable `DECODE_CARD = True` + +### Examples +The Pyscan has several examples: +* [Scanning](/tutorials/expansionboards/scanning/) + +## Features + +![](/gitbook/assets/pyscan-pinout-1.png) ## Datasheet & Pinout The pinout and datasheet of the Pyscan is available as a [PDF File](/gitbook/assets/pyscan-pinout.pdf) @@ -18,7 +31,7 @@ The pinout and datasheet of the Pyscan is available as a [PDF File](/gitbook/ass The Pyscan is certified for: * [ROHS certification](/gitbook/assets/RoHs_declarations/RoHS-for-Pyscan(8286-00031P)-20190523.pdf) -![](/gitbook/assets/pyscan-pinout-1.png) + ## Pyscan Libraries @@ -50,4 +63,4 @@ The board features a single cell Li-Ion/Li-Po charger with a JST PHR‑2 connect ## 3D model for case design -* Please see the [3D model] (/gitbook/assets/PyScan_v0.7.step) (step format) +* Please see the [3D model](/gitbook/assets/PyScan_v0.7.step) (step format) diff --git a/content/datasheets/expansionboards/pysense.md b/content/datasheets/expansionboards/pysense.md index 143c1b7b..5f99b74f 100644 --- a/content/datasheets/expansionboards/pysense.md +++ b/content/datasheets/expansionboards/pysense.md @@ -8,8 +8,26 @@ aliases: --- **Store**: [Buy Here](https://pycom.io/product/pysense/) +The Pysense shield allows you to sense the environment using 5 different sensors: +* Accelerometer (LIS2HH12) +* Light Sensor (LTR329ALS01) +* Pressure Sensor (MPL3115A2) +* Temperature / Humidity Sensor (SI7006A20) -![](/gitbook/assets/pysense.png) +## Getting started +1. Find the libraries for the Pysense in the [Pycom libraries](https://github.com/pycom/pycom-libraries/releases/) repository on Github. +1. Download the files and extract them into the project folder in Pymakr +1. Click the `upload project to device` button. This will store all necessary files on the device and allow you to import them in the example `main.py`. +1. Check the REPL. If you have Pybytes activated, the example will send the sensor data to Pybytes automatically. + + +### Examples +The Pysense has several examples: +* [Sensing](/tutorials/expansionboards/sensing/) + +## Features + +![](/gitbook/assets/pysense-pinout-1.png) ## Datasheet @@ -24,7 +42,7 @@ The Pysense is certified for: The pinout of the Pysense is available as a [PDF File](/gitbook/assets/pysense-pinout.pdf) * The user button is connected to `P14`. This button can also be used to put the Pysense board in `dfu-bootloader` mode to update the firmware. -![](/gitbook/assets/pysense-pinout-1.png) + ## Notes ### Battery Charger diff --git a/content/datasheets/expansionboards/pysense2.md b/content/datasheets/expansionboards/pysense2.md index 47598047..b5a8d6e6 100644 --- a/content/datasheets/expansionboards/pysense2.md +++ b/content/datasheets/expansionboards/pysense2.md @@ -7,6 +7,25 @@ aliases: - chapter/datasheets/boards/pysense2 --- +The Pysense 2.0 X shield allows you to sense the environment using 5 different sensors: +* Accelerometer (LIS2HH12) +* Light Sensor (LTR329ALS01) +* Pressure Sensor (MPL3115A2) +* Temperature / Humidity Sensor (SI7006A20) + +## Getting started +1. Find the libraries for the Pysense 2.0 X in the [Pycom libraries](https://github.com/pycom/pycom-libraries/releases/) repository on Github. +1. Download the files and extract them into the project folder in Pymakr +1. Click the `upload project to device` button. This will store all necessary files on the device and allow you to import them in the example `main.py`. +1. Check the REPL. If you have Pybytes activated, the example will send the sensor data to Pybytes automatically. + + +### Examples +The Pysense has several examples: +* [Sensing](/tutorials/expansionboards/sensing/) + +## Features + ![](/gitbook/assets/pysense2_desc.png) ## Datasheet diff --git a/content/datasheets/expansionboards/pytrack.md b/content/datasheets/expansionboards/pytrack.md index f7bc9406..822ac265 100644 --- a/content/datasheets/expansionboards/pytrack.md +++ b/content/datasheets/expansionboards/pytrack.md @@ -8,6 +8,21 @@ aliases: --- **Store**: [Buy Here](https://pycom.io/product/pytrack/) +The Pytrack shield allows you track your location using the onboard GPS and accelerometer. + +## Getting started +1. Find the libraries for the Pytrack in the [Pycom libraries](https://github.com/pycom/pycom-libraries/releases/) repository on Github. +1. Download the files and extract them into the project folder in Pymakr +1. Click the `upload project to device` button. This will store all necessary files on the device and allow you to import them in the example `main.py`. +1. Check the REPL. If you have Pybytes activated, the example will send the location data to Pybytes automatically. + + +### Examples +The Pytrack has several examples: +* [Tracking](/tutorials/expansionboards/tracking/) + +## Features + ![](/gitbook/assets/pytrack.png) diff --git a/content/datasheets/expansionboards/pytrack2.md b/content/datasheets/expansionboards/pytrack2.md index d6e30dc2..08d97f83 100644 --- a/content/datasheets/expansionboards/pytrack2.md +++ b/content/datasheets/expansionboards/pytrack2.md @@ -7,6 +7,21 @@ aliases: - chapter/datasheets/boards/pytrack2 --- +The Pytrack 2.0 X shield allows you track your location using the onboard GPS and accelerometer. + +## Getting started +1. Find the libraries for the Pytrack 2.0 X in the [Pycom libraries](https://github.com/pycom/pycom-libraries/releases/) repository on Github. +1. Download the files and extract them into the project folder in Pymakr +1. Click the `upload project to device` button. This will store all necessary files on the device and allow you to import them in the example `main.py`. +1. Check the REPL. If you have Pybytes activated, the example will send the location data to Pybytes automatically. + + +### Examples +The Pytrack has several examples: +* [Tracking](/tutorials/expansionboards/tracking/) + +## Features + ![](/gitbook/assets/pytrack2_decs.png) ## Datasheet diff --git a/content/firmwareapi/pycom/expansionboards/_index.md b/content/firmwareapi/pycom/expansionboards/_index.md index 333ee88d..e9aa598b 100644 --- a/content/firmwareapi/pycom/expansionboards/_index.md +++ b/content/firmwareapi/pycom/expansionboards/_index.md @@ -14,7 +14,7 @@ Note that this functionality is not built into the firmware, and you will need t The API pages are separated per sensor: * [Accelerometer](lis2hh12/) (LIS2HH12) * [Light Sensor](ltr329als01/) (LTR329ALS01) -* [Temperature Sensor](si7006a20/) (SI7006A20) +* [Temperature / Humidity Sensor](si7006a20/) (SI7006A20) * [Pressure Sensor](mpl3115a2/) (MPL3115A2) * [RFID / NFC](mfrc630/) (MFRC630) * [GPS](l76gnss/) (L76GNSS) diff --git a/content/gettingstarted/_index.md b/content/gettingstarted/_index.md index 9cc982fd..097dc258 100644 --- a/content/gettingstarted/_index.md +++ b/content/gettingstarted/_index.md @@ -131,9 +131,9 @@ If you need to remove files from your device you can use the following commands: From here on, you can continue to use the additional features of your expansionboard: >Note The Expansionboard requires no additional libraries and all functions work out of the box! -|[ Pygate](/tutorials/expansionboards/pygate/)| [Pysense](/tutorials/expansionboards/pysense/) | [Pysense 2.0 X](/tutorials/expansionboards/pysense2/)| [Pytrack](/tutorials/expansionboards/pytrack/)| [Pytrack 2.0 X](/tutorials/expansionboards/pytrack2/)| [PyScan ](/tutorials/expansionboards/pyscan/)| +|[ Pygate](/datasheets/expansionboards/pygate/)| [Pysense](/datasheets/expansionboards/pysense/) | [Pysense 2.0 X](/datasheets/expansionboards/pysense2/)| [Pytrack](/datasheets/expansionboards/pytrack/)| [Pytrack 2.0 X](/datasheets/expansionboards/pytrack2/)| [PyScan ](/datasheets/expansionboards/pyscan/)| |:----|:-----|:-----|:-----|:-----|:----| -| [![](/gitbook/assets/expansionboards/pygate.png)](/tutorials/expansionboards/pygate/)|[![](/gitbook/assets/expansionboards/pysense1.png)](/tutorials/expansionboards/pysense/) | [![](/gitbook/assets/expansionboards/pysense2.png)](/tutorials/expansionboards/pysense2/)| [![](/gitbook/assets/expansionboards/pytrack1.png)](/tutorials/expansionboards/pytrack/)| [![](/gitbook/assets/expansionboards/pytrack2.png)](/tutorials/expansionboards/pytrack2/)| [![](/gitbook/assets/expansionboards/pyscan.png)](/tutorials/expansionboards/pyscan/) | +| [![](/gitbook/assets/expansionboards/pygate.png)](/datasheets/expansionboards/pygate/)|[![](/gitbook/assets/expansionboards/pysense1.png)](/datasheets/expansionboards/pysense/) | [![](/gitbook/assets/expansionboards/pysense2.png)](/datasheets/expansionboards/pysense2/)| [![](/gitbook/assets/expansionboards/pytrack1.png)](/datasheets/expansionboards/pytrack/)| [![](/gitbook/assets/expansionboards/pytrack2.png)](/datasheets/expansionboards/pytrack2/)| [![](/gitbook/assets/expansionboards/pyscan.png)](/datasheets/expansionboards/pyscan/) | ## Step 5: Connecting to a network diff --git a/content/tutorials/expansionboards/_index.md b/content/tutorials/expansionboards/_index.md index a3adad2a..903a722a 100644 --- a/content/tutorials/expansionboards/_index.md +++ b/content/tutorials/expansionboards/_index.md @@ -9,15 +9,15 @@ disable_breadcrumbs: true >Note: Before using the Pysense, Pytrack and Pyscan boards, check the [GitHub](https://github.com/pycom/pycom-libraries) for the latest version of the libraries. -To use the Pysense, Pytrack or Pyscan, make a folder inside your project folder and call it `lib`. Then, copy the appropiate sensor libraries from the github repository to the folder. Always copy the `pysense.py` or `pytrack.py` and `pycoproc.py` files if you want to use the boards' functions. The `pycoproc.py` library also allows for a special sleep mode. An example for this is provided [here](../expansionboards/sleep/) +To use the Pysense, Pytrack or Pyscan, make a folder inside your project folder and call it `lib`. Then, copy the appropiate sensor libraries from the github repository to the folder. Always copy the `pysense.py` or `pytrack.py` and `pycoproc.py` files if you want to use the boards' functions. The `pycoproc.py` library also allows for a special sleep mode. An example for this is provided [here](sleep/) + +* [Asset tracking](tracking/) +* [Environment sensing](sensing/) +* [Scanning RFID / NFC Tags](scanning/) +* [Pysleep](sleep/) +* [Movement detection](/accelerometer/) -* [Pygate](../expansionboards/pygate/) -* [Pysense](../expansionboards/pysense/) -* [Pysense 2.0 X](../expansionboards/pysense2/) -* [Pytrack](../expansionboards/pytrack/) -* [Pytrack 2.0 X](../expansionboards/pytrack2/) -* [Pyscan](../expansionboards/pyscan/) >Note: Make sure to click `upload to device` to be able to `import` the appropriate libraries in your code! diff --git a/content/tutorials/expansionboards/scanning.md b/content/tutorials/expansionboards/scanning.md new file mode 100644 index 00000000..b60233bc --- /dev/null +++ b/content/tutorials/expansionboards/scanning.md @@ -0,0 +1,58 @@ +--- +Title: "Scanning" +--- + +>This example can be used on the **Pyscan** + +You can use the example below to scan RFID / NFC cards presented to the scanner: +```python +from pyscan import Pyscan +from MFRC630 import MFRC630 +import time +import pycom +import _thread + +VALID_CARDS = [[0x43, 0x95, 0xDD, 0xF8], + [0x43, 0x95, 0xDD, 0xF9]] + +py = Pyscan() +nfc = MFRC630(py) + +RGB_BRIGHTNESS = 0x8 + +RGB_RED = (RGB_BRIGHTNESS << 16) +RGB_GREEN = (RGB_BRIGHTNESS << 8) +RGB_BLUE = (RGB_BRIGHTNESS) + +# Make sure heartbeat is disabled before setting RGB LED +pycom.heartbeat(False) + +# Initialise the MFRC630 with some settings +nfc.mfrc630_cmd_init() + +def check_uid(uid, len): + return VALID_CARDS.count(uid[:len]) + +def discovery_loop(nfc, id): + while True: + # Send REQA for ISO14443A card type + atqa = nfc.mfrc630_iso14443a_WUPA_REQA(nfc.MFRC630_ISO14443_CMD_REQA) + if (atqa != 0): + # A card has been detected, read UID + uid = bytearray(10) + uid_len = nfc.mfrc630_iso14443a_select(uid) + if (uid_len > 0): + if (check_uid(list(uid), uid_len)) > 0: + pycom.rgbled(RGB_GREEN) + else: + pycom.rgbled(RGB_RED) + else: + # No card detected + pycom.rgbled(RGB_BLUE) + nfc.mfrc630_cmd_reset() + time.sleep(.5) + nfc.mfrc630_cmd_init() + +# This is the start of our main execution... start the thread +_thread.start_new_thread(discovery_loop, (nfc, 0)) +``` \ No newline at end of file diff --git a/content/tutorials/expansionboards/sensing.md b/content/tutorials/expansionboards/sensing.md new file mode 100644 index 00000000..91e25531 --- /dev/null +++ b/content/tutorials/expansionboards/sensing.md @@ -0,0 +1,84 @@ +--- +title: "Sensing" +--- +> This example can be used on the **Pysense** and **Pysense 2.0 X** + +The Pysense has a variety of sensors available: +* Accelerometer +* Light sensor +* Temperature / Humidity sensor +* Pressure / Altitude sensor + +The examples covered on this page: +* [Using all sensors](#using-all-senors) +* [Sending sensor data to Pybytes](#sensor-data-to-pybytes) + +## Using all sensors + +```python +import time +import pycom +import machine + +from LIS2HH12 import LIS2HH12 +from SI7006A20 import SI7006A20 +from LTR329ALS01 import LTR329ALS01 +from MPL3115A2 import MPL3115A2,ALTITUDE,PRESSURE + +pycom.heartbeat(False) +pycom.rgbled(0x0A0A08) # white + +py = Pycoproc() + +alt = MPL3115A2(py,mode=ALTITUDE) # Returns height in meters. Mode may also be set to PRESSURE, returning a value in Pascals +print("MPL3115A2 temperature: " + str(alt.temperature())) +print("Altitude: " + str(alt.altitude())) +pres = MPL3115A2(py,mode=PRESSURE) # Returns pressure in Pa. Mode may also be set to ALTITUDE, returning a value in meters +print("Pressure: " + str(press.pressure())) +# send to pybytes + + +dht = SI7006A20(py) +print("Temperature: " + str(dht.temperature())+ " deg C and Relative Humidity: " + str(dht.humidity()) + " %RH") +print("Dew point: "+ str(dht.dew_point()) + " deg C") +#change to your ambient temperature +t_ambient = 24.4 +print("Humidity Ambient for " + str(t_ambient) + " deg C is " + str(dht.humid_ambient(t_ambient)) + "%RH") + + +li = LTR329ALS01(py) +print("Light (channel Blue lux, channel Red lux): " + str(li.light())) + +acc = LIS2HH12(py) +print("Acceleration: " + str(acc.acceleration())) +print("Roll: " + str(acc.roll())) +print("Pitch: " + str(acc.pitch())) + +print("Battery voltage: " + str(py.read_battery_voltage())) +``` + +## Sensor data to Pybytes +Pybytes is an online IoT platform, where you can receive data from your sensors and visualize it over time. +To forward generated sensor data to Pybytes, you'll first have to [provision your device](/pybytes/gettingstarted/) to Pybytes, and have it activated on boot. Then, you can use the following example to send the light sensor data to Pybytes: + +```python +import time +import pycom +import machine + +from LTR329ALS01 import LTR329ALS01 +sleeptime = 60*1000 # 1 minute + +pycom.heartbeat(False) +pycom.rgbled(0x0A0A08) # white + +py = Pycoproc() + +li = LTR329ALS01(py) +light = li.light(); +print("Light (channel Blue lux, channel Red lux): " + str(light)) +pybytes.send_signal(0, light[0]) # channel Blue +pybytes.send_signal(1, light[1]) # channel Red +time.sleep(2) # we need to sleep to make sure the signal gets sent + +machine.deepsleep(sleeptime) \ No newline at end of file diff --git a/content/tutorials/expansionboards/sleep.md b/content/tutorials/expansionboards/sleep.md index 98814384..6fb4ec90 100644 --- a/content/tutorials/expansionboards/sleep.md +++ b/content/tutorials/expansionboards/sleep.md @@ -1,17 +1,27 @@ --- title: 'Sleep' --- +> This example can be used on a **All shields** -The expansionboards (Pysense 2.0 X, and Pytrack 2.0 X, DeepSleep shield) use a different mechanism to put the controller to sleep. A separate controller on the expansion board will put the main controller to sleep. This will actually cut all power from the module for the set amount of time, hard resetting it. Cutting power to the expansion board will work as well. Using this method, we can still recover the wake up reason and remaining sleep time. The example below works was written for a Pysense, but works on any of the boards by changing the first lines - +On these shields, an additional sleep method is available. Next to [`machine.deepsleep()`](/firmwareapi/pycom/machine/#machinedeepsleeptime_ms). there is `py.go_to_sleep()`, which is able to completely cut the power to the development board, and using only the coprocessor to keep track of when to wake up again. This way, we can save more power, which is especially useful when operating on a battery. On this page, we will cover the following: +* [Simple Pysleep](#simple-pysleep) +* [Wake up from accelerometer](#wake-up-from-accelerometer) +* +## Simple Pysleep ```python -from pysense import Pysense -py = Pysense() -py.setup_sleep(10) # set sleep time of 10 seconds +from pycoproc import Pycoproc +py = Pycoproc() +# setup the sleep time in seconds +py.setup_sleep(10) +# go to pysleep py.go_to_sleep() print("this will never be printed") ``` -Using this method, we can also wake the board using the accelerometer interrupt method: +## Wake up from accelerometer + +> This example can be used on the first generation boards + +Using this method, we can also wake the board using the onboard accelerometer to wake up from pysleep after we detect movement. The example below shows how to achieve that: ```python @@ -20,9 +30,6 @@ from pysense import Pysense from LIS2HH12 import LIS2HH12 import time -#py = Pytrack() -py = Pysense() - # display the reset reason code and the sleep remaining in seconds # possible values of wakeup reason are: # WAKE_REASON_ACCELEROMETER = 1 @@ -49,3 +56,71 @@ acc.enable_activity_interrupt(2000, 200) py.setup_sleep(300) py.go_to_sleep() ``` + +## Pysleep Accelerometer 2 +Use this example for a **Pysense 2** or **Pytrack 2** shield: +```python + +# This script demonstrates two examples: +# * go to ultra low power mode (~10uA @3.75V) with all sensors, incl accelerometer and also pycom module (Fipy, Gpy, etc) off - tap the MCLR button for this +# * go to low power mode (~165uA @3.75V) with accelerometer on, pycom module in deepsleep and wake from accelerometer interrupt - hold the MCLR button down for this + +# See https://docs.pycom.io for more information regarding library specifics + +import time +import pycom +import struct +from machine import Pin +from pycoproc import Pycoproc +import machine + +from LIS2HH12 import LIS2HH12 +from SI7006A20 import SI7006A20 +from LTR329ALS01 import LTR329ALS01 +from MPL3115A2 import MPL3115A2,ALTITUDE,PRESSURE + +def accelerometer(): + print("ACCELEROMETER:", "accel:", accelerometer_sensor.acceleration(), "roll:", accelerometer_sensor.roll(), "pitch:", accelerometer_sensor.pitch(), "x/y/z:", accelerometer_sensor.x, accelerometer_sensor.y, accelerometer_sensor.z ) + +def activity_int_handler(pin_o): + if pin_o(): + print('[Activity]') + pycom.rgbled(0x00000A) # blue + else: + print('[Inactivity]') + pycom.rgbled(0x0A0A00) # yellow + +def activity_int_handler_none(pin_o): + pass + +############################################################### +sleep_time_s = 300 # 5 min +pycom.heartbeat(False) +pycom.rgbled(0x0a0a0a) # white +print("pycoproc init") +py = Pycoproc() +print("battery {:.2f} V".format(py.read_battery_voltage())) +py.setup_sleep(sleep_time_s) + +# init accelerometer +accelerometer_sensor = LIS2HH12() +# read accelerometer sensor values +accelerometer() +print("enable accelerometer interrupt") + +# enable_activity_interrupt( [mG], [ms], callback) +# accelerometer_sensor.enable_activity_interrupt(8000, 200, activity_int_handler) # low sensitivty +# accelerometer_sensor.enable_activity_interrupt(2000, 200, activity_int_handler) # medium sensitivity +accelerometer_sensor.enable_activity_interrupt( 100, 200, activity_int_handler) # high sensitivity +# accelerometer_sensor.enable_activity_interrupt(63, 160, activity_int_handler) # ultra sensitivty + +print("enable pycom module to wake up from accelerometer interrupt") +wake_pins = [Pin('P13', mode=Pin.IN, pull=Pin.PULL_DOWN)] +machine.pin_sleep_wakeup(wake_pins, machine.WAKEUP_ANY_HIGH, True) + +print("put pycoproc to sleep and pycom module to deepsleep") +py.go_to_sleep(pycom_module_off=False, accelerometer_off=False, wake_interrupt=True) +machine.deepsleep(sleep_time_s * 1000) + +print("we never reach here!") +``` \ No newline at end of file diff --git a/content/tutorials/expansionboards/tracking.md b/content/tutorials/expansionboards/tracking.md new file mode 100644 index 00000000..b3e256c4 --- /dev/null +++ b/content/tutorials/expansionboards/tracking.md @@ -0,0 +1,122 @@ +--- +title: "Asset Tracking" +--- +> This example can be used on a **Pytrack** and **Pytrack 2.0 X** + +Using the Pytrack, you are able to gather location data of your device. In this tutorial, we will go through how to set up your device, such that you can save the data on a SD card. Extending this example with a Pybytes integration on any network will allow you to forward any data to the cloud. +On this page, we cover the following: +* [Save data to a SD card](#save-data-to-a-sd-card) +* [Forwarding data to Pybytes](#forwarding-data-to-pybytes) +* [Save power](#save-power) + +## Save data to a SD card +For this example, you will need to insert a SD card into the Pytrack board to save the data locally. We will get the data every 60 seconds sleep in between. + +### main.py + +```python +import machine +import math +import network +import os +import time +import utime +import gc +import pycom +from machine import RTC +from machine import SD +from L76GNSS import L76GNSS +from pytrack import Pytrack +from network import WLAN + +pycom.heartbeat(False) +pycom.rgbled(0x0A0A08) # white + +time.sleep(2) +gc.enable() + +py = Pytrack() + +time.sleep(1) +l76 = L76GNSS(py, timeout=30, buffer=512) + +# Load SD card +sd = SD() +os.mount(sd, '/sd') +os.listdir('/sd') + +# Read SD card +print('Reading from file:') +f = open('/sd/test.txt', 'r') +print(f.readlines()) +f.close() +print("Read from file.") + +time.sleep(1) + +while (True): + coord = l76.coordinates() + print("{} - {}".format(coord, gc.mem_free())) + f = open('/sd/test.txt', 'a') # Append + f.write("{}".format(coord[1])) + f.write(' ') + f.write("{}".format(coord[0])) + f.write(',\n') + f.close() + print('Sleep for 1 minute.') + time.sleep(60) +``` + +### Visualizing data +The data in the textfile on the SD card will look like this: +``` +latitude, longitude +latitude, longitude +``` +We can use this data to make a .kml file, or Keyhole Makrup Language, to display our tracks on for example Google Maps. Use the following format and save the file as a `.kml` file: +``` +Placemark> + Untitled Path + + 1 + relativeToGround + + Paste location data + + + +``` + +## Forwarding data to Pybytes + +If we take the example above, and modify it such that instead of saving the data to a SD card, we send it to Pybytes. For this, make sure to [provision your device to Pybytes](/pybytes/gettingstarted/). If you already provisioned your device, make sure to start Pybytes from boot. Use the following to replace the loop: + +```python +while (True): + coord = l76.coordinates() + print("{} - {}".format(coord, gc.mem_free())) + pybytes.send_signal(1, coord) + time.sleep(60) +``` +Using this, you will see your data show up as signal 1 in Pybytes + +## Save power + +Having the GPS enabled continuously on can drain the battery quite quickly. We can put the GPS in standby mode while we deepsleep the module to save some additional power. This will have some drawbacks, as it could take some time to regain the location fix after waking up. Instead of the loop, you could use the following example. If you're looking to wake up from movement on the accelerometer, have a look at the [accelerometer sleep](../sleep/) example. + +```python +coord = l76.coordinates() +print("{} - {}".format(coord, gc.mem_free())) +f = open('/sd/test.txt', 'a') # Append +f.write("{}".format(coord[1])) +f.write(' ') +f.write("{}".format(coord[0])) +f.write(',\n') +f.close() +print('Sleep for 1 minute.') +py.setup_sleep() #sleep time in seconds +# Shield version 1 +py.go_to_sleep(arguments) +# Shield version 2 +py.go_to_sleep(different arguments) +``` \ No newline at end of file