Skip to content

Commit

Permalink
Merge pull request #35 from ArminJo/master
Browse files Browse the repository at this point in the history
2 examples added
  • Loading branch information
AndyEngland521 committed Mar 17, 2020
2 parents 60062d0 + 2c0a4d2 commit 298d23b
Show file tree
Hide file tree
Showing 7 changed files with 429 additions and 2 deletions.
158 changes: 158 additions & 0 deletions .github/workflows/LibraryBuild.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
# LibraryBuild.yml
# Github workflow script to test compile all examples of an Arduino library repository.
#
# Copyright (C) 2020 Armin Joachimsmeyer
# https://github.com/ArminJo/Github-Actions
# License: MIT
#
# Before being able to push to my .github\workflows directories,
# I had to create a new personal token with workflow enabled at https://github.com/settings/tokens

# This is the name of the workflow, visible on GitHub UI.
name: LibraryBuild
on: [push, pull_request] # see: https://help.github.com/en/actions/reference/events-that-trigger-workflows#pull-request-event-pull_request

jobs:
build:
name: ${{ matrix.arduino-boards-fqbn }} - test compiling examples

runs-on: ubuntu-latest # I picked Ubuntu to use shell scripts.

env:
# Space separated list without double quotes around the list.
# If you need a library with a space in its name, like Adafruit NeoPixel or Adafruit INA219, you must use double quotes
# around the name and have at least 2 entries, where the first must be without double quotes! You may use Servo as dummy entry.
REQUIRED_LIBRARIES: EspSoftwareSerial

# Global color definitions for output colors
RED: '\033[0;31m'
GREEN: '\033[0;32m'
YELLOW: '\033[1;33m'
BLUE: '\033[0;34m'

strategy:
matrix:
# The matrix will produce one job for each configuration parameter of type `arduino-boards-fqbn`
# In the Arduino IDE, the fqbn is printed in the first line of the verbose output for compilation as parameter -fqbn=... for the "arduino-builder -dump-prefs" command
#
# Examples: arduino:avr:uno, arduino:avr:leonardo, arduino:avr:nano, arduino:avr:mega
# arduino:sam:arduino_due_x, arduino:samd:arduino_zero_native"
# ATTinyCore:avr:attinyx5:chip=85,clock=1internal, digistump:avr:digispark-tiny, digistump:avr:digispark-pro
# STM32:stm32:GenF1:pnum=BLUEPILL_F103C8
# esp8266:esp8266:huzzah:eesz=4M3M,xtal=80, esp32:esp32:featheresp32:FlashFreq=80
# You may add a suffix behind the fqbn with "|" to specify one board for e.g. different compile options like arduino:avr:uno|trace
#############################################################################################################
arduino-boards-fqbn:
- arduino:avr:uno
- arduino:avr:leonardo
- arduino:avr:mega
- arduino:sam:arduino_due_x
- esp8266:esp8266:huzzah:eesz=4M3M,xtal=80
- esp32:esp32:featheresp32:FlashFreq=80
- STM32:stm32:GenF1:pnum=BLUEPILL_F103C8

# Choose the right platform for the boards we want to test. (maybe in the future Arduino will automatically do this for you).
# This works like this: when the fqbn is "arduino:avr:uno" the variable `platform` is set to "arduino:avr".
# Just take the first 2 token of the fqbn - this cannot be automatically done by GitHub workflow :-(
# You may exclude specific examples for a board with examples-exclude: Use a space separated list.
#############################################################################################################
include:
- arduino-boards-fqbn: arduino:avr:uno
platform: arduino:avr

- arduino-boards-fqbn: arduino:avr:leonardo
platform: arduino:avr

- arduino-boards-fqbn: arduino:avr:mega
platform: arduino:avr

- arduino-boards-fqbn: arduino:sam:arduino_due_x
platform: arduino:sam
examples-exclude: Example5_LCDDemo # No SoftwareSerial available. Space separated list of (unique substrings of) example names to exclude in build

- arduino-boards-fqbn: esp8266:esp8266:huzzah:eesz=4M3M,xtal=80
platform: esp8266:esp8266

- arduino-boards-fqbn: esp32:esp32:featheresp32:FlashFreq=80
platform: esp32:esp32

- arduino-boards-fqbn: STM32:stm32:GenF1:pnum=BLUEPILL_F103C8
platform: STM32:stm32

######################################################
# End of configuration, start of fixed script section
######################################################

# Do not cancel all jobs / architectures if one job fails
fail-fast: false

# This is the list of steps this job will run.
steps:

# First of all, we clone the repo using the `checkout` action.
- name: Checkout
uses: actions/checkout@master

# We use the `arduino/setup-arduino-cli` action to install and
# configure the Arduino CLI on the system.
- name: Setup Arduino CLI
uses: arduino/[email protected]

- name: Link this repository as Arduino library
run: |
mkdir -p $HOME/Arduino/libraries
ln -s $PWD $HOME/Arduino/libraries/.
- name: Install platform from build matrix
env:
FQBN: ${{ matrix.arduino-boards-fqbn }}
run: |
arduino-cli core update-index
if [ "${{ matrix.platform }}" == "" ]; then echo -e ""$RED"ERROR: platform missing for board ${FQBN%|*}. Check your matrix.includes entries"; exit 1; fi
if [[ ${{ matrix.platform }} != *"arduino"* && ! -f ./arduino-cli.yaml ]]; then echo -e ""$RED"Non Arduino platform ${{ matrix.platform }} requested, but file arduino-cli.yaml is missing."; exit 1; fi
arduino-cli core install ${{ matrix.platform }} # for each job / board one platform is installed
arduino-cli board listall
if [ ${{ matrix.platform }} == "esp32:esp32" ]; then pip install pyserial; fi
- name: List installed boards with their FQBN
run: |
arduino-cli board listall
# ls -l $HOME/.arduino15/packages/ # I see only arduino and one of the Attiny cores but not all 3 together
# echo -e HOME=\"$HOME\" # /home/runner
# echo PWD=$PWD # /home/runner/work/Github-Actions-Test/Github-Actions-Test
# which arduino-cli # /opt/hostedtoolcache/arduino-cli/0.9.0/x64/arduino-cli
- name: Install libraries
run: if [[ "$REQUIRED_LIBRARIES" != "" ]]; then arduino-cli lib install ${{ env.REQUIRED_LIBRARIES }}; fi

# Finally, we compile the sketch, using the FQBN that was set in the build matrix.
- name: Compile all examples
env:
FQBN: ${{ matrix.arduino-boards-fqbn }}
BUILD_PROPERTIES: ${{ toJson(matrix.examples-build-properties) }}
run: |
BUILD_PROPERTIES=${BUILD_PROPERTIES#\{} # remove "{"
# if matrix.examples-build-properties are specified, create an associative shell array
if [[ $BUILD_PROPERTIES != "null" ]]; then declare -A PROP_MAP="( $(echo $BUILD_PROPERTIES | sed -E 's/"(\w*)": *([^,}]*)[,}]/\[\1\]=\2/g' ) )"; fi
echo -e "Compiling examples for board ${{ matrix.arduino-boards-fqbn }} \n"
EXAMPLES=($(find . -name "*.ino"))
for example in "${EXAMPLES[@]}"; do # Loop over all example directories
EXAMPLE_NAME=$(basename $(dirname $example))
if [[ "${{ matrix.examples-exclude }}" == *"$EXAMPLE_NAME"* ]]; then
echo -e "Skipping $EXAMPLE_NAME \xe2\x9e\x9e" # Right arrow
else
# check if there is an entry in the associative array and create a compile parameter
echo -n "Compiling $EXAMPLE_NAME "
if [[ "${PROP_MAP[$EXAMPLE_NAME]}" != "" ]]; then echo -n "with ${PROP_MAP[$EXAMPLE_NAME]} "; fi
build_stdout=$(arduino-cli compile --verbose --warnings all --fqbn ${FQBN%|*} --build-properties compiler.cpp.extra_flags="${PROP_MAP[$EXAMPLE_NAME]}" $(dirname $example) 2>&1);
if [ $? -ne 0 ]; then
echo -e ""$RED"\xe2\x9c\x96" # If ok output a green checkmark else a red X and the command output.
exit_code=1
echo -e "$build_stdout \n"
else
echo -e ""$GREEN"\xe2\x9c\x93"
fi
fi
done
exit $exit_code
shell: bash {0} # Needed to avoid an exit at first error
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
SparkFun Qwiic 4m Distance Sensor with VL53L1X
========================================
[![Build Status](https://github.com/sparkfun/SparkFun_VL53L1X_Arduino_Library/workflows/LibraryBuild/badge.svg)](https://github.com/sparkfun/SparkFun_VL53L1X_Arduino_Library/actions)


![SparkFun Distance Sensor Breakout - 4 Meter, VL53L1X (Qwiic)](https://cdn.sparkfun.com//assets/parts/1/2/9/4/8/14722-SparkFun_Distance_Sensor_Breakout-_4_Meter__VL53L1X__Qwiic_-01.jpg)

Expand Down
7 changes: 7 additions & 0 deletions arduino-cli.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
board_manager:
additional_urls:
- http://digistump.com/package_digistump_index.json
- http://drazzy.com/package_drazzy.com_index.json
- http://arduino.esp8266.com/stable/package_esp8266com_index.json
- https://dl.espressif.com/dl/package_esp32_index.json
- https://github.com/stm32duino/BoardManagerFiles/raw/dev/STM32/package_stm_index.json
6 changes: 5 additions & 1 deletion examples/Example5_LCDDemo/Example5_LCDDemo.ino
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ SFEVL53L1X distanceSensor;
//Uncomment the following line to use the optional shutdown and interrupt pins.
//SFEVL53L1X distanceSensor(Wire, SHUTDOWN_PIN, INTERRUPT_PIN);

#if defined(ESP8266)
SoftwareSerial lcd(10, 9); // RX, TX
#else
SoftwareSerial lcd(10, A3); // RX, TX
#endif

//Store distance readings to get rolling average
#define HISTORY_SIZE 8
Expand Down Expand Up @@ -136,7 +140,7 @@ void loop(void)

instantMPH = abs(instantMPH); //We want to measure as you walk away

ceil(instantMPH); //Round up to the next number. This is helpful if we're not displaying decimals.
instantMPH = ceil(instantMPH); //Round up to the next number. This is helpful if we're not displaying decimals.

if (instantMPH > maxMPH)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#include <Arduino.h>

#include <ComponentObject.h>
#include <RangeSensor.h>
#include <SparkFun_VL53L1X.h>
#include <vl53l1x_class.h>
#include <vl53l1_error_codes.h>

/*
Reading distance from the laser based VL53L1X
By: Armin Joachimsmeyer
for SparkFun Electronics
Date: February 20th, 2020
License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license).
SparkFun labored with love to create this code. Feel like supporting open source hardware?
Buy a board from SparkFun! https://www.sparkfun.com/products/14667
This example prints the distance to an object to the Arduino Serial Plotter and generates a tone depending on distance.
Are you getting weird readings? Be sure the vacuum tape has been removed from the sensor.
*/

#include <Wire.h>
#include "SparkFun_VL53L1X.h"

//Optional interrupt and shutdown pins.
#define SHUTDOWN_PIN 2
#define INTERRUPT_PIN 3
#define TONE_PIN 11

SFEVL53L1X distanceSensor;
//Uncomment the following line to use the optional shutdown and interrupt pins.
//SFEVL53L1X distanceSensor(Wire, SHUTDOWN_PIN, INTERRUPT_PIN);

void setup(void) {
Wire.begin();

// initialize the digital pin as an output.
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(9600);
while (!Serial)
; //delay for Leonardo
// Just to know which program is running on my Arduino
Serial.println(F("START " __FILE__));

#if ! defined (ESP32) && ! defined(ARDUINO_SAM_DUE) && ! defined(__SAM3X8E__)
// test beep for the connected speaker
tone(TONE_PIN,1000,100);
delay(200);
#endif

if (distanceSensor.begin() == 0) { //Begin returns 0 on a good init
Serial.println("Sensor online!");
}

// Short mode max distance is limited to 1.3 m but has a better ambient immunity.
// Above 1.3 meter error 4 is thrown (wrap around).
distanceSensor.setDistanceModeShort();
//distanceSensor.setDistanceModeLong(); // default

// Print Legend
Serial.println("Distance Signal-Rate/100 Ambient-Rate/100");

/*
* The minimum timing budget is 20 ms for the short distance mode and 33 ms for the medium and long distance modes.
* Predefined values = 15, 20, 33, 50, 100(default), 200, 500.
* This function must be called after SetDistanceMode.
*/
distanceSensor.setTimingBudgetInMs(50);

// measure periodically. Intermeasurement period must be >/= timing budget.
distanceSensor.setIntermeasurementPeriod(100);
distanceSensor.startRanging(); // Start once

}

void loop(void) {
while (!distanceSensor.checkForDataReady()) {
delay(1);
}
byte rangeStatus = distanceSensor.getRangeStatus();
unsigned int distance = distanceSensor.getDistance(); //Get the result of the measurement from the sensor
distanceSensor.clearInterrupt();

/*
* With signed int we get overflow at short distances.
* With unsigned we get an overflow below around 2.5 cm.
*/
unsigned int tSignalRate = distanceSensor.getSignalRate();
unsigned int tAmbientRate = distanceSensor.getAmbientRate();

if (rangeStatus == 0) {
#if ! defined (ESP32) && ! defined(ARDUINO_SAM_DUE) && ! defined(__SAM3X8E__)
tone(11, distance + 500);
#endif
} else {
// if tAmbientRate > tSignalRate we likely get a signal fail error condition
// in Distance mode short we get error 4 (out of bounds) or 7 (wrap around) if the distance is greater than 1.3 meter.
distance = rangeStatus;
#if ! defined (ESP32) && ! defined(ARDUINO_SAM_DUE) && ! defined(__SAM3X8E__)
noTone(11);
#endif
}

Serial.print(distance);
Serial.print(' ');
Serial.print(tSignalRate / 100);
Serial.print(' ');
Serial.println(tAmbientRate / 100);
}

Loading

0 comments on commit 298d23b

Please sign in to comment.