Adding UltrasonicSensor software

Adding UltrasonicSensor software

/*
Attiny84 8mhz only
*/
#include <TinyWire.h>
#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>
#include <NewPing.h>

uint8_t address;
uint8_t triggerdistance;
uint8_t humidity;
uint8_t temperature;
uint8_t distance;

float duration;
float soundcm;
float soundsp;
DHT dht(10, DHT11);
NewPing sonar(3, 2);
void setup(){
  pinMode(0,INPUT_PULLUP);
  pinMode(8,INPUT_PULLUP);
  pinMode(9,INPUT_PULLUP);
  pinMode(7,OUTPUT);

  address = get_address();
  TinyWire.begin(address);
  TinyWire.onRequest(requestEvent);

}
void loop()
  {
    triggerdistance = map(analogRead(A1),0,1023,10,50);
    humidity = dht.readHumidity();
    temperature = dht.readTemperature();
    if (isnan(humidity) || isnan(temperature)) {
      soundsp = 331.4 + (0.606 * temperature) + (0.0124 * humidity);
    }
    else{
      soundsp = 331.4;
    }
    soundcm = soundsp / 10000;
    duration = sonar.ping_median(3);
    distance = (duration / 2) * soundcm;
    if (distance >= 100 || distance == 0){
      distance = 200;
    }
    if(distance < triggerdistance){
      digitalWrite(7,HIGH);
    }
    else{
      digitalWrite(7,LOW);
    }
    delay(30);
  }
void requestEvent()
{
  TinyWire.send(distance);
  TinyWire.send(temperature);
  TinyWire.send(humidity);
  TinyWire.send(triggerdistance);
}
uint8_t get_address(){
  uint8_t address = 16 + !digitalRead(0)*1+!digitalRead(8)*2+!digitalRead(9)*4;
  return address;
}

error: pathspec 'Software/Sensors/Ultrasonic_Sensor/Ultrasonic_Sensor.ino' did not match any file(s) known to git


Added file for picture streaming development

// ArduCAM demo (C)2015 Lee
// web: http://www.ArduCAM.com
// This program is a demo of how to use most of the functions
// of the library with a supported camera modules.
//
// This demo was made for Aptina MT9D111 standard camera module.
// It will turn the ArduCAM into a real digital camera with capture and playback functions.
// Before use this example, please uncomment the line #define MT9D111_CAM in the memorysaver.h file.
// 1. Preview the live video on LCD Screen.
// 2. Capture and buffer the image to FIFO when shutter pressed quickly.
// 3. Store the image to Micro SD/TF card with BMP format.
// 4. Playback the capture photos one by one when shutter buttom hold on for 3 seconds.
// This program requires the ArduCAM V3.3.0 (or above) library and Rev.C ArduCAM shield
// and use Arduino IDE 1.5.8 compiler or above

#include <UTFT_SPI.h>
#include <SD.h>
#include <Wire.h>
#include "ArduCAM.h"
#include <SPI.h>
#include "memorysaver.h"

#if defined(__arm__)
#include <itoa.h>
#endif

#define SD_CS 9
#define BMPIMAGEOFFSET 66

// set pin 10 as the slave select for the ArduCAM shield
const int SPI_CS = 10;

const char bmp_header[BMPIMAGEOFFSET] PROGMEM =
{
  0x42, 0x4D, 0x36, 0x58, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x00, 0x00, 0x28, 0x00,
  0x00, 0x00, 0x40, 0x01, 0x00, 0x00, 0xF0, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x00, 0x03, 0x00,
  0x00, 0x00, 0x00, 0x58, 0x02, 0x00, 0xC4, 0x0E, 0x00, 0x00, 0xC4, 0x0E, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x00, 0x00, 0xE0, 0x07, 0x00, 0x00, 0x1F, 0x00,
  0x00, 0x00
};

ArduCAM myCAM(MT9D111_A, SPI_CS);
UTFT myGLCD(SPI_CS);

void setup()
{
  uint8_t vid, pid;
  uint8_t temp;

#if defined (__AVR__)
  Wire.begin();
#endif
#if defined(__arm__)
  Wire1.begin();
#endif
  Serial.begin(115200);
  Serial.println("ArduCAM Start!");

  // set the SPI_CS as an output:
  pinMode(SPI_CS, OUTPUT);

  // initialize SPI:
  SPI.begin();
  //Check if the ArduCAM SPI bus is OK
  myCAM.write_reg(ARDUCHIP_TEST1, 0x55);
  temp = myCAM.read_reg(ARDUCHIP_TEST1);
  if (temp != 0x55)
  {
    Serial.println("SPI interface Error!");
    while (1);
  }

  //Change MCU mode
  myCAM.set_mode(MCU2LCD_MODE);

  //Initialize the LCD Module
  myGLCD.InitLCD();

  myCAM.InitCAM();
  myCAM.set_format(JPEG);

  //Initialize SD Card
  if (!SD.begin(SD_CS))
  {
    //while (1);		//If failed, stop here
    Serial.println("SD Card Error");
  }
  else
    Serial.println("SD Card detected!");
}

void loop()
{
  uint8_t temp,temp_last;
  uint8_t start_capture = 0;

  temp = Serial.read();
  start_capture = 1;
  Serial.println("Start Capture");
  myCAM.flush_fifo();
  //start_capture = 1;
  if(start_capture)
  {
    //Clear the capture done flag
    myCAM.clear_fifo_flag();
    //Start capture
    myCAM.start_capture();
  }
  if(myCAM.get_bit(ARDUCHIP_TRIG,CAP_DONE_MASK))
  {
    Serial.println("Capture Done!");

    while( (temp != 0xD9) | (temp_last != 0xFF) )
    {
        temp_last = temp;
	temp = myCAM.read_fifo();
	Serial.write(temp);
    }

    //Clear the capture done flag
    myCAM.clear_fifo_flag();
    start_capture = 0;
  /*
  char str[8];
  static int k = 0;
  uint8_t temp;
  myCAM.set_mode(CAM2LCD_MODE);		 	//Switch to CAM

  while (1)
  {

    if (!myCAM.get_bit(ARDUCHIP_TRIG, VSYNC_MASK))		//New Frame is coming
    {
      myCAM.set_mode(MCU2LCD_MODE);    	//Switch to MCU
      myGLCD.resetXY();
      myCAM.set_mode(CAM2LCD_MODE);    	//Switch to CAM
      while (!myCAM.get_bit(ARDUCHIP_TRIG, VSYNC_MASK)); 	//Wait for VSYNC is gone
    }
    else if (myCAM.get_bit(ARDUCHIP_TRIG, SHUTTER_MASK))
    {
      k = k + 1;
      itoa(k, str, 10);
      strcat(str, ".bmp");				//Generate file name
      myCAM.set_mode(MCU2LCD_MODE);    	//Switch to MCU, freeze the screen
      GrabImage(str);
    }
  }
    */
  }
}

/*
void GrabImage(char* str)
{
  File outFile;
  char VH, VL;
  uint8_t temp;
  byte buf[256];
  static int k = 0;
  int i, j = 0;

  outFile = SD.open(str, O_WRITE | O_CREAT | O_TRUNC);
  if (! outFile)
  {
    Serial.println("Open File Error");
    return;
  }

  //Switch to FIFO Mode
  myCAM.write_reg(ARDUCHIP_TIM, MODE_MASK);
  //Flush the FIFO
  myCAM.flush_fifo();
  //Start capture
  myCAM.start_capture();
  Serial.println("Start Capture");

  //Polling the capture done flag
  while (!myCAM.get_bit(ARDUCHIP_TRIG, CAP_DONE_MASK));
  Serial.println("Capture Done!");

  k = 0;
  //Write the BMP header
  for ( i = 0; i < BMPIMAGEOFFSET; i++)
  {
    char ch = pgm_read_byte(&bmp_header[i]);
    buf[k++] = ch;
  }
  outFile.write(buf, k);
  //Read the first dummy byte
  myCAM.read_fifo();

  k = 0;
  //Read 320x240x2 byte from FIFO
  //Save as RGB565 bmp format
  for (i = 0; i < 240; i++)
    for (j = 0; j < 320; j++)
    {
      VH = myCAM.read_fifo();
      VL = myCAM.read_fifo();
      buf[k++] = VL;
      buf[k++] = VH;
      //Write image data to bufer if not full
      if (k >= 256)
      {
        //Write 256 bytes image data to file from buffer
        outFile.write(buf, 256);
        k = 0;
      }
    }
  //Close the file
  outFile.close();
  //Clear the capture done flag
  myCAM.clear_fifo_flag();

  //Switch to LCD Mode
  myCAM.write_reg(ARDUCHIP_TIM, 0);
  return;
}
*/

error: pathspec 'Arduino/ArduCAM/ArduCAM_Tim_Dev_1/ArduCAM_Tim_Dev_1.ino' did not match any file(s) known to git


Got the csv value display working

Got the csv value display working

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/WestwoodRobotics/BEST-2015.git/'


add FadeColorHsv variant

add FadeColorHsv variant

// Love to Code

// Rainbow tape "Fade Color" demo.

// This simple demo enables you to fade a pixel between two colors
// In this variant, we fade using HSV space, instead of alpha blending

// select colors codes using the "Rainbow Gadget".
// or use any color from https://github.com/chibitronics/ltc-compiler-layer/blob/master/support/html_colors.h
#include "html_colors.h"
int pix0_colorA = 0x17c7d1;      // can specify color as hex code
int pix0_colorB = COLOR_DARKRED; // or specify color as html-standard name
int pix0_speed = 3;              // a number 0-100
int pix0_brightness = 50;        // a number 0-100

int pix1_colorA = COLOR_GREEN;
int pix1_colorB = COLOR_RED;
int pix1_speed = 5;
int pix1_brightness = 20;

int pix2_colorA = COLOR_BLUE;
int pix2_colorB = COLOR_HOTPINK;
int pix2_speed = 4;
int pix2_brightness = 100;

int pix3_colorA = COLOR_TEAL;
int pix3_colorB = COLOR_FUCHSIA;
int pix3_speed = 3;
int pix3_brightness = 80;

int pix4_colorA = COLOR_RED;
int pix4_colorB = COLOR_BLUE;
int pix4_speed = 2;
int pix4_brightness = 15;

#include "Adafruit_NeoPixel.h"

#define pixelCount 5 // number of pixels in the chain; doesn't hurt to have less actual pixels in your project
Adafruit_NeoPixel strip = Adafruit_NeoPixel(pixelCount, LED_BUILTIN_RGB, NEO_GRB + NEO_KHZ800);

typedef struct RgbColor {
  uint8_t r;
  uint8_t g;
  uint8_t b;
} RgbColor;

typedef struct HsvColor {
  int h;
  int s;
  int v;
} HsvColor;

// from https://gist.github.com/mity/6034000
#define HUE_DEGREE    512 // hue is 0 ... (360*HUE_DEGREE - 1)
#define MIN(a,b)      ((a) < (b) ? (a) : (b))
#define MAX(a,b)      ((a) > (b) ? (a) : (b))

#define MIN3(a,b,c)   MIN((a), MIN((b), (c)))
#define MAX3(a,b,c)   MAX((a), MAX((b), (c)))

