|
Fig 1: Three experiment--two with the samsung remote on the left, one with the Radio Shack remote on the right--to control a +Adafruit Industries 8x8 Bicolor LED Matrix |
I haven't posted in a while because several interests have kept me very busy. This all started withe the +Parallax Board of Education (BOE) Robot kit. I asked for and received on for Christmas a couple of years ago and let it ripen until I was ready. I decided that it would make a good project to do with my 7-year-old granddaughter when she visits this summer--but first, I should make sure that I can build it without a lot of fumbling. Fumbling is good, but watching me figure out what dumb thing I did is not always interesting to a 7yr-old. I followed
the tutorial and learned quite a bit, The last project that I did used infrared for proximity sensing to avoid obstacles. At the same time,
+Adafruit Industries, via
The Desk of Lady Ada, provided some great information on IR. So, I decided to play and learn further.
|
Fig 2: +Parallax BOE Bot with 2 IR transmitters aand 2 IR receivers |
IR Decoding the Hard Way
Following the
+Adafruit Industries tutorial on IR Sensing, I was able to decode only some of the buttons on my Samsung TV Remote (see Figure 1). Using the remote is a 2-step process: first decode the signals send by the buttons, then use the decoded signals in a different sketch that takes action based on the buttons. Using this method (see the
Raw IR Decoder and
ircommander code on github), I was able to decode some of the buttons and use them in a sketch.
Quick diversion: I have had big plans to use a
32x32 LED Matrix that I bought in a parking assistant project that will display faces to convey the emotions evoked by a car getting increasingly closer. I decided to use the
8x8 bicolor matrix and backpack to prove the concept, and use the remote to signal which face to display. Figure 1 shows the initialized yellow face (looks orange to me). So, I needed to follow the
tutoral for the matrix and backback library.
I was able to merge code from the bicolor8x8 example code in the Adafruit LED Backpack library with code from the ircommander sketch referenced above. After adding the decoded remote buttons to a newly created library (see the IR Sensor tutorial and the project video cited at the end of this post), I was able to change the face on the matrix based on the remote buttons.
I found both the coding aspect and the operation of the technique to be less than perfect. Maintaining a separate library with very long sequences of numbers just to test what button was pressed seems a bit much. In operation, the code seems to reset itself randomly, and only respond to buttons when it feels like. This may be me, and I will investigate, but read on to see a much neater technique.
IR Decoding an Easier Way
After working through the above, I watched Lady Ada work through Chris Young's IRLib2 in one of the Desk of Lady Ada epdisodes cited above. Chris, aka cyborg5, is a frequent visitor to the Adafruit Show and Tell, and has done a lot of great work (
see his blog). Both the decoding and the processing techniques are simplifies greatly, and his library handles several IR protocols. The
IRLIB2 tutorial describes it all very well. You wind up with one simple code that you supply in a sketch so you can determine what button was pressed--straightforward, and I was able to decode all the buttons with no missed presses. From there it was a matter of simplifying the sketch I wrote earlier to display faces on the LED matrix. Again, the project video shows all this.
Controlling Motors with IR
Since we started with robots, I thought it would be interesting to control motors with IR. It was a simple matter to modify the IRLib2 sketch above to direct the
continuous rotation servos. I took code from the BOE-Bot project, and code from the
Adafruit_PWMServoDriver library tutorial, and it went smoothly. The servos in the BOE-Bot are different from the Adafruit ones, so I had to go to the data sheet to see what values to use to get them to move as I wanted. I was able to decode all the buttons on the Samsung remote, and used the arrow keys to simulate moving the robot forward, back, left, and right.
I first did this without the
PWM Servo FeatherWing. Because the feather is 3V logic, I needed a
level shifter to handle the signals from the board to the servos. That worked, but added a few connections and I used the Arduino servo library as opposed to the Adafruit library which allowed for simpler code.
Another thing I needed to worry about was timer conflicts. I had come across this before,
in my Donkey Project, but Chris' tutorial gave a straightforward explanation and solution. The problem is that the servo library uses Timer1 and on the 32u4 Feather IRLib2 does too. It was necessary to go into one of the associated libraries and change one line of code to re-assign the timer. You'll get better instruction in the tutorial than I can give here. Again, the project video shows the results.
|
Controlling 2 FS90R continuous rotation servos from an Adafruit BLE Feather and PWM Servo FeatherWing |
Trying a Different Remote
A while back, Radio Shack sold some MAKE project kits, including robotics. During an earlier RS bankruptcy, I acquired a RS remote at a big discount and still had it in inventory, so I decided to try it out. Using the IRLib2 approach to decoding, I found the the protocol was not one of supported ones. A look at the datasheet for the PT2248 chip in the remote revealed that ot used the Toshiba protocol. So, I had to go back to the hard way, and I got that to work. See the video.
IR Affects the BOE-Bot
Just for grins, I took out the BOE-Bot, let it runon the floor, and chased it with a remote. The bot's IR retrievers detected the transmissions, and the bot reacted accordingly (moving left or right as if it had detected an obstacle).
Project Video