Rewrote my code using the libraries from this blog:
http://www.arcfn.com/2009/08/multi-protocol-infrared-remote-library.html
After a little stumble with a == instead of a =, i got the first version running. Now the IR
receiver doesn't block the code execution and I can run a timer marking when the last IR event
happened. Also this code seems to see just about any IR activity, not just the Sony.
Feel bad that i haven't taken the time to understand what he did, just borrowed it.
This guy has also a bunch of stuff on IR remotes and interrupts too, didn't use it but wanted to note it.
http://minkbot.blogspot.com/2009/08/arduino-ir-receiver-with-interrupts.html
I wrote the code as a simple state machine (my background as a RTL designer is showing). There are three states. TV_OFF, TV_ON, DROWSY. It stays in TV_OFF unless the IR activity sends it to TV_ON. It starts a timer and kicks back to TV_ON every time the IR remote is detected. If the timer times out without any IR activity, it moves to DROWSY. DROWSY sends the sleep command to the TV and starts a timer. If the timer expires, it assumes the TV sleep timer turned off the TV and goes to TV_OFF. Any IR activity moves you back to TV_ON. DROWSY state isn't absolutely necessary, but it prevents sending sleep again too soon and extending the sleep timer time.
Now to clean up the hardware in a more permanent form and write it up for the next post!
Hobby blog about tech tips I've picked up, projects I'm working on, or links to useful information and cool stuff. I'm an Electrical Engineer and professional Analog IC designer for 25 years playing in my spare time. Arduino, hacking consumer electronics, video game hardware, satellite TV, PC building, Android apps, appliance repairs and whatever else that interests me.
Search This Blog
Monday, September 27, 2010
Sunday, September 26, 2010
Back working on the Arduino IR TV sleep timer setter
Now that the GPS is working, i'm back working on a project that stalled.
This project has an IR receiver that looks for any traffic, from multiple remotes. Point is not to decode them, just to detect them. A timer runs and if no traffic has been seen for a set time (say 1/2 hour) it sends via an IR diode a sleep timer set code for the TV. The device is placed in front of the TV where it will see the IR remote and be able to send a code to the TV out the back. The point is that when someone is watching, they skip commercials, change volume, channel, etc. When they fall asleep they stop using the remote. If we mess up and accidentally set the sleep timer on an awake user, so what. They will notice.
I had been using code from the Arduino playground and successfully detected Sony remote codes at just bout 100% accuracy.
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1176098434
I had some trouble sending the same codes to the TV. There were two problems. First the bit order was opposite what i thought, and I think the code on the website was not symmetrical. After printing the codes out I figured that out. More vexing however was that the TV ignored the codes I sent. I tried several Sony TVs. Luckily the TV I want to use is a Sony, which has easier codes. I discovered after playing a long while, and looking at the time measurements of the real IR remote versus what I was sending (this took two Arduinos with the same hardware) that my pulses were longer than the real remote. The real remote times were much less than the spec times of 600us and 1200us . I think the clock in the Arduinos are off. By changing the bit transmit times in the code to what i measured, I got the TV to respond. That took a while to sort out. However this varies Arduino to Arduino, so you have to tweak the times to the specific Arduino. Disappointing but I'll live.
The problem that finally stalled me, was that the Arduino IR remote code is using a pulse measurement command and a while loop.
while(pulseIn(ir_pin, LOW) < 2200) { //Wait for a start bit
} data[0] = pulseIn(ir_pin, LOW);
Problem is that I want a timer to increment, and this command uses up the whole of the Arduino's attention. Additionally it is reliable with only Sony remotes, but remember i want to notice codes from a variety of remotes. The 2000us pulse width doesn't apply to the other protocols and doesn't work reliably.
Whoa! ... a google search just turned up this blog, which is much more professional than mine, and has a lot of useful information. Early posts point to the code i had been using.
http://www.arcfn.com/2009/08/multi-protocol-infrared-remote-library.html
http://www.arduino.cc/playground/Code/InfraredReceivers
Alright. Off to lick this problem with some new code!!
This project has an IR receiver that looks for any traffic, from multiple remotes. Point is not to decode them, just to detect them. A timer runs and if no traffic has been seen for a set time (say 1/2 hour) it sends via an IR diode a sleep timer set code for the TV. The device is placed in front of the TV where it will see the IR remote and be able to send a code to the TV out the back. The point is that when someone is watching, they skip commercials, change volume, channel, etc. When they fall asleep they stop using the remote. If we mess up and accidentally set the sleep timer on an awake user, so what. They will notice.
I had been using code from the Arduino playground and successfully detected Sony remote codes at just bout 100% accuracy.
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1176098434
I had some trouble sending the same codes to the TV. There were two problems. First the bit order was opposite what i thought, and I think the code on the website was not symmetrical. After printing the codes out I figured that out. More vexing however was that the TV ignored the codes I sent. I tried several Sony TVs. Luckily the TV I want to use is a Sony, which has easier codes. I discovered after playing a long while, and looking at the time measurements of the real IR remote versus what I was sending (this took two Arduinos with the same hardware) that my pulses were longer than the real remote. The real remote times were much less than the spec times of 600us and 1200us . I think the clock in the Arduinos are off. By changing the bit transmit times in the code to what i measured, I got the TV to respond. That took a while to sort out. However this varies Arduino to Arduino, so you have to tweak the times to the specific Arduino. Disappointing but I'll live.
The problem that finally stalled me, was that the Arduino IR remote code is using a pulse measurement command and a while loop.
while(pulseIn(ir_pin, LOW) < 2200) { //Wait for a start bit
} data[0] = pulseIn(ir_pin, LOW);
Problem is that I want a timer to increment, and this command uses up the whole of the Arduino's attention. Additionally it is reliable with only Sony remotes, but remember i want to notice codes from a variety of remotes. The 2000us pulse width doesn't apply to the other protocols and doesn't work reliably.
Whoa! ... a google search just turned up this blog, which is much more professional than mine, and has a lot of useful information. Early posts point to the code i had been using.
http://www.arcfn.com/2009/08/multi-protocol-infrared-remote-library.html
http://www.arduino.cc/playground/Code/InfraredReceivers
Alright. Off to lick this problem with some new code!!
Friday, September 24, 2010
Repairing the L + R buttons on Nintendo DS
The most common failure I've seen is that either the R or L button stop working on Nintendo DS and DSlite. I've not opened a DSi yet.
Basically I've found that you just have to disassemble the DS, blow it out and splash the button with some rubbing alcohol. That has worked every time. The odd thing is I can't really figure out what has gone wrong. If I use an ohm meter on the switch, they always seem to work. Maybe dirt has gotten in that falls out when the DS lite is disassembled.
Anyway, you need a Tri Wing screwdriver, available on ebay for less than $5. You can get by with a small jewelers flat head if you force it into the screw. It is do-able but a bit difficult if the screws are stuck in tight. The tri wing is worth the investment.
You have to take out the battery and all the screws under it. You have to pry off the two rubber feet and there are screws under them. There is a small screw near the game slot too. Take them all out.
Gently pry open the case. The L R buttons have a small spring, be careful you don't lose it. It likes to fall out as you are taking the DS apart. Watch the power and volume buttons. The little plastic slider will get out of position and you should make sure they are still working before you put all the screws back in. You might have to futz with them to get them back into position.
Of course, if your DS is relatively new, like less than a year, I have sent them back to Nintendo and they have replaced them, very few questions asked. Just go on the nintendo website customer support and fill out an RMA. I've found that if you avoid talking to anyone and get to the step where you just send it back, they will fix it even if it is borderline your fault. If you phone or even email in too much depth, they will tell you that the repair isn't covered and charge you.
Basically I've found that you just have to disassemble the DS, blow it out and splash the button with some rubbing alcohol. That has worked every time. The odd thing is I can't really figure out what has gone wrong. If I use an ohm meter on the switch, they always seem to work. Maybe dirt has gotten in that falls out when the DS lite is disassembled.
Anyway, you need a Tri Wing screwdriver, available on ebay for less than $5. You can get by with a small jewelers flat head if you force it into the screw. It is do-able but a bit difficult if the screws are stuck in tight. The tri wing is worth the investment.
You have to take out the battery and all the screws under it. You have to pry off the two rubber feet and there are screws under them. There is a small screw near the game slot too. Take them all out.
Gently pry open the case. The L R buttons have a small spring, be careful you don't lose it. It likes to fall out as you are taking the DS apart. Watch the power and volume buttons. The little plastic slider will get out of position and you should make sure they are still working before you put all the screws back in. You might have to futz with them to get them back into position.
Of course, if your DS is relatively new, like less than a year, I have sent them back to Nintendo and they have replaced them, very few questions asked. Just go on the nintendo website customer support and fill out an RMA. I've found that if you avoid talking to anyone and get to the step where you just send it back, they will fix it even if it is borderline your fault. If you phone or even email in too much depth, they will tell you that the repair isn't covered and charge you.
Thursday, September 23, 2010
Trick to get a 20x4 Optrex display working
Bought this display from Digikey for the Arduino. It was the biggest and cheapest display I can find, and it is pretty cool. 20x4 display.
Previously I only used NewHaven Displays, and they all worked out of the box with the Arduino examples.
Optrex LCD worked very sporadically. Every once in a while i'd see the correct text, but usually i got garbage on the display. I ohmed out the board, and all was wired right. I found a post that indicated that in 4 bit
mode the display waits between sending bytes, and the default code does not read the busy bits. I thought maybe i needed to add some time between the nibbles in the library.
However it was much easier than that. I wasn't sure how to recompile the library, etc, so i experimented with adding some delays in the sketch. Turns out this big module just takes longer to boot up.
I added a delay like this:
lcd.begin(20,4);
delay(500);
lcd.print("hello, world!");
Ba Da Bing! The display works now, every time.
| 73-1249-ND | LCD MOD CHAR 20X4 WHT TRANSFLECT | 0 | 17.72000 |
Previously I only used NewHaven Displays, and they all worked out of the box with the Arduino examples.
Optrex LCD worked very sporadically. Every once in a while i'd see the correct text, but usually i got garbage on the display. I ohmed out the board, and all was wired right. I found a post that indicated that in 4 bit
mode the display waits between sending bytes, and the default code does not read the busy bits. I thought maybe i needed to add some time between the nibbles in the library.
However it was much easier than that. I wasn't sure how to recompile the library, etc, so i experimented with adding some delays in the sketch. Turns out this big module just takes longer to boot up.
I added a delay like this:
lcd.begin(20,4);
delay(500);
lcd.print("hello, world!");
Ba Da Bing! The display works now, every time.
Wednesday, September 22, 2010
Arduino GPS Tracker completed
Wrapped up the Arduino based GPS tracker project!
This project used a SIRF GPS module I bought off Ebay, integrated with a data logging shield that can write to an SD card. The Arduino microcontroller board makes it all work together. The code supports and LCD readout of the GPS coordinates, heading, speed, etc. In the photos below the LCD is removed because it didn't fit in the case nicely. I'm making another version that has a readout when the parts come.
Basically this is a teen tracker. As long as it is powered, it logs GPS coordinates of the trip every few seconds. It records speed as well (not perfectly accurate). Using gpsvisualizer web site, you can pull out the SD card, put it in your computer, point to the file that is saved and draw a map of the trip. I even tested this in the trunk of the car, and it worked perfectly.
Here is a photo of the completed unit, in it's box. Also shown is the cell phone USB battery that I got at Target, foam taped to the side of the unit. This might seem odd, but the unit would normally draw power from a USB adapter from a car, not from this battery.
Here is a shot with the case open, showing the adafruit data logger shield with the GPS module hanging off to the side, installed in the prototype area of the shield. The Arduino itself is beneath the shield that you can see.
It all snaps inside this project box from Sparkfun.
I polished up the code so the waypoints are taken more often, unless the speed is low in which case some delays are added to keep the file down. I added some LCD display improvements including displaying the compass direction next to the heading (i.e. N, E, S, W, NE, etc). Took it bike riding at it worked perfectly too.
Earlier posts have links to the build, but a couple notes on the circuit, since i havent drawn it.
The box is $11.95 from Sparkfun http://www.sparkfun.com/commerce/product_info.php?products_id=10088
The adafruit sd logger card is the base prototype board. I built it up according to it's directions, it is a nice prototype card. I attached the GPS in the empty prototype area. $19.50 and worth every penny.
http://www.adafruit.com/index.php?main_page=product_info&cPath=17_21&products_id=243
It supports the SDFat library, which writes to and SD card in a format that is directly readable by your PC in a .csv file.
You can get several LCD modules from Digikey if you want one. I used this one for $9.25
http://search.digikey.com/scripts/DkSearch/dksus.dll?WT.z_header=search_go&lang=en&site=us&keywords=NHD-0208AZ-FL-YBW-ND&x=21&y=15
The GPS module came for $30 from ebay http://cgi.ebay.com/ws/eBayISAPI.dll?ViewItem&item=250686123796&ssPageName=STRK:MEWAX:IT#ht_500wt_898
The GPS has a two wire serial interface, described in it's documentation and the photo below. Instead of pins 2,3 I moved the interface to pins 8,9 to avoid conflicts with the LCD and SD card. Pins 10 and above are used by the SD card interface built into the proto board. I did not use a serial LCD like in this example, i used a parallel one. The LCD is hooked up like the Arduino library examples, except the pins are moved to 7,6,5,4,3,2.
(photo borrowed from i182will)
Here is a dump of the code. Atrocious coding as it is. I works though! I am a brute force programmer.
Tuesday, September 21, 2010
Awesome - The GPS tracker makes a map
Hooray, the GPS worked perfectly, the logger logged and the gpsvisualizer sucked in the data and made a map.
By now someone could figure out where i live by these posts, but i'm pretty sure nobody will ever read any of this.
The log file can be uploaded directly to this website, and badabing, a map like this one:
http://www.gpsvisualizer.com/map_input?form=google
By now someone could figure out where i live by these posts, but i'm pretty sure nobody will ever read any of this.
The log file can be uploaded directly to this website, and badabing, a map like this one:
http://www.gpsvisualizer.com/map_input?form=google
Arduino GPS Unit, photos and links to parts

