Sunday, October 7, 2012

Arduino Adventures - part II

OK, I am stuck trying to transmit an IR code to turn my air condition on (see previous post here: http://srooltheknife.blogspot.co.il/2012/10/adventures-with-arduino.html). It is getting hot, and I want to turn the damn thing on...

So, next step is trying to debug what's wrong with my IR transmission. I decided that I need to somehow visually see how my signal looks and compare it to the (working) original remote control signal. So decided to hack a little Oscilloscope - hey, I already made a wave printing arduino sketch in the last round. If I can just measure the signal from the IR receiver using Arduino analog in pin, decode it and send it over the serial connection to the Mac, I can display it nicely on the screen. Ummm... interesting... a new sub-project.

First, had to get the serial connection between the mac and arduino working. The power of the internet and the cool people helped. Found this:
http://code.google.com/p/xcode-arduino-serial-communication/
thanks to Pat OKeefe (and in turn to Andreas Mayer's AMSerialPort).

Next was a simple Arduino sketch to measure and send the analog input from pin 1 using the fastest baud rate possible. Quite simple:

// The Arduino code.

#define ANALOG_IN 1

void setup() {
  Serial.begin(115200); // possible values: 9600, 14400, 19200, 28800, 38400, 57600, or 115200
  pinMode(ANALOG_IN, INPUT);
}

void loop() {
  int val = analogRead(ANALOG_IN);
  Serial.write( val & 0xff);
}


Using the Mac code on this github repo [https://github.com/iroth/simplearduinoscope] you select and connect the right serial port, and can see the signal on the screen. If you select the wait for trigger (or click the re-trigger button), the scope will freeze when a signal is detected so you can examine the signal.

I added a copy to ref button, so I can record the original remote signal, display it as a reference and compare to my transmission.
Here is a screen dump of the two signals. I am not sure why my signal is not affecting the air condition, they look quite similar, no?



The top white line is the signal from the original remote control, the bottom is from my IR transmitter.
Note that my little scope has a scale up and down buttons too - this helps. I am not sure how accurate my scope is, but the signals look quite similar. Still not working.

Well, at least I hope the digital scope projects helps someone. It is not very accurate, but can be useful for debugging the IR codes (note that the signal above is the decoded signal from the TSOP382 sensor, not the 38 kHz modulated signal which is way too fast for this scope). It can be useful for simple audio frequency examination (but still at the low range of the audio spectrum).
I will need a much faster processor, and probably a much faster communication link to get the samples fast enough to the computer to really make it a useful scope for a wider range of frequencies.


No comments:

Post a Comment