11#!/usr/bin/env python
2- #-----------------------------------------------------------------------------
3- # qwiic_env_bme280_ex4 .py
2+ #-------------------------------------------------------------------------------
3+ # qwiic_veml6030_ex2_settings .py
44#
5- # Simple Example for the Qwiic BME280 Device
6- #------------------------------------------------------------------------
5+ # Demonstrates how to change basic settings of the Qwiic Ambient Light Sensor
6+ #-------------------------------------------------------------------------------
7+ # Written by SparkFun Electronics, November 2023
78#
8- # Written by SparkFun Electronics, May 2019
9- #
10- # This python library supports the SparkFun Electroncis qwiic
11- # qwiic sensor/board ecosystem on a Raspberry Pi (and compatable) single
12- # board computers.
9+ # This python library supports the SparkFun Electroncis Qwiic ecosystem
1310#
14- # More information on qwiic is at https:# www.sparkfun.com/qwiic
11+ # More information on Qwiic is at https:// www.sparkfun.com/qwiic
1512#
1613# Do you like this library? Help support SparkFun. Buy a board!
17- #
18- #==================================================================================
19- # Copyright (c) 2019 SparkFun Electronics
14+ #===============================================================================
15+ # Copyright (c) 2023 SparkFun Electronics
2016#
2117# Permission is hereby granted, free of charge, to any person obtaining a copy
2218# of this software and associated documentation files (the "Software"), to deal
3531# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
3632# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3733# SOFTWARE.
38- #==================================================================================
39- # Example 4 - port of the Arduino example 4
40- #
34+ #===============================================================================
4135
42- from __future__ import print_function
43- import qwiic_bme280
36+ import qwiic_veml6030
4437import time
4538import sys
4639
4740def runExample ():
41+ print ("\n Qwiic Ambient Light Sensor Example 2 - Settings\n " )
4842
49- print ( " \n SparkFun BME280 Sensor Example 4 \n " )
50- mySensor = qwiic_bme280 . QwiicBme280 ()
43+ # Create instance of device
44+ light_sensor = qwiic_veml6030 . QwiicVEML6030 ()
5145
52- if mySensor .connected == False :
53- print ("The Qwiic BME280 device isn't connected to the system. Please check your connection" , \
46+ # Check if it's connected
47+ if light_sensor .is_connected () == False :
48+ print ("The device isn't connected to the system. Please check your connection" , \
5449file = sys .stderr )
5550return
5651
57- mySensor .begin ()
52+ # Initialize the device
53+ light_sensor .begin ()
5854
59- # setup the sensor
60- mySensor .filter = 1 # 0 to 4 is valid. Filter coefficient. See 3.4.4
61- mySensor .standby_time = 0 # 0 to 7 valid. Time between readings. See table 27.
62-
63- mySensor .over_sample = 1 # 0 to 16 are valid. 0 disables temp sensing. See table 24.
64- mySensor .pressure_oversample = 1 # 0 to 16 are valid. 0 disables pressure sensing. See table 23.
65- mySensor .humidity_oversample = 1 # 0 to 16 are valid. 0 disables humidity sensing. See table 19.
66- mySensor .mode = mySensor .MODE_NORMAL # MODE_SLEEP, MODE_FORCED, MODE_NORMAL is valid. See 3.3
67-
68- while True :
69- print ("Humidity:\t %.3f" % mySensor .humidity )
55+ # Set the gain. Can be any of the following:
56+ # 1/8, 1/4, 1, and 2
57+ gain = 0.125
58+ light_sensor .set_gain (gain )
7059
71- print ("Pressure:\t %.3f" % mySensor .pressure )
60+ # Set the integration time in ms. Can be any of the following:
61+ # 25, 50, 100, 200, 400, and 800
62+ integ_time = 100
63+ light_sensor .set_integ_time (integ_time )
7264
73- print ("Altitude:\t %.3f" % mySensor .altitude_feet )
74-
75- print ("Temperature:\t %.2f\n " % mySensor .temperature_fahrenheit )
65+ # Read back the settings and print to confirm they were set correctly
66+ gain = light_sensor .read_gain ()
67+ integ_time = light_sensor .read_integ_time ()
68+ print ("Gain set:" , gain )
69+ print ("Integration time set:" , integ_time )
70+
71+ # Extra space for some visual separation
72+ print ()
7673
74+ # Loop forever
75+ while True :
76+ # Give some delay between prints
7777time .sleep (1 )
7878
79+ # Get light measured by sensor in Lux
80+ ambient_light = light_sensor .read_light ()
81+
82+ # Print measurement
83+ print ("Lux:\t %.3f" % ambient_light )
7984
8085if __name__ == '__main__' :
8186try :
8287runExample ()
8388except (KeyboardInterrupt , SystemExit ) as exErr :
84- print ("\n Ending Example 4 " )
89+ print ("\n Ending Example" )
8590sys .exit (0 )
0 commit comments