How to control more than one LED on the same Arduino

52 views
Skip to first unread message

Luc.

unread,
Nov 12, 2015, 12:48:34 PM11/12/15
to Lelylan
Hi there,

I'm pretty new to Lelylan so my question may seems obvious to the most of you.

I've got the basic smart light example running on my Arduino YUN. Now it's time to do a step forward: I'd like to control two LED on the same Arduino YUN. 
Is this possible? How can I do this on the Arduino side?

On the Dashboard side I'm going to create one device for each LED. But I cannot figure how to manage more than one Lelylan device on Arduino.
Keeping the code on the webpage http://lelylan.github.io/lab-projects/arduino-yun-light/ as a reference:

Am I correct to declare as many deviceId, deviceSecret, outTopic and inTopic variables as the number of LEDs I need? 
And what about the callback function and the related payload strings?


Any hint is welcome.

Thanks in advance,
Luca

Lelylan Touch

unread,
Nov 17, 2015, 7:21:14 AM11/17/15
to lel...@googlegroups.com
Hi Luca, 

your question is not obvious. 

With Arduino (as far as I know) you can build up one single MQTT connection. This means that you can control one device at time. In the case of the tutorial, one single light. A solution to overcome this problem is to define a new device type that has as many "status properties" as many lights you want to control with one Arduino.

Let me make an example. Right now you have the Light Type with one property "status". This makes it possible to change the status of one single light in your Arduino.

Suppose you want to control two lights (but it could be 5, 10, 100). You can create a new type where you define 2 properties. You could name them "Status Light One" and "Status Light Two". Each of them could control one of the two lights in the Arduino by checking out the property ID. These are the basics. Then you could create functions to turn on and off every light and also all of them.

I think a good starting point here is to read more about the Types API.

Looking forward to hearing more.

--
You received this message because you are subscribed to the Google Groups "Lelylan" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lelylan+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Andrea Reginato
Lelylan, Building the Connected Home
http://lelylan.com

Find me on phone +393408529726
or Skype as andrea.reginato

Ricardo Rubio

unread,
Nov 19, 2015, 2:21:30 PM11/19/15
to Lelylan
Hi Luca.
As Andrea points out, it is not feasible to have one arduino behaving as two devices. This was one of my first approaches and I ran into many problems, even memory and  stack size problems (I was using an arduino YUN, wich is not that small). What I finally did was:
  • On the Lelylan side I defined a new device type, with a single status property, but many possible statuses, and as many functions to make the device go into any of the statuses whenever I decide to call a function. Think of this as a TV remote: a single emitter (the IR diode in the TV remote/the status variable in my Lelylan device) that emits different commands (the IR frequency/status value) according to wich action is taken (the TV remote buttons/the Lelylan functions). To understand this, take a look at the Types API that Andrea suggested.
  • On the arduino YUN side, I streamlined the program a bit and added more possible payload values according to the different status values possible, so in the callback function, upon recognizing the different payloads, the appropiate action is taken on the output pins.
I have an arduino YUN sketch that I can share, but first I need to know from Andrea if it is acceptable to paste arduino code here in the group, and I can also share the device type definition, but Lelylan is currently with some problem and I cannot access the dashboard.

Hi Andrea, please tell me if this very small project (double light switch) is of interest for you to publish on your blog, lab or wherever you want. As I previously said to Luca, I can share the arduino code and put the device type as public.

Best regards for both of you guys!

Ricardo

Lelylan Touch

unread,
Nov 25, 2015, 4:22:10 AM11/25/15
to lel...@googlegroups.com
Hi Ricardo, 

thanks for pointing out your experience. From my point of view (being this question a question asked several times) would be nice to have an article on our blog describing the approach you are following to deal with the issue.

Give me a title and I'll be happy to open up a new article on Medium where you can write your experience.
All the best

--
You received this message because you are subscribed to the Google Groups "Lelylan" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lelylan+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages