QT PY SAMD21 compiler error after upgrade

Please tell us which board you are using.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Post Reply
User avatar
jimk123
 
Posts: 426
Joined: Sun Dec 26, 2010 7:04 pm

QT PY SAMD21 compiler error after upgrade

Post by jimk123 »

I have been using this QT PY board for over a year https://www.adafruit.com/product/4600 Adafruit QT Py - SAMD21 Dev Board with STEMMA QT and recently upgraded the SAMD board manger and a sketch no longer compiles. I have two windows PC's (win10b I upgraded) and the one I did not upgrade (call it win10a) still compiles fine.

My first q is did adafruit change the board name ? on the PC win10a I did not upgrade (arduino IDE 1.8.5) under tools, board the board says "Adafruit QT PY (SAMD21)" and on the PC (win10b) after the upgrade (arduino IDE 1.8.10) board name shows as "Adafruit QT PY M0 (SAMD21)"

the compiler error I get after the upgrade is:
C:\Users\Jim\Documents\Arduino\libraries\SparkFun_AS6212_Qwiic_Arduino_Library\src\SparkFun_AS6212_Qwiic.cpp: In member function 'uint16_t AS6212::getConversionCycleTime()':
C:\Users\Jim\Documents\Arduino\libraries\SparkFun_AS6212_Qwiic_Arduino_Library\src\SparkFun_AS6212_Qwiic.cpp:361:1: error: control reaches end of non-void function [-Werror=return-type]
361 | }
| ^

but I can still compile it fine on the win10a pc.

thoughts ?

User avatar
jimk123
 
Posts: 426
Joined: Sun Dec 26, 2010 7:04 pm

Re: QT PY SAMD21 compiler error after upgrade

Post by jimk123 »

not sure if this is the solution but I googled that error and on a thread about esp32 ( i know different board) there was a similar error someone had and were told to add a return value. https://github.com/chrisjoyce911/esp32FOTA/issues/3

I am in way over my head but for the fun of it I edited SparkFun_AS6212_Qwiic.cpp and on the line the compiler said it was an error I added return 0; as the last line, and it compiled ok, still not sure why after the upgrade of the SAMD boards I got that error. I can certainly reach out to the SF folks and suggest a fix if that is the problem.

uint16_t AS6212::getConversionCycleTime()
{
// sorry had to drop some lines here the post said were spam

// conversion rate value is stored in just 2 bits in the config reg,
// so we must convert from stored values (0-3) to "human readable" values (125/250/1000/4000).
if(cycleTime == AS6212_CONVERSION_CYCLE_TIME_125MS) return 125;
if(cycleTime == AS6212_CONVERSION_CYCLE_TIME_250MS) return 250;
if(cycleTime == AS6212_CONVERSION_CYCLE_TIME_1000MS) return 1000;
if(cycleTime == AS6212_CONVERSION_CYCLE_TIME_4000MS) return 4000;
return 0; // I ADDED THIS TO GET AROUND THE COMPILER ERROR error: control reaches end of non-void function [-Werror=return-type]
}

User avatar
adafruit_support_carter
 
Posts: 24401
Joined: Tue Nov 29, 2016 2:45 pm

Re: QT PY SAMD21 compiler error after upgrade

Post by adafruit_support_carter »

What is the full code for the sketch that will not compile?

User avatar
jimk123
 
Posts: 426
Joined: Sun Dec 26, 2010 7:04 pm

Re: QT PY SAMD21 compiler error after upgrade

Post by jimk123 »

Code: Select all

// 10/4/21 used on boat to control the cooling fans where the batteries are

// https://www.sparkfun.com/products/18521  AS6212 temp sensor

// https://www.sparkfun.com/products/15093 Sparkfun qwiic relay to turn fans on/off

// used the Adafruit QT Py - SAMD21 Dev Board with STEMMA QT PRODUCT ID: 460
// https://www.adafruit.com/product/4600
// select board type as Adafruit QT PY (SAMD21)

// low threhold 65,  high threshold 70
// 6/21/22 changed the threholds to:
// low threhold 68,  high threshold 75

