WiFi IR Remote

Postings related to the second version of the WiShield

WiFi IR Remote

Postby dlevans » Wed Sep 15, 2010 10:10 pm

I'm trying to make an Android powered universal IR Remote that is controllable via the WiShield 2.0.

Like this:
http://hackaday.com/2010/09/10/internet ... ed-remote/

I've gotten the IR send/receive info on a regular Arduino using this guy's library:
http://www.arcfn.com/2009/08/multi-prot ... brary.html

I'm just not sure how to implement the WiShield to control it over the network. I've gotten the server to work. The sketch with the Hello World and the LED on and off. Like I said.. I'm just not sure how to implement the IR library with the internet. I'd like a button on the site to record the IR code then later send the code with a button or image on the website.

Thanks for your help.
dlevans
 
Posts: 13
Joined: Wed Sep 15, 2010 10:05 pm

Re: WiFi IR Remote

Postby dlevans » Fri Sep 17, 2010 11:50 am

No one has any idea how to do this?
dlevans
 
Posts: 13
Joined: Wed Sep 15, 2010 10:05 pm

Re: WiFi IR Remote

Postby GregEigsti » Fri Sep 17, 2010 10:44 pm

No one has any idea how to do this?

But of course! Study the uIP docs and understand how the WiShield and its stack work; then study the other stuff that you have found and understand how it works. Then glue it all together using your understanding as a basis for that work.
Check out the wiki!
uIP Stack Docs
Compatible Access Point List
WiShield user contrib branch - DNS, DHCP, AP Scanning, bug fixes, etc.
SlackLab.org - My geek projects blog.
User avatar
GregEigsti
 
Posts: 1067
Joined: Sun Aug 02, 2009 5:23 pm
Location: Sammamish WA USA (near Seattle)
  • Website

Re: WiFi IR Remote

Postby dlevans » Sat Sep 18, 2010 1:00 am

Does it seem possible? A few other forums I've checked said something about the Arduino not being fast enough...
dlevans
 
Posts: 13
Joined: Wed Sep 15, 2010 10:05 pm

Re: WiFi IR Remote

Postby dlevans » Sat Sep 18, 2010 1:05 am

Also another question.

Is there anyway to AdHoc to the WiShield to configure the ip address, security, etc and then restart it for infrastructure mode?

or read from an SD card or something?
dlevans
 
Posts: 13
Joined: Wed Sep 15, 2010 10:05 pm

Re: WiFi IR Remote

Postby GregEigsti » Sat Sep 18, 2010 2:02 am

Its very possible and will probably be one of my upcoming winter projects. I did it with a PIC running a 4mhz crystal (no network rather USB connection to computer); the onboard mux ran the PIC at 20-25 mhz (I think...) - it was fast enough for USB and that sounds about right. Since you are talking about very limited/fast network traffic there should not be a problem sending/receiving a packet and blasting an IR "sentence" in between. My project is documented here and has some info that may be of interest - I used PWM to drive the 38khz IR signal and switched it on/off with a transistor. I also do not attempt to reproduce any "standard" protocol; rather utilize a "record and playback" methodology. Seems to have worked for everything that I have thrown at it (well that is at/near the 38khz range).

I will not use a web page served by the Arduino/WiShield rather I'll have some other UI that sends a UDP or TCP (probly TCP) packet to the device. Anyway, yes it should be very possible - even easy with the code that you found. You will just need to glue the network code and IR code together in such a way that they easily interact with one another.

A few other forums I've checked said something about the Arduino not being fast enough

Fast enough for what? 38khz PWM or to run IR and network together? Its only a few bucks worth of parts to find out ;) My gut feeling is no problem - a comparable PIC can do it - and squeezing the network and IR in together is just a matter of thinking it through.
AdHoc to the WiShield to configure the ip address, security, etc and then restart it for infrastructure mode?

Yes in the WiShield user contrib branch there is a AP scanner sample that does just this.

Greg
Check out the wiki!
uIP Stack Docs
Compatible Access Point List
WiShield user contrib branch - DNS, DHCP, AP Scanning, bug fixes, etc.
SlackLab.org - My geek projects blog.
User avatar
GregEigsti
 
Posts: 1067
Joined: Sun Aug 02, 2009 5:23 pm
Location: Sammamish WA USA (near Seattle)
  • Website

Re: WiFi IR Remote

Postby dlevans » Sat Sep 18, 2010 3:10 am

Yes I know it will scan for an open network but is there a way to do the password? (I haven't checked the sketch as the device isn't with me so sorry if it's a simple answer)

The "not fast enough" question came from this article:
http://hackaday.com/2010/09/10/internet ... ed-remote/

that led me to his Instructables article where I asked him if an Arduino would work:
http://www.instructables.com/id/Control ... our-Phone/

I asked and got this in response:
"No. I'm not actually sure you can do it with the Arduino libraries - the capture code has to be pretty fast, it's doing several things on each transition (incrementing the transition counter, checking for a time out, etc), and if the instructions are executed too slowly, it will miss transitions...."

As you can tell I've been doing homework on this for awhile. Thanks for all your help so far. I've been reading the uIP doc from your sig.
(http://www.sics.se/~adam/download/uip-1.0-refman.pdf)

*edit*
I've got the parts. I've got the Arduino, the IR LED, the IR Receiver (RadioShack part in the IR library link in my first post), and I've got the WiShield. I'm ready to get my hands dirty. Just trying to figure out where to dig in.

*edit 2*
Looks like I'm working with the exact same IR Receiver you showed me in your IRNetPRoxy setup.
dlevans
 
Posts: 13
Joined: Wed Sep 15, 2010 10:05 pm

Re: WiFi IR Remote

Postby GregEigsti » Sat Sep 18, 2010 11:06 am

I read through the hackaday comments (quickly) and did not see where the speed of the Arduino was questioned; in fact there were some comments that folks had similar goop running on an Arduino. So I'm thinking it is all very possible - however there's probably a sticky spot or two where you will need to keep performance in mind. How you implement it is up to you - trying to use protocols or trying to go protocol agnostic (as I did) - the fact that Ken Shirriff's Arduino library exists is another good sign that the Arduino will work for you. If you think about it this device will sit idle most of the time and occasionally be asked to learn or send - and then there is the network aspect of it - but the IR and network aspects should be isolated from each other.

So how to get started... I don't know your level of skill with hardware or programming but I would "divide and conquer" - breaking the features down into "functional units" and getting stuff working one bit at a time. Of course you will want to be mindful of the "other features" while working on a feature (so you don't dig yourself into a hole).
  • Which approach will you take - use protocols or go protocol agnostic?
  • Review any lib code that you might use - is there anything in there that would conflict with the use of a WiShield (e.g. pin assignment, long executing code, etc.). You should be aware that for the WiShield to work properly it needs to be serviced quickly/often (your WiFi.run() and/or WiServer.server_task() needs to be called lots and often in loop()). For instance "sleeping" for one second between servicing the WiShield will cause it to drop off of the network.
  • Break the project down into functional units - I would probably start with receiving/learning, then transmitting/sending and finally networking - in that order. The further ahead that you can think in all steps the better off you will be (e.g. when working on transmitting/sending keep networking in mind and don't dig yourself into a hole).
  • What kind of network interface do you desire? A web page or something that sits on the network and listens for packets? Personally I prefer the latter - it will have better performance among other things.
  • Take a complete inventory of your project's needs (e.g. pin usage, PWM speed, etc.) - there is no excuse for not being prepared and finding that part A is incompatible with part B at the end of the project. For instance you will likely need a 38khz carrier - how will you achieve this? Is the Arduino capable of generating this carrier? Given all the bits that you will use do you have enough pins available? For instance if you decide to use PWM for the carrier you should know ahead of time if you will have an available pin that is PWM capable.

Ok that is enough of Project Management 101 :lol:
I would start with learning/receiving - after you decide what you will do to interface with the IR bits (protocol or protocol agnostic) you can connect up the receiver and see if you can start receiving anything that makes sense. My approach was to externally put the device into learning mode and then blast the receiver with the desired remote/function. You can then use Serial.println() to spew out some info to gauge the success of the read. Once that is working you can move on to sending - if you learn a code can you successfully send it back out and control the intended device? Oh yeah, take an inventory of what devices will use what pins on the Arduino and use those pins from the get-go. Having to rewire and change code after the fact (when you add some new bit) sucks.

I think breaking things down into handleable features will also help you not to be overwhelmed - this is not a beginner project - more of a medium project. The hardware is easy but the code will be timing dependent and could get "interesting".

Greg
Check out the wiki!
uIP Stack Docs
Compatible Access Point List
WiShield user contrib branch - DNS, DHCP, AP Scanning, bug fixes, etc.
SlackLab.org - My geek projects blog.
User avatar
GregEigsti
 
Posts: 1067
Joined: Sun Aug 02, 2009 5:23 pm
Location: Sammamish WA USA (near Seattle)
  • Website

Re: WiFi IR Remote

Postby GregEigsti » Sat Sep 18, 2010 11:35 am

PM me with your email addr and I'll send you my PIC protocol agnostic code. It contains copyrighted stuff so I'd rather not post it to the forum... :o
It does not know anything about the network (it uses USB) but might be helpful if you decide to go protocol agnostic.

Greg
Check out the wiki!
uIP Stack Docs
Compatible Access Point List
WiShield user contrib branch - DNS, DHCP, AP Scanning, bug fixes, etc.
SlackLab.org - My geek projects blog.
User avatar
GregEigsti
 
Posts: 1067
Joined: Sun Aug 02, 2009 5:23 pm
Location: Sammamish WA USA (near Seattle)
  • Website

Re: WiFi IR Remote

Postby GregEigsti » Sat Sep 18, 2010 4:56 pm

Here is the protocol agnostic receive code :D
Certainly could use some cleansing but its a start. Sending is next - which will tell me how valid this code is - but from past experience I'm thinking its good.

The Radio Shack IR receiver part connects to digital pin 3 on the Arduino. Kinda fun - you pushed me into the conversion of this project from PIC/USB to Arduino/WiShield early :lol:

Code: Select all
// ----------------------------------------------------------------------------
// --
// -- Program defines
// --
#define INT_RECV_NUMBER 1
#define INT_RECV_PIN    3
#define PWM_CARRIER     5
#define RECV_TIMEOUT    3000
#define CNT_TRANSITION  128

// ----------------------------------------------------------------------------
// --
// -- Program shared global variables
// -- Variables used in the ISR should be marked "volatile"
// --
volatile boolean recvStarted;
volatile boolean recvInProgress;
volatile unsigned long timeIO[CNT_TRANSITION];
volatile unsigned long timeCapture;
volatile unsigned long timeBase;
volatile unsigned char transitions;

// ----------------------------------------------------------------------------
// --
// -- IR receive ISR (Interrupt Service Routine)
// -- IMPORTANT - do as little as possible in any ISR; this ISR grabs a bit of current state data
// --  and sets the "message" variable to signal that further processing is required in loop()
// --
void IRRecvISR()
{
   int state;
   
   // Reverse HIGH/LOW as Radio Shack IR receiver 276-640 reverses
   // HIGH and LOW (for this part 0 == HIGH and 1 == LOW)
   state = !digitalRead(INT_RECV_PIN);
   
   // If recv has just begun set program state and set first transition to 0
   if(0 == transitions) {
      // If state is HIGH set high bit to 1; otherwise set high bit to 0
      //  Indicates if this was a transition HIGH or LOW
      timeIO[transitions++] = 0 + (HIGH == state ? 0x80000000 : 0);
      // Set global to indicate receive has begun
      recvStarted = true;
      recvInProgress = true;
      // Start the capture window (RECV_TIMEOUT milliseconds)
      timeCapture = millis();
   }
   // Guard against overflowing timeIO buffer
   else if(true == recvInProgress && transitions < CNT_TRANSITION) {
      // Capture the timestamp for the current transition
      // Subtract timeBase to get the length between transitions rather than timestamp
      // If state is HIGH set high bit to 1; otherwise set high bit to 0
      //  Indicates if this was a transition HIGH or LOW
      timeIO[transitions++] = (micros() - timeBase) + (HIGH == state ? 0x80000000 : 0);
   }
   else {
      // DEBUG ONLY!!! Too fat for an ISR!!!
      Serial.println("====== overflowed timeIO buffer!!! ======");
      recvStarted = false;
      recvInProgress = false;
   }

   // Grab timeBase so that we can store time between transitions rather
   //  than just a timestamp
   timeBase = micros();
}

// ----------------------------------------------------------------------------
// --
// -- setup() - program initialization happens here
// --
void setup()
{
   // Enable serial output for debugging
   Serial.begin(57600);
   Serial.println("setup() begin");
   
   // Set initial program state
   recvStarted = false;
   timeBase = 0;
   transitions = 0;
   recvInProgress = false;
   
   // Attach the IR receive interrupt with the mode of "CHANGE".  We are interested in both rising and
   //  falling changes from the IR receiver.
   attachInterrupt(INT_RECV_NUMBER, IRRecvISR, CHANGE);
   Serial.println("setup() end");
}

// ----------------------------------------------------------------------------
// --
// -- loop() - program's run loop
// --
void loop()
{
   int i;
   
   // Print out debugging statement indicating capture window has started
   if(true == recvStarted && true == recvInProgress && millis() <= (timeCapture + RECV_TIMEOUT)) {
      Serial.println("");
      Serial.println("capture window started");
      recvStarted = false;
   }
   // Take action when capture window has expired
   else if(true == recvInProgress && millis() > (timeCapture + RECV_TIMEOUT)) {
      // Print some data about the recv
      Serial.println("capture window expired");     
      Serial.print("  transition count: ");     
      Serial.println(transitions, DEC);     
      for(i = 0; i < transitions; i++) {
         Serial.print("    ");
         Serial.print(i, DEC);
         Serial.print((timeIO[i] & 0x80000000) ? " HIGH for " : " LOW for ");
         // No need to print duration of last transition (nor is it captured)
         if((i + 1) != transitions) {
            Serial.print(timeIO[i + 1] & 0x7FFFFFFF, DEC);
            Serial.println(" microseconds");
         }
         else {
            Serial.println("duration");
         }
         
      }
     
      // Reset program state
      recvInProgress = false;
      recvStarted = false;
      transitions = 0;
   }
   
   // Service the WiShield - coming soon...
   // WiFi.run();
}
Check out the wiki!
uIP Stack Docs
Compatible Access Point List
WiShield user contrib branch - DNS, DHCP, AP Scanning, bug fixes, etc.
SlackLab.org - My geek projects blog.
User avatar
GregEigsti
 
Posts: 1067
Joined: Sun Aug 02, 2009 5:23 pm
Location: Sammamish WA USA (near Seattle)
  • Website

Next

Return to WiShield 2.0

Who is online

Users browsing this forum: No registered users and 1 guest