Robot-Will / Stino

A Sublime Text Plugin for Arduino
Other
1.58k stars 250 forks source link

How to use libraries? #15

Closed stibi closed 11 years ago

stibi commented 11 years ago

Hello, I'd like to ask, how to use libraries for Arduino with Stino? I have this problem with "OneWire" library, which I need for DS18B20 temperature sensor. Let's take a example source code from http://www.pjrc.com/teensy/td_libs_OneWire.html. I have the library in "sketchbook/libraries/", when I try to compile in Stino, it fails:

/home/stibi/Arduino_Build/simple_temperature/simple_temperature.cpp.o: In function `setup':
/home/stibi/Arduino_Build/simple_temperature/simple_temperature.cpp:13: undefined reference to `OneWire::OneWire(unsigned char)'
/home/stibi/Arduino_Build/simple_temperature/simple_temperature.cpp:14: undefined reference to `OneWire::search(unsigned char*)'
/home/stibi/Arduino_Build/simple_temperature/simple_temperature.cpp:14: undefined reference to `OneWire::reset_search()'
/home/stibi/Arduino_Build/simple_temperature/simple_temperature.cpp:14: undefined reference to `OneWire::crc8(unsigned char const*, unsigned char)'

...etc...

I thought I have to tell Stino where it can find the OneWire library, Via "Add extra flags": -I/home/stibi/Development/Arduino/sketchbook/libraries/OneWire/ Btw, is it correct?

Unfortunately, it doesn't work. What I have missing there?

stibi commented 11 years ago

Now I have verbose compilation output from Arduino IDE and from Stino to compare, so I guess there is possible to find out what is the problem...

Robot-Will commented 11 years ago

Let me find out the reason. No need to add -I manually.

Robot-Will commented 11 years ago

I downloaded the zip file and extracted to sketchbook libraries folder (E:\Documents\Arduino\libraries), in E:\Documents\Arduino\libraries\OneWire, there are some files: [examples] OneWire.cpp OneWire.h keywords.txt

Restart ST2, and you will find OneWire in Import Library... menu, and it's ready for use.

Gathering compilation infomation... Compiling sketch... Cleaning... Creating E:/Documents/Arduino_Build/Blink/Blink.cpp.o... Creating E:/Documents/Arduino_Build/Blink/CDC.cpp.o... Creating E:/Documents/Arduino_Build/Blink/HardwareSerial.cpp.o... Creating E:/Documents/Arduino_Build/Blink/HID.cpp.o... Creating E:/Documents/Arduino_Build/Blink/IPAddress.cpp.o... Creating E:/Documents/Arduino_Build/Blink/main.cpp.o... Creating E:/Documents/Arduino_Build/Blink/malloc.c.o... Creating E:/Documents/Arduino_Build/Blink/new.cpp.o... Creating E:/Documents/Arduino_Build/Blink/Print.cpp.o... Creating E:/Documents/Arduino_Build/Blink/Stream.cpp.o... Creating E:/Documents/Arduino_Build/Blink/Tone.cpp.o... Creating E:/Documents/Arduino_Build/Blink/USBCore.cpp.o... Creating E:/Documents/Arduino_Build/Blink/WInterrupts.c.o... Creating E:/Documents/Arduino_Build/Blink/wiring.c.o... Creating E:/Documents/Arduino_Build/Blink/wiring_analog.c.o... Creating E:/Documents/Arduino_Build/Blink/wiring_digital.c.o... Creating E:/Documents/Arduino_Build/Blink/wiring_pulse.c.o... Creating E:/Documents/Arduino_Build/Blink/wiring_shift.c.o... Creating E:/Documents/Arduino_Build/Blink/WMath.cpp.o... Creating E:/Documents/Arduino_Build/Blink/WString.cpp.o... Creating E:/Documents/Arduino_Build/Blink/OneWire.cpp.o... Creating E:/Documents/Arduino_Build/Blink/core.a... Creating E:/Documents/Arduino_Build/Blink/Blink.elf... Creating E:/Documents/Arduino_Build/Blink/Blink.eep... Creating E:/Documents/Arduino_Build/Blink/Blink.hex... Binary sketch size: 4,826 bytes (of a 28,672 byte maximum, 16.83%). Estimated memory use: 157 bytes (of a 2,560 byte maximum, 6.13%). [Stino - Done compiling.]

Robot-Will commented 11 years ago

For the example in OneWire: DS18x20_Temperature

Gathering compilation infomation... Compiling sketch... Cleaning... Creating E:/Documents/Arduino_Build/DS18x20_Temperature/DS18x20_Temperature.cpp.o... Creating E:/Documents/Arduino_Build/DS18x20_Temperature/CDC.cpp.o... Creating E:/Documents/Arduino_Build/DS18x20_Temperature/HardwareSerial.cpp.o... Creating E:/Documents/Arduino_Build/DS18x20_Temperature/HID.cpp.o... Creating E:/Documents/Arduino_Build/DS18x20_Temperature/IPAddress.cpp.o... Creating E:/Documents/Arduino_Build/DS18x20_Temperature/main.cpp.o... Creating E:/Documents/Arduino_Build/DS18x20_Temperature/malloc.c.o... Creating E:/Documents/Arduino_Build/DS18x20_Temperature/new.cpp.o... Creating E:/Documents/Arduino_Build/DS18x20_Temperature/Print.cpp.o... Creating E:/Documents/Arduino_Build/DS18x20_Temperature/Stream.cpp.o... Creating E:/Documents/Arduino_Build/DS18x20_Temperature/Tone.cpp.o... Creating E:/Documents/Arduino_Build/DS18x20_Temperature/USBCore.cpp.o... Creating E:/Documents/Arduino_Build/DS18x20_Temperature/WInterrupts.c.o... Creating E:/Documents/Arduino_Build/DS18x20_Temperature/wiring.c.o... Creating E:/Documents/Arduino_Build/DS18x20_Temperature/wiring_analog.c.o... Creating E:/Documents/Arduino_Build/DS18x20_Temperature/wiring_digital.c.o... Creating E:/Documents/Arduino_Build/DS18x20_Temperature/wiring_pulse.c.o... Creating E:/Documents/Arduino_Build/DS18x20_Temperature/wiring_shift.c.o... Creating E:/Documents/Arduino_Build/DS18x20_Temperature/WMath.cpp.o... Creating E:/Documents/Arduino_Build/DS18x20_Temperature/WString.cpp.o... Creating E:/Documents/Arduino_Build/DS18x20_Temperature/OneWire.cpp.o... Creating E:/Documents/Arduino_Build/DS18x20_Temperature/core.a... Creating E:/Documents/Arduino_Build/DS18x20_Temperature/DS18x20_Temperature.elf... Creating E:/Documents/Arduino_Build/DS18x20_Temperature/DS18x20_Temperature.eep... Creating E:/Documents/Arduino_Build/DS18x20_Temperature/DS18x20_Temperature.hex... Binary sketch size: 9,048 bytes (of a 28,672 byte maximum, 31.56%). Estimated memory use: 373 bytes (of a 2,560 byte maximum, 14.57%). [Stino - Done compiling.]

stibi commented 11 years ago

Thanks for the reponse. I don't understand why it just doesn't work for me. Still "undefined reference to `OneWire::OneWire(unsigned char)'" .. The library is definitelly linked there, but something is still wrong. I'm out of ideas now.

