first of all I want to say “Hello”.
Therefore: Hello to the community.
So, back to business I´ll try to keep this as short as possible…:). If i say something completely wrong trust me that is not my intention. I try to learn something new, thus it is possible that I make mistakes! I need some help. Help that I can read on and do some “further investigations” on how it is possible to port my current Android Nano v3 project to my ordert Spark Core.
Short project describtion:
The current project is mainly used as a, aehm, twilight control?! Hope you know what I mean. The Arduino Nano v3 checks the time of a day and if the time is between X and Y and the photo resistor goes under my predefined value a relay is switched on for a given time. Date and time and the photoresistor value is send to a 1602lcd display. Mainly that´s it…
To get this work with Arduino I use 4 libraries. After I have read in the forum I come to the conclusion that I don´t need all of them with the Core again.
Here’s what I’ve found and hopefully understand correctly:
RTClib.h / Wire.h
Both of them are used for a DS1307 RTC module. I don´t think I need them again when I use the Core. Because I can use NTP, right?! I need something like the unixtime to do some timing functions analog to the well known millis() function.
Like int functionunixtime if functionunixtime >= currentunixtime do something
pt.h
Last one and very important for me. This is a protothread library (https://code.google.com/p/arduinode/downloads/detail?name=pt.zip) anyone knows if there is a similar lib for the Core out there which I can use, or maybe someone has ported that lib already?
Do I get it? Am I right or wrong?
In advanced - thx for any help on this topic.
Tried to used my best translation skills (and they are not very skilled) for this.
Have mercy on me cheers clyde
I guess you have self-figured out the cool stuff the community has put together which allows you to build your project fast
As for pt.h , i will take a look and see if i can port it. If you don’t hear from me in a few hours, just @ me. I’m busy doing more projects and might slip my mind
EDIT: I quickly tried copying a few files and they didn’t give me any headache. Have to be on the road now! More updates tonight!
The real-time clock part is pretty easy–the core firmware has features being added right now to get the real time from the cloud connection, so that is coming very soon.
If you want to get started right now, you can use my NTP library described here:
It can do a few things the core firmware doesn’t do yet, like handle daylight-saving or summer time in the US and Europe.
Good news! So like what the PT library author has claimed, it is non-platform specific and you only need to copy 2 file: PT.h and lc.h to get it working.
Maybe the other header files are required for advanced functions but i guess porting is like copying + paste.
So i’m not going to claim any credit for this but if you really would like to see a demo or want it stored for the core, i can save this library under the SparkCoreLibraries in github for easy reference.
keenethlimcp:
Woohooo thank you so much! Really great work and a really great community.
After writing another question to you I give the WebIDE another shot and tadaaa I found the “+” button in the upper left corner. Now I understand what you mean with “copy + paste”! I think it´s enough if you can save it to the SparkCoreLibs.
That helps me a lot, could be that this is not my last question.
Now fingers crossed and waiting for my spark
Got my Spark Core and do some tests, but have problems with the protothreads…
Here my test code:
#include "pt-sem.h"
#include "lc-switch.h"
#include "lc.h"
#include "pt.h"
static long threadTest = 5000; // Run every X sec
static int th = 0;
static struct pt pt1;
void setup() { PT_INIT( &pt1 ); }
void loop() { thread1( &pt1, th, threadTest ); }
void Gatekeeper() {
Serial.println( "I´am the Gatekeeper are you the Keymaster?" );
}
// Keymaster
static int thread1( struct pt *pt, int th, long timeout ) {
static long t1 = 0;
while(1) {
PT_WAIT_UNTIL( pt, (millis() - t1) > timeout );
callGatekeeper(); // There is no Dana, only Zuuul
t1 = millis();
}
PT_END( pt );
}
But sadly returns a lot of errors? Anyone else who use protothreads? Or do I miss something. I used exact the same code with my arduino nano ATMEL328 and it works like a charm.
My debugging skills are not very impressive; therefore I have to call for help
@clyde, I compile your example and there seems to be a problem with the macro expansion causing syntax errors. @zachary may know how to get the compiler to produce a macro-expanded version of the code so we can get an idea of where the error occurs.
Any news on this topic?
Sorry for bring this up, but I need that library.
@peekay123:
If I understand what you say, this is a problem of the cloud IDE - therefore there is a chance when I use a offline compilation program?
Should I try to contact zachary via PM? Think he had a bunch of work to do and I don´t want to disturb him.
i had a go at compiling it locally and got it to work with some changes to your demo code - that code doesn’t even compile for arduino without changes, you’ve missed PT_BEGIN(pt); for a start and callGatekeeper() should be replaced with Gatekeeper()
anyway, this works for me, you need lc.h, lc-switch.h, pt.h and pt-sem.h, as they include each other.
#include "application.h"
#include "pt.h"
static long threadTest = 5000;
static int th = 0;
static struct pt pt1;
void Gatekeeper()
{
Serial.println("I am the Gatekeeper are you the Keymaster?");
}
static int thread1(struct pt *pt, int th, long timeout)
{
static long t1 = 0;
PT_BEGIN(pt);
while(1)
{
PT_WAIT_UNTIL(pt, (millis() - t1) > timeout);
Gatekeeper();
t1 = millis();
}
PT_END(pt);
}
void setup()
{
PT_INIT(&pt1);
}
void loop()
{
thread1(&pt1, th, threadTest);
}
sej7278:
Oh dear,…
Shame over me, I copied this from my arduino script… and do not doublechecked it… ;(
I´ve I use your code (the PT_BEGIN) and it compiles in the Spark Cloud IDE!
Wohooo, when I´am home today I will try if it works. But I see no problem now.
Thank you all for your support,… and sorry again taking your time for a mistake I made…
out of interest, what did you actually need the threading for though - there’s no button presses or anything expecting input (you could use interrupts for that anyway) and no complex graphical output to maintain the state of…?