From 009b388b2d9321391b392583cdff5403f8dda42a Mon Sep 17 00:00:00 2001 From: gijsio <67470426+gijsio@users.noreply.github.com> Date: Mon, 27 Jul 2020 13:01:36 +0200 Subject: [PATCH] added extra examples --- content/tutorials/basic/print.md | 2 + content/tutorials/expansionboards/_index.md | 6 +- content/tutorials/expansionboards/pysense.md | 64 ++++++++++++++++- content/tutorials/expansionboards/pysense2.md | 66 +++++++++++++++++ content/tutorials/expansionboards/pytrack.md | 8 +-- content/tutorials/expansionboards/pytrack2.md | 70 +++++++++++++++++++ 6 files changed, 206 insertions(+), 10 deletions(-) diff --git a/content/tutorials/basic/print.md b/content/tutorials/basic/print.md index 8b5f437..72f3a7e 100644 --- a/content/tutorials/basic/print.md +++ b/content/tutorials/basic/print.md @@ -19,4 +19,6 @@ print("\n") #feed a new line print("\t tabbed in") #you can specify a variable into the string as well! print("hello world: " + str(machine.rng()) + " random number" ) +#or use format +print("hello world: {} {}".format(machine.rng(), " random number")) ``` \ No newline at end of file diff --git a/content/tutorials/expansionboards/_index.md b/content/tutorials/expansionboards/_index.md index 23fa7c0..d8afefe 100644 --- a/content/tutorials/expansionboards/_index.md +++ b/content/tutorials/expansionboards/_index.md @@ -8,11 +8,13 @@ disable_breadcrumbs: true --- >Note: Before using the pysense and pytrac boards, check the [GitHub](https://github.com/pycom/pycom-libraries) for the latest version of the libraries. -Make a folder inside your project folder and call it `lib`. Then, copy the appropiate 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 +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. * [Pygate](../expansionboards/pygate/) * [Pysense](../expansionboards/pysense/) * [Pysense 2.0 X](../expansionboards/pysense2/) * [Pytrack](../expansionboards/pytrack/) * [Pytrack 2.0 X](../expansionboards/pytrack2/) -* [Pyscan](../expansionboards/pyscan/) \ No newline at end of file +* [Pyscan](../expansionboards/pyscan/) + +>Note: Make sure to click `upload to device` to be able to `import` the appropriate libraries in your code! \ No newline at end of file diff --git a/content/tutorials/expansionboards/pysense.md b/content/tutorials/expansionboards/pysense.md index a71ee97..577ee81 100644 --- a/content/tutorials/expansionboards/pysense.md +++ b/content/tutorials/expansionboards/pysense.md @@ -6,6 +6,64 @@ aliases: - chapter/tutorials/pysense --- +## All sensors +>Note: You can find this example in the [GitHub repository](https://github.com/pycom/pycom-libraries/tree/master/pysense). Over there, you can also find the relevant libraries. +```python +#!/usr/bin/env python +# +# Copyright (c) 2020, Pycom Limited. +# +# This software is licensed under the GNU GPL version 3 or any +# later version, with permitted additional terms. For more information +# see the Pycom Licence v1.0 document supplied with this file, or +# available at https://www.pycom.io/opensource/licensing +# + +# See https://docs.pycom.io for more information regarding library specifics + +import time +import pycom +from pysense import Pysense +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 = Pysense() + +mp = MPL3115A2(py,mode=ALTITUDE) # Returns height in meters. Mode may also be set to PRESSURE, returning a value in Pascals +print("MPL3115A2 temperature: " + str(mp.temperature())) +print("Altitude: " + str(mp.altitude())) +mpp = MPL3115A2(py,mode=PRESSURE) # Returns pressure in Pa. Mode may also be set to ALTITUDE, returning a value in meters +print("Pressure: " + str(mpp.pressure())) + + +si = SI7006A20(py) +print("Temperature: " + str(si.temperature())+ " deg C and Relative Humidity: " + str(si.humidity()) + " %RH") +print("Dew point: "+ str(si.dew_point()) + " deg C") +t_ambient = 24.4 +print("Humidity Ambient for " + str(t_ambient) + " deg C is " + str(si.humid_ambient(t_ambient)) + "%RH") + + +lt = LTR329ALS01(py) +print("Light (channel Blue lux, channel Red lux): " + str(lt.light())) + +li = LIS2HH12(py) +print("Acceleration: " + str(li.acceleration())) +print("Roll: " + str(li.roll())) +print("Pitch: " + str(li.pitch())) + +print("Battery voltage: " + str(py.read_battery_voltage())) + +time.sleep(3) +py.setup_sleep(10) +py.go_to_sleep() +``` ## Accelerometer This basic example shows how to read pitch and roll from the on-board accelerometer and output it in comma separated value (CSV) format over serial. @@ -24,7 +82,7 @@ while True: time.sleep_ms(100) ``` -![](/gitbook/assets/accelerometer_visualiser.png) - -If you want to visualise the data output by this script a Processing sketch is available [here](https://github.com/pycom/pycom-libraries/tree/master/examples/pytrack_pysense_accelerometer) that will show the board orientation in 3D. +>Note: Use [Processing](https://processing.org/) to visualize the orientation of your board using the example. You can find the Processing sketch [here](https://github.com/pycom/pycom-libraries/tree/master/examples/pytrack_pysense_accelerometer) +> +>![](/gitbook/assets/accelerometer_visualiser.png) diff --git a/content/tutorials/expansionboards/pysense2.md b/content/tutorials/expansionboards/pysense2.md index e69de29..22a785c 100644 --- a/content/tutorials/expansionboards/pysense2.md +++ b/content/tutorials/expansionboards/pysense2.md @@ -0,0 +1,66 @@ +--- +title: "Pysense 2.0 X Examples" +aliases: + - tutorials/pysense.html + - tutorials/pysense.md + - chapter/tutorials/pysense +--- +The Pysense 2.0 X has an external header that allows you to attach all kinds of sensors. +## All sensors +>Note: You can find this example in the [GitHub repository](https://github.com/pycom/pycom-libraries/tree/master/pysense-2). Over there, you can also find the relevant libraries. +```python +#!/usr/bin/env python +# +# Copyright (c) 2020, Pycom Limited. +# +# This software is licensed under the GNU GPL version 3 or any +# later version, with permitted additional terms. For more information +# see the Pycom Licence v1.0 document supplied with this file, or +# available at https://www.pycom.io/opensource/licensing +# + +# See https://docs.pycom.io for more information regarding library specifics + +import time +import pycom +from pysense import Pysense +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 = Pysense() + +mp = MPL3115A2(py,mode=ALTITUDE) # Returns height in meters. Mode may also be set to PRESSURE, returning a value in Pascals +print("MPL3115A2 temperature: " + str(mp.temperature())) +print("Altitude: " + str(mp.altitude())) +mpp = MPL3115A2(py,mode=PRESSURE) # Returns pressure in Pa. Mode may also be set to ALTITUDE, returning a value in meters +print("Pressure: " + str(mpp.pressure())) + + +si = SI7006A20(py) +print("Temperature: " + str(si.temperature())+ " deg C and Relative Humidity: " + str(si.humidity()) + " %RH") +print("Dew point: "+ str(si.dew_point()) + " deg C") +t_ambient = 24.4 +print("Humidity Ambient for " + str(t_ambient) + " deg C is " + str(si.humid_ambient(t_ambient)) + "%RH") + + +lt = LTR329ALS01(py) +print("Light (channel Blue lux, channel Red lux): " + str(lt.light())) + +li = LIS2HH12(py) +print("Acceleration: " + str(li.acceleration())) +print("Roll: " + str(li.roll())) +print("Pitch: " + str(li.pitch())) + +print("Battery voltage: " + str(py.read_battery_voltage())) + +# time.sleep(3) +# py.setup_sleep(10) +# py.go_to_sleep() +``` \ No newline at end of file diff --git a/content/tutorials/expansionboards/pytrack.md b/content/tutorials/expansionboards/pytrack.md index a9c8395..7868c35 100644 --- a/content/tutorials/expansionboards/pytrack.md +++ b/content/tutorials/expansionboards/pytrack.md @@ -7,12 +7,9 @@ aliases: --- Both the Pysense and Pytrack use the same accelerometer. Please see the [Pysense Examples](../pysense) to see how to use the accelerometer. +>Note: You can find this example in the [GitHub repository](https://github.com/pycom/pycom-libraries/tree/master/pytrack). Over there, you can also find the relevant libraries. -## Example - ->Note: You need to add the libraries in the `lib` folder before the example will work - -You can find this example in the [pycom/pycom-libraries](https://github.com/pycom/pycom-libraries) GitHub repository. +## GPS Example ```python @@ -56,3 +53,4 @@ while (True): * [micropyGPS](https://github.com/inmcm/micropyGPS) * [Alternative L76GNSS module](https://github.com/andrethemac/L76GLNSV4/blob/master/L76GNSV4.py) + diff --git a/content/tutorials/expansionboards/pytrack2.md b/content/tutorials/expansionboards/pytrack2.md index e69de29..bd375d9 100644 --- a/content/tutorials/expansionboards/pytrack2.md +++ b/content/tutorials/expansionboards/pytrack2.md @@ -0,0 +1,70 @@ +--- +title: "Pytrack 2.0 X Examples" +aliases: + - tutorials/pysense.html + - tutorials/pysense.md + - chapter/tutorials/pysense +--- +The Pytrack 2.0 X has an external header that allows you to attach all kinds of sensors. +## All sensors +>Note: You can find this example in the [GitHub repository](https://github.com/pycom/pycom-libraries/tree/master/pytrack-2). Over there, you can also find the relevant libraries. +```python +#!/usr/bin/env python +# +# Copyright (c) 2020, Pycom Limited. +# +# This software is licensed under the GNU GPL version 3 or any +# later version, with permitted additional terms. For more information +# see the Pycom Licence v1.0 document supplied with this file, or +# available at https://www.pycom.io/opensource/licensing +# + +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 + +pycom.heartbeat(False) +pycom.rgbled(0x0A0A08) # white + +time.sleep(2) +gc.enable() + +# setup rtc +rtc = machine.RTC() +rtc.ntp_sync("pool.ntp.org") +utime.sleep_ms(750) +print('\nRTC Set from NTP to UTC:', rtc.now()) +utime.timezone(7200) +print('Adjusted from UTC to EST timezone', utime.localtime(), '\n') + +py = Pytrack() + +time.sleep(1) +l76 = L76GNSS(py, timeout=30, buffer=512) + +# sd = SD() +# os.mount(sd, '/sd') +# f = open('/sd/gps-record.txt', 'w') + +# while (True): +for _ in range(5): + coord = l76.coordinates() + #f.write("{} - {}\n".format(coord, rtc.now())) + print("{} - {} - {}".format(coord, rtc.now(), gc.mem_free())) + +""" +# sleep procedure +time.sleep(3) +py.setup_sleep(10) +py.go_to_sleep() +""" +``` \ No newline at end of file