/******************************************************************************
  
  Example_05_Alert.ino
  Example for the SparkFun Digital Temperature Sensor Breakout - AS6212 (Qwiic)
  
    
  We will setup the temp sensor to watch for a high and low threshhold.
  Then the Alert will go ACTIVE LOW when we cross the uppder threshhold.
  We can cause this effect be breathing on the sensor.

  Then the Alert status will remain active low until we lower the temp and 
  cross the lower threshold.
  If you let the sensor sit in room temp, it should lower enough to cause this
  effect.
  
  This sort of setup would be useful if you didn't want to know the exact temp 
  all the time, but wanted to monitor the alert pin to see if the temp goes too hot.

******************************************************************************/

#include "SparkFun_AS6212_Qwiic.h"      //Click here to get the library: http://librarymanager/All#SparkFun_AS6212
#include <Wire.h>
#include <Adafruit_NeoPixel.h>

// create a pixel strand with 1 pixel on PIN_NEOPIXEL
Adafruit_NeoPixel pixels(1, PIN_NEOPIXEL);

AS6212 sensor;

#include "SparkFun_Qwiic_Relay.h"

#define RELAY_ADDR 0x18 // Alternate address 0x19


Qwiic_Relay relay(RELAY_ADDR); 
//Initialize temperature variables as floats
float tempC;
float tempF;
int tempLowThreshold = 68;
int tempHighThreshold = 75;
bool alertStatus;



void setup() 
{
  // red 255,0,0
// green 0,255,0
// blue 0,0,255
  pixels.begin();  // initialize the pixel
  pixels.setPixelColor(0, pixels.Color(0, 0, 255));  // BLUE at startup
  pixels.show();
  delay(2000);
    
//while(!Serial);  // use this on the QT PY board
  Serial.begin(115200);

  Serial.println("SparkFun AS6212 Qwiic Example 5 - Alert");

  Wire.begin();

  // Check to see if AS6212 Qwiic is present on the bus
  // Note, here we are calling begin() with no arguments = defaults (address:0x48, I2C-port:Wire)
  if (sensor.begin() == false)
  {
    Serial.println("AS6212 Qwiic failed to respond. Please check wiring and possibly the I2C address. Freezing...");
    while (1);
  };

  // check to see if the sensor might be in sleep mode (maybe from a previous arduino example)
  if (sensor.getSleepMode() == true)
  {
    Serial.println("Sensor was asleep, waking up now");
    sensor.sleepModeOff();
    delay(150); // wait for it to wake up
  }

  sensor.setDefaultSettings(); // return to default settings 
                               // in case they were set differenctly by a previous example

//  sensor.setTHighF(80); // set high threshhold ALERT ACTIVE alertstatus = 0
//  sensor.setTLowF(70); // set low threshhold  at 78 ALERT ACTIVE LOW cleared alertstatus = 1
//  Serial.print("\tThighF: ");  Serial.print(sensor.getTHighF(), 2);  Serial.print("\tTlowF: ");  Serial.println(sensor.getTLowF(), 2);
// ThighF: 78.80  TlowF: 69.80

//  sensor.setTHighF(75); // set high threshhold ALERT ACTIVE alertstatus = 0
//  sensor.setTLowF(70); // set low threshhold  at 78 ALERT ACTIVE LOW cleared alertstatus = 1
//  Serial.print("\tThighF: ");  Serial.print(sensor.getTHighF(), 2);  Serial.print("\tTlowF: ");  Serial.println(sensor.getTLowF(), 2);
// ThighF: 73.40  TlowF: 69.80


  sensor.setTHighF(tempHighThreshold); // set high threshhold ALERT ACTIVE alertstatus = 0
  sensor.setTLowF(tempLowThreshold); // set low threshhold  at 78 ALERT ACTIVE LOW cleared alertstatus = 1
  Serial.print("\tThighF: ");  Serial.print(sensor.getTHighF(), 2);  Serial.print("\tTlowF: ");  Serial.println(sensor.getTLowF(), 2);
// ThighF: 69.80  TlowF: 64.40





// noticed the qry showed:
// 20:26:17.881 -> SparkFun AS6212 Qwiic Example 5 - Alert
// 20:26:17.881 ->  ThighF: 82.40 TlowF: 78.80

// > 79 alertstatus = 0
// < 79 alertstatus = 1
//  the Alert will go ACTIVE LOW when we cross the uppder threshhold.
//  Then the Alert status will remain active low until we lower the temp and  cross the lower threshold.

  
  // Note, we could also set threshholds using the Celsius funtions like this:
  // sensor.setTHighC(27);
  // sensor.setTLowC(25);

  Serial.print("\tThighF: ");  Serial.print(sensor.getTHighF(), 2);  Serial.print("\tTlowF: ");  Serial.println(sensor.getTLowF(), 2);

  if(!relay.begin())
    Serial.println("Check connections to Qwiic Relay.");
  else
    Serial.println("Ready to flip some switches.");

  float version = relay.singleRelayVersion();
  Serial.print("Firmware Version: ");
  Serial.println(version);
  
  // Let's turn that relay off...
  relay.turnRelayOff(); 
  delay(1500);
}






