import time
from envirophat import light, motion, weather, ledsExplorations of Pimoroni’s Enviro pHAT sensor HAT on a Raspberry Pi Zero
RPi on battery running a Jupyter notebook server, accessed remotely via wifi
4207
(120, 108, 103)
26.0951736262
99278.0698014
(0.08953857421875, 0.24188232421875, 0.957275390625)
223.83
307
(225, 179, 186)
26.0460905325
99277.2708534
(0.09661865234375, 0.241455078125, 0.96038818359375)
224.47
out = open('enviro.log', 'w')
try:
while True:
lux = light.light()
leds.on()
rgb = light.rgb()
leds.off()
acc = motion.accelerometer()
heading = motion.heading()
temp = weather.temperature()
press = weather.pressure()
print('%d %d %d %d %f %f %f %f %f %f' % \
(lux, rgb[0], rgb[1], rgb[2], acc[0], acc[1], acc[2], heading, temp, press))
out.write('%d %d %d %d %f %f %f %f %f %f\n' % \
(lux, rgb[0], rgb[1], rgb[2], acc[0], acc[1], acc[2], heading, temp, press))
time.sleep(1) # (set to "time.sleep(0.1)" for second run)
except KeyboardInterrupt:
leds.off()
out.close()3744 121 103 103 -0.019531 0.085449 1.002563 305.720000 24.042208 99279.639506
3744 121 103 103 -0.022339 0.086243 1.003113 306.690000 24.040343 99279.521707
3744 121 103 103 -0.023682 0.083069 1.003784 304.800000 24.040343 99279.521707
3744 121 103 103 -0.021362 0.086121 0.998962 305.500000 24.040343 99279.521707
3754 121 103 103 -0.023132 0.084412 1.008240 303.990000 24.040343 99279.521707
3754 121 103 103 -0.025085 0.085144 1.003967 305.410000 24.039722 99279.592733
3754 121 103 103 -0.021851 0.087891 1.005432 305.410000 24.039722 99279.592733
3754 121 103 103 -0.026245 0.087830 1.001648 304.810000 24.039722 99279.592733
3754 121 103 103 -0.017639 0.087158 1.004883 305.450000 24.039722 99279.592733
3763 121 103 103 -0.023376 0.086060 1.002380 305.870000 24.039722 99279.592733
3763 121 103 103 -0.023193 0.085632 0.998230 305.550000 24.039722 99279.592733
3763 121 103 103 -0.021423 0.085571 1.000732 303.750000 24.039722 99279.592733
3763 121 103 103 -0.023010 0.089233 0.994568 305.960000 24.039722 99279.592733
3758 122 103 103 0.049072 0.074524 1.158630 311.690000 24.039722 99279.592733
3758 122 103 103 -0.038269 0.015686 0.804749 296.140000 24.040343 99279.521707
3758 122 103 103 0.229187 0.234009 1.039001 341.790000 24.040343 99279.521707
3758 122 103 103 0.036560 0.053040 1.287048 330.400000 24.040343 99279.521707
3469 124 103 102 -0.421692 -0.169250 0.836060 310.080000 24.040343 99279.521707
3469 124 103 102 -0.621582 -0.000366 0.954285 286.840000 24.041897 99279.261422
3469 124 103 102 -0.416321 0.026245 0.915894 311.750000 24.041897 99279.261422
3469 124 103 102 -0.315063 -0.025513 0.934998 306.480000 24.041897 99279.261422
2746 123 105 100 -0.340637 -0.024780 0.861755 277.590000 24.041897 99279.261422
2746 123 105 100 -0.185791 0.291687 1.994873 256.210000 24.042830 99279.072162
2746 123 105 100 -0.200989 0.518005 1.752075 81.410000 24.042830 99279.072162
2746 123 105 100 -0.174377 -0.045593 0.082458 332.930000 24.042830 99279.072162
2746 123 105 100 -0.257690 -0.355286 -0.446960 330.670000 24.042830 99279.072162
2677 124 103 94 0.235840 0.018127 -0.416443 7.370000 24.040654 99278.245404
2677 124 103 94 0.362976 0.554138 1.714539 19.340000 24.040654 99278.245404
2677 124 103 94 -0.159058 0.429688 1.999512 268.750000 24.040654 99278.245404
2677 124 103 94 -0.312927 0.503418 1.999512 57.830000 24.040654 99278.245404
2960 117 104 97 -0.676514 0.960754 1.999512 230.680000 24.040654 99278.245404
2960 117 104 97 0.341980 0.181519 -0.216553 22.560000 24.039411 99278.387458
2960 117 104 97 -0.190186 -0.501526 -0.789429 340.070000 24.039411 99278.387458
2960 117 104 97 -0.260864 -0.304382 -0.658691 0.600000 24.039411 99278.387458
1631 125 106 94 0.070496 0.449158 -0.118835 31.290000 24.039411 99278.387458
1631 125 106 94 0.340210 0.711670 1.999512 24.440000 24.035992 99278.033632
1631 125 106 94 0.440369 0.154236 1.733154 315.260000 24.035992 99278.033632
1631 125 106 94 0.176819 0.469360 1.999512 353.460000 24.035992 99278.033632
3320 119 103 97 0.124939 0.833862 1.202759 46.470000 24.035992 99278.033632
3320 119 103 97 0.070496 -0.054504 -0.698730 35.070000 24.032573 99277.679804
3320 119 103 97 0.011047 -0.688293 -0.958618 351.510000 24.032573 99277.679804
3320 119 103 97 0.392761 0.052307 0.217468 42.680000 24.032573 99277.679804
1008 125 112 95 0.341125 0.666199 1.002441 64.810000 24.032573 99277.679804
1008 125 112 95 0.928833 0.086304 1.999512 340.010000 24.028533 99277.396999
1008 125 112 95 0.424805 0.191711 1.999512 316.640000 24.028533 99277.396999
1008 125 112 95 0.094360 0.685425 1.999512 48.980000 24.028533 99277.396999
3017 123 103 96 -0.278931 0.255249 0.686462 69.740000 24.028533 99277.396999
3017 123 103 96 -0.131409 -0.329468 -0.270020 24.650000 24.024803 99276.995961
3017 123 103 96 -0.006592 -0.589355 -1.002869 348.920000 24.024803 99276.995961
3017 123 103 96 0.226990 0.524841 0.128845 49.900000 24.024803 99276.995961
1103 122 111 93 -0.139160 0.400024 1.999512 11.680000 24.024803 99276.995961
1103 122 111 93 0.720520 -0.203430 1.511169 240.050000 24.020763 99276.878583
1103 122 111 93 -0.108826 0.020630 1.910645 282.100000 24.020763 99276.878583
1103 122 111 93 -0.146667 0.543457 0.601868 52.850000 24.020763 99276.878583
2690 123 102 94 0.086365 -0.022095 -0.873962 39.130000 24.016412 99276.548560
2690 123 102 94 0.127380 -0.430054 -0.651489 28.930000 24.016412 99276.548560
2690 123 102 94 0.170959 0.279724 0.603943 46.760000 24.016412 99276.548560
994 125 112 95 -0.350830 0.280884 1.831360 6.410000 24.016412 99276.548560
994 125 112 95 0.006531 0.116150 1.858948 288.640000 24.012371 99276.596602
994 125 112 95 0.064819 0.108948 0.918213 302.780000 24.012371 99276.596602
994 125 112 95 -0.018799 0.069763 0.868347 297.360000 24.012371 99276.596602
3237 125 102 98 -0.082275 -0.077454 1.041992 285.940000 24.012371 99276.596602
3237 125 102 98 0.367432 0.029419 1.059265 324.260000 24.008642 99276.857274
3237 125 102 98 -0.676453 0.244751 1.067383 161.400000 24.008642 99276.857274
3237 125 102 98 -0.854492 0.525391 1.211792 143.350000 24.008642 99276.857274
2785 130 102 94 1.178467 0.045654 1.153625 349.450000 24.008642 99276.857274
2785 130 102 94 1.191345 -0.185242 1.049988 350.160000 24.004601 99276.905299
2785 130 102 94 1.226746 0.346252 0.914978 346.570000 24.004601 99276.905299
2785 130 102 94 -0.838501 0.726257 1.263855 206.170000 24.004601 99276.905299
2676 130 104 96 -1.236572 0.356689 0.934937 202.730000 24.004601 99277.732444
2676 130 104 96 -1.180725 0.414246 0.705505 200.480000 23.999628 99276.977122
2676 130 104 96 -0.322327 0.829834 1.176758 104.200000 23.999628 99276.977122
2158 131 107 95 1.306091 0.761597 1.234680 346.750000 23.999628 99276.977122
2158 131 107 95 1.783630 -0.259460 0.854919 350.500000 23.994966 99276.930714
2158 131 107 95 1.206421 0.384216 1.101013 344.010000 23.994966 99276.930714
2158 131 107 95 -0.098022 1.067688 1.168762 280.600000 23.994966 99276.930714
2950 129 103 98 -1.313660 0.621582 1.244446 209.350000 23.994966 99276.930714
2950 129 103 98 -1.211426 0.402100 0.861389 206.280000 23.989683 99276.955305
2950 129 103 98 -0.380432 0.852173 0.976074 113.660000 23.989683 99276.955305
2950 129 103 98 0.754822 0.646484 1.235962 18.920000 23.989683 99276.955305
2548 128 106 98 1.503113 -0.194336 1.180420 345.040000 23.989683 99276.955305
2548 128 106 98 1.169189 0.116394 0.939392 343.480000 23.983466 99277.003682
2548 128 106 98 0.366455 0.973633 1.083862 305.320000 23.983466 99277.003682
2548 128 106 98 -0.887939 0.788574 1.299133 215.340000 23.983466 99277.003682
2961 126 103 98 -1.445374 0.311523 0.941284 203.840000 23.983466 99277.003682
2961 126 103 98 -0.640503 0.707947 0.854492 149.790000 23.977561 99276.933827
2961 126 103 98 0.171875 0.726562 1.119446 52.420000 23.977561 99276.933827
2961 126 103 98 1.138428 0.205688 1.149841 341.110000 23.977561 99276.933827
2588 128 105 98 1.331909 -0.211731 1.009583 345.220000 23.977561 99276.934960
2588 128 105 98 0.675293 0.210083 0.972778 350.760000 23.971034 99276.934960
2588 128 105 98 0.253113 0.727783 0.997742 37.260000 23.971034 99276.934960
2983 127 103 99 -0.493713 0.824219 1.152100 137.470000 23.971034 99276.934960
2983 127 103 99 -1.158142 0.367310 1.151917 202.330000 23.963886 99277.007072
2983 127 103 99 -0.746338 0.468079 0.898560 172.570000 23.963886 99277.007072
2983 127 103 99 -0.133972 0.867004 1.119019 90.740000 23.963886 99277.007072
2202 129 108 97 0.767456 0.572266 1.282410 14.290000 23.963886 99277.007072
2202 129 108 97 1.392029 -0.191528 0.982361 347.570000 23.956426 99277.031949
2202 129 108 97 0.957520 -0.056274 0.912659 349.660000 23.956426 99277.031949
2202 129 108 97 0.375549 0.622559 1.034363 17.000000 23.956426 99277.031949
3047 128 103 99 -0.604126 0.892334 1.266113 232.610000 23.956426 99277.031949
3047 128 103 99 -1.051270 0.269409 1.103760 203.790000 23.948345 99277.127793
3047 128 103 99 -0.950195 0.445984 1.007629 205.520000 23.948345 99277.127793
3047 128 103 99 -0.141541 0.797852 1.028748 100.410000 23.948345 99277.127793
2165 127 107 96 0.766724 0.551331 1.116394 13.430000 23.948345 99277.127793
2165 127 107 96 1.275024 -0.214294 0.835083 346.360000 23.939643 99276.963771
2165 127 107 96 1.115723 -0.084167 0.963196 345.650000 23.939643 99276.963771
2165 128 103 100 0.569763 0.637817 1.001587 25.990000 23.939643 99276.963771
3111 128 103 100 -0.490051 0.788208 1.261414 137.710000 23.939643 99278.688539
3111 128 103 100 -0.963867 0.255310 1.032410 185.520000 23.931251 99277.177750
3111 128 103 100 -0.326599 0.095703 0.933411 259.120000 23.931251 99277.177750
2242 127 105 95 0.184875 0.015137 1.006042 282.040000 23.931251 99277.177750
2242 127 105 95 0.203979 0.040405 1.106445 290.530000 23.922859 99277.060878
2242 127 105 95 0.118286 0.077209 1.027954 278.690000 23.922859 99277.060878
2242 127 105 95 0.164062 0.429504 1.099670 61.630000 23.922859 99277.060878
2200 127 103 93 -0.031616 0.322876 0.703857 233.950000 23.922859 99277.060878
2200 127 103 93 -0.397949 -0.962891 0.851257 240.720000 23.915710 99276.967423
2200 127 103 93 -0.441833 -0.825256 1.194153 239.400000 23.915710 99276.967423
2200 127 103 93 -0.460022 -0.863281 0.927063 244.620000 23.915710 99276.967423
1819 130 108 96 0.903992 0.785522 0.602417 347.970000 23.915710 99276.967423
1819 130 108 96 0.043518 0.588318 1.015381 46.100000 23.909183 99276.968375
1819 130 108 96 0.230591 1.002991 0.775330 321.070000 23.909183 99276.968375
1819 130 108 96 0.091797 -0.529175 0.622009 283.730000 23.909183 99276.968375
2338 130 101 89 0.171936 -1.229614 1.179199 303.750000 23.909183 99276.968375
2338 130 101 89 0.248169 -0.797241 1.435486 286.320000 23.902656 99277.134710
2338 130 101 89 -0.340210 -0.416138 0.175781 287.290000 23.902656 99277.134710
2056 128 105 94 0.571167 1.152832 1.154724 264.470000 23.902656 99277.134710
2056 128 105 94 -0.079834 0.858276 0.962280 94.700000 23.902656 99277.134710
2056 128 105 94 0.039673 -0.030396 0.700134 327.420000 23.896440 99277.017435
2056 128 105 94 0.395935 -0.924927 1.433838 337.240000 23.896440 99277.017435
2342 129 103 94 0.213623 -1.065613 1.352417 335.370000 23.896440 99277.017435
2342 129 103 94 -0.056824 -0.781738 0.665222 275.000000 23.890845 99276.994575
2342 129 103 94 0.381165 1.288635 1.019409 309.870000 23.890845 99276.994575
2342 129 103 94 -0.136719 0.808228 0.692139 79.260000 23.890845 99276.994575
2408 129 103 93 -0.149963 0.563477 0.579773 27.840000 23.890845 99276.994575
2408 129 103 93 0.092163 -0.830200 1.123352 274.420000 23.884940 99276.759089
2408 129 103 93 0.780884 -1.012390 1.538269 335.080000 23.884940 99276.759089
2408 129 103 93 0.026794 -0.905090 0.573608 272.380000 23.884940 99276.759089
2111 127 106 96 0.688538 1.637085 1.197266 324.380000 23.884940 99276.759089
2111 127 106 96 -0.452393 0.554871 0.872986 120.270000 23.879035 99276.854384
2111 127 106 96 -0.186646 0.500916 0.566711 103.800000 23.879035 99276.854384
2111 127 106 96 0.054810 -0.354126 0.906372 270.780000 23.879035 99276.854384
2558 129 102 93 0.939209 -1.038818 1.753357 334.980000 23.879035 99276.854384
2558 129 102 93 0.254272 -0.835205 1.080322 284.800000 23.872508 99276.524441
2558 129 102 93 0.305054 0.744202 0.474731 64.560000 23.872508 99276.524441
2300 127 105 96 0.126770 0.727661 0.718933 58.360000 23.872508 99276.524441
2300 127 105 96 -0.321838 0.841492 0.718018 104.230000 23.872508 99277.351412
2300 127 105 96 0.086609 -0.307068 0.931702 281.720000 23.866602 99276.454311
2300 127 105 96 0.802063 -1.088074 1.410828 336.050000 23.866602 99276.454311
2492 128 104 96 0.449829 -0.799255 1.049927 295.690000 23.866602 99276.454311
2492 128 104 96 0.182495 0.207214 0.573975 18.060000 23.861007 99276.596773
2492 128 104 96 -0.018250 1.295288 1.382507 285.050000 23.861007 99276.596773
2492 128 104 96 -0.125916 0.960571 0.819031 86.800000 23.861007 99276.596773
2493 129 102 94 -0.215271 -0.007996 0.216431 219.180000 23.861007 99276.596773
2493 129 102 94 0.610229 -1.249268 1.619324 324.860000 23.854480 99276.762958
2493 129 102 94 0.511475 -0.820435 1.418884 300.330000 23.854480 99276.762958
2493 129 102 94 -0.805481 -0.671326 0.561462 179.660000 23.854480 99276.762958
2006 126 107 96 -0.016357 1.097900 1.233032 291.560000 23.854480 99276.762958
2006 126 107 96 0.028015 -0.356506 0.915833 292.520000 23.848886 99276.905385
2006 126 107 96 0.096985 -0.170288 1.095459 312.880000 23.848886 99276.905385
2006 130 101 89 0.100220 -0.147705 1.046448 319.540000 23.848886 99276.905385
2358 130 101 89 -0.047241 -0.033081 1.072815 333.350000 23.848886 99276.905385
2358 130 101 89 0.043701 0.057617 0.970581 310.770000 23.843602 99276.764240
2358 130 101 89 -0.168823 0.056091 0.928040 292.500000 23.843602 99276.764240
3141 126 101 97 -0.383667 -0.104675 0.102844 279.240000 23.843602 99276.764240
3141 126 101 97 -0.025085 0.606750 1.130127 8.790000 23.843602 99276.764738
3141 126 101 97 -0.142700 0.356689 1.099243 332.780000 23.839250 99276.764738
3141 126 101 97 -0.401245 0.134583 0.950684 306.350000 23.839250 99276.764738
3809 118 105 103 -1.018860 0.043030 1.119751 210.740000 23.839250 99276.764738
3809 118 105 103 0.017883 0.098450 0.162048 330.640000 23.834277 99276.670791
3809 118 105 103 0.159485 -0.287476 0.746826 297.110000 23.834277 99276.670791
3809 118 105 103 -0.065308 0.226807 1.039185 280.850000 23.834277 99276.670791
3386 122 104 101 -0.045349 0.163208 0.975586 282.630000 23.834277 99276.670791
3386 122 104 101 -0.064880 0.153992 1.005676 280.600000 23.828993 99276.860382
3386 122 104 101 -0.057556 0.154297 0.996704 280.840000 23.828993 99276.860382
3386 122 104 101 -0.066956 0.152893 0.990479 280.150000 23.828993 99276.860382
3947 120 104 104 -0.055908 0.148376 0.988647 281.650000 23.828993 99276.860382
3947 120 104 104 -0.059875 0.148865 0.989624 280.420000 23.823710 99277.049957
3947 120 104 104 -0.048340 0.148560 0.992554 282.980000 23.823710 99277.049957
3956 120 104 104 -0.052734 0.148254 0.983948 281.370000 23.823710 99277.049957
3956 120 104 104 -0.050598 0.151123 0.993652 281.250000 23.823710 99277.049957
3956 120 104 104 -0.059387 0.145813 0.990784 280.440000 23.819358 99277.215794
3956 120 104 104 -0.044373 0.151184 0.993835 284.320000 23.819358 99277.215794
3943 120 104 104 -0.060303 0.144897 0.989441 280.660000 23.819358 99277.215794
3943 120 104 104 -0.055481 0.153442 0.966125 281.940000 23.815628 99277.310680
3943 120 104 104 -0.055298 0.155396 0.978882 280.980000 23.815628 99277.310680
3943 120 104 104 -0.048401 0.142578 0.983276 281.870000 23.815628 99277.310680
3935 120 104 104 -0.047729 0.142761 1.001587 281.150000 23.815628 99277.310680
3935 120 104 104 -0.057434 0.148254 0.981201 281.040000 23.811898 99277.240181
import csv
data_file = open('enviro.log')
file_reader = csv.reader(data_file, delimiter=' ')
lux=[]; colorR=[]; colorG=[]; colorB=[]
accX=[]; accY=[]; accZ=[]; heading=[]; temp=[]; press=[];
for row in file_reader:
lux.append(row[0])
colorR.append(row[1])
colorG.append(row[2])
colorB.append(row[3])
accX.append(row[4])
accY.append(row[5])
accZ.append(row[6])
heading.append(row[7])
temp.append(row[8])
press.append(row[9])import matplotlib.pyplot as plt
%matplotlib inline
f, ax = plt.subplots(6, sharex=True, figsize=(15, 12))
ax[0].plot(lux,'k')
ax[0].set_ylabel('light')
ax[0].grid(True)
ax[1].plot(colorR,'r')
ax[1].plot(colorG,'g')
ax[1].plot(colorB,'b')
ax[1].set_ylabel('colorRGB')
ax[1].grid(True)
ax[2].plot(accX,'r')
ax[2].plot(accY,'g')
ax[2].plot(accZ,'b')
ax[2].set_ylabel('accelXYZ')
ax[2].grid(True)
ax[3].plot(heading,'k')
ax[3].set_ylabel('heading')
ax[3].grid(True)
ax[4].plot(temp,'k')
ax[4].set_ylabel('temp')
ax[4].grid(True)
ax[5].plot(press,'k')
ax[5].set_ylabel('pressure')
ax[5].grid(True)
ax[5].set_xlabel('time (s)') # sample rate was 1sec
f.savefig("data.png")
# second dataset focusing on acccelerations in 3 axis directions...
# (note this run was done with sample rate 10 Hz)
import numpy as np
f, ax = plt.subplots(1, figsize=(15, 3))
t=np.arange(0,float(len(accX))/10.0,0.1)
ax.plot(t,accX,'r.-')
ax.plot(t,accY,'g.-')
ax.plot(t,accZ,'b.-')
ax.set_ylabel('accelXYZ')
ax.grid(True)
ax.set_xlabel('time (s)') # sample rate was 1sec
f.savefig("data2.png")
With roughly 1Hz period, I first shook the device vertically up and down about 5-6 times, then left/right about 5-6 times, then fwd/back 5-6 times. We can see the three directions reasonably well in the data, given the caveat that I had no idea which directions were the device’s unit directions and wasn’t be very careful anyway. Note for this run I increased the sampling rate to 10Hz to catch my roughly 1Hz shaking period.