Rosetta Stone for people familiar with Arduino?

Hello, I just opened my Spark Core and connected it to the network. Well done! I’m really happy with how easily that went.

Next, I tried copy/pasting the library for an I2C gyro into the spark editor. I get errors that seem really basic, which indicates to me that I’m missing something simple or misunderstanding how this should work. For example, the https://github.com/pololu/l3g-arduino library uses an “#include <Arduino.h>” in it. But that library can’t be found. Same with “#include <Wire.h>” which is a standard I2C library for Arduino. What am I missing?

I guess the overall question is, is there a Rosetta Stone type of instructional page for people like me who are familiar with Arduino, but not the web-based spark editor?

Hi there @canadaduane , great question!

Have you seen this post:

this should help you dig in and see if the lib you're trying to use will work in the Spark Core context.

Regarding wire.h + wire.cpp, you definitely don't want to include that, those include platform dependent elements not designed for the micro-controller on the Spark Core. Working "Wire" functions are available within your firmware without including anything and are documented on our core firmware reference docs:

@canadaduane: You can safely remove the “#include <Arduino.h>” line, as it’s only necessary for libraries - it’s automatically imported in sketches, which is what you’re effectively creating in the Spark web IDE.

I just started trying to get an I2C device working with the Spark core, and have run into the same problem with Wire.h not existing. I’ve seen some documentation indicating that the basic Arduino libraries have all been ported, so I’m not sure what I’ve done wrong. Is there another way to use I2C devices on the core?

Not quite, I guess.

As for Arduino sketches, you’d tell the compiler/linker which libraries out your repository you’d need for this sketch to build by using #include “[NeededLibX].h”;
But at the moment the Spark Core IDE does only support libs that are already present in the firmware, hence there is no need for #include, yet.

But I guess and hope this will change in future, when Spark creates a public lib repository to contribute and reuse libs without having to squeeze every kind of thinkable lib into the Cores firmware - there is only limited store space on board, after all.

This thread brings up some major deficiencies.

  1. If I can’t import sketches from my Arduino IDE, then is SparkCore really Arduino compatible? When will we be able to import working Arduino code into the Spark world if ever?
  2. I’m trying to bring over a simple library and the hack of copying and pasting into one giant non-searchable text pad seriously sucks. When will you have a real IDE?

It would be really useful to have a guide for porting code over from Arduino and a real IDE. Thanks. My core is going back into its box for a while and I got it today, but the blinking LED is nice, thanks.

@jgc94131 while you can't currently import sketches from the Arduino IDE (as far as I know), you can certainly port Arduino code to be used on your cores.

This post in particular, which was linked to earlier within this thread, describes it well.

If you look at the library .h and .cpp files, and it is platform independent, then you can just paste them into Spark Build

The platform independent part is key. You won't be able to simply port code written for very specific architectures (which you'd have a hard time porting to any other hardware, not just the Spark Core). But code that was written and intended to be used on all Arduino based devises should, in theory, port without changes.

I agree with you - not being able to just migrate an Arduino project and having to copy and paste isn't ideal. But those two minor bits of friction aren't going to stop me from making neat things with this very clever piece of hardware.

2 Likes

Hi @jgc94131,

Not sure if you’ve seen the core firmware docs http://docs.spark.io/#/firmware, but you can definitely run arduino compatible code on the core.

Also you certainly aren’t required to use the web IDE. You can write code in any environment you feel most comfortable in, and you can even compile binaries on your system if you prefer. You can flash whole binaries over the air using our API ( http://docs.spark.io/#/api/verifing-and-flashing-new-firmware-flash-a-core-with-a-pre-compiled-binary ).

If you want to develop locally in your preferred environment, the https://github.com/spark/core-firmware repository has a guide on getting it setup.

The build server does support multiple source files, but we’re working on letting the API more easily accept multiple source files at once. I’d love to see someone setup a Heroku style git hook that compiles / flashes on pushes.

It’s really exciting to see the cool stuff people are already building (smart roombas, project notifiers, door openers, etc), and I’m sure as more people build cool stuff, there will be better and better examples and tutorials :smile:

Thanks,
David

Thanks! This is just what I was looking for.

1 Like

Hi, I am just getting started with this and was wondering, is there anyway to access the serial monitor over curl/wifi without a webserver?

I am basically looking for the simplest way to read output out of it!

Hey @kidrock - check out our TCP functions, which let you open a TCP socket and chatter in a Serial-like way:

http://docs.spark.io/#/firmware/communication-tcpclient

Hi @zach, thanks, will give that a looksee!

I was playing around with the IDE, but I am not finding it a bit challenging to use the DHT arduino lib.

Is there any documentation of the datatypes supported by the IDE?

Hey @kidrock! Any data types supported by Arduino/C++ are also supported by our IDE. For a quick reference, you can visit Arduino’s data type reference. Does that help answer your question, or did I misunderstand what you meant by “datatypes”?

Just wanted to mention that this problem isn’t limited to the Spark Core, you have similar issues with the Arduino Due (which is ARM based) coming from the AVR based devices.

If you look at a well written library, it will have if statements that define various Arduino platforms (Uno, Mega, Leonardo, Due, etc.) since they’re all based on different chips and even—in the Due’s case—different architectures. I’ve seen some sketches/libs that will compile on an Uno but not on a Leonardo due to differences in the hardware, even though they’re the same architecture (AVR).

Even better libraries will actually support entirely different platforms! Arduino, chipKit, Energia, Maple and, hopefully soon, Spark Core!

I have a hard time porting other people’s libraries over to new platforms, because I get in and see one tiny problem with the code and end up fixing that, which leads to another change and that turns into a two weeks of me re-writing the whole thing and at that point I don’t remember why I needed the library in the first place and I end up never releasing it anyway because I “need to go back and clean a few things up and add some comments” which invariably never happens! It’s a vicious cycle.

1 Like

Hello guys, I just bought my spark core and I’m trying to write a library for an I2C temperature sensor. To do this I need the “Wire” object. As far as I know the web IDE includes a “Wire” object “ready to use” without the need of adding a library (#include blablabla.h) Well, that works perfect on my “.ino” file, but when I create my “.h” and my “.cpp” the compiler doesn’t recognize the “Wire” object in it. What am I missing?

Hi @skynett

You need to add

#include "application.h"

This is a lot like including Arduino.h on that platform. The .ino file is run through the Arduino-like preprocessor that includes this automatically and handles function prototypes etc. but .h and .cpp files are not.

1 Like