Page 1 of 1
Forum

Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!

Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.

Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is no translation for that post!



Arduino All Effects...
 
Share:
Notifications
Clear all

[Solved] Arduino All Effects with IR support

10 Posts
4 Users
0 Likes
2,225 Views
(@dai-trying)
Active Member
Joined: 5 years ago
Posts: 10
Topic starter  

I have been working on a solution to get the all-in-one sketch to work using an IR remote, this has proved to be very problematic in getting correct readings from the remote and implementing it in the sketch.

I ended up re-writing almost the entire sketch to prevent the use of delay() which was part (but not all) of the problem. The only way I have found to implement it was to use two (2) arduinos connected by serial communication, the first arduino simply catches the IR signal and interprets it and then sends the appropriate signal to the second arduino. The second arduino contains the (re-written) All-In-One sketch which reacts immediately to the command and sets the effect accordingly.

One thing I should say before finalising this post, (1) when programming either arduino you should disconnect the rx/tx pins, I have read it will not work correctly with them connected and it could conceivably cause damage so please remember this when uploading code.

Connections are made as follows:-

Arduino1 pin rx -> Arduino2 pin tx
Arduino1 pin tx -> Arduino2 pin rx
Arduino1 pin 6 -> IR signal
Arduino2 pin 6 -> LED strip signal

As well as the required power pins, and remember to use common ground where applicable.

Two sketches are attached and it is very likely that further adjustments will need to be made but I was so relieved to have finally managed it I wanted to post immediately. Any comments/improvements always welcome.


   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2678
 

Hi Dai!

Great to hear you found a way to get this to work - and thank you very much for posting your code 

The second Arduino is almost unavoidable since catching the IR codes does not trigger an interrupt. More advanced interrupt code may be able to catch it, but it's trick. An Arduino in the end is not build for "real" multitasking ...


   
ReplyQuote
(@dai-trying)
Active Member
Joined: 5 years ago
Posts: 10
Topic starter  

Yes, I tried many tricks to attempt to make it work but in the end this was the only way I could get it to work with immediate change. Some of the code might be a bit coarse and I'm certain it can be improved upon, but that is for another day, I forgot to mention I have not yet coded the functions for Fire and BouncingColoredBalls as they seemed more complex but I will see if they can be written without the delay() function at some time.

I do think using two arduino's that cost around £1.30 (GBP) each is a very cheap fix.


   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2678
 

You're absolutely right; Arduino's can be had real cheap - isn't that the beauty of it? 


   
ReplyQuote
(@arduinobini)
New Member
Joined: 5 years ago
Posts: 1
 

This is awesome man. I just had 3 evenings of trying and wondering what was wrong. I will give it a try tonight :D 

But one question, just curious: isnt the use of delay() the reason we have to use an interrupt? Arent you able to read IR at any time without the delay() ?


   
ReplyQuote
(@dai-trying)
Active Member
Joined: 5 years ago
Posts: 10
Topic starter  

When the arduino is in a delay() it cannot process any other commands, and AFAIK this includes interupts as an interupt will "interrupt a running process and I'm not sure if delay() is counted as one. Maybe somebody more familiar with it might correct me if I'm wrong.

The reason I use two arduinos to make it work is that when the lighting process is running it seems to scramble the ir timings which result in a wrong code being given.


   
ReplyQuote
(@wibert27)
New Member
Joined: 5 years ago
Posts: 3
 

Hey all, new here, found the code that hans made originally and was working on getting it to work with a bluetooth module instead of IR, but running into issues as the original code used the Delay function. Did some research and found that using Delay would be an issue and I didn't think I'd be able to do what I wanted. I knew that the Delay would need to be eliminated but that it was beyond my abilities. Programming is not my strong suite. Then I found this thread.

I've been slowly working on using dai's code for two Arduinos with IR support, adapting it for a Bluetooth module and custom Android app to change effects. But I'm taking it a bit further than that. In addition to changing effects, I also want to be able to change the color and speed of the LED presets, control the speed of a stepper motor and retain all of these settings so when the Arduino is powered off it will resume from where it left off. It's been a challenge, to put it lightly. 
I'm still not there, I actually stopped working on it several weeks ago as I was getting burnt out on it and when I resume working on it, I think I might just start fresh. The code was getting bloated and I was confusing myself trying to get it sorted. Just wanted to pop in here, say 'hi' and let you fine people know that someone else has found your previous work very helpful. I think it's cool how hans originally wrote the effects code, then tied them together into one sketch, then dai trying took that code and reworked it and now I'm here doing the same. Cool little circle. I do plan on making a separate thread and uploading the code once I'm done with it so that other people can benefit from it but it's nowhere near ready yet. 
Cheers.

   
ReplyQuote
(@wibert27)
New Member
Joined: 5 years ago
Posts: 3
 

Hey all, new here, found the code that hans made originally and was working on getting it to work with a bluetooth module instead of IR, but running into issues as the original code used the Delay function. Did some research and found that using Delay would be an issue and I didn't think I'd be able to do what I wanted. I knew that the Delay would need to be eliminated but that it was beyond my abilities. Programming is not my strong suite. Then I found this thread.

I've been slowly working on using dai's code for two Arduinos with IR support, adapting it for a Bluetooth module and custom Android app to change effects. But I'm taking it a bit further than that. In addition to changing effects, I also want to be able to change the color and speed of the LED presets, control the speed of a stepper motor and retain all of these settings so when the Arduino is powered off it will resume from where it left off. It's been a challenge, to put it lightly. 

I'm still not there, I actually stopped working on it several weeks ago as I was getting burnt out on it and when I resume working on it, I think I might just start fresh. The code was getting bloated and I was confusing myself trying to get it sorted. Just wanted to pop in here, say 'hi' and let you fine people know that someone else has found your previous work very helpful. I think it's cool how hans originally wrote the effects code, then tied them together into one sketch, then dai trying took that code and reworked it and now I'm here doing the same. Cool little circle. I do plan on making a separate thread and uploading the code once I'm done with it so that other people can benefit from it but it's nowhere near ready yet. 

Cheers.


   
ReplyQuote
(@dai-trying)
Active Member
Joined: 5 years ago
Posts: 10
Topic starter  

It's awesome that is has been found to be useful, my code isn't perfect and maybe you have some magic that could make it better. And I will be sure to keep an eye out for your post as I would be interested to see where it goes.

Don't forget you could always post whatever you have and others (including myself) might be able to help


   
ReplyQuote
(@wibert27)
New Member
Joined: 5 years ago
Posts: 3
 

Maybe I will do that. I was considering it before when I was working on it but since I'm not using a simple hardware setup of just an Arduino and some addressable LEDs, figured it would be a pain for other people to try to help. My setup currently consists of the following: (1) Arduino Mega, (1) Arduino Nano, (126) WS2812B addressable LEDs, (1) Bluetooth module, (1) SD card reader and (1) A4988 motor driver board.

I did manage to get Bluetooth functionality and the various LED presets working on one board, initially. I found a writeup on the Aruduino forums regarding non-blocking serial input reading that allowed me to do that. I'm actually using the Nano in my current setup for motor control and that's it. I was originally planning on using 2 Nanos, but eventually the code for the LEDs grew too large for the storage space on the Nano and that's why I bumped up to the Mega. Even though I'm only using the Nano for motor control, I still have the two Arduinos linked together as the Bluetooth aspect off all of this is on the Mega and I want to be able to control the motor. 

I'm doing this for a gift that I'm making. I started working with stained glass a few years ago and one thing that I've been wanting to do from the start is combine stained glass with lights to make unique items. I found out about Arduinos a few years ago and have dabbled with them a bit. I realized that I could make some really cool things with them. Currently working on a lantern with a Tardis inside from Dr. Who. The Tardis is mounted on a carbon fiber pole, attached to a stepper motor. There are 126 LEDs sprinkled throughout, some of them inside the Tardis. I've completely made this entire thing, the lantern is made out of oak, I made the stained glass panels in the front and figured out various challenges on the electronics side, like how to supply power to a rotating object......

Well, I'm going to stop typing now. Didn't mean to hijack your thread, sometimes I explain things in a bit too much detail.


   
ReplyQuote
Share: