Skip to content
Prev Previous commit
Next Next commit
added example text
  • Loading branch information
gijsio committed Mar 12, 2021
commit c994d250dc29ec153e1fb09b779ddb33c169ef6e
51 changes: 51 additions & 0 deletions content/tutorials/expansionboards/sensing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
title: "Sensing"
---
The Pysense has a variety of sensors available:
* Accelerometer
* Light sensor
* Temperature / Humidity sensor
* Pressure / Altitude sensor

Lets make use of all of them:
```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()))
```
27 changes: 24 additions & 3 deletions content/tutorials/expansionboards/tracking.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
---
title: "Asset Tracking"
---
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
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.
Expand Down Expand Up @@ -85,7 +89,7 @@ Placemark>

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()))
Expand All @@ -96,4 +100,21 @@ Using this, you will see your data show up as signal 1 in Pybytes

## Save power

Having the GPS enabled continuously
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)
```