こんにちは、昨日に続いての初心者質問をお許しください。
ただいまRaspberry Pi3とRGBカラーセンサーモジュール(TCS34725)を使いカラーのデータを記録しようとしています。このセンサーはRed,Green,Blue,Clearの他にcolor tempurture,Luxを取得できます。
サンプルでデータの取得はできるのですが、それを継続し記録していく方法がわかりません。
python
1# Simple demo of reading color data with the TCS34725 sensor. 2# Will read the color from the sensor and print it out along with lux and 3# color temperature. 4# Author: Tony DiCola 5# License: Public Domain 6import time 7 8# Import the TCS34725 module. 9import Adafruit_TCS34725 10 11 12# Create a TCS34725 instance with default integration time (2.4ms) and gain (4x). 13import smbus 14tcs = Adafruit_TCS34725.TCS34725() 15 16# You can also override the I2C device address and/or bus with parameters: 17#tcs = Adafruit_TCS34725.TCS34725(address=0x30, busnum=2) 18 19# Or you can change the integration time and/or gain: 20#tcs = Adafruit_TCS34725.TCS34725(integration_time=Adafruit_TCS34725.TCS34725_INTEGRATIONTIME_700MS, 21# gain=Adafruit_TCS34725.TCS34725_GAIN_60X) 22# Possible integration time values: 23# - TCS34725_INTEGRATIONTIME_2_4MS (2.4ms, default) 24# - TCS34725_INTEGRATIONTIME_24MS 25# - TCS34725_INTEGRATIONTIME_50MS 26# - TCS34725_INTEGRATIONTIME_101MS 27# - TCS34725_INTEGRATIONTIME_154MS 28# - TCS34725_INTEGRATIONTIME_700MS 29# Possible gain values: 30# - TCS34725_GAIN_1X 31# - TCS34725_GAIN_4X 32# - TCS34725_GAIN_16X 33# - TCS34725_GAIN_60X 34 35# Disable interrupts (can enable them by passing true, see the set_interrupt_limits function too). 36tcs.set_interrupt(False) 37 38# Read the R, G, B, C color data. 39r, g, b, c = tcs.get_raw_data() 40 41# Calculate color temperature using utility functions. You might also want to 42# check out the colormath library for much more complete/accurate color functions. 43color_temp = Adafruit_TCS34725.calculate_color_temperature(r, g, b) 44 45# Calculate lux with another utility function. 46lux = Adafruit_TCS34725.calculate_lux(r, g, b) 47 48# Print out the values. 49print('Color: red={0} green={1} blue={2} clear={3}'.format(r, g, b, c)) 50 51# Print out color temperature. 52if color_temp is None: 53 print('Too dark to determine color temperature!') 54else: 55 print('Color Temperature: {0} K'.format(color_temp)) 56 57# Print out the lux. 58print('Luminosity: {0} lux'.format(lux)) 59 60# Enable interrupts and put the chip back to low power sleep/disabled. 61tcs.set_interrupt(True) 62tcs.disable()
これを実行すると
Color: red=540 green=563 blue=413 clear=1024
Color Temperature: 4545 K
Luminosity: 411 lux
と出ます。
http://deviceplus.jp/hobby/raspberrypi_entry_039/ この方のやられているようにこのサンプルに書き加えてやろうとしたのですが、readDataの付け方の失敗だったりとうまくいきません。何かアドバイスや参考になるサイトなどを教えていただけませんか?
温度センサなどと違いこのセンサーはあまり他のサイトなどで例になっていなく、初心者には全くどこをどう変えていけばいいかの方向性が見つかりません、、何卒ご協力お願いいたします、、
https://github.com/adafruit/Adafruit_Python_TCS34725.git ここにあったサンプルです。
回答1件
あなたの回答
tips
プレビュー