stibi commented 11 years ago

Oookey but the "DS18x20_Temperature" example project from OneWire library is compiled without problems... So the problem is definitely on my side, in my project. I'll let you know once I find out the problem.

stibi commented 11 years ago

Ok so I created a brand new sketch, added OneWire library, write a piece of code and compiled, so far so good, no error. Then I added also LiquidCrystal.h library because I need to use LCD display and at this point it failed - this time with "undefined reference to `LiquidCrystal::begin(unsigned char, unsigned char, unsigned char)'". So, when these two libraries are used - there is the problem. I haven't tried any other libraries combinations, so hard to say if only these two are affected or what. Does it ring any bell?

Robot-Will commented 11 years ago

I copied two examples into one file:

#include <LiquidCrystal.h>

#include <OneWire.h>

OneWire  ds(10);  // on pin 10 (a 4.7K resistor is necessary)
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  Serial.begin(9600);
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("hello, world!");
}

void loop() {
  byte i;
  byte present = 0;
  byte type_s;
  byte data[12];
  byte addr[8];
  float celsius, fahrenheit;

  if ( !ds.search(addr)) {
    Serial.println("No more addresses.");
    Serial.println();
    ds.reset_search();
    delay(250);
    return;
  }

  Serial.print("ROM =");
  for( i = 0; i < 8; i++) {
    Serial.write(' ');
    Serial.print(addr[i], HEX);
  }

  if (OneWire::crc8(addr, 7) != addr[7]) {
      Serial.println("CRC is not valid!");
      return;
  }
  Serial.println();

  // the first ROM byte indicates which chip
  switch (addr[0]) {
    case 0x10:
      Serial.println("  Chip = DS18S20");  // or old DS1820
      type_s = 1;
      break;
    case 0x28:
      Serial.println("  Chip = DS18B20");
      type_s = 0;
      break;
    case 0x22:
      Serial.println("  Chip = DS1822");
      type_s = 0;
      break;
    default:
      Serial.println("Device is not a DS18x20 family device.");
      return;
  } 

  ds.reset();
  ds.select(addr);
  ds.write(0x44, 1);        // start conversion, with parasite power on at the end

  delay(1000);     // maybe 750ms is enough, maybe not
  // we might do a ds.depower() here, but the reset will take care of it.

  present = ds.reset();
  ds.select(addr);    
  ds.write(0xBE);         // Read Scratchpad

  Serial.print("  Data = ");
  Serial.print(present, HEX);
  Serial.print(" ");
  for ( i = 0; i < 9; i++) {           // we need 9 bytes
    data[i] = ds.read();
    Serial.print(data[i], HEX);
    Serial.print(" ");
  }
  Serial.print(" CRC=");
  Serial.print(OneWire::crc8(data, 8), HEX);
  Serial.println();

  // Convert the data to actual temperature
  // because the result is a 16 bit signed integer, it should
  // be stored to an "int16_t" type, which is always 16 bits
  // even when compiled on a 32 bit processor.
  int16_t raw = (data[1] << 8) | data[0];
  if (type_s) {
    raw = raw << 3; // 9 bit resolution default
    if (data[7] == 0x10) {
      // "count remain" gives full 12 bit resolution
      raw = (raw & 0xFFF0) + 12 - data[6];
    }
  } else {
    byte cfg = (data[4] & 0x60);
    // at lower res, the low bits are undefined, so let's zero them
    if (cfg == 0x00) raw = raw & ~7;  // 9 bit resolution, 93.75 ms
    else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms
    else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms
    //// default is 12 bit resolution, 750 ms conversion time
  }
  celsius = (float)raw / 16.0;
  fahrenheit = celsius * 1.8 + 32.0;
  Serial.print("  Temperature = ");
  Serial.print(celsius);
  Serial.print(" Celsius, ");
  Serial.print(fahrenheit);
  Serial.println(" Fahrenheit");

  // Turn off the display:
  lcd.noDisplay();
  delay(500);
   // Turn on the display:
  lcd.display();
  delay(500);
}

Compilation had no error.

Gathering compilation infomation... Compiling sketch... Cleaning... Creating E:/Documents/Arduino_Build/testOneWire/testOneWire.cpp.o... Creating E:/Documents/Arduino_Build/testOneWire/CDC.cpp.o... Creating E:/Documents/Arduino_Build/testOneWire/HardwareSerial.cpp.o... Creating E:/Documents/Arduino_Build/testOneWire/HID.cpp.o... Creating E:/Documents/Arduino_Build/testOneWire/IPAddress.cpp.o... Creating E:/Documents/Arduino_Build/testOneWire/main.cpp.o... Creating E:/Documents/Arduino_Build/testOneWire/malloc.c.o... Creating E:/Documents/Arduino_Build/testOneWire/new.cpp.o... Creating E:/Documents/Arduino_Build/testOneWire/Print.cpp.o... Creating E:/Documents/Arduino_Build/testOneWire/Stream.cpp.o... Creating E:/Documents/Arduino_Build/testOneWire/Tone.cpp.o... Creating E:/Documents/Arduino_Build/testOneWire/USBCore.cpp.o... Creating E:/Documents/Arduino_Build/testOneWire/WInterrupts.c.o... Creating E:/Documents/Arduino_Build/testOneWire/wiring.c.o... Creating E:/Documents/Arduino_Build/testOneWire/wiring_analog.c.o... Creating E:/Documents/Arduino_Build/testOneWire/wiring_digital.c.o... Creating E:/Documents/Arduino_Build/testOneWire/wiring_pulse.c.o... Creating E:/Documents/Arduino_Build/testOneWire/wiring_shift.c.o... Creating E:/Documents/Arduino_Build/testOneWire/WMath.cpp.o... Creating E:/Documents/Arduino_Build/testOneWire/WString.cpp.o... Creating E:/Documents/Arduino_Build/testOneWire/LiquidCrystal.cpp.o... Creating E:/Documents/Arduino_Build/testOneWire/OneWire.cpp.o... Creating E:/Documents/Arduino_Build/testOneWire/core.a... Creating E:/Documents/Arduino_Build/testOneWire/testOneWire.elf... Creating E:/Documents/Arduino_Build/testOneWire/testOneWire.eep... Creating E:/Documents/Arduino_Build/testOneWire/testOneWire.hex... Binary sketch size: 9,716 bytes (of a 258,048 byte maximum, 3.77%). Estimated memory use: 966 bytes (of a 8,196 byte maximum, 11.79%). [Stino - Done compiling.]

I can't repeat your problem, and would you like send to me a copy of your source code that I can repeat the error? Or try the newest plugin to see whether the error still here? I update the plugin everyday.

stibi commented 11 years ago

Hi, sure, I'll try later today, once I get back to home. Thanks for help!

zdennis commented 11 years ago

I have the same problem at @stibi. I cannot get anything to compile via ST2 that uses libraries. They compile fine with Arduino IDE though.

hermanschutte commented 11 years ago

I had the same problem using Bounce and EEPROM libraries in an existing sketch. If I create a new sketch, copy the code from the old sketch and compile it works.

Robot-Will commented 11 years ago

Sorry about this problem. These days I am busy, but I will think about this problem. Thanks a lot.

ironstrider commented 11 years ago

This was recommended to me by a colleague, and I thought it was wonderful that I could use Sublime for Arduino, but not being able to compile libraries would functionally cripple me, so this is unfortunately a deal breaker for me.

Robot-Will commented 11 years ago

:), I will fix this problem. But I need some time. I am learning Arduino now.

gschora commented 11 years ago

Any news on this issue? because I'm having trouble using chibios with the adafruit ads1015 library. If I'm writing a sketch using only the ads1015 library everything works normal and compiles, adding chibios to that sketch, compiling stops with an error "undefined reference to Adafruit_ADS1015".

I also had the same issue with the wire library, but restarting ST2 worked, but not for the Adafruit lib. Just for information: I keep my libraries in the arduino IDE application folder...

And please keep up the great work, I really love this plugin :-)

gschora commented 11 years ago

I have found one solution to the problem, don't know if it works for everyone but I'm posting it anyway :-)

If you accidently press the combination ctrl-alt-f (on Windows) you will trigger a reformat of the code. The problem is that now the code has whitespaces where there shouldn't any: # include < ST7565.h > instead of #include <ST7565.h>

So I removed the whitespaces and everything worked fine. Hope that helps someone.

simonbarker commented 11 years ago

I'm finding that the best way to fix errors when using external libraries is to manually delete the file created in the Arduino Build directory for the project - this forces the compiler to recompile all the files and not just the top level .ino etc. Maybe this could be built into the build process automatically? I think it's what MPLAB8 for PIC used to do

JohanBas commented 11 years ago

Selecting "Arduino" > "Preferences" > "Full Compilation" solved my problem.

dogmatic69 commented 11 years ago

I have installed this and was quite happy to find an alternative to the Arduino IDE, until I got this problem. Simple code compiles in Arduino IDE and not in Sublime...

/**
 * Main OpenVape sketch
 *
 */
#include <Wire.h>
#include <I2Cdev.h>
#include <AD7746.h>

void setup() {

}

void loop() {

}

This problem makes the plugin pretty much useless :cry:

Robot-Will commented 11 years ago

I am sorry about it. Currently I am rewriting this plugin for ST3 and this version plugin will not be revised. Sorry.

chriddyp commented 10 years ago

@JohanBas +1 """ Selecting "Arduino" > "Preferences" > "Full Compilation" solved my problem. """

matthova commented 10 years ago

Ditto. Thanks @JohanBas! That worked

ericbenwa commented 10 years ago

@JohanBas @Robot-Will Enabling "Full Compilation" didn't work for me. Using ST3 and Arduino 1.0.2.

This is what I see...

/Applications/Arduino.app/Contents/Resources/Java/libraries/SoftwareSerial/SoftwareSerial.cpp: In member function 'void SoftwareSerial::begin(long int)':
/Applications/Arduino.app/Contents/Resources/Java/libraries/SoftwareSerial/SoftwareSerial.cpp:396: error: 'PCICR' was not declared in this scope
/Applications/Arduino.app/Contents/Resources/Java/libraries/SoftwareSerial/SoftwareSerial.cpp:399: error: 'PCMSK2' was not declared in this scope
/Applications/Arduino.app/Contents/Resources/Java/libraries/SoftwareSerial/SoftwareSerial.cpp:399: error: 'PCMSK0' was not declared in this scope
/Applications/Arduino.app/Contents/Resources/Java/libraries/SoftwareSerial/SoftwareSerial.cpp:399: error: 'PCMSK1' was not declared in this scope
/Applications/Arduino.app/Contents/Resources/Java/libraries/SoftwareSerial/SoftwareSerial.cpp: In member function 'void SoftwareSerial::end()':
/Applications/Arduino.app/Contents/Resources/Java/libraries/SoftwareSerial/SoftwareSerial.cpp:414: error: 'PCMSK2' was not declared in this scope
/Applications/Arduino.app/Contents/Resources/Java/libraries/SoftwareSerial/SoftwareSerial.cpp:414: error: 'PCMSK0' was not declared in this scope
/Applications/Arduino.app/Contents/Resources/Java/libraries/SoftwareSerial/SoftwareSerial.cpp:414: error: 'PCMSK1' was not declared in this scope
[Stino - Error 1]

When trying

#include "SoftwareSerial.h"

Any thoughts?

matthova commented 10 years ago

I realized that renaming my file is what started the issues for me. I have to put the new file in its own folder of the same name. Doing this and selecting "Full Compilation" has gotten rid of all of my issues with Stino.

ericbenwa commented 10 years ago

I'm still seeing errors.

This is what I'm doing: • 'Full Compilation' checked • Create new arduino .ino file, 'testing.ino' • Save this file in the Arduino directory, inside a folder with same name as .ino file, /Arduino/testing/testing.ino • Click 'Verify/Compile'

My .ino file looks like:

#include "SoftwareSerial.h"
void setup() { }
void loop() { }

What am I screwing up?

bveenema commented 10 years ago

I'm having the same issue with the SoftwareSerial library. Has there been any resolution on this?

bveenema commented 10 years ago

I realized I didn't have a board selected, and when I selected the uno board it was able to compile the SoftwareSerial library.

ghost commented 10 years ago

I'm using teensy 3.1 with these libraries: EEPROM.h Audio.h Bounce.h Wire.h SD.h

Lots of errors when compiling these libraries wit stino, none using Arduino IDE

KATT commented 10 years ago

Got the same problem as @ericbenwa and @bveenema. If anyone finds a solution to it, please let me know.

fdellavedova-zz commented 10 years ago

Same problem here... ant the 'full compilation' option doesn't seem to be available anymore/in linux

Arielhh commented 10 years ago

same problem with OSX

devicee commented 10 years ago

I can confirm the same problem in Ubuntu 14.04.1. Is there any solution so far related to it? I tried it in Sublime 2 and 3, same bug! Thank you.

hosaka commented 9 years ago

Same issue here, seem to be missing quite a lot, trying to add SoftwareSerial.h.

avenantsoftware commented 9 years ago

I have the same problem on OSX Yosemite but with a different library, the plotly library https://github.com/plotly/arduino-api

errors:

/tmp/Stino_build/Domotica/Domotica.ino.cpp.o: In function __static_initialization_and_destruction_0': /Users/htpc/Documents/Arduino/Domotica/Domotica.ino:182: undefined reference toplotly::plotly(char, char, char*, char, int)' /tmp/Stinobuild/Domotica/Domotica.ino.cpp.o: In function loop': /Users/htpc/Documents/Arduino/Domotica/Domotica.ino:2588: undefined reference toplotly::plot(unsigned long, float, char)' /Users/htpc/Documents/Arduino/Domotica/Domotica.ino:2589: undefined reference to plotly::plot(unsigned long, float, char_)' /tmp/Stino_build/Domotica/Domotica.ino.cpp.o: In functionsetup': /Users/htpc/Documents/Arduino/Domotica/Domotica.ino:2475: undefined reference toplotly::init()' /Users/htpc/Documents/Arduino/Domotica/Domotica.ino:2476: undefined reference toplotly::openStream()'

avenantsoftware commented 9 years ago

I was able to fix it, the library has several libraries in 1 folder, I moved the folder: plotly_streaming_ethernet from the main folder into the arduino library folder as a seperate library and then it worked, it showed up in stino as imported library, no more compile errors.., also when getting the code from github it had the folder name arduino-api, arduino doesn't like it when there is a "-" in a library folder name, maybe others have a "-" in their folder name? the original arduino program also didn't see the library folder when it was named: "arduino-api", so i renamed it to "Plotly" then the original arduino program was able to see the library

phoenixperry commented 9 years ago

Same problem. I'm trying to use the Bare Conductive Board and it hangs on the two libraries it needs

#include <MPR121.h> #include <Wire.h>

reconlap commented 9 years ago

I had this issue to start with as well, I was compiling a .ino that was linking to a library on xUbuntu 14.03

#include AccelStepper.h

and was causing the error

ino:33:26: fatal error: AccelStepper.h: No such file or directory

I could compile in arduino IDE without issue. after a bit of checking I noticed I have the library was installed to the user directory

sketchbook/libraries/AccelStepper/

so I created a link from the arduino system library directory to the sketchbook AccelStepper directory.

/usr/share/arduino/libraries/AccelStepper -> /home/user1/sketchbook/libraries/AccelStepper/

then updated the menus in stino and the library now appeared in the "Arduino->Import Libraries" list. I imported it and it was added to the build.

Hope this helps.

adriancuervo commented 9 years ago

#Solved on osx . Put the libraries on: /Applications/Arduino.app/Contents/Java/libraries Is not the cleanest way, but works. Steps: Right click on Arduino app, "Show content..."