Author Topic: IR-Based Arduino to Digispark Communication  (Read 4111 times)

beiju

  • Newbie
  • *
  • Posts: 2
IR-Based Arduino to Digispark Communication
« on: June 07, 2013, 04:55:30 pm »
I have an Arduino Uno, a Digispark with an IR shield, and an idea for using them to communicate four 0-255 values.


The idea is that I would have the Arduino generate a 1-second pulse that switches between 4 different frequencies, one for each value I want to communicate. The Digispark would detect that a pulse had begun, wait 125ms (until the middle of the first pulse segment), then sample the frequency, wait 250ms (until the middle of the next segment), then sample the frequency, and so on. It was slightly confusing even to me, so I made a diagram:





(The colors are to differentiate between segments, not to indicate frequency. You may have guessed that I intend the values to control a servo and an RGB LED.)


Background info:
  • The receiver is the one that came in the DigiSpark IR shield kit. It was shipped as part of the original Kickstarter project, in case that matters.
  • I have an 850nm and a 950nm IR LED, both from SparkFun.
  • I want to use IR because the DigiSpark part of the project will be portable while the Arduino part will be stationary.
  • I have some experience programming for Arduinos, less experience with hardware design, and almost no experience using hardware-constrained platforms like the DigiSpark.
My questions:
  • Is it possible to generate and receive tones like this? I don't expect much accuracy (5% is good, 10% is acceptable). If so, what frequencies should I use to represent values of 0 and 255?
  • It looks like tone() and noTone() analogWrite() [Arduino] and analogRead() [DigiSpark], are the functions I need, is that correct? [Edit: analogWrite is obviously the one to use if analogRead is detecting it, not sure why I thought otherwise]
  • Are interrupts the best way of detecting when a pulse has started? If not, what is?
  • Do you see any other potential problems?
Thanks for your help.
« Last Edit: June 07, 2013, 05:44:20 pm by beiju »

Bluebie

  • Sr. Member
  • ****
  • Posts: 486
Re: IR-Based Arduino to Digispark Communication
« Reply #1 on: June 08, 2013, 07:51:32 am »
The IR receiver uses a tight midpass filter to only receive around 38khz pulses, while the decoder logic uses a very low low pass filter to smooth out incoming data. This effectively prohibits you from using frequency to transfer data as proposed. You might instead like to consider using PPM - it's the type of signalling used with RC helicopters to multiplex several servo values in to a single digital wire. It's very simple to implement and friendly to IR recivers (some tiny helicopters use the same IR detectors in fact!)


For the transmit side, use tone() to generate a 38khz square wave to drive the IR LED - if you just light the LED up (fully 100% on) it will not trigger the receiver module. It must be pulsed at 38khz and not for too long - if it keeps pulsing for too long eventually the auto gain control in the receiver will remove the signal (presuming it to be environmental noise) and the device will read nothing.

beiju

  • Newbie
  • *
  • Posts: 2
Re: IR-Based Arduino to Digispark Communication
« Reply #2 on: June 09, 2013, 04:50:25 pm »
Thanks for the advice. I've heard of PPM in the context of RF transmissions. It makes sense that it would work just as well with IR. I found a few examples of PPM generation for the Arduino, so I'll give those a try. The advice about tone() sending a signal that could be picked up by an IR detector was useful too, when making a proof-of-concept of that just detected whether the transmitting LED was on or not.