ARTEMIS REDBOARD ZIO QWIIC ULTRASONIC DISTANCE SENSOR

I have to say that after trying two different things with the Redboard, and following the instructions… not one has gone well.

I bought some of these:

https://www.sparkfun.com/products/15171

went to the “Documents” section, and tried following both links…

Installed the required libraries (Adafruit GFX and SSD…)

Got the sample sketch…

Error:

:\Users\ecorrales\Documents\Arduino\libraries\Adafruit_SSD1306\Adafruit_SSD1306.cpp: In member function ‘boolean Adafruit_SSD1306::begin(uint8_t, uint8_t, boolean, boolean)’:

C:\Users\ecorrales\Documents\Arduino\libraries\Adafruit_SSD1306\Adafruit_SSD1306.cpp:482:47: error: ‘digitalPinToPort’ was not declared in this scope

dcPort = (PortReg *)portOutputRegister(digitalPinToPort(dcPin));

^~~~~~~~~~~~~~~~

C:\Users\ecorrales\Documents\Arduino\libraries\Adafruit_SSD1306\Adafruit_SSD1306.cpp:482:47: note: suggested alternative: ‘digitalPinToInterrupt’

dcPort = (PortReg *)portOutputRegister(digitalPinToPort(dcPin));

^~~~~~~~~~~~~~~~

digitalPinToInterrupt

C:\Users\ecorrales\Documents\Arduino\libraries\Adafruit_SSD1306\Adafruit_SSD1306.cpp:482:28: error: ‘portOutputRegister’ was not declared in this scope

dcPort = (PortReg *)portOutputRegister(digitalPinToPort(dcPin));

^~~~~~~~~~~~~~~~~~

C:\Users\ecorrales\Documents\Arduino\libraries\Adafruit_SSD1306\Adafruit_SSD1306.cpp:483:17: error: ‘digitalPinToBitMask’ was not declared in this scope

dcPinMask = digitalPinToBitMask(dcPin);

^~~~~~~~~~~~~~~~~~~

C:\Users\ecorrales\Documents\Arduino\libraries\Adafruit_SSD1306\Adafruit_SSD1306.cpp:483:17: note: suggested alternative: ‘digitalPinToInterrupt’

dcPinMask = digitalPinToBitMask(dcPin);

^~~~~~~~~~~~~~~~~~~

digitalPinToInterrupt

Multiple libraries were found for “Adafruit_SSD1306.h”

Used: C:\Users\ecorrales\Documents\Arduino\libraries\Adafruit_SSD1306

Multiple libraries were found for “SPI.h”

Used: C:\Users\ecorrales\AppData\Local\Arduino15\packages\SparkFun\hardware\apollo3\1.0.12\libraries\SPI

Multiple libraries were found for “Wire.h”

Used: C:\Users\ecorrales\AppData\Local\Arduino15\packages\SparkFun\hardware\apollo3\1.0.12\libraries\Wire

Multiple libraries were found for “Adafruit_GFX.h”

Used: C:\Users\ecorrales\Documents\Arduino\libraries\Adafruit_GFX_Library

Hi ecorrales,

That compile error is due to the fact the AdafruitGFX and SSD1306 libraries are not compatible with the Artemis core. That code is not really necessary to use the sensor unless you intend to use it with an Adafruit OLED display. Simply remove or comment out any of the code that is referring to a display or either library. Here’s a stripped-down version of the example that should work:

/**
 * HC-SR04 Demo
 * Demonstration of the HC-SR04 Ultrasonic Sensor
 * Date: August 3, 2016
 * 
 * Description:
 *  Connect the ultrasonic sensor to the Arduino as per the
 *  hardware connections below. Run the sketch and open a serial
 *  monitor. The distance read from the sensor will be displayed
 *  in centimeters and inches.
 * 
 * Hardware Connections:
 *  Arduino | HC-SR04 
 *  -------------------
 *    5V    |   VCC     
 *    7     |   Trig     
 *    8     |   Echo     
 *    GND   |   GND
 *  
 * License:
 *  Public Domain
 */
#include <Wire.h>

// Pins
const int TRIG_PIN = 7;
const int ECHO_PIN = 8;

// Anything over 400 cm (23200 us pulse) is "out of range"
const unsigned int MAX_DIST = 23200;

void setup() {

  // The Trigger pin will tell the sensor to range find
  pinMode(TRIG_PIN, OUTPUT);
  digitalWrite(TRIG_PIN, LOW);

  // We'll use the serial monitor to view the sensor output
  Serial.begin(9600);
  //display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initialize with the I2C addr 0x3C (for the 128x32)
  //display.clearDisplay();
}

void loop() {

  unsigned long t1;
  unsigned long t2;
  unsigned long pulse_width;
  float cm;
  float inches;

  // Hold the trigger pin high for at least 10 us
  digitalWrite(TRIG_PIN, HIGH);
  delayMicroseconds(50);
  digitalWrite(TRIG_PIN, LOW);

  // Wait for pulse on echo pin
  while ( digitalRead(ECHO_PIN) == 0 );

  // Measure how long the echo pin was held high (pulse width)
  // Note: the micros() counter will overflow after ~70 min
  t1 = micros();
  while ( digitalRead(ECHO_PIN) == 1);
  t2 = micros();
  pulse_width = t2 - t1;

  // Calculate distance in centimeters and inches. The constants
  // are found in the datasheet, and calculated from the assumed speed 
  //of sound in air at sea level (~340 m/s).
  cm = pulse_width / 58.0;
  inches = pulse_width / 148.0;

  // Print out results
  if ( pulse_width > MAX_DIST ) {
    Serial.println("Out of range");
  } else {
    Serial.print(cm);
    Serial.print(" cm \t");
    Serial.print(inches);
    Serial.println(" in");  
  }
  
  // Wait at least 60ms before next measurement
  delay(60);
}

oh, nice! thanks… (sorry for delayed reply). I will try it.