void rgb2hsv(uint8_t r, uint8_t g, uint8_t b, HsvColor* hsv) {
  int m = MIN3(r, g, b);
  int M = MAX3(r, g, b);
  int delta = M - m;

  if(delta == 0) {
    /* Achromatic case (i.e. grayscale) */
    hsv->h = -1;          /* undefined */
    hsv->s = 0;
  } else {
    int h;

    if(r == M)
      h = ((g-b)*60*HUE_DEGREE) / delta;
    else if(g == M)
      h = ((b-r)*60*HUE_DEGREE) / delta + 120*HUE_DEGREE;
    else /*if(b == M)*/
      h = ((r-g)*60*HUE_DEGREE) / delta + 240*HUE_DEGREE;

    if(h < 0)
      h += 360*HUE_DEGREE;

    hsv->h = h;

    /* The constatnt 8 is tuned to statistically cause as little
     * tolerated mismatches as possible in RGB -> HSV -> RGB conversion.
     * (See the unit test at the bottom of this file.)
     */
    hsv->s = (256*delta-8) / M;
  }
  hsv->v = M;
}

void hsv2rgb(int h, int s, int v, RgbColor *c) {
  uint8_t r, g, b;

  if(s == 0) {
    r = g = b = v;
  } else {
    int i = h / (60*HUE_DEGREE);
    int p = (256*v - s*v) / 256;

    if(i & 1) {
      int q = (256*60*HUE_DEGREE*v - h*s*v + 60*HUE_DEGREE*s*v*i) / (256*60*HUE_DEGREE);
      switch(i) {
      case 1:   r = q; g = v; b = p; break;
      case 3:   r = p; g = q; b = v; break;
      case 5:   r = v; g = p; b = q; break;
      }
    } else {
      int t = (256*60*HUE_DEGREE*v + h*s*v - 60*HUE_DEGREE*s*v*(i+1)) / (256*60*HUE_DEGREE);
      switch(i) {
      case 0:   r = v; g = t; b = p; break;
      case 2:   r = p; g = v; b = t; break;
      case 4:   r = t; g = p; b = v; break;
      }
    }
  }

  c->r = r;
  c->g = g;
  c->b = b;
}

// blend 8-bit number, alpha is a number 1-100
uint8_t blend8(uint8_t a, uint8_t b, uint8_t alpha) {
  if( alpha < 1 )
    alpha = 0;
  if( alpha > 100 )
    alpha = 100;

  uint32_t retval = (((uint32_t)a) * alpha) + (((uint32_t)b) * (100 - alpha));
  retval /= 100;
  if( retval > 255 )
    retval = 255;
  return( (uint8_t) retval );
}

RgbColor blend_rgb(RgbColor a, RgbColor b, uint8_t alpha) {
  RgbColor result;

  result.r = blend8(a.r, b.r, alpha);
  result.g = blend8(a.g, b.g, alpha);
  result.b = blend8(a.b, b.b, alpha);

  return result;
}

// alpha is 0-100
void blend_hsv( HsvColor a, HsvColor b, int alpha, HsvColor *c ) {
  c->h = (a.h * alpha + b.h * (100 - alpha)) / 100;
  c->s = (a.s * alpha + b.s * (100 - alpha)) / 100;
  c->v = (a.v * alpha + b.v * (100 - alpha)) / 100;
}

uint8_t alpha8(uint8_t a, uint8_t alpha) {
  uint32_t q;

  if( alpha > 100 )
    alpha = 100;

  q = (uint32_t) a * (uint32_t) alpha;

  return (uint8_t) ((q / 100) & 0xFF);
}

RgbColor alpha_rgb(RgbColor a, uint8_t alpha) {
  RgbColor result;

  result.r = alpha8(a.r, alpha);
  result.g = alpha8(a.g, alpha);
  result.b = alpha8(a.b, alpha);

  return result;
}

RgbColor hexcolor_to_rgb(uint32_t hexcolor) {
  RgbColor result;

  result.r = (hexcolor >> 16) & 0xff;
  result.g = (hexcolor >> 8) & 0xff;
  result.b = (hexcolor >> 0) & 0xff;

  return result;
}

uint32_t rgb_to_hexcolor(RgbColor rgbcolor) {
  return rgbcolor.r << 16 | rgbcolor.g << 8 | rgbcolor.b;
}

struct pix_config {
  HsvColor colorA;
  HsvColor colorB;
  int speed;
  uint8_t brightness;
  int state;
};
static pix_config config[pixelCount];

RgbColor rgb_a;
RgbColor rgb_b;
int step = 0;
int rate = 3;

void setup() {
  int i;
  RgbColor c;

  strip.begin();
  strip.show();

  rgb2hsv((pix0_colorA >> 16) & 0xff, (pix0_colorA >> 8 & 0xff), pix0_colorA & 0xff,
	  &config[0].colorA);
  rgb2hsv((pix0_colorB >> 16) & 0xff, (pix0_colorB >> 8 & 0xff), pix0_colorB & 0xff,
	  &config[0].colorB);
  config[0].speed = pix0_speed;
  config[0].brightness = pix0_brightness;

  rgb2hsv((pix1_colorA >> 16) & 0xff, (pix1_colorA >> 8 & 0xff), pix1_colorA & 0xff,
	  &config[1].colorA);
  rgb2hsv((pix1_colorB >> 16) & 0xff, (pix1_colorB >> 8 & 0xff), pix1_colorB & 0xff,
	  &config[1].colorB);
  config[1].speed = pix1_speed;
  config[1].brightness = pix1_brightness;

  rgb2hsv((pix2_colorA >> 16) & 0xff, (pix2_colorA >> 8 & 0xff), pix2_colorA & 0xff,
	  &config[2].colorA);
  rgb2hsv((pix2_colorB >> 26) & 0xff, (pix2_colorB >> 8 & 0xff), pix2_colorB & 0xff,
	  &config[2].colorB);
  config[2].speed = pix2_speed;
  config[2].brightness = pix2_brightness;

  rgb2hsv((pix3_colorA >> 16) & 0xff, (pix3_colorA >> 8 & 0xff), pix3_colorA & 0xff,
	  &config[3].colorA);
  rgb2hsv((pix3_colorB >> 26) & 0xff, (pix3_colorB >> 8 & 0xff), pix3_colorB & 0xff,
	  &config[3].colorB);
  config[3].speed = pix3_speed;
  config[3].brightness = pix3_brightness;

  rgb2hsv((pix4_colorA >> 16) & 0xff, (pix4_colorA >> 8 & 0xff), pix4_colorA & 0xff,
	  &config[4].colorA);
  rgb2hsv((pix4_colorB >> 26) & 0xff, (pix4_colorB >> 8 & 0xff), pix4_colorB & 0xff,
	  &config[4].colorB);
  config[4].speed = pix4_speed;
  config[4].brightness = pix4_brightness;

  for( i = 0; i < pixelCount; i++ ) {
    config[i].state = 0;
    hsv2rgb(config[i].colorA.h, config[i].colorA.s, config[i].colorA.v, &c);
    strip.setPixelColor(i, rgb_to_hexcolor(alpha_rgb(c, config[i].brightness)));
  }

  strip.show();
}

void loop() {
  HsvColor blended;
  RgbColor blended_rgb;
  uint8_t fadevalue;
  int i;

  for( i = 0; i < pixelCount; i++ ) {
    blend_hsv( config[i].colorA, config[i].colorB, config[i].state, &blended );

    if( config[i].state < 50 ) {
      fadevalue = 100 - 2 * config[i].state;
    } else {
      fadevalue = (config[i].state - 50) * 2;
    }
    hsv2rgb( blended.h, blended.s, blended.v, &blended_rgb );
    blended_rgb = alpha_rgb( blended_rgb, fadevalue );
    blended_rgb = alpha_rgb( blended_rgb, config[i].brightness );

    strip.setPixelColor(i, rgb_to_hexcolor(blended_rgb));

    config[i].state = config[i].state + config[i].speed;
    if( config[i].state <= 0 || config[i].state >= 100 ) {
      config[i].speed = -config[i].speed;
    }
    if( config[i].state <= 0 )
      config[i].state = 0;
    if( config[i].state >= 100 )
      config[i].state = 100;
  }

  strip.show();

  delay(50);
}

error: pathspec 'examples-ltc/4.RainbowTape/5_FadeColor/FadeColorHsv.ino' did not match any file(s) known to git


Initial working implementation (limited decoding)

#include <Wire.h>
#include <SPI.h>

#define mySerial SerialUSB

/*
   Pin multiplexer value names (PMUXn.PMUXE/O)
*/
const char *pinmux_names[8] = {
  "EIC",   // "A": External Interrupts
  "ADC",   // "B": REF, ADC, AC, PTC, DAC
  "SERCOM",   /* "C": SerCom */
  "SERCOMALT",  /* "D": Alternate SERCOM */
  "TC/TCC",     /* "E": TC or TCC Timer */
  "TCC",        /* "F": TCC Timer*/
  "COM",        /* "G": Other Comm - USB, I2S */
  "AC/GCLK"     /* "H": Analog Comparator or GCLKs */
};

boolean print_pinno(int i)
{
  int pintype = g_APinDescription[i].ulPinType;
  if (pintype == PIO_NOT_A_PIN) {
    return false;
  }
  mySerial.print(i);
  if (i < 10)
    mySerial.print(" ");
  if (pintype == PIO_ANALOG) {  // try to detect and renumber Analog pins.
    mySerial.print(" (A");
    mySerial.print(i - PIN_A0);
    mySerial.print(") ");
  } else {
    mySerial.print("      ");
  }
  return true;
}

void print_pinmux(int pmuxval)
{
  mySerial.print("PMUX");
  mySerial.print("(");
  mySerial.print(pmuxval);
  mySerial.print(") ");
  mySerial.print(pinmux_names[pmuxval]);
}

void setup() {
  mySerial.begin(9600);
  while (!mySerial)
    ;
  mySerial.println("SAMD Pin State Report");
  mySerial.println();

  // Set some pins up doing something different, so that the display will be
  //   more ... interesting.
  Serial1.begin(9600);
  Serial.begin(9600);
  SPI.begin();
  Wire.begin();
  for (int j = 0; j < 6; j++)
    (void) analogRead(j);  // read from analog pins
}

void loop() {
  for (int pin = 0; pin < PINS_COUNT; pin++) {
    if (print_pinno(pin)) {  // Does pin exist?

      int bitno = g_APinDescription[pin].ulPin;
      PortGroup *port = digitalPinToPort(pin);
      int pmuxval;

      if (port->PINCFG[bitno].bit.PMUXEN) {  // Is pinmux enabled?
        // If pinmux is enabled, further report it's value
        if (bitno & 1) {
          // Odd pin numbers
          pmuxval = port->PMUX[bitno / 2].bit.PMUXO;
        } else {
          pmuxval = port->PMUX[bitno / 2].bit.PMUXE;
        }
        print_pinmux(pmuxval);
      } else {
        // Pinmux not enabled - port is GPIO
        mySerial.print("GPIO ");
        if (port->DIR.reg & (1 << bitno)) { // Decode pinmode (direction.)
          mySerial.print("O");
        } else {
          mySerial.print("I");
        }
      } // Pinmux or GPIO
    } // Pin existance
    mySerial.println();
  } // "pin" for loop

  while (mySerial.read() < 0)
    ;  // wait for character to run again.
  mySerial.println("\nRunning again!\n");
}

