mirror of
https://github.com/sascha-hemi/pycom-documentation.git
synced 2026-03-21 11:06:37 +01:00
added extra examples
This commit is contained in:
@@ -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"))
|
||||
```
|
||||
@@ -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/)
|
||||
* [Pyscan](../expansionboards/pyscan/)
|
||||
|
||||
>Note: Make sure to click `upload to device` to be able to `import` the appropriate libraries in your code!
|
||||
@@ -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)
|
||||
```
|
||||
|
||||

|
||||
|
||||
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)
|
||||
>
|
||||
>
|
||||
|
||||
|
||||
@@ -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()
|
||||
```
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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()
|
||||
"""
|
||||
```
|
||||
Reference in New Issue
Block a user