void loop() {
  tempF = sensor.readTempF();
 alertStatus = sensor.getAlertStatus();

// when the temp is rising set the color to yellow one degree before the upper threhold ,
// just before it goes red
// onboard Neopixel values
// red 255,0,0
// green 0,255,0
// blue 0,0,255

  if ((tempF >= tempHighThreshold -1) && (tempF < tempHighThreshold ) && (alertStatus == 1))
    {
      Serial.println("YELLOW");
      pixels.setPixelColor(0, pixels.Color(255, 255, 0));  // yellow
      pixels.show();
      delay(1000);  // PAUSE FOR A FEW SECONDS AT YELLOW
      
    }

    
  //Serial.print("Temperature (°F): ");
  //Serial.print(tempF, 2);              //Reads out 6 characters of the temperature float

  //Serial.print("\talertStatus: ");
  //Serial.print(alertStatus);
  
// 65 - 70
    
  if (alertStatus == false) // be default alertStatus is active low
  {
    if (tempF > tempLowThreshold )
    {
      pixels.setPixelColor(0, pixels.Color(255, 0, 0));  // red
      pixels.show();
      //Serial.print("\tAlert ACTIVE");
      relay.turnRelayOn();
    }
  }
  else
  {
    if (tempF < tempLowThreshold )
    {
      pixels.setPixelColor(0, pixels.Color(0, 255, 0));  //green
      pixels.show();
      relay.turnRelayOff(); 
    }
  }

  Serial.println();
  delay(1000);
}

User avatar
adafruit_support_carter
 
Posts: 24401
Joined: Tue Nov 29, 2016 2:45 pm

Re: QT PY SAMD21 compiler error after upgrade

Post by adafruit_support_carter »

Thanks. Recreated the issue here. This is an error with the SparkFun AS6212 library. It's a somewhat benign error that was previously being ignored and only being flagged as a warning.

As of the 1.7.6 release of the Adafruit SAMD Board Support Package, a compiler check for return type has been enabled:
https://github.com/adafruit/ArduinoCore ... /tag/1.7.6
https://github.com/adafruit/ArduinoCore ... 633eda02f1

The getConversionCycleTime() function is suppose to return a uint16_t:
https://github.com/sparkfun/SparkFun_AS ... c.cpp#L343
However, if none of the conditionals are satisfied, it will reach the end the code block and return nothing. The compiler is seeing that and raising the error.

Unfortunately, it looks like issues are turned off for that repo:
https://github.com/sparkfun/SparkFun_AS ... no_Library
So not sure how to raise this with SparkFun. Could try a Pull Request maybe? Should be a fairly simple fix, potentially just one line of code.

Code: Select all

  // conversion rate value is stored in just 2 bits in the config reg,
  // so we must convert from stored values (0-3) to "human readable" values (125/250/1000/4000).
  if(cycleTime == AS6212_CONVERSION_CYCLE_TIME_125MS) return 125;
  if(cycleTime == AS6212_CONVERSION_CYCLE_TIME_250MS) return 250;
  if(cycleTime == AS6212_CONVERSION_CYCLE_TIME_1000MS) return 1000;
  if(cycleTime == AS6212_CONVERSION_CYCLE_TIME_4000MS) return 4000;
  return 0; //gotta return something
}

User avatar
jimk123
 
Posts: 426
Joined: Sun Dec 26, 2010 7:04 pm

Re: QT PY SAMD21 compiler error after upgrade

Post by jimk123 »

Thank you so much for digging into this and finding the root cause. That explains why it stopped compiling when I upgraded the SAMD boards on one of my windows machines. I appreciate you taking the time to debug this, I know it can be a gray area when boards from different manufacturers are involved. I opened a ticket with the sparkfun folks and hopefully they will update their library.
Thanks again !

Post Reply
Please be positive and constructive with your questions and comments.

Return to “Itsy Bitsy 32u4, M0, M4”