error: pathspec 'SAMD_pins.ino' did not match any file(s) known to git


Update ProbeCube_pc_v099b0224.ino

Update ProbeCube_pc_v099b0224.ino

error: pathspec 'Photon' did not match any file(s) known to git
error: pathspec 'based/code/ProbeCube_pc_v099b0224.ino' did not match any file(s) known to git


Added a bit and took out serial stuff in order to test this timer with the oscilloscope. It works, and well! Not going to characterize it further -- I need to use it! Maybe later, but moving onto the next step, for now...

error: pathspec 'Motor' did not match any file(s) known to git
error: pathspec 'Speed/testTimerTwo/testTimerTwo.ino' did not match any file(s) known to git


Added cloud pubsub hello world

Added cloud pubsub hello world

/**
 * Copyright 2016 Google Inc. All Rights Reserved.
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 /**
 Here's my Cloud Pub/Sub hello world!
 Create an OAuth token, paste it into this file, and your ESP8266
 will push a payload to Cloud Pub/Sub until it expires.

 Next up: Get auth working
 Someday: Build a library around this
 */
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>

void setup() {
  Serial.begin(9600);

  // connect to wifi.
  WiFi.begin("WIFI_SSID");
  Serial.print("connecting");
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(500);
  }
  Serial.println();
  Serial.print("connected: ");
  Serial.println(WiFi.localIP());

  // Send an http request
  String url = "";
  HTTPClient http;
  http.begin("https://pubsub.googleapis.com/v1/projects/mimming-demo/topics/esp8266hello:publish", "A0 F0 5C 41 6A 66 54 6E 26 C6 8B E6 39 0E 32 51 51 9D A3 23");
  http.addHeader("content-type", "application/json");
  http.addHeader("authorization", "Bearer OAUTH_TOKEN_GOES_HERE");
  String value = "{\"messages\": [{\"data\": \"SGVsbG8gQ2xvdWQgUHViL1N1YiEgSGVyZSBpcyBteSBtZXNzYWdlIQ==\"}]}";
  int statusCode =  http.sendRequest("POST", (uint8_t*)value.c_str(), value.length());

  Serial.println(statusCode);
  Serial.println(http.getString());
}

void loop() {
}

error: pathspec '2016-02-12-cloud-pubsub-esp8266/experiment.ino' did not match any file(s) known to git


Added: first version of programmer that accepts commands via Serial communication

#include <stdlib.h>

#include <StringSplitter.h>

const int POWER_PIN = 40;
const int PROG_POWER_PIN = 41;

class Command {
  public:
    typedef Command* Ptr;

    virtual bool match(const String& name) const;
    virtual void execute(const String& commandString);
    virtual void printHelpString() const;
};

const size_t COMMAND_COUNT = 1;
Command::Ptr commands[1] = {nullptr};

class HelpCommand : public Command {
  public:
    virtual bool match(const String& name) const {
      return name == "help";
    }

    virtual void execute(const String& commandString) {
      Serial.println("Available commands:");
      for (size_t i = 0; i < COMMAND_COUNT; i++) {
        commands[i]->printHelpString();
      }
    }

    virtual void printHelpString() const {
      Serial.println("  help             prints this help screen");
    }
};

void setup() {
  commands[0] = new HelpCommand();

  Serial.begin(57600);
}

void loop() {
  String cmd = Serial.readString();
  cmd.trim();
  if (cmd.length() > 0) {
    bool cmatched = false;
    for (int i = 0; i < COMMAND_COUNT; i++) {
      if (commands[i]->match(cmd)) {
        commands[i]->execute(cmd);
        cmatched = true;
        break;
      }
    }
    if (!cmatched) {
      Serial.println("invalid command, use 'help' to show all available commands");
    }
  }
}


horloge_cycles_ultradiens

/*

HORLOGE À CYCLES ULTRADIENS

http://ouilogique.com/horloge_cycles_ultradiens/

DESCRIPTION DU PROGRAMME
Ce programme affiche le pourcentage d’attention d’une personne en fonction de l’heure. Il se base sur les hypothèses suivantes :
- Le corps humain est soumis à des cycles d’attention d’une durée d’une heure et demie, soit 16 cycles de 5400 secondes par jour.
- Lors de ces cycles, l’attention passe par un minimum et par un maximum et peut être représentée sous la forme d’un cosinus.
- Le seul paramètre qui change d’une personne à l’autre est le déphasage de la courbe.

Pour utiliser ce programme, il faut donc connaître une des 16 heures d’attention maximum possibles lors d’une journée et de modifier la constante “heureAttentionMax” en conséquence.

Pour mettre à jour l’heure de l’horloge, il faut changer la valeur de “avecSerial” à “true” et recharger le programme sur le microcontrôleur. Cette valeur est à “false” par défaut pour limiter l’utilisation de la RAM.

HORLOGE DS1307 I²C
    RÉFÉRENCE AliExpress
    http://fr.aliexpress.com/item/5pcs-lot-Tiny-RTC-I2C-AT24C32-DS1307-Real-Time-Clock-Module-Board-For-Arduino-With-A/32327865928.html

    ADRESSES I²C
    0x50 (EEPROM AT24C32)
    0x68 (DS1307)

    LIBRAIRIE Adafruit
    https://github.com/adafruit/RTClib.git

    CONNEXIONS
    GND    GND
    VCC    +5V
    SDA    pin A4
    SCL    pin A5

ÉCRAN OLED 128×64 I²C
    RÉFÉRENCE AliExpress
    http://fr.aliexpress.com/item/1Pcs-Yellow-blue-double-color-128X64-OLED-LCD-LED-Display-Module-For-Arduino-0-96/32305641669.html

    ADRESSE I²C
    0x3C

    LIBRAIRIE Adafruit
    https://github.com/adafruit/Adafruit_SSD1306.git

    CONNEXIONS
    GND    GND
    VDD    +5V
    SCK    pin A5
    SDA    pin A4

PULLUPS I²C
    4.7 kΩ

MICROCONTRÔLEUR
    Clone Arduino Nano

juin 2016, ouilogique.com

*/

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <math.h>
#include "RTClib.h"
RTC_DS1307 RTC = RTC_DS1307();
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4
Adafruit_SSD1306 display( OLED_RESET );
#if( SSD1306_LCDHEIGHT != 64 )
#error( "Height incorrect, please fix Adafruit_SSD1306.h!" );
#endif

#define avecSerial false

// Modifier ici l’heure d’attention maximum.
// Par exemple, si 7 h 15 est une heure d’attention maximum :
// heureAttentionMax = 7 h 15
// heureAttentionMax = MOD( 7*3600 + 15*60, 5400 )
// heureAttentionMax = 4500 s
// (5400 est le nombre de secondes dans 1 h 30)
const long heureAttentionMax = 4500;
const byte displayWidth = 128;
static const unsigned char cosinus_cmap[ displayWidth ] PROGMEM =
{
  63, 63, 63, 63, 63, 62, 62, 62,
  62, 62, 62, 61, 61, 61, 61, 60,
  60, 60, 59, 59, 58, 58, 57, 57,
  56, 56, 55, 55, 54, 54, 53, 53,
  52, 52, 51, 51, 50, 50, 49, 49,
  48, 48, 47, 47, 46, 46, 45, 45,
  45, 44, 44, 44, 44, 43, 43, 43,
  43, 43, 43, 42, 42, 42, 42, 42,
  42, 42, 42, 42, 42, 43, 43, 43,
  43, 43, 43, 44, 44, 44, 44, 45,
  45, 45, 46, 46, 47, 47, 48, 48,
  49, 49, 50, 50, 51, 51, 52, 52,
  53, 53, 54, 54, 55, 55, 56, 56,
  57, 57, 58, 58, 59, 59, 60, 60,
  60, 61, 61, 61, 61, 62, 62, 62,
  62, 62, 62, 63, 63, 63, 63, 63
};

void prepareCourbeCycle( int16_t frac16eJourPx )
{
  unsigned char py;
  // Partie de la courbe avec remplissage
  for( int16_t px=0; px<=frac16eJourPx; px++ )
  {
    py = pgm_read_byte( &cosinus_cmap[ px ] );
    display.drawLine( px, display.height()-1, px, py, WHITE );
  }
  // Partie de la courbe sans remplissage
  for( int16_t px=frac16eJourPx+1; px<displayWidth; px++ )
  {
    py = pgm_read_byte( &cosinus_cmap[ px ] );
    display.drawPixel( px, py, WHITE );
  }
}

#if avecSerial
void serialEvent()
{
  // Cette procédure permet de régler l’heure de l’horloge
  // via le bus RS232.
  // Exemple de commande à envoyer :
  // 2016,6,8,9,36,30

  const byte nbCharMax = 19;
  char str[ nbCharMax ] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };

  // Lecture de la nouvelle heure sur le port série
  byte compteur = 0;
  while( Serial.available() && compteur <= nbCharMax )
  {
    char inChar = ( char )Serial.read();
    if( inChar == '\n' ) break;
    str[ compteur++ ] = inChar;
  }

  // Séparation des éléments
  const char sep[ 2 ] = ",";
  char *token;
  int dateHeureInt[ 6 ];
  compteur = 0;
  // Trouve le premier séparateur
  token = strtok( str, sep );
  dateHeureInt[ 0 ] = atoi( token );
  // Trouve les autres séparateurs
  while( token != NULL )
  {
    token = strtok( NULL, sep );
    dateHeureInt[ ++compteur ] = atoi( token );
  }

  // Réglage de l’horloge et affichage de la nouvelle heure
  RTC.adjust( DateTime(
    dateHeureInt[ 0 ],
    dateHeureInt[ 1 ],
    dateHeureInt[ 2 ],
    dateHeureInt[ 3 ],
    dateHeureInt[ 4 ],
    dateHeureInt[ 5 ] ) );
  DateTime now = RTC.now();
  char nowChar[ 19 ];
  sprintf(
    nowChar,
    "Heure actuelle : %1d-%02d-%02d %02d:%02d:%02d",
    now.year(), now.month(),  now.day(),
    now.hour(), now.minute(), now.second() );
  Serial.println( nowChar );
}
#endif

void setup()
{
  #if avecSerial
  // Initalisation de la communication série pour régler l’heure
  Serial.begin( 115200 );
  #endif

  // Initialisation de l’horloge
  RTC.begin();

  // Initialisation de l’écran
  display.begin( SSD1306_SWITCHCAPVCC, 0x3C );
  display.clearDisplay();
  display.setTextColor( WHITE );
}

