Hey guys, I’m trying to make a program that follows this flowchart I’ve created
So I’ve been looking around on the web and there’s so much complicated things about libraries and installing them which I don’t understand how to put it into the web IDE for Spark. I was hoping to just use the IFTTT service (so the flowchart can be simplified to the basic conditions IFTTT weather offers such as: cloudy, rain, clear, and snow), but I’m not sure how the coding goes for this flowchart to work. I know I’ll have to be using Spark.subscribe if I published an event, but that’s all I know.
I was hoping to use and LCD screen and a few RGB LEDs for my project. Can anyone be my mentor/tutor on how to tackle this project?
I want my LCD screen to be somewhat like @Coffee’s weather forecast display. Which can be seen here.
If @peekay123 has time left, with the Maker Faire coming up, he should be able to help you. He’s doing a similar project like yours, but is using the webhooks/cloud JSON parsing features. Perhaps he can help out a bit.
Thanks for the reply and commendation @Moors7, to tell you in advance this is due on June 12. @peekay123 was able to reply to a comment:
@MrNodus, I have used a “parsing” webhook with openweather to do all the work of getting only the forecast data I wanted. I will be publishing the RGBPongClock project I did for the upcoming San Francisco Faire which includes getting a 7day weather forecast and displaying it on a 16x32 RGB Matrix display.
@MrNodus, I would suggest you use openweathermap to get your weather data. From the looks of your flowchart, you want the current day forecast. Using the api at openweather.org, the call will look something like this:
This will return the weather for London in JSON format which can be parsed by a webhook. Which city are you interested in getting the weather for? Click on the above link to see what it returns in your browser. Then change the London,uk part for your city and see what you get again.
If you refer to the API documentation and the API Parameters for the current weather, you can pick the data that you are interested in displaying and/or acting upon. Play with the API call, look at the parameters and get back to me with a list of parameters you want to use.
Hey, @peekay123 thanks for getting back with me. I’ve had a look at openweathermap and signed up and looked at current weather API for Melbourne, AU. Here’s what I’ve done following the steps of @Coffee
The data I’m only interested in is temp_min; temp_max; weather condition; time. Generally what is displayed on the screen from Coffee’s post. I’m not sure what you mean by:
Play with the API call, look at the parameters
This will return the weather for London in JSON format which can be parsed by a webhook
@MrNodus, the approach I propose you take will NOT use the HttpClient or openweathermap libraries! @Coffee’s example is fantastic but you will be using a webhook instead and getting the Spark Cloud to do a bunch of work.
When I say play with the API, I mean open the link I provided using a browser (e.g. Chrome) and change the name of the city/country to what you want and look at the raw data (LEARN!). You will see the data is in JSON format.
Once you understand how the data is structured, we can talk about using a webhook to a) Request the data from openweathermap and b) specify the JSON objects we want parsed from the response. Get familiar with JSON so you won’t be lost in the next step.
BTW, to create a webhook you will need to have Spark CLI installed and working on your PC.
@peekay123, that’s what you mean. I was able to do that before I posted this topic, but had no idea what to do with the data it showed me. This was the result: (note at the end of the script it failed something, but that disappeared after I changed the location again on the url)
I had a little google search into what JSON and what parsing is, also wiki what webhook is. I have a shallow knowledge of it now.
Having done a little research with Spark, do you think I can opt for an IFTTT service? I personally think this will make it easier for me to use, so I don’t have to put you through too much trouble with the little knowledge I have. I’ve installed the app on my iOS device. I’ve learnt a little bit of the interaction with Spark and IFTTT in class.
I haven’t mentioned this, the reason why I keep saying little is because I’m not studying comp-sci or computer programming/engineering. Currently studying Industrial Design, part of my task is to use technology to integrate with design. I’m trying my best to learn this new area for myself. Sorry for the any inconvenience I’ve set upon you.
@MrNodus, no problem! I love ID! My best buddy quit Electrical Engineering to go into ID back when I was in University.
If I understand correctly, you want to use IFTTT to send your Core weather data on a regular basis? Heck yes! You will need to activate the Spark channel, as well as, the weather channel and then create your recipe to fire off the weather to your Core via a Spark.function(). Absolutely do-able
@peekay123 , yea I’m enjoying the many fields it touches on.
Yea you’re on par. But I don’t think it will be able to display the data on a screen right? I’ve asked a friend and advised me to just not display the data on a screen, but instead go with my initial idea of using weather conditions to trigger LED functions. Do you have any tutorials to suggest about how to control RGB LEDs? My lecturer broke it down to:
- change the colour of an RGB LED
- change the brightness/flashing of an RGB LED
Will this work if I use the code on the spark IDE?
This is what I’ve done so far, but I know this doesn’t give me the outcome I want with a RGB LED. This is the code we’ve done in class, I’ve just replicated them so there are separate functions for the differing weather condition triggers. See here.
You should be able to display the data on a screen, there’s not really a reason why it wouldn’t be possible. You just have to ask yourself whether or not it’s necessary or if the LED system would suffice.
Here’s a neat tutorial by Adafruit on using RGB LEDS.
The code you’ve included looks to be an extract of the tinker firmware. While this isn’t bad code, it’s not really suited for your project. The amount of functions that can be used is limited to four, which you’d exceed with the number of scenarios. Rather, you should use the argument to specify a certain behavior, combined with perhaps a switch/case statement.
Regarding IFTTT: if you’re planning on having it update every hour, you’ll have to create 24 recipes. I genuinely think the webhooks offer the cleanest implementation, in that everything is contained to the Spark (Cloud). You also make the cloud do the heavy work (requesting/parsing), which takes some strain away from your Core.
Regardless of which path you choose to take, I’m sure we’ll be able to help you out, where/if needed. Best of luck :)!
Just so that it doesn’t get forgotten
If you’d be happy to use the Core on-board RGB LED it’s dead simple
RGB.color(rNew, gNew, bNew);
On the other end of the spectrum (overkill???) you could go for NeoPixel or such
@Moors7, it’s part of the design that I want to make with the LED system as I will enclose it like this. So I’ll probably need a couple in the circuit, otherwise I will opt for LED strips. I’ve linked a tutorial that showed some case statements here. Is it possible to display the weather data from IFTTT on a screen though? Or are you saying that using webhooks from openweathermap?
Why do I need 24 recipes? I only need the three recipes that triggers when the current weather conditions change to rain, sunny or cloudy.
I’ll probably update my flowchart to suit the IFTTT service by not updating every hour, but instead update whenever the weather changes. Just to keep things simple for the project. We’re getting assessed also by problem solving and the prototypes we will make. Not so much on the code, so it’s best to keep it simple.
@ScruffR, The LED on the core will not suffice for what I intend to design it to look like. Hahaha, unless the core had multiple LEDs on it. But thanks for that suggestion. Neopixel is somewhere on the line what I want to use, or just the common cathode RGB LEDs. But I’m not sure if they are coded differently or not.
Hey guys, here’s an update on the code I’ve compiled so far, I have verified it and there are no errors. Can someone please check this if this will actually work for what I want it to do. The objective is to use IFTTT to trigger events: rain; cloudy; sunny. It will call a function on the spark core that will initiate the led functions.
For a refresher:
I want my ‘cloud’ to light up orange when it becomes sunny, dark blue when it rains and white when it’s cloudy.
The code doesn’t look bad, although there are some improvements to be made.
int sunny(String command)
int state = 0;
//find out the pin number and convert the ascii to integer
int pinNumber = command.charAt(0) - '0';
//Sanity check to see if the pin numbers are within limits
if (pinNumber < 0 || pinNumber > 7) return -1;
// find out the state of the led
if(command.substring(2,6) == "HIGH") state = 1;
else if(command.substring(2,5) == "LOW") state = 0;
else return -1;
// write to the appropriate pin
setColor(255, 191, 0); // sunburst orange
It looks to me like the only thing you’ve added is the setColor() part. Why did you copy it there, and leave the rest of the code? What is that code, according to you, supposed to do? Does it serve any practical purpose, and if not, why is it there?
Also, in the setColor function, you use AnalogWrite, yet you’ve used digital pins. You might want to check on that again.
Further thing to check on, after the above mentioned things are taken care of, is the fact that you can combine those three functions into one, using the arguments you can pass it.
Have a look at this, and report back (I’ll be in a plane the coming ~11 hours, so I won’t be too quick to respond )
Hahaha thanks for pointing that out @Moors7. Here’s the updated version. I’ve combined them myself into one function.
Does anyone know how to display the data onto an LCD screen? I get a notification on my phone when the weather condition changes and it displays the current condition and temperature.
Hey @Moors7, @peekay123. @ScruffR,
I’ve looked online, but I have no luck finding a guide into making a parallel circuit for RGB LEDs. I’ve set it up on my breadboard and when I make them blue, they all work fine. But once I make them white or yellow, they half the colours (I have four in parallel). How do I fix this?
Thanks a lot for all your help.
Are you driving four RGB LEDs directly off three PWM pins of your Core?
If so your LEDs would need more current than the pins can drive and you won’t get all your colors and you might even fry your pins.
You should rather drive the LEDs via some transistors.
At http://playground.arduino.cc/uploads/Learning/multiple_leds2.jpg you can find this schematic of how to parallel power four LEDs.
You’d need this three times for each color and you may want to adapt the resistor (330R) values, since different color LEDs have different forward voltages, so you need to adjust the resistors to get similar currents running through all your LEDs.