Pages: [1]   Go Down
Author Topic: Compiling on Linux vs Windows?  (Read 1134 times)
0 Members and 1 Guest are viewing this topic.
Cairns, Australia
Offline Offline
Sr. Member
****
Karma: 2
Posts: 280
Arduino??
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey all,

I have a AS3935 lightning sensor here I'm trying to interface with a Uno, but I keep getting errors trying to compile. It is this lib here: https://github.com/raivisr/AS3935-Arduino-Library

He states it works fine on 1.0.1, so I tried that, but still the same error. I emailed him, and he said that he compiled on Linux, and that maybe Windows is different.

The errors I'm getting are:

Code:
LightningDetector:48: error: 'AS3935' does not name a type
LightningDetector.pde: In function 'void setup()':
LightningDetector:64: error: 'AS3935' was not declared in this scope
LightningDetector.pde: In function 'void loop()':
LightningDetector:102: error: 'AS3935' was not declared in this scope
LightningDetector.pde: In function 'void printAS3935Registers()':
LightningDetector:130: error: 'AS3935' was not declared in this scope

In the example code:

Code:
/*
  LightningDetector.pde - AS3935 Franklin Lightning Sensor™ IC by AMS library demo code
  Copyright (c) 2012 Raivis Rengelis (raivis [at] rrkb.lv). All rights reserved.

  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 3 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.

  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

#include <SPI.h>
#include <AS3935.h>

void printAS3935Registers();

// Function prototype that provides SPI transfer and is passed to
// AS3935 to be used from within library, it is defined later in main sketch.
// That is up to user to deal with specific implementation of SPI
// Note that AS3935 library requires this function to have exactly this signature
// and it can not be member function of any C++ class, which happens
// to be almost any Arduino library
// Please make sure your implementation of choice does not deal with CS pin,
// library takes care about it on it's own
byte SPItransfer(byte sendByte);

// Iterrupt handler for AS3935 irqs
// and flag variable that indicates interrupt has been triggered
// Variables that get changed in interrupt routines need to be declared volatile
// otherwise compiler can optimize them away, assuming they never get changed
void AS3935Irq();
volatile int AS3935IrqTriggered;

// First parameter - SPI transfer function, second - Arduino pin used for CS
// and finally third argument - Arduino pin used for IRQ
// It is good idea to chose pin that has interrupts attached, that way one can use
// attachInterrupt in sketch to detect interrupt
// Library internally polls this pin when doing calibration, so being an interrupt pin
// is not a requirement
AS3935 AS3935(SPItransfer,SS,2);

void setup()
{
  Serial.begin(9600);
  // first begin, then set parameters
  SPI.begin();
  // NB! chip uses SPI MODE1
  SPI.setDataMode(SPI_MODE1);
  // NB! max SPI clock speed that chip supports is 2MHz,
  // but never use 500kHz, because that will cause interference
  // to lightning detection circuit
  SPI.setClockDivider(SPI_CLOCK_DIV16);
  // and chip is MSB first
  SPI.setBitOrder(MSBFIRST);
  // reset all internal register values to defaults
  AS3935.reset();
  // and run calibration
  // if lightning detector can not tune tank circuit to required tolerance,
  // calibration function will return false
  if(!AS3935.calibrate())
    Serial.println("Tuning out of range, check your wiring, your sensor and make sure physics laws have not changed!");

  // since this is demo code, we just go on minding our own business and ignore the fact that someone divided by zero

  // first let's turn on disturber indication and print some register values from AS3935
  // tell AS3935 we are indoors, for outdoors use setOutdoors() function
  AS3935.setIndoors();
  // turn on indication of distrubers, once you have AS3935 all tuned, you can turn those off with disableDisturbers()
  AS3935.enableDisturbers();
  printAS3935Registers();
  AS3935IrqTriggered = 0;
  // Using interrupts means you do not have to check for pin being set continiously, chip does that for you and
  // notifies your code
  // demo is written and tested on ChipKit MAX32, irq pin is connected to max32 pin 2, that corresponds to interrupt 1
  // look up what pins can be used as interrupts on your specific board and how pins map to int numbers

  // ChipKit Max32 - irq connected to pin 2
  attachInterrupt(1,AS3935Irq,RISING);
  // uncomment line below and comment out line above for Arduino Mega 2560, irq still connected to pin 2
  // attachInterrupt(0,AS3935Irq,RISING);
}

void loop()
{
  // here we go into loop checking if interrupt has been triggered, which kind of defeats
  // the whole purpose of interrupts, but in real life you could put your chip to sleep
  // and lower power consumption or do other nifty things
  if(AS3935IrqTriggered)
  {
    // reset the flag
    AS3935IrqTriggered = 0;
    // first step is to find out what caused interrupt
    // as soon as we read interrupt cause register, irq pin goes low
    int irqSource = AS3935.interruptSource();
    // returned value is bitmap field, bit 0 - noise level too high, bit 2 - disturber detected, and finally bit 3 - lightning!
    if (irqSource & 0b0001)
      Serial.println("Noise level too high, try adjusting noise floor");
    if (irqSource & 0b0100)
      Serial.println("Disturber detected");
    if (irqSource & 0b1000)
    {
      // need to find how far that lightning stroke, function returns approximate distance in kilometers,
      // where value 1 represents storm in detector's near victinity, and 63 - very distant, out of range stroke
      // everything in between is just distance in kilometers
      int strokeDistance = AS3935.lightningDistanceKm();
      if (strokeDistance == 1)
        Serial.println("Storm overhead, watch out!");
      if (strokeDistance == 63)
        Serial.println("Out of range lightning detected.");
      if (strokeDistance < 63 && strokeDistance > 1)
      {
        Serial.print("Lightning detected ");
        Serial.print(strokeDistance,DEC);
        Serial.println(" kilometers away.");
      }
    }
  }
}

void printAS3935Registers()
{
  int noiseFloor = AS3935.getNoiseFloor();
  int spikeRejection = AS3935.getSpikeRejection();
  int watchdogThreshold = AS3935.getWatchdogThreshold();
  Serial.print("Noise floor is: ");
  Serial.println(noiseFloor,DEC);
  Serial.print("Spike rejection is: ");
  Serial.println(spikeRejection,DEC);
  Serial.print("Watchdog threshold is: ");
  Serial.println(watchdogThreshold,DEC); 
}

// this is implementation of SPI transfer that gets passed to AS3935
// you can (hopefully) wrap any SPI implementation in this
byte SPItransfer(byte sendByte)
{
  return SPI.transfer(sendByte);
}

// this is irq handler for AS3935 interrupts, has to return void and take no arguments
// always make code in interrupt handlers fast and short
void AS3935Irq()
{
  AS3935IrqTriggered = 1;
}

Is there any difference in compiling in Windows vs Linux in regards to these errors?

Regards,
Dan
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48556
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Is there any difference in compiling in Windows vs Linux in regards to these errors?
No. If you don't download and install the library in the correct place, compilation will fail in the same way on both operating systems.
Logged

Cairns, Australia
Offline Offline
Sr. Member
****
Karma: 2
Posts: 280
Arduino??
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Library was downloaded, extracted and placed in the libraries folder, I don't remember having to do anything else, unless it's changed in the new Arduino. It appears in the Open dropdown list
« Last Edit: December 19, 2012, 06:16:23 am by Things » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48556
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I downloaded the library, unzipped it properly, and started the IDE (1.0.1), in Win7/64. I pasted your code, and hit Verify. I'll leave it as an exercise for you to resolve this "error" message:
Quote
Binary sketch size: 5,052 bytes (of a 30,720 byte maximum)
Logged

Cairns, Australia
Offline Offline
Sr. Member
****
Karma: 2
Posts: 280
Arduino??
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Just redownloaded the Arduino IDE, re-extracted the library into the libraries folder and still get the same errors. I have no idea.

EDIT: Bah, looks like Windows was to blame .. once again.
« Last Edit: December 19, 2012, 07:11:10 am by Things » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48556
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
re-extracted the library into the libraries folder
Which libraries folder? The one in the Arduino core folder or the one (the correct one) in your sketch directory?
Logged

Cairns, Australia
Offline Offline
Sr. Member
****
Karma: 2
Posts: 280
Arduino??
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorry, restarting somehow managed to fix it. No idea what was going on there. Thanks for checking it out for me.
Logged

New Jersey
Online Online
Faraday Member
**
Karma: 65
Posts: 3643
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

After installing a new library, you need to restart the IDE - may have been the problem?
Logged

Cairns, Australia
Offline Offline
Sr. Member
****
Karma: 2
Posts: 280
Arduino??
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yeah, I did restart the IDE, apparently the whole computer wanted a restart too smiley-grin
Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 47
I'm glad I bought an Arduino Leonardo
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Your new library is the github folder "AS3935" copy that folder with all the files and examples folder.
in the arduino install folder "xxx\arduino-1.0.x\libraries" make sure its "libraries" NOT "lib".


FYI:After install I used the example sketch and it verified fine on win7 64-bit, Arduino 1.0.2
« Last Edit: December 19, 2012, 07:49:18 am by S_Flex » Logged

Gosport, UK
Offline Offline
Faraday Member
**
Karma: 21
Posts: 3113
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Your new library is the github folder "AS3935" copy that folder with all the files and examples folder.
in the arduino install folder "xxx\arduino-1.0.x\libraries" make sure its "libraries" NOT "lib".


FYI:After install I used the example sketch and it verified fine on win7 64-bit, Arduino 1.0.2

That's not the correct place for third-party libraries. They should go, as PaulS said, in the libraries subdirectory of your sketchbook directory. If you don't know the location of the sketchbook directory, look in preferences.
Logged

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12579
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That's not the correct place for third-party libraries. They should go, as PaulS said, in the libraries subdirectory of your sketchbook directory.

Just out of curiosity, what's the reasoning behind this advice?

Given that 3rd party libraries have, in the past, been Arduino-version-specific, doesn't it make more sense to keep the libraries within the relevant Arduino installation? By my understanding they behave the same in either case and it's just a question of whether you want to be able to upgrade the IDE and keep using the same copy of all the 3rd party libraries, or [need to] install a separate copy for each IDE version.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48556
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Given that 3rd party libraries have, in the past, been Arduino-version-specific
There were major changes needed between 0023 and 1.0.0, but relatively few between releases up to 0023 and relatively few needed between post 1.0.0 releases.

One could copy all the non-core libraries from the Arduino 1.0.x libraries folder to the 1.0.y libraries folder, if one is careful NOT to overwrite any Arduino-supplied (core) library files.

That it is too easy to screw up is why the recommendation is to NOT put user-downloaded libraries in with core libraries.
Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 47
I'm glad I bought an Arduino Leonardo
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That's not the correct place for third-party libraries. They should go, as PaulS said, in the libraries subdirectory of your sketchbook directory.

Just out of curiosity, what's the reasoning behind this advice?

Given that 3rd party libraries have, in the past, been Arduino-version-specific, doesn't it make more sense to keep the libraries within the relevant Arduino installation? By my understanding they behave the same in either case and it's just a question of whether you want to be able to upgrade the IDE and keep using the same copy of all the 3rd party libraries, or [need to] install a separate copy for each IDE version.

Well I was thinking there should be an add-on library, but didnt know where it was.
Logged

Pages: [1]   Go Up
Jump to: