Arduino 3rd Party Libraries > Spark Libraries

Since I learned that I can’t just use (many? most?) existing 3rd party libraries from the Arduino IDE because of hardware differences (ARM <> Cortex), I thought it might be a good idea to create a thread where we can address this.

I saw some people are already working on some ports but this info is probably a bit scattered around the forum or we don’t even know about it. Maybe we can get of an exchange going here of which libraries are needed by people and who is possily developing them already or someone has tried a library and it’s working without a port? Unfortunately I can’t port anything but I can start by asking if any of the following libraries are already ported or work without a port…

Request:

1 Like

Perhaps the Spark team can create a forum category specifically for these ports? It would help keep things a little more organized.

I’m still trying to port a DHT11 library, but I’m still a bit of a noob at C. I can get my “port” to compile, but it doesn’t seem to work right in the real world. :-/

1 Like

I’d suggest (aka desperately needed :wink: ) RC-Switch

https://code.google.com/p/rc-switch/

Cheers,

Frido.

1 Like

Until the Spark team creates a workflow for this in the web IDE, here’s my recommendation. Use the forum—have one topic thread per library. Great idea @wgbartley—I just added a Libaries category. If there’s already a topic for the library you’re wondering about, keep posting there rather than creating a new topic. When you create a new topic, be sure the name of the library is in the topic title. As these topics grow, we can add a pinned topic that lists the libraries in progress and links to the topic for each.

@exposure I saw the system marked your message as spam—I’ve cleared that flag and bumped up your trust level.

Also @exposure, SPI is already built in, no #include necessary:
http://docs.spark.io/#/firmware/communication-spi

@exposure It’s not an “ARM<>Cortex” difference, since Cortex is a type of ARM processor. (The ARM Cortex-M3/M4 is a line of processors designed from the ground up to be low power, cool running and high speed, specifically for mobile devices.)

Traditionally, Arduino has always used AVR based chips from Atmel. The original used an ATmega128P, while the Uno had a 328P, the Leonardo used a surface mount ATmega32U4 that featured built-in USB! Even though all of these ran on the AVR platform, some sketches and libraries still required modifications to make them function on all of the various AVR chips used by different Arduino boards!

Then the Arduino Due came out, which used the SAM3X chip from Atmel, which was an ARM Cortex-M3! This required drastic changes to not only the Arduino IDE itself (which now had to include both an AVR compiler and the entire ARM toolchain) but also pretty much every sketch and library out there.

So it’s not just a difference in hardware, it’s also a difference in platforms. (All AVR based Arduino boards share the same platform even though the hardware is different. The Arduino Uno and Due are both different platforms and different hardware.)

Keep in mind there are many, many variations in the Arduino ecosystem, such as Energia (MSP430 and Tiva C [ARM Cortex] from Texas Insturments), chipKit (PIC Devices), Maple, Tiny and—now—Spark Core. Any sketch or library will work on these Arduino Compatible platforms, after being modified for any platform specific quirks.

The good news out of all of this is, since the Spark Core is using an ARM Cortex processor, it should be fairly easy to modify any existing sketch or library that currently works on the Arduino Due, Energia [Tiva C] or Maple boards.

Hopefully this clears some stuff up. Let me know if you’re confused on any of the specifics and I’ll be glad to try and explain it better. :smile:

@zachary I like the new Library category, that should be very helpful in the near future!

3 Likes

That's good to know! I have some TI Launchpads collecting dust and tinkered with Energia for a bit. I'm going to start including the term "energia" in my searches for library ports!

So far, I’ve found that Energia libraries are much, much easier to get working on the Spark Core than their Arduino counterparts. I think that’s partly because a good deal of them were Arduino libraries that were made more “platform neutral” when ported to Energia.

A good source of candidates for porting might be here: http://forum.43oh.com/forum/30-energia-libraries/

By the way, Energia just got an update with a ton of improvements. If you haven’t played with it in awhile you should really check it out!

1 Like

Exosite library would be useful

I really enjoying working around with the Spark Core. However, I ran into a situation where I need the Wifi.h class to be able to scan for networks. I tried to use Arduino IDE to import them and without success ran into this post and wanted to know if there are any plans to upload this Library (Wifi.h) to the Spark Cloud any time soon??

I saw that Network is available, but only gives me information of current connected network.

Thanks and keep up the great work.

Tim I find this interesting. I don’t know much about Energia but am extremely interested in porting some of these libraries and am also interested in creating some of my own.

However I am unsure how to do this using the Spark Core programming IDE (given it’s compiled in the cloud and then sent to the spark from the web). I think I am stuck on the basics (syntax of how to do this) and would appreciate you pointing me in the right direction, possibly even giving a small example. I’m not new to programming but just new to this environment.

In a nutshell, why is it that the classic Arduino libraries do not work on the Spark Core? I realize that it’s a different microcontroller, but is it because of the different resources available to to the chip or is it language differences?

Thanks for any help.
Pete

@peteA Good question! I’d be happy to help!

In a nutshell, Arduino is based on Wiring, which is a hardware extension to the Processing language. For the most part, Spark has the same basic functions as Arduino, however the differences come down the architectural differences between ATmega chips and the ARM Cortex used in the Core. As an example, a lot of Arduino sketches use PROGMEM to store arrays that we’d just put in a const unsigned char. Programming the Spark Core is more like normal C(++) programming than it is embedded programming (like the Arduino).

The real changes come in Arduino sketches that use commands outside of Wiring, like if they’re directly manipulating port registers to toggle pins high and low, or sketches that have been tuned to the basic Arduino’s 16MHz speed.

Previously, we’d copy the contents of the library’s .H and .CPP files into the top of the Web IDE, but as of yesterday the Web IDE now supports multiple files! So you can hit the little + button next to the sketch name in the top tab, which will add a .H and .CPP file, then just copy the contents of the Arduino Library’s .H and .CPP files in. Then you can try to compile your sketch and—if it fails—start making the required changes.

Is there a particular library you’re interested in porting? If so we can give you some help, that’s really the best way to learn. Also if you have any specific questions I’d be happy to try and answer them! :smiley:

3 Likes

Hi @a3electroniks,

Timb and BDub posted some code to do a Wifi scan for nearby networks here:

Thanks!
David

@Dave Thats exactly what I needed. Thanks

Hi Timb,
Great work BTW!
I am receiving an LSM303 carrier from Pololu which provide Arduino code. Within the LSM303 code, it specifies Arduino.h, math.h and wire.h
If I understand within Spark core firmware, wire is included and math, correct? What the heck do I do with Arduino.h? :smile:
Thanks!
Dup

Remove it! :smiley:

It’s not needed at all, as all the required equivalents are #included for you automagically.

(Arduino.h is basically a file that includes other standard libs and does stuff such as defining all the hardware specific functions for a particular board. I.e. If the board is an Uno, D1 maps to pin_register_73_subsector_alpha_quadrant_whiskey_tango_foxtrot; If the board is a Mega, D1 maps to pinSet72HFCS_qwerty_8==D.)

If you need any help with that controller, open a thread and @ tag me, I’ll be happy to help!

REMOVED!
Thanks timb, and thanks for the thread option for help!

1 Like