~alienagain/Navecita

6ec9520c112e72473192849a4348206164cc8761 — alien 4 months ago 0b98ef7 master
adding code for UVA reading
2 files changed, 82 insertions(+), 0 deletions(-)

A code/read_it_once.sh
A code/read_uva.ino
A code/read_it_once.sh => code/read_it_once.sh +24 -0
@@ 0,0 1,24 @@
#!/bin/bash

hace_sol(){

        declare -a frases_de_sol=("A ponerse gafitas de sol para regar 8)" "¡me estoy cargando! ¡fotosíntesis! ¿Soy una planta?" "¿Las raspberry pis se pueden poner morenas?
" "Es un buen momento para hacerme compañía en el balcón (pero ponte cremita eh)")
mi_frase=$(( $RANDOM % 3 + 0 ))

echo ${frases_de_sol[mi_frase]}

}


sudo cat -v /dev/ttyUSB1 > myuva

uva_line=$(head -n 1 myuva | sed 's/M//' | sed 's/\^//')
int=${uva_line%.*}

rm myuva

if [ $int -gt 20 ]; then
        hace_sol
fi


A code/read_uva.ino => code/read_uva.ino +58 -0
@@ 0,0 1,58 @@
#include <Wire.h>
#include "Adafruit_VEML6075.h"

Adafruit_VEML6075 uv = Adafruit_VEML6075();

void setup() {
  Serial.begin(115200);
  //Serial.println("VEML6075 Full Test");
  if (! uv.begin()) {
    Serial.println("Failed to communicate with VEML6075 sensor, check wiring?");
  }
  //Serial.println("Found VEML6075 sensor");

  // Set the integration constant
  uv.setIntegrationTime(VEML6075_100MS);
  // Get the integration constant and print it!
  //Serial.print("Integration time set to ");
  switch (uv.getIntegrationTime()) {
    //case VEML6075_50MS: Serial.print("50"); break;
    //case VEML6075_100MS: Serial.print("100"); break;
    //case VEML6075_200MS: Serial.print("200"); break;
    //case VEML6075_400MS: Serial.print("400"); break;
    //case VEML6075_800MS: Serial.print("800"); break;
  }
  //Serial.println("ms");

  // Set the high dynamic mode
  uv.setHighDynamic(true);
  // Get the mode
  if (uv.getHighDynamic()) {
   // Serial.println("High dynamic reading mode");
  } else {
    //Serial.println("Normal dynamic reading mode");
  }

  // Set the mode
  uv.setForcedMode(false);
  // Get the mode
  if (uv.getForcedMode()) {
    //Serial.println("Forced reading mode");
  } else {
    //Serial.println("Continuous reading mode");
  }

  // Set the calibration coefficients
  uv.setCoefficients(2.22, 1.33,  // UVA_A and UVA_B coefficients
                     2.95, 1.74,  // UVB_C and UVB_D coefficients
                     0.001461, 0.002591); // UVA and UVB responses
}


void loop() {
  Serial.println(abs(uv.readUVA()));
  //Serial.println(uv.readUVB());
  //Serial.print("UV Index reading: "); Serial.println(uv.readUVI());

  delay(3000);
}