void loop()
{

  // ****
  // Calculs du pourcentage du cycle d’attention (cycleAtt)
  // et du temps équivalent en 1/16e de jour exprimé en pixels (frac16eJourPx)
  // **

  // lecture de l’heure actuelle
  DateTime now = RTC.now();

  // Calcul du temps équivalent en 1/16e de jour
  // NB : - Il y a 16 cycles d’1 h 30 dans 24 h
  //      - 1 h 30 = 5400 s
  long frac16eJour = ( now.secondstime() - heureAttentionMax ) % 5400;

  // Calcul du pourcentage du cycle d’attention
  // 2 * π * 16 / 86400 = 0.0011635528
  double cycleAtt = 100.0 * 0.5 * ( 1.0 + cos( ( double )( frac16eJour ) * 0.0011635528 ) );

  // Conversion de “frac16eJour” en pixels.
  // Le cosinus est affiché avec un déphasage d’une demi-période, donc
  // les valeurs de la 1ère moitié du cycle correspondent à la partie droite du cosinus et
  // les valeurs de la 2e moitié du cycle correspondent à la partie gauche du cosinus.
  // Le code ci-dessous permute les deux moitiés pour qu’elles s’affichent du bon côté.
  int16_t frac16eJourPx;
  if( frac16eJour < 5400/2 )
    { frac16eJourPx = map( frac16eJour,
                              0,              5400/2-1,
                              displayWidth/2, displayWidth-1 ); }
  else
    { frac16eJourPx = map( frac16eJour,
                              5400/2,         5400-1,
                              0,              displayWidth/2-1 ); }

  // ****
  //  Affichage des résultats
  // **

  // Effacement de l’écran
  display.clearDisplay();

  // Préparation de l’affichage de la date
  display.setTextSize( 1 );
  display.setCursor( 0, 0 );
  display.print( now.day() );
  display.print( " " );
  switch( now.month() )
  {
    case  1: display.print( F( "JAN"  ) ); break;
    case  2: display.print( F( "FEV"  ) ); break;
    case  3: display.print( F( "MARS" ) ); break;
    case  4: display.print( F( "AVR"  ) ); break;
    case  5: display.print( F( "MAI"  ) ); break;
    case  6: display.print( F( "JUIN" ) ); break;
    case  7: display.print( F( "JUIL" ) ); break;
    case  8: display.print( F( "AOUT" ) ); break;
    case  9: display.print( F( "SEPT" ) ); break;
    case 10: display.print( F( "OCT"  ) ); break;
    case 11: display.print( F( "NOV"  ) ); break;
    case 12: display.print( F( "DEC"  ) );
  }
  display.setCursor( 0, 9 );
  display.print( now.year() );

  // Préparation de l’affichage de l’heure et des minutes
  char texteAffichage[ 5 ];
  sprintf( texteAffichage, "%2d:%02d", now.hour(), now.minute() );
  display.setTextSize( 2 );
  display.setCursor( 49, 0 );
  display.print( texteAffichage );

  // Préparation de l’affichage des secondes
  sprintf( texteAffichage, ":%02d", now.second() );
  display.setTextSize( 1 );
  display.print( texteAffichage );

  // Préparation de l’affichage du pourcentage du cycle
  display.setTextSize( 2 );
  if( cycleAtt < 0.01 )
    { display.setCursor( 53, 21 ); display.print( cycleAtt, 0 ); }
  else if( cycleAtt < 10 )
    { display.setCursor( 34, 21 ); display.print( cycleAtt, 2 ); }
  else if( cycleAtt < 99.5 )
    { display.setCursor( 34, 21 ); display.print( cycleAtt, 1 ); }
  else
    { display.setCursor( 42, 21 ); display.print( cycleAtt, 0 ); }
  display.print( char( 37 ) ); // signe %

  // Préparation de l’affichage de la courbe du cycle
  prepareCourbeCycle( frac16eJourPx );

  // Met à jour l’affichage
  display.display();

  _delay_ms( 1000 );
}

/*

HORLOGE À CYCLES ULTRADIENS

http://ouilogique.com/horloge_cycles_ultradiens/

HORLOGE DS1307 I²C
    RÉFÉRENCE AliExpress
    http://fr.aliexpress.com/item/5pcs-lot-Tiny-RTC-I2C-AT24C32-DS1307-Real-Time-Clock-Module-Board-For-Arduino-With-A/32327865928.html

    ADRESSES I²C
    0x50 (EEPROM AT24C32)
    0x68 (DS1307)

    LIBRAIRIE Adafruit
    https://github.com/adafruit/RTClib.git

    CONNEXIONS
    GND    GND
    VCC    +5V
    SDA    pin A4
    SCL    pin A5

ÉCRAN OLED 128×64 I²C
    RÉFÉRENCE AliExpress
    http://fr.aliexpress.com/item/1Pcs-Yellow-blue-double-color-128X64-OLED-LCD-LED-Display-Module-For-Arduino-0-96/32305641669.html

    ADRESSE I²C
    0x3C

    LIBRAIRIE Adafruit
    https://github.com/adafruit/Adafruit_SSD1306.git

    CONNEXIONS
    GND    GND
    VDD    +5V
    SCK    pin A5
    SDA    pin A4

PULLUPS I²C
    4.7 kΩ

MICROCONTRÔLEUR
    Clone Arduino Nano

juin 2016, ouilogique.com

*/

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <math.h>
#include "RTClib.h"
RTC_DS1307 RTC = RTC_DS1307();
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4
Adafruit_SSD1306 display( OLED_RESET );
#if( SSD1306_LCDHEIGHT != 64 )
#error( "Height incorrect, please fix Adafruit_SSD1306.h!" );
#endif

#define avecSerial false

// “heureAttentionMax = 4500” correspond à 7 h 15,
// car   7:15 = 26100 s
// et    26100 % 5400 = 4500 s
// où 5400 est le nombre de secondes dans 1 h 30
const long heureAttentionMax = 4500;
const byte displayWidth = 128;
static const unsigned char cosinus_cmap[ displayWidth ] PROGMEM =
{
  63, 63, 63, 63, 63, 62, 62, 62,
  62, 62, 62, 61, 61, 61, 61, 60,
  60, 60, 59, 59, 58, 58, 57, 57,
  56, 56, 55, 55, 54, 54, 53, 53,
  52, 52, 51, 51, 50, 50, 49, 49,
  48, 48, 47, 47, 46, 46, 45, 45,
  45, 44, 44, 44, 44, 43, 43, 43,
  43, 43, 43, 42, 42, 42, 42, 42,
  42, 42, 42, 42, 42, 43, 43, 43,
  43, 43, 43, 44, 44, 44, 44, 45,
  45, 45, 46, 46, 47, 47, 48, 48,
  49, 49, 50, 50, 51, 51, 52, 52,
  53, 53, 54, 54, 55, 55, 56, 56,
  57, 57, 58, 58, 59, 59, 60, 60,
  60, 61, 61, 61, 61, 62, 62, 62,
  62, 62, 62, 63, 63, 63, 63, 63
};

void prepareCourbeCycle( int16_t frac16eJourPx )
{
  unsigned char py;
  // Partie de la courbe avec remplissage
  for( int16_t px=0; px<=frac16eJourPx; px++ )
  {
    py = pgm_read_byte( &cosinus_cmap[ px ] );
    display.drawLine( px, display.height()-1, px, py, WHITE );
  }
  // Partie de la courbe sans remplissage
  for( int16_t px=frac16eJourPx+1; px<displayWidth; px++ )
  {
    py = pgm_read_byte( &cosinus_cmap[ px ] );
    display.drawPixel( px, py, WHITE );
  }
}

#if avecSerial
void serialEvent()
{
  // Cette procédure permet de régler l’heure de l’horloge
  // via le bus RS232.
  // Exemple de commande à envoyer :
  // 2016,6,7,21,00,30

  const byte nbCharMax = 19;
  char str[ nbCharMax ] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };

  // Lecture de la nouvelle heure sur le port série
  byte compteur = 0;
  while( Serial.available() && compteur <= nbCharMax )
  {
    char inChar = ( char )Serial.read();
    if( inChar == '\n' ) break;
    str[ compteur++ ] = inChar;
  }

  // Séparation des éléments
  const char sep[ 2 ] = ",";
  char *token;
  int dateHeureInt[ 6 ];
  compteur = 0;
  // Trouve le premier séparateur
  token = strtok( str, sep );
  dateHeureInt[ 0 ] = atoi( token );
  // Trouve les autres séparateurs
  while( token != NULL )
  {
    token = strtok( NULL, sep );
    dateHeureInt[ ++compteur ] = atoi( token );
  }

  // Réglage de l’horloge et affichage de la nouvelle heure
  RTC.adjust( DateTime(
    dateHeureInt[ 0 ],
    dateHeureInt[ 1 ],
    dateHeureInt[ 2 ],
    dateHeureInt[ 3 ],
    dateHeureInt[ 4 ],
    dateHeureInt[ 5 ] ) );
  DateTime now = RTC.now();
  char nowChar[ 19 ];
  sprintf(
    nowChar,
    "Heure actuelle : %1d-%02d-%02d %02d:%02d:%02d",
    now.year(), now.month(),  now.day(),
    now.hour(), now.minute(), now.second() );
  Serial.println( nowChar );
}
#endif

void setup()
{
  #if avecSerial
  // Initalisation de la communication série pour régler l’heure
  Serial.begin( 115200 );
  #endif

  // Initialisation de l’horloge
  RTC.begin();

  // Initialisation de l’écran
  display.begin( SSD1306_SWITCHCAPVCC, 0x3C );
  display.clearDisplay();
  display.setTextColor( WHITE );
}

void loop()
{

  // ****
  // Calculs du pourcentage du cycle d’attention (cycle)
  // et du temps équivalent en 1/16e de jour exprimé en pixels (frac16eJourPx)
  // **

  // lecture de l’heure actuelle
  DateTime now = RTC.now();

  // Calcul du temps équivalent en 1/16e de jour
  // NB : - Il y a 16 cycles d’1 h 30 dans 24 h
  //      - 1 h 30 = 5400 s
  long frac16eJour = ( now.secondstime() - heureAttentionMax ) % 5400;

  // Calcul du pourcentage du cycle d’attention
  // 2 * π * 16 / 86400 = 0.0011635528
  double cycle = 100.0 * 0.5 * ( 1.0 + cos( ( double )( frac16eJour ) * 0.0011635528 ) );

  // Conversion de “frac16eJour” en pixels
  // Les valeurs de la 1ère moitié du cycle correspondent à la partie droite du cosinus.
  // Les valeurs de la 2e moitié du cycle correspondent à la partie gauche du cosinus.
  // Le code ci-dessous permute les deux moitiés pour qu’elles s’affichent du bon côté.
  int16_t frac16eJourPx;
  if( frac16eJour < 5400/2 )
    { frac16eJourPx = map( frac16eJour,
                              0,              5400/2-1,
                              displayWidth/2, displayWidth-1 ); }
  else
    { frac16eJourPx = map( frac16eJour,
                              5400/2,         5400-1,
                              0,              displayWidth/2-1 ); }

  // ****
  //  Affichage des résultats
  // **

  // Effacement de l’écran
  display.clearDisplay();

  // Préparation de l’affichage de la date
  display.setTextSize( 1 );
  display.setCursor( 0, 0 );
  display.print( now.day() );
  display.print( " " );
  switch( now.month() )
  {
    case  1: display.print( F( "JAN"  ) ); break;
    case  2: display.print( F( "FEV"  ) ); break;
    case  3: display.print( F( "MARS" ) ); break;
    case  4: display.print( F( "AVR"  ) ); break;
    case  5: display.print( F( "MAI"  ) ); break;
    case  6: display.print( F( "JUIN" ) ); break;
    case  7: display.print( F( "JUIL" ) ); break;
    case  8: display.print( F( "AOUT" ) ); break;
    case  9: display.print( F( "SEPT" ) ); break;
    case 10: display.print( F( "OCT"  ) ); break;
    case 11: display.print( F( "NOV"  ) ); break;
    case 12: display.print( F( "DEC"  ) );
  }
  display.setCursor( 0, 9 );
  display.print( now.year() );

  // Préparation de l’affichage de l’heure et des minutes
  char texteAffichage[ 5 ];
  sprintf( texteAffichage, "%2d:%02d", now.hour(), now.minute() );
  display.setTextSize( 2 );
  display.setCursor( 49, 0 );
  display.print( texteAffichage );

  // Préparation de l’affichage des secondes
  sprintf( texteAffichage, ":%02d", now.second() );
  display.setTextSize( 1 );
  display.print( texteAffichage );

  // Préparation de l’affichage du pourcentage du cycle
  display.setTextSize( 2 );
  if( cycle < 10 )
    { display.setCursor( 34, 21 ); display.print( cycle, 2 ); }
  else if( cycle < 99.5 )
    { display.setCursor( 34, 21 ); display.print( cycle, 1 ); }
  else
    { display.setCursor( 42, 21 ); display.print( cycle, 0 ); }
  display.print( char( 37 ) ); // signe %

  // Préparation de l’affichage de la courbe du cycle
  prepareCourbeCycle( frac16eJourPx );

  // Met à jour l’affichage
  display.display();

  _delay_ms( 1000 );
}


