Skip to content

Commit 298d23b

Browse files
Merge pull request #35 from ArminJo/master
2 examples added
2 parents 60062d0 + 2c0a4d2 commit 298d23b

File tree

7 files changed

+429
-2
lines changed

7 files changed

+429
-2
lines changed

Diff for: .github/workflows/LibraryBuild.yml

+158
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
# LibraryBuild.yml
2+
# Github workflow script to test compile all examples of an Arduino library repository.
3+
#
4+
# Copyright (C) 2020 Armin Joachimsmeyer
5+
# https://github.com/ArminJo/Github-Actions
6+
# License: MIT
7+
#
8+
# Before being able to push to my .github\workflows directories,
9+
# I had to create a new personal token with workflow enabled at https://github.com/settings/tokens
10+
11+
# This is the name of the workflow, visible on GitHub UI.
12+
name: LibraryBuild
13+
on: [push, pull_request] # see: https://help.github.com/en/actions/reference/events-that-trigger-workflows#pull-request-event-pull_request
14+
15+
jobs:
16+
build:
17+
name: ${{ matrix.arduino-boards-fqbn }} - test compiling examples
18+
19+
runs-on: ubuntu-latest # I picked Ubuntu to use shell scripts.
20+
21+
env:
22+
# Space separated list without double quotes around the list.
23+
# If you need a library with a space in its name, like Adafruit NeoPixel or Adafruit INA219, you must use double quotes
24+
# around the name and have at least 2 entries, where the first must be without double quotes! You may use Servo as dummy entry.
25+
REQUIRED_LIBRARIES: EspSoftwareSerial
26+
27+
# Global color definitions for output colors
28+
RED: '\033[0;31m'
29+
GREEN: '\033[0;32m'
30+
YELLOW: '\033[1;33m'
31+
BLUE: '\033[0;34m'
32+
33+
strategy:
34+
matrix:
35+
# The matrix will produce one job for each configuration parameter of type `arduino-boards-fqbn`
36+
# 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
37+
#
38+
# Examples: arduino:avr:uno, arduino:avr:leonardo, arduino:avr:nano, arduino:avr:mega
39+
# arduino:sam:arduino_due_x, arduino:samd:arduino_zero_native"
40+
# ATTinyCore:avr:attinyx5:chip=85,clock=1internal, digistump:avr:digispark-tiny, digistump:avr:digispark-pro
41+
# STM32:stm32:GenF1:pnum=BLUEPILL_F103C8
42+
# esp8266:esp8266:huzzah:eesz=4M3M,xtal=80, esp32:esp32:featheresp32:FlashFreq=80
43+
# You may add a suffix behind the fqbn with "|" to specify one board for e.g. different compile options like arduino:avr:uno|trace
44+
#############################################################################################################
45+
arduino-boards-fqbn:
46+
- arduino:avr:uno
47+
- arduino:avr:leonardo
48+
- arduino:avr:mega
49+
- arduino:sam:arduino_due_x
50+
- esp8266:esp8266:huzzah:eesz=4M3M,xtal=80
51+
- esp32:esp32:featheresp32:FlashFreq=80
52+
- STM32:stm32:GenF1:pnum=BLUEPILL_F103C8
53+
54+
# Choose the right platform for the boards we want to test. (maybe in the future Arduino will automatically do this for you).
55+
# This works like this: when the fqbn is "arduino:avr:uno" the variable `platform` is set to "arduino:avr".
56+
# Just take the first 2 token of the fqbn - this cannot be automatically done by GitHub workflow :-(
57+
# You may exclude specific examples for a board with examples-exclude: Use a space separated list.
58+
#############################################################################################################
59+
include:
60+
- arduino-boards-fqbn: arduino:avr:uno
61+
platform: arduino:avr
62+
63+
- arduino-boards-fqbn: arduino:avr:leonardo
64+
platform: arduino:avr
65+
66+
- arduino-boards-fqbn: arduino:avr:mega
67+
platform: arduino:avr
68+
69+
- arduino-boards-fqbn: arduino:sam:arduino_due_x
70+
platform: arduino:sam
71+
examples-exclude: Example5_LCDDemo # No SoftwareSerial available. Space separated list of (unique substrings of) example names to exclude in build
72+
73+
- arduino-boards-fqbn: esp8266:esp8266:huzzah:eesz=4M3M,xtal=80
74+
platform: esp8266:esp8266
75+
76+
- arduino-boards-fqbn: esp32:esp32:featheresp32:FlashFreq=80
77+
platform: esp32:esp32
78+
79+
- arduino-boards-fqbn: STM32:stm32:GenF1:pnum=BLUEPILL_F103C8
80+
platform: STM32:stm32
81+
82+
######################################################
83+
# End of configuration, start of fixed script section
84+
######################################################
85+
86+
# Do not cancel all jobs / architectures if one job fails
87+
fail-fast: false
88+
89+
# This is the list of steps this job will run.
90+
steps:
91+
92+
# First of all, we clone the repo using the `checkout` action.
93+
- name: Checkout
94+
uses: actions/checkout@master
95+
96+
# We use the `arduino/setup-arduino-cli` action to install and
97+
# configure the Arduino CLI on the system.
98+
- name: Setup Arduino CLI
99+
uses: arduino/[email protected]
100+
101+
- name: Link this repository as Arduino library
102+
run: |
103+
mkdir -p $HOME/Arduino/libraries
104+
ln -s $PWD $HOME/Arduino/libraries/.
105+
106+
- name: Install platform from build matrix
107+
env:
108+
FQBN: ${{ matrix.arduino-boards-fqbn }}
109+
run: |
110+
arduino-cli core update-index
111+
if [ "${{ matrix.platform }}" == "" ]; then echo -e ""$RED"ERROR: platform missing for board ${FQBN%|*}. Check your matrix.includes entries"; exit 1; fi
112+
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
113+
arduino-cli core install ${{ matrix.platform }} # for each job / board one platform is installed
114+
arduino-cli board listall
115+
if [ ${{ matrix.platform }} == "esp32:esp32" ]; then pip install pyserial; fi
116+
117+
- name: List installed boards with their FQBN
118+
run: |
119+
arduino-cli board listall
120+
# ls -l $HOME/.arduino15/packages/ # I see only arduino and one of the Attiny cores but not all 3 together
121+
# echo -e HOME=\"$HOME\" # /home/runner
122+
# echo PWD=$PWD # /home/runner/work/Github-Actions-Test/Github-Actions-Test
123+
# which arduino-cli # /opt/hostedtoolcache/arduino-cli/0.9.0/x64/arduino-cli
124+
125+
- name: Install libraries
126+
run: if [[ "$REQUIRED_LIBRARIES" != "" ]]; then arduino-cli lib install ${{ env.REQUIRED_LIBRARIES }}; fi
127+
128+
# Finally, we compile the sketch, using the FQBN that was set in the build matrix.
129+
- name: Compile all examples
130+
env:
131+
FQBN: ${{ matrix.arduino-boards-fqbn }}
132+
BUILD_PROPERTIES: ${{ toJson(matrix.examples-build-properties) }}
133+
run: |
134+
BUILD_PROPERTIES=${BUILD_PROPERTIES#\{} # remove "{"
135+
# if matrix.examples-build-properties are specified, create an associative shell array
136+
if [[ $BUILD_PROPERTIES != "null" ]]; then declare -A PROP_MAP="( $(echo $BUILD_PROPERTIES | sed -E 's/"(\w*)": *([^,}]*)[,}]/\[\1\]=\2/g' ) )"; fi
137+
echo -e "Compiling examples for board ${{ matrix.arduino-boards-fqbn }} \n"
138+
EXAMPLES=($(find . -name "*.ino"))
139+
for example in "${EXAMPLES[@]}"; do # Loop over all example directories
140+
EXAMPLE_NAME=$(basename $(dirname $example))
141+
if [[ "${{ matrix.examples-exclude }}" == *"$EXAMPLE_NAME"* ]]; then
142+
echo -e "Skipping $EXAMPLE_NAME \xe2\x9e\x9e" # Right arrow
143+
else
144+
# check if there is an entry in the associative array and create a compile parameter
145+
echo -n "Compiling $EXAMPLE_NAME "
146+
if [[ "${PROP_MAP[$EXAMPLE_NAME]}" != "" ]]; then echo -n "with ${PROP_MAP[$EXAMPLE_NAME]} "; fi
147+
build_stdout=$(arduino-cli compile --verbose --warnings all --fqbn ${FQBN%|*} --build-properties compiler.cpp.extra_flags="${PROP_MAP[$EXAMPLE_NAME]}" $(dirname $example) 2>&1);
148+
if [ $? -ne 0 ]; then
149+
echo -e ""$RED"\xe2\x9c\x96" # If ok output a green checkmark else a red X and the command output.
150+
exit_code=1
151+
echo -e "$build_stdout \n"
152+
else
153+
echo -e ""$GREEN"\xe2\x9c\x93"
154+
fi
155+
fi
156+
done
157+
exit $exit_code
158+
shell: bash {0} # Needed to avoid an exit at first error

Diff for: README.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
SparkFun Qwiic 4m Distance Sensor with VL53L1X
22
========================================
3+
[![Build Status](https://github.com/sparkfun/SparkFun_VL53L1X_Arduino_Library/workflows/LibraryBuild/badge.svg)](https://github.com/sparkfun/SparkFun_VL53L1X_Arduino_Library/actions)
4+
35

46
![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)
57

Diff for: arduino-cli.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
board_manager:
2+
additional_urls:
3+
- http://digistump.com/package_digistump_index.json
4+
- http://drazzy.com/package_drazzy.com_index.json
5+
- http://arduino.esp8266.com/stable/package_esp8266com_index.json
6+
- https://dl.espressif.com/dl/package_esp32_index.json
7+
- https://github.com/stm32duino/BoardManagerFiles/raw/dev/STM32/package_stm_index.json

Diff for: examples/Example5_LCDDemo/Example5_LCDDemo.ino

+5-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ SFEVL53L1X distanceSensor;
2626
//Uncomment the following line to use the optional shutdown and interrupt pins.
2727
//SFEVL53L1X distanceSensor(Wire, SHUTDOWN_PIN, INTERRUPT_PIN);
2828

29+
#if defined(ESP8266)
30+
SoftwareSerial lcd(10, 9); // RX, TX
31+
#else
2932
SoftwareSerial lcd(10, A3); // RX, TX
33+
#endif
3034

3135
//Store distance readings to get rolling average
3236
#define HISTORY_SIZE 8
@@ -136,7 +140,7 @@ void loop(void)
136140

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

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

141145
if (instantMPH > maxMPH)
142146
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
#include <Arduino.h>
2+
3+
#include <ComponentObject.h>
4+
#include <RangeSensor.h>
5+
#include <SparkFun_VL53L1X.h>
6+
#include <vl53l1x_class.h>
7+
#include <vl53l1_error_codes.h>
8+
9+
/*
10+
Reading distance from the laser based VL53L1X
11+
By: Armin Joachimsmeyer
12+
for SparkFun Electronics
13+
Date: February 20th, 2020
14+
License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license).
15+
16+
SparkFun labored with love to create this code. Feel like supporting open source hardware?
17+
Buy a board from SparkFun! https://www.sparkfun.com/products/14667
18+
19+
This example prints the distance to an object to the Arduino Serial Plotter and generates a tone depending on distance.
20+
21+
Are you getting weird readings? Be sure the vacuum tape has been removed from the sensor.
22+
*/
23+
24+
#include <Wire.h>
25+
#include "SparkFun_VL53L1X.h"
26+
27+
//Optional interrupt and shutdown pins.
28+
#define SHUTDOWN_PIN 2
29+
#define INTERRUPT_PIN 3
30+
#define TONE_PIN 11
31+
32+
SFEVL53L1X distanceSensor;
33+
//Uncomment the following line to use the optional shutdown and interrupt pins.
34+
//SFEVL53L1X distanceSensor(Wire, SHUTDOWN_PIN, INTERRUPT_PIN);
35+
36+
void setup(void) {
37+
Wire.begin();
38+
39+
// initialize the digital pin as an output.
40+
pinMode(LED_BUILTIN, OUTPUT);
41+
Serial.begin(9600);
42+
while (!Serial)
43+
; //delay for Leonardo
44+
// Just to know which program is running on my Arduino
45+
Serial.println(F("START " __FILE__));
46+
47+
#if ! defined (ESP32) && ! defined(ARDUINO_SAM_DUE) && ! defined(__SAM3X8E__)
48+
// test beep for the connected speaker
49+
tone(TONE_PIN,1000,100);
50+
delay(200);
51+
#endif
52+
53+
if (distanceSensor.begin() == 0) { //Begin returns 0 on a good init
54+
Serial.println("Sensor online!");
55+
}
56+
57+
// Short mode max distance is limited to 1.3 m but has a better ambient immunity.
58+
// Above 1.3 meter error 4 is thrown (wrap around).
59+
distanceSensor.setDistanceModeShort();
60+
//distanceSensor.setDistanceModeLong(); // default
61+
62+
// Print Legend
63+
Serial.println("Distance Signal-Rate/100 Ambient-Rate/100");
64+
65+
/*
66+
* The minimum timing budget is 20 ms for the short distance mode and 33 ms for the medium and long distance modes.
67+
* Predefined values = 15, 20, 33, 50, 100(default), 200, 500.
68+
* This function must be called after SetDistanceMode.
69+
*/
70+
distanceSensor.setTimingBudgetInMs(50);
71+
72+
// measure periodically. Intermeasurement period must be >/= timing budget.
73+
distanceSensor.setIntermeasurementPeriod(100);
74+
distanceSensor.startRanging(); // Start once
75+
76+
}
77+
78+
void loop(void) {
79+
while (!distanceSensor.checkForDataReady()) {
80+
delay(1);
81+
}
82+
byte rangeStatus = distanceSensor.getRangeStatus();
83+
unsigned int distance = distanceSensor.getDistance(); //Get the result of the measurement from the sensor
84+
distanceSensor.clearInterrupt();
85+
86+
/*
87+
* With signed int we get overflow at short distances.
88+
* With unsigned we get an overflow below around 2.5 cm.
89+
*/
90+
unsigned int tSignalRate = distanceSensor.getSignalRate();
91+
unsigned int tAmbientRate = distanceSensor.getAmbientRate();
92+
93+
if (rangeStatus == 0) {
94+
#if ! defined (ESP32) && ! defined(ARDUINO_SAM_DUE) && ! defined(__SAM3X8E__)
95+
tone(11, distance + 500);
96+
#endif
97+
} else {
98+
// if tAmbientRate > tSignalRate we likely get a signal fail error condition
99+
// in Distance mode short we get error 4 (out of bounds) or 7 (wrap around) if the distance is greater than 1.3 meter.
100+
distance = rangeStatus;
101+
#if ! defined (ESP32) && ! defined(ARDUINO_SAM_DUE) && ! defined(__SAM3X8E__)
102+
noTone(11);
103+
#endif
104+
}
105+
106+
Serial.print(distance);
107+
Serial.print(' ');
108+
Serial.print(tSignalRate / 100);
109+
Serial.print(' ');
110+
Serial.println(tAmbientRate / 100);
111+
}
112+

0 commit comments

Comments
 (0)