Here are pictures of the completed working unit. A quick compilation of what it is made of:
Arduino board from hacktronics via Amazon $28
http://www.amazon.com/gp/product/B004A7L3NC/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&tag=workingsilico-20&linkCode=as2&camp=1789&creative=9325&creativeASIN=B004A7L3NC
Adafruit datalogger board
http://www.adafruit.com/index.php?main_page=product_info&products_id=243
GPS module from Ebay $30 This is a SIRF3 module
http://cgi.ebay.com/ws/eBayISAPI.dll?ViewItem&item=250686123796&ssPageName=STRK:MEWAX:IT#ht_500wt_1154
NewHaven LCD DisplayNHD-0216K1Z-FS(RGB)-FBW-REV1-ND from digikey $8
http://search.digikey.com/scripts/DkSearch/dksus.dll?WT.z_header=search_go&lang=en&site=us&keywords=NHD-0216K1Z-FS(RGB)-FBW-REV1-ND&x=0&y=0
Duracell Instant USB Charger with Lithium ion battery / includes universal cable with USB and mini USB $26 (paid too much!)
http://www.amazon.com/gp/product/B002FU6KF2/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&tag=workingsilico-20&linkCode=as2&camp=1789&creative=9325&creativeASIN=B002FU6KF2
I will post the circuit and code in a later post, as soon as i clean up some LCD display formatting issues
GPS to do list
Tracked some car trips today, worked awesome. It showed my position to within a few feet.
Some things on my to do list for the GPS:
-More frequent GPS updates. At highway speed the waypoints are too far apart and it looks like I'm going off the road. I have a lot of delays, like 5sec, to make the LCD readable. I only have a 2x8 LCD on the unit, and i have to switch from lat/lon, speed/course, time/altitude. That loop takes 5 seconds and meanwhile the GPS is waiting. I think i will add code to log more often
-I think i need a push switch to scroll between the three possible readouts. The constantly switching display is kinda hard to monitor anyway.
-Put the speed column ahead of altitiude in the log file. gpsvisualizer wants to color my route for altitude, not for speed.
Some things on my to do list for the GPS:
-More frequent GPS updates. At highway speed the waypoints are too far apart and it looks like I'm going off the road. I have a lot of delays, like 5sec, to make the LCD readable. I only have a 2x8 LCD on the unit, and i have to switch from lat/lon, speed/course, time/altitude. That loop takes 5 seconds and meanwhile the GPS is waiting. I think i will add code to log more often
-I think i need a push switch to scroll between the three possible readouts. The constantly switching display is kinda hard to monitor anyway.
-Put the speed column ahead of altitiude in the log file. gpsvisualizer wants to color my route for altitude, not for speed.
GPS battery and Monoprice.com for cable
I used this rechargeable battery to power the Arduino GPS.
Duracell Instant USB Charger with Lithium ion battery / includes universal cable with USB and mini USB
It worked well, i haven't seen how long it lasts, but it has a USB plug that can connect to the Arduino and it charges from a PC USB or wall charger. It was a bit expensive but it seemed like such a nice solution for portable power, rather than burning through 9V batteries.
Monoprice.com is a crazy cheap place to buy cables. I needed a short USB cable to connect the Arduino to the rechargeable battery with a USB plug. The USB cables at best buy were $25.00 and up! At Target they were $15. At monoprice the cables were $0.84 plus $2.24 to ship. I got a cord to charge my cell phone while I was at it. All for $4.24.
Monday, September 20, 2010
Arduino GPS - data logger added
Woot!
I got the data logger shield from adafruit. A nice kit
http://www.adafruit.com/index.php?main_page=product_info&cPath=17_21&products_id=243
It was 19.50, which if you count the parts and proto board, i think it is a good deal. It would have cost me more to buy separately and it looks professional and fits right on top of the Arduino.
The sdfat library i mentioned in an earlier post worked first try after i soldered up the board. I was able to run their data logging example first try on an SD card. Pop it in the computer and the file is there. Totally awesome.
I pasted my gps code from the ebay SIRF3 tinygps library (in an earlier post) together with the sdfat data logger code. I made it only record data when it had a GPS fix that was >0ms and <2000ms to filter out no signal cases that were filling the file with zeros. A little messing with the header that gps visualizer wants on top the file. http://www.gpsvisualizer.com and i was good to go. Sitting at the kitchen table it logged data just fine.
Tossed on a small LCD 8x2 display i got off EBAY so i could tell what it was doing. Between the SD card, GPS and LCD the pins are maxed out on the Arduino.
I used a USB cigarette lighter plug and a USB cable and took it in the car with me. I drove on some errands. The GPS showed all zeros, no signal. boo!!!!! Held it up through the sunroof. Still NADA. Frustration mounted. Tried again the next day driving to work. Nothing. AAAAARRRGH. Is the GPS signal that weak?
Brought it back inside, plugged the USB into my computer. Bingo! signal! Working great again. Walked out to the car.. still working fine. Sat in the car with the Arduino and GPS powered from the laptop USB on battery power. Works great. Here is a picture of my walk to the car, from gps visualizer.
So the problem was the power, either the current or the voltage supplied by the cheapo USB cigarette plug is too low for the GPS to get signal. OK tomorrow we run with the 9V adapter and my inverter! Banzai!
I got the data logger shield from adafruit. A nice kit
http://www.adafruit.com/index.php?main_page=product_info&cPath=17_21&products_id=243
It was 19.50, which if you count the parts and proto board, i think it is a good deal. It would have cost me more to buy separately and it looks professional and fits right on top of the Arduino.
The sdfat library i mentioned in an earlier post worked first try after i soldered up the board. I was able to run their data logging example first try on an SD card. Pop it in the computer and the file is there. Totally awesome.
I pasted my gps code from the ebay SIRF3 tinygps library (in an earlier post) together with the sdfat data logger code. I made it only record data when it had a GPS fix that was >0ms and <2000ms to filter out no signal cases that were filling the file with zeros. A little messing with the header that gps visualizer wants on top the file. http://www.gpsvisualizer.com and i was good to go. Sitting at the kitchen table it logged data just fine.
Tossed on a small LCD 8x2 display i got off EBAY so i could tell what it was doing. Between the SD card, GPS and LCD the pins are maxed out on the Arduino.
I used a USB cigarette lighter plug and a USB cable and took it in the car with me. I drove on some errands. The GPS showed all zeros, no signal. boo!!!!! Held it up through the sunroof. Still NADA. Frustration mounted. Tried again the next day driving to work. Nothing. AAAAARRRGH. Is the GPS signal that weak?
Brought it back inside, plugged the USB into my computer. Bingo! signal! Working great again. Walked out to the car.. still working fine. Sat in the car with the Arduino and GPS powered from the laptop USB on battery power. Works great. Here is a picture of my walk to the car, from gps visualizer.
So the problem was the power, either the current or the voltage supplied by the cheapo USB cigarette plug is too low for the GPS to get signal. OK tomorrow we run with the 9V adapter and my inverter! Banzai!
Subscribe to:
Posts (Atom)