Add script to read HX711 and load cell

Add script to read HX711 and load cell

/*
 Inspired from code HX711 demo from Nathan Seidle, SparkFun Electronics

 This example code uses bogde's excellent library: https://github.com/bogde/HX711
 bogde's library is released under a GNU GENERAL PUBLIC LICENSE

 The HX711 does one thing well: read load cells. T

 Arduino pin (Nano)
 2    -> HX711 CLK
 3    -> HX711 DAT
 3V3  -> HX711 VCC
 GND  -> HX711 GND

 5V   -> Radio VCC
 4    -> Radio GND
 RX   -> Radio TX
 TX   -> Radio RX

 The HX711 board can be powered from 2.7V to 5V so the Arduino 5V power should be fine.

*/

#include "HX711.h"

#define calibration_factor -7050.0 //This value is obtained using the SparkFun_HX711_Calibration sketch

#define DOUT  3
#define CLK  2
#define GND  4

HX711 scale(DOUT, CLK);

void setup() {
  pinMode(GND, OUTPUT);
  Serial.begin(57600);
  Serial.println("HX711 scale demo");

  // Result of calibration
  scale.set_offset(8177300);
  scale.set_scale(-146.7); //Read the raw value

  Serial.println("Readings:");
}

void loop() {
  digitalWrite(GND, LOW);
  Serial.print("Reading: ");
  Serial.print(scale.read_average(), 1); //raw value
  Serial.print(" ");
  Serial.print(scale.get_units(), 1); //scaled and offset after calibration
  Serial.print(" g");
  Serial.println();
}

error: pathspec 'Arduino/HX711_LoadCell/HX711_LoadCell.ino' did not match any file(s) known to git


added IR calibration, smoothing and left/right/Tjunction discrimination

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/manashmndl/bluebrain.git/'


Final code which we used.

Final code which we used.

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/Valay/ArduinoGesture.git/'


_06_kidSerie_sketch_02.Adafruit_fake_feeds.ino - #kidSerie-06

_06_kidSerie_sketch_02.Adafruit_fake_feeds.ino - #kidSerie-06

/*
  Project name:
     05 #kidSerie - Adafruit-IO Meets ESP8266, Arduino & MIT App Inventor 2
     (Awesome Smart Phone App!)
     Flavour III -
     Hex File: _06_kidSerie_sketch_02.Adafruit_fake_feeds.ino
   Revision History:
     20161029:
       - from github adafruit/Adafruit_MQTT_Library
  https://github.com/adafruit/Adafruit_MQTT_Library/blob/master/examples/mqtt_esp8266/mqtt_esp8266.ino
  https://learn.adafruit.com/mqtt-adafruit-io-and-you/intro-to-adafruit-mqtt
   Description:
     How to teach young people how to take advantage of already tested codes and create a new one from them.
     I decided to face a new challenge. This code is the second one and joining the first one we will communicate with
     the Adafruit-io Broker to send temperature and humidity data via MQTT Protocol.
   MCU:                  Arduino 1.6.12 - @16MHz       http://www.arduino.cc/
   ESP8266:              ESP-01                        https://goo.gl/E0Eq4l
   DHT11:                PRODUCT ID: 386               https://www.adafruit.com/product/386
   Connections:
      See Official youtube channel vids: https://youtu.be/cwYix_Oyui4
   Based on:   Tony DiCola for Adafruit Industries - see below!
   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License v3 as published by
   the Free Software Foundation
*/
/***************************************************
  Adafruit MQTT Library ESP8266 Example
  Must use ESP8266 Arduino from:
    https://github.com/esp8266/Arduino
  Works great with Adafruit's Huzzah ESP board & Feather
  ----> https://www.adafruit.com/product/2471
  ----> https://www.adafruit.com/products/2821
  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing
  products from Adafruit!
  Written by Tony DiCola for Adafruit Industries.
  MIT license, all text above must be included in any redistribution
 ****************************************************/
 /******************************* Adafruit MQTT *******************************/

#include "Adafruit_MQTT.h"
#include "Adafruit_MQTT_Client.h"

/******************************* Esp8266**************************************/

#include <ESP8266WiFi.h>

/************************* WiFi Access Point *********************************/

#define WLAN_SSID       "...your SSID..."
#define WLAN_PASS       "...your password..."

/************************* Adafruit.io Setup *********************************/

#define AIO_SERVER      "io.adafruit.com"
#define AIO_SERVERPORT  1883                   // use 8883 for SSL
#define AIO_USERNAME    "...your AIO username (see https://accounts.adafruit.com)..."
#define AIO_KEY         "...your AIO key..."

/************ Global State (you don't need to change this!) ******************/

// Create an ESP8266 WiFiClient class to connect to the MQTT server.
WiFiClient client;
// or... use WiFiFlientSecure for SSL
//WiFiClientSecure client;

// Setup the MQTT client class by passing in the WiFi client and MQTT server and login details.
Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_KEY);

/****************************** Feeds ***************************************/
/****************************** Topics ***************************************/
// Setup a feed called 'photocell' for publishing.
// Notice MQTT paths for AIO follow the form: <username>/feeds/<feedname>
Adafruit_MQTT_Publish photocell = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/photocell");
/****************************** Subscriptions*********************************/
// Setup a feed called 'photocell' for subscribing to changes.
Adafruit_MQTT_Subscribe photocell_subsc = Adafruit_MQTT_Subscribe(&mqtt, AIO_USERNAME "/feeds/photocell");

/***************************  MQTT Conn   ************************************/

// Bug workaround for Arduino 1.6.6, it seems to need a function declaration
// for some reason (only affects ESP8266, likely an arduino-builder bug).
void MQTT_connect();

/****************************** Setup  ***************************************/
void setup() {
  Serial.begin(115200);
  delay(10);

  Serial.println(F("Adafruit MQTT demo"));

  // Connect to WiFi access point.
  Serial.println(); Serial.println();
  Serial.print("Connecting to ");
  Serial.println(WLAN_SSID);

  WiFi.begin(WLAN_SSID, WLAN_PASS);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println();

  Serial.println("WiFi connected");
  Serial.println("IP address: "); Serial.println(WiFi.localIP());

  // Setup MQTT subscription for onoff feed.
  mqtt.subscribe(&photocell_subsc);
}

uint32_t x=0;    // Mock data

/****************************** Loop  ***************************************/
void loop() {
  // Ensure the connection to the MQTT server is alive (this will make the first
  // connection and automatically reconnect when disconnected).  See the MQTT_connect
  // function definition further below.
  MQTT_connect();

  // this is our 'wait for incoming subscription packets' busy subloop
  // try to spend your time here

 /****************************** Subscript  ***********************************/
 Adafruit_MQTT_Subscribe *subscription;
  while ((subscription = mqtt.readSubscription(5000))) {
    if (subscription == &photocell_subsc) {
      Serial.print(F("Got: "));
      Serial.println((char *)photocell_subsc.lastread);
    }
  }
 /****************************** Publish  **********************************/
   // Now we can publish stuff!
  Serial.print(F("\nSending photocell val "));
  Serial.print(x);
  Serial.print("...");
  if (! photocell.publish(x++)) {
    Serial.println(F("Failed"));
  } else {
    Serial.println(F("OK!"));
  }
/****************************** Ping  ***************************************/

  // ping the server to keep the mqtt connection alive
  // NOT required if you are publishing once every KEEPALIVE seconds
  /*
  if(! mqtt.ping()) {
    mqtt.disconnect();
  }
  */
}
/********************************* MQTT Conn  ********************************/
// Function to connect and reconnect as necessary to the MQTT server.
// Should be called in the loop function and it will take care if connecting.
void MQTT_connect() {
  int8_t ret;

  // Stop if already connected.
  if (mqtt.connected()) {
    return;
  }

  Serial.print("Connecting to MQTT... ");

  uint8_t retries = 3;
  while ((ret = mqtt.connect()) != 0) { // connect will return 0 for connected
       Serial.println(mqtt.connectErrorString(ret));
       Serial.println("Retrying MQTT connection in 5 seconds...");
       mqtt.disconnect();
       delay(5000);  // wait 5 seconds
       retries--;
       if (retries == 0) {
         // basically die and wait for WDT to reset me
         while (1);
       }
  }
  Serial.println("MQTT Connected!");
}

error: pathspec '_06_kidSerie_sketch_02.Adafruit_fake_feeds.ino' did not match any file(s) known to git


go faster

go faster

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/wsnook/farm.git/'


Add framework and convenience functions for gear puzzle

// hard-coded pins
int gear_connections[3][12] = {{ 2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13},
                               {14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25},
                               {26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37}};

int output_lights[7] = {38, 39, 40, 41, 42, 43, 44};

int gear_lodged[3] = {45, 46, 47};

int pot = A0;

// TODO(bhomberg): calculate these numbers for real once mechanism is built; this is approx
int pot_locs[8] = {100, 200, 300, 400, 500, 600, 700, 800};

// TODO(benkraft): add any state variables you need

// this runs once when the program starts
void setup()
{
  Serial.begin(9600);

  // init all gear connections as inputs
  for(int i=0; i<3; i++)
  {
    for(int j=0; j<12; j++)
    {
      pinMode(gear_connections[i][j], INPUT);
    }
  }

  // init all output lights as outputs which are off
  for(int i=0; i<7; i++)
  {
    pinMode(output_lights[i], OUTPUT);
    digitalWrite(output_lights[i], LOW);
  }

  // init all outputs for gear being lodged correctly
  for(int i=0; i<3; i++)
  {
    pinMode(gear_lodged[i], OUTPUT);
    digitalWrite(gear_lodged[i], LOW);
  }
}

// this is run continuously after setup has completed
void loop()
{
  delay(50);
  // print out position of the pot
  Serial.print(getSelectorGearPosition());
  Serial.print("  ");
  Serial.println(getConnection(gear_connections[0][0], gear_connections[0][1]));

  // TODO(benkraft)
  // this should probably be a state machine since the loop function loops
  // every cycle -- check if gears are removed, if so, reset (check by making sure gear orientations/types are the same)
  // first state -- gear insertion
  // some kind of check that all gears are good
  // second state -- move through selector gear connections
  // verify which ones should be connections
  // if connection is good, turn on specific light/solenoid for feedback
  // if all 7 connections were good, send message for success
  // if you need to send any other messages back to the castle, lemme know

}

void sendCastleSuccessMessage()
{
  // 20's -- 2nd puzzle message
  // -0   -- first message from this puzzle
  Serial.println(20);
}

void sendCastleErrorMessage()
{
  Serial.println(21);
}

// TODO(benkraft): change return signature to however you want to represent gears
// returns which gear type is inserted + the orientation of the gear
void getOrientationAndTypeForGear(int gear_num)
{
  // so the basic idea here is that each gear is attached in 12 places
  // a pair of them will be connected
  // on gear A, they're consecutive
  // on gear B, they're 1 away
  // on gear C, they're 2 away
  // since they're flip symmetric(yay!) this will uniquely identify each gear + its orientation

  // example: check whether slots 0 and 1 are connected on gear #0
  getConnection(gear_connections[0][0], gear_connections[0][1]);
}

// all pins are tied to ground with a 12kOhm resistor
// we drive one of the pins high (changing its impedance mode) and read the other pin
// if high, we're connected, if low, not connected
// pins on separate gears will never be connected
// returns true if the pins are connected
// side effects: briefly turns pin1 high, but returns it to input mode after
boolean getConnection(int pin1, int pin2)
{
  pinMode(pin1, OUTPUT);
  digitalWrite(pin1, HIGH);

  boolean rtrn = false;
  if (digitalRead(pin2)) {
    rtrn = true;
  }
  delay(2000);

  digitalWrite(pin1, LOW);
  pinMode(pin1, INPUT);

  return rtrn;
}

// based on the pot value, we know which of the 7 positions the selector gear is in
// returns an int 0-6 inclusive or -1 in error cases
// if the pot value is out of range, throws an error and informs the castle operators that the puzzle is broken
// the position of the selector gear uniquely determines the position of all of the other gears
int getSelectorGearPosition()
{
  int val = analogRead(pot);

  for (int i=0; i<7; i++)
  {
    if (val > pot_locs[i] && val < pot_locs[i+1])
    {
      return i;
    }
  }

  // else: val is below pot_locs[0] or greater than pot_locs[7]
  // puzzle is borken
  sendCastleErrorMessage();
  return -1;
}

// turn on light / open solenoid for selector connection #n
void showCorrect(int n)
{
  // turn on light
  digitalWrite(output_lights[n], HIGH);

  // TODO(bhomberg): open solenoid??
}

// gears have been taken out / selector gear goes back to beginning, reset everything
void reset()
{
  // TODO(benkraft): clear all known gears

  // turn off all lights
  for(int i=0; i<7; i++)
  {
    digitalWrite(output_lights[i], LOW);
  }
  for(int i=0; i<3; i++)
  {
    digitalWrite(gear_lodged[i], LOW);
  }

  // TODO(bhomberg): close all solenoids (??)
}

error: pathspec 'crypt-gears/gear_arduino/gear_arduino.ino' did not match any file(s) known to git


Add webclient examples

Add webclient examples

#include <SPI.h>
#include <Ethernet.h>

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
char server[] = "192.168.3.12";

// Set the static IP address to use if the DHCP fails to assign
IPAddress ip(192,168,3,200);

// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

  // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    // try to congifure using IP address instead of DHCP:
    Ethernet.begin(mac, ip);
  }
  // give the Ethernet shield a second to initialize:
  delay(1000);
  Serial.println("connecting...");

  // if you get a connection, report back via serial:
  if (client.connect(server, 3000)) {
    Serial.println("connected");
    // Make a HTTP request:
    client.println("GET /api/1 HTTP/1.1");
    client.println("Host: 192.168.3.12");
    client.println("Connection: close");
    client.println();
  }
  else {
    Serial.println("connection failed");
  }
}

void loop()
{
  // if there are incoming bytes available
  // from the server, read them and print them:
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }

  // if the server's disconnected, stop the client:
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();

    // do nothing forevermore:
    while (true);
  }
}

error: pathspec 'chapter5/WebClient/WebClient.ino' did not match any file(s) known to git


add arduino program

add arduino program

/***************************************************
 * This is an example for the DFRobot Wido - Wifi Integrated IoT lite sensor and control node
 * Product Page & More info: http://www.dfrobot.com.cn/goods-997.html
 * Designed specifically to work with the DFRobot Wido products:
 *
 * The library is forked from Adafruit
 *
 * Written by Lauren
 * BSD license, all text above must be included in any redistribution
 *
 ****************************************************/

/*
This example code is used to connect the Yeelink cloud service (Official homepage: www.yeelink.net).

 The device required is just:

 1. LM35 low cost temperature sensor or any device you used to upload data
 2. And Wido

Note: Please don't forget to change the setting below before using!
 1. WLAN_SSID & WlAN_PASS
 2. API_key
 3. device ID & sensor ID

 */

#include <Adafruit_CC3000.h>
#include <ccspi.h>
#include <SPI.h>
#define Wido_IRQ   3
#define Wido_VBAT  5
#define Wido_CS    10

Adafruit_CC3000 Wido = Adafruit_CC3000(Wido_CS, Wido_IRQ, Wido_VBAT,
                                       SPI_CLOCK_DIVIDER); // you can change this clock speed

// Security can be WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2
#define WLAN_SECURITY   WLAN_SEC_WPA2

#define WLAN_SSID       "242"           // cannot be longer than 32 characters!
#define WLAN_PASS       "4659875admin"          // For connecting router or AP, don't forget to set the SSID and password here!!

#define DEVICE_ID       "561083be06dd6162658ae8c8"  //arduiview device id

#define TCP_TIMEOUT      3000
//#define CC3000_TINY_DRIVER

#define WEBSITE  "arduiview.herokuapp.com"

void setup() {

  Serial.begin(115200);
  Serial.println(F("Hello, CC3000!\n"));

  /* Initialise the module */
  Serial.println(F("\nInitialising the CC3000 ..."));
  if (!Wido.begin())
  {
    Serial.println(F("Unable to initialise the CC3000! Check your wiring?"));
    while (1);
  }

  /* Attempt to connect to an access point */
  char *ssid = WLAN_SSID;             /* Max 32 chars */
  Serial.print(F("\nAttempting to connect to "));
  Serial.println(ssid);

  /* NOTE: Secure connections are not available in 'Tiny' mode!
   By default connectToAP will retry indefinitely, however you can pass an
   optional maximum number of retries (greater than zero) as the fourth parameter.
   */
  if (!Wido.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) {
    Serial.println(F("Failed!"));
    while (1);
  }

  Serial.println(F("Connected!"));

  /* Wait for DHCP to complete */
  Serial.println(F("Request DHCP"));
  while (!Wido.checkDHCP())
  {
    delay(1000); // ToDo: Insert a DHCP timeout!
  }

}

uint32_t ip = 0;
float temp = 0;

void loop() {

  static Adafruit_CC3000_Client WidoClient;
  static unsigned long RetryMillis = 0;
  static unsigned long uploadtStamp = 0;
  static unsigned long sensortStamp = 0;

  if (!WidoClient.connected() && millis() - RetryMillis > TCP_TIMEOUT) {
    // Update the time stamp
    RetryMillis = millis();

    Serial.println(F("Try to connect the cloud server"));
    WidoClient.close();

    // Get cloud server IP address
    Serial.print(WEBSITE);
    while  (ip  ==  0)  {
      if  (!Wido.getHostByName(WEBSITE, &ip))  {    //  Get the server IP address based on the domain name
        Serial.println(F("Couldn't resolve!"));
      }
      delay(500);
    }
    Wido.printIPdotsRev(ip);
    Serial.println(F(""));

    // Connect to the aruduiview Server
    WidoClient = Wido.connectTCP(ip, 80);          // Try to connect cloud server
  }

  if (WidoClient.connected() && millis() - uploadtStamp > 2000) {
    uploadtStamp = millis();
    // If the device is connected to the cloud server, upload the data every 2000ms.

    // Prepare Http Package for Yeelink & get length
    int length = 0;
    char lengthstr[3];

    // Create Http data package
    char httpPackage[] = "";

    strcat(httpPackage , "{\"values\":[");
    strcat(httpPackage , "{\"timestamp\" : ");
    //convert long to char array
    char sTimeStamp[] = "";
    sprintf(sTimeStamp,"%d",uploadtStamp);
    strcat(httpPackage , sTimeStamp);
    strcat(httpPackage , ",");
    strcat(httpPackage , "\"temperature\" : ");
    char sTemp[] = "";
    printf(sTemp,"%f",temp);
    strcat(httpPackage , sTemp);    // push the data(temp) to the http data package
    strcat(httpPackage , "}");
    strcat(httpPackage , "]}");

    length = strlen(httpPackage);                           // get the length of data package
    itoa(length, lengthstr, 10);                            // convert int to char array for posting
    Serial.print(F("Length = "));
    Serial.println(length);

    Serial.println(F("Connected to arduiview server."));

    // Send headers
    Serial.print(F("Sending headers"));

    WidoClient.fastrprint(F("PUT /api/sensors/"));
    char *deviceId = DEVICE_ID;
    WidoClient.fastrprint(deviceId);
    WidoClient.fastrprint(F("/values"));

    //Please change your device ID and sensor ID here, after creating
    //Please check the link: http://www.yeelink.net/user/devices
    //The example URL: http://api.yeelink.net/v1.1/device/100/sensor/20/datapoints
    WidoClient.fastrprintln(F(" HTTP/1.1"));
    Serial.print(F("."));

    WidoClient.fastrprintln(F("Host: arduiview.herokuapp.com"));
    Serial.print(F("."));

    WidoClient.fastrprint(F("content-type: "));
    WidoClient.fastrprintln("application/json");
    Serial.print(F("."));

    WidoClient.fastrprint("Content-Length: ");
    WidoClient.fastrprintln(lengthstr);
    WidoClient.fastrprintln("");
    Serial.print(F("."));

    Serial.println(F(" done."));

    // Send data
    Serial.print(F("Sending data"));

    //char payload[600] = "";
    //strcat(payload,httpPackage);
    WidoClient.fastrprintln(httpPackage);

    Serial.println(F("-----"));
    Serial.println(httpPackage);
    Serial.println(F("-----"));

    Serial.println(F(" done."));

    /********** Get the http page feedback ***********/

    unsigned long rTimer = millis();
    Serial.println(F("Reading Cloud Response!!!\r\n"));
    while (millis() - rTimer < 2000) {
      while (WidoClient.connected() && WidoClient.available()) {
        char c = WidoClient.read();
        Serial.print(c);
      }
    }
    delay(1000);             // Wait for 1s to finish posting the data stream
    WidoClient.close();      // Close the service connection

    RetryMillis = millis();  // Reset the timer stamp for applying the connection with the service
  }

  if (millis() - sensortStamp > 100) {
    sensortStamp = millis();
    // read the LM35 sensor value and convert to the degrees every 100ms.

    int reading = analogRead(0);
    temp = reading * 0.0048828125 * 100;
    Serial.print(F("Real Time Temp: "));
    Serial.println(temp);
  }
}

error: pathspec 'arduino/arduibiew-lm35/arduibiew-lm35.ino' did not match any file(s) known to git


arduino code added

arduino code added

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/adilsonchacon/web-ecg.git/'


Added example to read force sensitive resistor.

/* FSR testing sketch.

Connect one end of FSR to 5V, the other end to Analog 0.
Then connect one end of a 10K resistor from Analog 0 to ground
Connect LED from pin 11 through a resistor to ground

For more information see www.ladyada.net/learn/sensors/fsr.html */

#define fsrAnalogPin 0 // FSR is connected to analog 0
int fsrReading;      // the analog reading from the FSR resistor divider

void setup(void) {
  Serial.begin(9600);   // We'll send debugging information via the Serial monitor
}

void loop(void) {
  fsrReading = analogRead(fsrAnalogPin);
  Serial.print("Analog reading = ");
  Serial.println(fsrReading);

  delay(100);
}

error: pathspec 'examples/fsr_analog_read/fsr_analog_read.ino' did not match any file(s) known to git


added firmware for the temperature prototype

#include <ComputerSerial.h>

ComputerSerial comp;

void* analogTemp(byte flag, byte content[], byte contentSize){
	int *status = (int*)malloc(sizeof(int));
	*status = analogRead(flag < 2 ? flag : 0);
	return status;
}

static unsigned long bytes = 0;
void setup(){
	comp.begin(9600);
	comp.attachFunction(comp.OPCODE_SENSOR, &analogTemp);
}

void loop(){

}

void serialEvent(){
	bytes += Serial.available();

	comp.serialEvent();
}

error: pathspec 'arduino/TempProto/TempProto.ino' did not match any file(s) known to git


trackballPro.ino

trackballPro.ino

Converts a Busmouse version of the CH Products Trackball Pro to USB HID.

error: pathspec 'trackballPro.ino' did not match any file(s) known to git


Created an analog reader that implements a moving average smoothing and change detection

const int potPin = A0;
const int BAUD_RATE = 9600;

// Array variables for tracking a window of potentiometer values
//  We want to hold on to the last NUM_SAMPLES values and perform
//  an average on them to arrive at a 'current' value - this
//  is called a moving average: http://en.wikipedia.org/wiki/Moving_average
const int NUM_SAMPLES = 10;
int potSamples[NUM_SAMPLES];
int potIndex = 0;
int totalPotValue = 0;

// Change detection variables
//  Even with the averaging, our pot value will likely still flip between
//  neighboring values, so this changeThreshold is used in order to only
//  update the pot value sent out from the arduino if the pot value
//  has changed by a specified amount
int lastAveragePotValue = 0;
int changeThreshold = 2;

void setup()
{
  Serial.begin(BAUD_RATE);

  // Fill the array of samples with zeros
  for (int i=0; i<NUM_SAMPLES; i++) potSamples[i] = 0;
}

void loop()
{
  // potSamples[potIndex] is the oldest data in the array
  // We are about to override it with a new value, but first
  // we need to subtract it from our running total of pot values
  totalPotValue -= potSamples[potIndex];

  // Get the current pot value
  int currentPotValue = analogRead(potPin);

  // Update our running total and add the new value to the array
  totalPotValue += currentPotValue;
  potSamples[potIndex] = currentPotValue;

  // Increment our index
  potIndex++;
  if (potIndex>NUM_SAMPLES-1) potIndex = 0;

  // Calculate the average pot value
  int averagePotValue = totalPotValue / NUM_SAMPLES;

  // Detect whether the new average pot value has changed enough
  // from our last saved average pot value
  if (abs(averagePotValue-lastAveragePotValue)>=changeThreshold){
    lastAveragePotValue = averagePotValue;
  }

  // Output the last saved average pot value
  // i.e. the last one that exceeeded the change threshold
  Serial.println(lastAveragePotValue);

  // Delay
  delay(50);
}

error: pathspec 'people/mikewesthad/Week5/Arduino/AnalogReadWithSmoothing/AnalogReadWithSmoothing.ino' did not match any file(s) known to git


Create bananaphone.ino

Create bananaphone.ino

#include "TinyGPS.h"
#include <Wire.h>
#include <IntersemaBaro.h>
#define compass 0x1E
#include <SoftwareSerial.h>
SoftwareSerial nss(6, 255);            // Yellow wire to pin 6
SoftwareSerial phone (7,8);
unsigned char buff[512]; /* buffer */
int index=0;
Intersema::BaroPressure_MS5607B baro(true);
TinyGPS gps;

void setup() {

  phone.begin(19200); /* baud rate */
  nss.begin(4800);
  Serial.begin(9600);
  baro.init();
  // Set operating mode to continuous
  Wire.beginTransmission(compass);
  Wire.write(byte(0x02));
  Wire.write(byte(0x00));
  Wire.endTransmission();
  power_state();
}

void loop(){
phone_interface();

}

float get_bearing() {
  int x, y, z;

  // Initiate communications with compass
  Wire.beginTransmission(compass);
  Wire.write(byte(0x03));       // Send request to X MSB register
  Wire.endTransmission();

  Wire.requestFrom(compass, 6);    // Request 6 bytes; 2 bytes per axis
  if(Wire.available() <=6) {    // If 6 bytes available
    x = Wire.read() << 8 | Wire.read();
    z = Wire.read() << 8 | Wire.read();
    y = Wire.read() << 8 | Wire.read();

  }
   // Calculate heading when the magnetometer is level, then correct for signs of axis.
  float heading = atan2(x, y);

  // Correct for when signs are reversed.
  /*if(heading < 0)
    heading += 2*PI;

  // Convert radians to degrees for readability.
  float h_deg = heading * 180/M_PI;
  */return (heading);
}
int get_height() {
  int alt = baro.getHeightCentiMeters();
  Serial.println(alt);
  delay(400);
  return alt;
}

void phone_interface(){
phone.listen();
if (phone.available())              /* wait for data */
  {
    while(phone.available())
    {
      buff[index++]=phone.read();     /* writing data into buff*/
      if(index == 256)break;
  }
    Serial.write(buff,index);         /*tx*/
    clr_buff_arr();              /*zero buffer array and index*/
    index = 0;

  }
  if (Serial.available())            /*wait*/
    phone.write(Serial.read());       /* rx*/
}
void clr_buff_arr()
{
  for (int i=0; i<index;i++)
    { buff[i]=NULL;}                  /* clear each index */
}

void print_gps(){
  bool newdata = false;
  unsigned long start = millis();
  while (millis() - start < 5000) {  // Update every 5 seconds
    if (feedgps())
      newdata = true;
  }
  if (newdata) {
    gpsdump(gps);
  }
}

// Get and process GPS data
void gpsdump(TinyGPS &gps) {
  float flat, flon;
  unsigned long age;
  gps.f_get_position(&flat, &flon, &age);
  Serial.print(flat, 4); Serial.print(", ");
  Serial.println(flon, 4);
}

// Feed data as it becomes available
bool feedgps() {
  nss.listen();
  while (nss.available()) {
    if (gps.encode(nss.read()))
      return true;
  }
  return false;
}

void power_state()
{
  pinMode(9, OUTPUT);
  digitalWrite(9,LOW);
  delay(1000);
  digitalWrite(9,HIGH);
  delay(2000);
  digitalWrite(9,LOW);
  delay(3000);
}

error: pathspec 'bananaphone.ino' did not match any file(s) known to git


Existing example doesn't work on my DS18B20. Added working example.

// Use this include for the Web IDE:
#include "Particle-OneWire/Particle-OneWire.h"

// Use this include for Particle Dev where everything is in one directory.
// #include "Particle-OneWire.h"

// This library can be tested on the Core/Photon by running the below
// DS18x20 example from PJRC:

// OneWire DS18S20, DS18B20, DS1822 Temperature Example
//
// http://www.pjrc.com/teensy/td_libs_OneWire.html
//
// The DallasTemperature library can do all this work for you!
// http://milesburton.com/Dallas_Temperature_Control_Library

OneWire ds(D0);  // on pin D0 (a 4.7K resistor is necessary)

void setup(void) {
  Serial.begin(57600);
}

void loop(void) {
  byte i;
  byte present = 0;
  byte type_s;
  byte data[12];
  byte addr[8];
  float celsius, fahrenheit;

  if ( !ds.search(addr)) {
    Serial.println("No more addresses.");
    Serial.println();
    ds.reset_search();
    delay(250);
    return;
  }

  Serial.print("ROM =");
  for( i = 0; i < 8; i++) {
    Serial.write(' ');
    Serial.print(addr[i], HEX);
  }

  if (OneWire::crc8(addr, 7) != addr[7]) {
      Serial.println("CRC is not valid!");
      return;
  }
  Serial.println();

  // the first ROM byte indicates which chip
  switch (addr[0]) {
    case 0x10:
      Serial.println("  Chip = DS18S20");  // or old DS1820
      type_s = 1;
      break;
    case 0x28:
      Serial.println("  Chip = DS18B20");
      type_s = 0;
      break;
    case 0x22:
      Serial.println("  Chip = DS1822");
      type_s = 0;
      break;
    default:
      Serial.println("Device is not a DS18x20 family device.");
      return;
  }

  ds.reset();
  ds.select(addr);
  ds.write(0x44, 1);        // start conversion, with parasite power on at the end

  delay(1000);     // maybe 750ms is enough, maybe not
  // we might do a ds.depower() here, but the reset will take care of it.

  present = ds.reset();
  ds.select(addr);
  ds.write(0xBE);         // Read Scratchpad

  Serial.print("  Data = ");
  Serial.print(present, HEX);
  Serial.print(" ");
  for ( i = 0; i < 9; i++) {           // we need 9 bytes
    data[i] = ds.read();
    Serial.print(data[i], HEX);
    Serial.print(" ");
  }
  Serial.print(" CRC=");
  Serial.print(OneWire::crc8(data, 8), HEX);
  Serial.println();

  // Convert the data to actual temperature
  // because the result is a 16 bit signed integer, it should
  // be stored to an "int16_t" type, which is always 16 bits
  // even when compiled on a 32 bit processor.
  int16_t raw = (data[1] << 8) | data[0];
  if (type_s) {
    raw = raw << 3; // 9 bit resolution default
    if (data[7] == 0x10) {
      // "count remain" gives full 12 bit resolution
      raw = (raw & 0xFFF0) + 12 - data[6];
    }
  } else {
    byte cfg = (data[4] & 0x60);
    // at lower res, the low bits are undefined, so let's zero them
    if (cfg == 0x00) raw = raw & ~7;  // 9 bit resolution, 93.75 ms
    else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms
    else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms
    //// default is 12 bit resolution, 750 ms conversion time
  }
  celsius = (float)raw / 16.0;
  fahrenheit = celsius * 1.8 + 32.0;
  Serial.print("  Temperature = ");
  Serial.print(celsius);
  Serial.print(" Celsius, ");
  Serial.print(fahrenheit);
  Serial.println(" Fahrenheit");
}

error: pathspec 'firmware/examples/DS18x20_Temperature.ino' did not match any file(s) known to git


Create Garage_opener.ino

Create Garage_opener.ino

/*
 * from
 * http://esp8266-server.de/
 *
 * Webserver as Accesspoint for ESP8266
 *
 * Free for anyone!!!
 *
 */

#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>

String html1 = "<!DOCTYPE html>\r\n\r\n\
\r\n<meta content=\"text/html; charset=ISO-8859-1\" http-equiv=\"content-type\">\r\n\
<title>WebSchalter</title>\r\n\
<form action=\"";
// String((val)?"/1.html":"/0.html")
String html2 = "\">\r\n<input value=\"ON/OFF\" style=\"";
String html3 = " width:15em;height:13em; font-size: 24px;\" type=\"submit\">\
</form>\r\n\r\n\r\n\r\n";

ESP8266WebServer server(80);    // Server Port  hier einstellen
int val = 1;                    //Startzustand ausgeschaltet
String Temp = "";

void Ereignis_SchalteON()       // Wird ausgefuehrt wenn "http://<ip address>/1.html" aufgerufen wurde
{
  val = 0;                      // Relais Aus
  digitalWrite(0, val);         // GPIO0
  Temp = html1 + String((val) ? "/1.html" : "/0.html");
  Temp += html2 + String((val) ? "BACKGROUND-COLOR: DarkGray;" : "BACKGROUND-COLOR: Chartreuse;") + html3;
  server.send(200, "text/html", Temp);
}

void Ereignis_SchalteOFF()  // Wird ausgefuehrt wenn "http://<ip address>//0.html" aufgerufen wurde
{
  val = 1;                      // Relais Ein
  digitalWrite(0, val);         // GPIO0
  Temp = html1 + String((val) ? "/1.html" : "/0.html");
  Temp += html2 + String((val) ? "BACKGROUND-COLOR: DarkGray;" : "BACKGROUND-COLOR: Chartreuse;") + html3;
  server.send(200, "text/html", Temp);
}

void Ereignis_Index()           // Wird ausgeuehrt wenn "http://<ip address>/" aufgerufen wurde
{
  Temp = html1 + String((val) ? "/1.html" : "/0.html");
  Temp += html2 + String((val) ? "BACKGROUND-COLOR: DarkGray;" : "BACKGROUND-COLOR: Chartreuse;") + html3;
  server.send(200, "text/html", Temp);
}

void setup()
{
  digitalWrite(0, 1);                   // Anfangszustand 1 (Relais ausgeschaltet)
  pinMode(0, OUTPUT);                   // GPIO0 als Ausgang konfigurieren
  pinMode(2, INPUT_PULLUP);             // GPIO2 als Eingang mit Pullup konfigurieren
  digitalWrite(0, 1);                   // Anfangszustand 1 (Relais ausgeschaltet)

  Serial.begin(115200);                 // Serielle schnittstelle initialisieren
  Serial.println("");                   // Leere Zeile ausgeben
  Serial.println("Starte WLAN-Hotspot \"astral\"");
  WiFi.mode(WIFI_AP);                   // access point modus
  WiFi.softAP("astral", "12345678");    // Name des Wi-Fi netzes
  delay(500);                           //Abwarten 0,5s
  Serial.print("IP Adresse ");          //Ausgabe aktueller IP des Servers
  Serial.println(WiFi.softAPIP());

  //  Bechandlung der Ereignissen anschlissen
  server.on("/", Ereignis_Index);
  server.on("/1.html", Ereignis_SchalteON);
  server.on("/0.html", Ereignis_SchalteOFF);

  server.begin();                       // Starte den Server
  Serial.println("HTTP Server gestartet");
}

void loop()
{
  server.handleClient();
//  if (!digitalRead(2))          //Wenn Taster an GPIO2 betetigt wurde
//  {
//    val = !val;                 // Schaltzuschtand andern
//    digitalWrite(0, val);
//    while (!digitalRead(2))server.handleClient(); // Warten bis der Taster losgelassen wird.
//  }
}

error: pathspec 'Garage_opener.ino' did not match any file(s) known to git


Adding GPIO measurement sketch for logic analyzer.

/**
 * @file CosaAnalyzerGPIO.ino
 * @version 1.0
 *
 * @section License
 * Copyright (C) 2015, Mikael Patel
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * @section Description
 * Logic Analyzer Cosa GPIO; trigger on rising edge transition
 * on ledPin. Measurement values are for Arduino Uno
 *
 * This file is part of the Arduino Che Cosa project.
 */

#include "Cosa/GPIO.hh"

GPIO outPin(Board::D8, GPIO::OUTPUT_MODE);
GPIO dataPin(Board::D9, GPIO::OUTPUT_MODE);
GPIO clockPin(Board::D10, GPIO::OUTPUT_MODE);
GPIO ledPin(Board::LED, GPIO::OUTPUT_MODE);
uint8_t data = 0x55;

void setup()
{
  // Initial pin state
  outPin = 0;
  dataPin = 0;
  clockPin = 0;
  ledPin = 0;

  // Allow some time to start logic analyzer trigger
  sleep(2);

  // Trigger sampling
  ~ledPin;
  DELAY(50);
  ~ledPin;
  DELAY(50);
}

void loop()
{
  // Measure overhead in test case marker;
  // 0.5 us
  ~ledPin;
  ~ledPin;
  DELAY(10);

  // Measure four pulses using assignment operator;
  // 4.5 us (1 us per pulse)
  ~ledPin;
  outPin = 1;
  outPin = 0;
  outPin = 1;
  outPin = 0;
  outPin = 1;
  outPin = 0;
  outPin = 1;
  outPin = 0;
  ~ledPin;
  DELAY(10);

  // Measure four pulses using toggle operator;
  // 4.5 us (1 us per pulse)
  ~ledPin;
  ~outPin;
  ~outPin;
  ~outPin;
  ~outPin;
  ~outPin;
  ~outPin;
  ~outPin;
  ~outPin;
  ~ledPin;
  DELAY(10);

  // Measure clocked serial transfer of a byte using assignment operator;
  // 23.375 us (2.86 us per bit)
  ~ledPin;
  for(uint8_t bit = 0x80; bit != 0; bit >>= 1) {
    dataPin = (data & bit);
    clockPin = 1;
    clockPin = 0;
  }
  ~ledPin;
  DELAY(10);

  // Measure clocked serial transfer of a byte using assignment operator
  // and toggle operator;
  // 21.875 us (2.67 us per bit)
  ~ledPin;
  for(uint8_t bit = 0x80; bit != 0; bit >>= 1) {
    dataPin = (data & bit);
    ~clockPin;
    ~clockPin;
  }
  ~ledPin;
  DELAY(10);

  // Measure clocked serial transfer of a byte using assignment operator
  // and toggle operator fully unrolled
  // 19.208 us (2.33 us per bit)
  ~ledPin;
  dataPin = (data & 0x80);
  ~clockPin;
  ~clockPin;
  dataPin = (data & 0x40);
  ~clockPin;
  ~clockPin;
  dataPin = (data & 0x20);
  ~clockPin;
  ~clockPin;
  dataPin = (data & 0x10);
  ~clockPin;
  ~clockPin;
  dataPin = (data & 0x08);
  ~clockPin;
  ~clockPin;
  dataPin = (data & 0x04);
  ~clockPin;
  ~clockPin;
  dataPin = (data & 0x02);
  ~clockPin;
  ~clockPin;
  dataPin = (data & 0x01);
  ~clockPin;
  ~clockPin;
  ~ledPin;
  DELAY(10);

  // Measure four pulses using static write member function;
  // 1.5 us (250 ns per pulse)
  ~ledPin;
  GPIO::write(Board::D8, 1);
  GPIO::write(Board::D8, 0);
  GPIO::write(Board::D8, 1);
  GPIO::write(Board::D8, 0);
  GPIO::write(Board::D8, 1);
  GPIO::write(Board::D8, 0);
  GPIO::write(Board::D8, 1);
  GPIO::write(Board::D8, 0);
  ~ledPin;
  DELAY(10);

  // Measure four pulses using static toggle member function
  // 1.0 us (125 ns per pulse)
  ~ledPin;
  GPIO::toggle(Board::D8);
  GPIO::toggle(Board::D8);
  GPIO::toggle(Board::D8);
  GPIO::toggle(Board::D8);
  GPIO::toggle(Board::D8);
  GPIO::toggle(Board::D8);
  GPIO::toggle(Board::D8);
  GPIO::toggle(Board::D8);
  ~ledPin;
  DELAY(10);

  // Measure clocked serial transfer of a byte using static write
  // member function
  // 10.875 us (1.29 us per bit)
  ~ledPin;
  for(uint8_t bit = 0x80; bit != 0; bit >>= 1) {
    GPIO::write(Board::D9, data & bit);
    GPIO::write(Board::D10, 1);
    GPIO::write(Board::D10, 0);
  }
  ~ledPin;
  DELAY(10);

  // Measure clocked serial transfer of a byte using static write
  // and toggle member functions
  // 9.875 us (1.17 us per bit)
  ~ledPin;
  for(uint8_t bit = 0x80; bit != 0; bit >>= 1) {
    GPIO::write(Board::D9, data & bit);
    GPIO::toggle(Board::D10);
    GPIO::toggle(Board::D10);
  }
  ~ledPin;
  DELAY(10);

  // Measure clocked serial transfer of a byte using static write
  // and toggle member functions fully unrolled
  // 7.167 us (0.83 us per bit)
  ~ledPin;
  GPIO::write(Board::D9, data & 0x80);
  GPIO::toggle(Board::D10);
  GPIO::toggle(Board::D10);
  GPIO::write(Board::D9, data & 0x40);
  GPIO::toggle(Board::D10);
  GPIO::toggle(Board::D10);
  GPIO::write(Board::D9, data & 0x20);
  GPIO::toggle(Board::D10);
  GPIO::toggle(Board::D10);
  GPIO::write(Board::D9, data & 0x10);
  GPIO::toggle(Board::D10);
  GPIO::toggle(Board::D10);
  GPIO::write(Board::D9, data & 0x08);
  GPIO::toggle(Board::D10);
  GPIO::toggle(Board::D10);
  GPIO::write(Board::D9, data & 0x04);
  GPIO::toggle(Board::D10);
  GPIO::toggle(Board::D10);
  GPIO::write(Board::D9, data & 0x02);
  GPIO::toggle(Board::D10);
  GPIO::toggle(Board::D10);
  GPIO::write(Board::D9, data & 0x01);
  GPIO::toggle(Board::D10);
  GPIO::toggle(Board::D10);
  ~ledPin;

  // Rotate data to avoid compiler optimization of data
  data = (data << 1) | ((data & 0x01) == 0);
  sleep(1);
}

error: pathspec 'examples/Analyzer/CosaAnalyzserGPIO/CosaAnalizerGPIO.ino' did not match any file(s) known to git


Update MCUBE3610demo.ino

Update MCUBE3610demo.ino

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/mcubemems/Accelerometer_MC3610.git/'