Wednesday, January 25, 2012

Parallax Smart Card Reader Samples for Arduino

Note:  There is a now an Arduino Library available for the Parallax Smart Card Reader, please see the new post in this blog.

I ordered one of the Parallax Smart Card Readers as listed on the Parallax web site.   I also went ahead and ordered one of each of the three (3) types of Smart Cards that Parallax provides for use with the reader to play around with ... and I believe I have code for the Arduino that works with each of the three types.

Note:  I did lock my first IS23SC4442 (32321) card while learning ... had to order more (this time I ordered a couple) ... but I did seem to get it working without locking a second one.   And ... once you lock one, it can't be unlocked (at least not that I know of) ... but I do now have the ability to make sure the lock-check logic works and see that it is impossible to write to the card's memory when it is locked. 

The IS24C16A (32322) and IS24C02A (32323) don't have any type of protection built in where they could be locked ... so no problems there.

Also Note:  All of the samples are derived from the PBASIC 2.5 and Propeller samples that Parallax provided.  So, if it doesn't seem to work for you, that's where I got my info from.

I think that I could have used the Arduino Wire library for the 32322 and 32323 cards, but decided not to go that deep yet ... I may eventually give it a try ... although it might have been easier.   When looking at the BASIC examples and the Propeller examples and converting to C/C++, it seemed easiest to keep things as similar as possible.

If you have access to one of each of the three types of cards, I recommend starting with the 32323, then trying the 32322 (all 8 pages) and then finally trying out the 32321 with its protection capabilities.

If you don't like the pins I used, certainly change as needed ... I have tried the samples with both an Uno SMD R2 and a Mega 2560 R3 ... both seem to work with the pins specified.

So, if you want, give the Adruino samples (one for each card type) a try ... they can be found here.   They all compile fine with Arduino 1.0 ... I didn't even try with any older Arduino versions.

Good Luck!  I'll try to help if you have problems.

Updates

6/27/2013 - I just hooked up my Card Reader and opened all 3 samples in Arduino 1.0.5 ... something I've been meaning to do for a while now ... they all compiled and ran fine.   So, if you are having problems, keep in mind that these samples were made specifically for the Parallax Smart Card Reader (you can find the link above in the very first sentence of this Post).   Also keep in mind that EVERY sample uses the following connections between the Reader and the Arduino:

Parallax Card Reader                          Arduino
           I/O         -----------------------           A4
           CD         -----------------------            3
           CLK      -----------------------           A5
           RST       -----------------------            2
           VCC      -----------------------           5V
           GND      -----------------------         GND

02-14-2015 - Moved Samples to Github.

Sunday, January 15, 2012

Amarino Software Serial Libary

I bought a really, really inexpensive Bluetooth module on eBay a while back to play around with on my Arduino ... and I've been playing around with Amarino (learn more about that on the Amarino website) which allows Bluetooth communication between an Android phone or tablet and an Arduino ... this is again related to my reading the Arduino + Android Projects for the Evil Genius book (by Simon Monk).

Unfortunately, I've tried and tried to get the two to communicate, with no luck.  I figured out how to change baud rates on the Bluetooth module using the Arduino Serial Monitor, so I knew I could send and receive fine between the Bluetooth module and the Arduino ... I could connect from my Android tablet to the Bluetooth module, so I knew Bluetooth was working (or, at least, connecting), but I could never get the Serial commuincation to work afterwards ... well, I could send to the Android, but I couldn't receive from the Android.   And I knew the Android was sending because if I held down the reset button on the Arduino (so the sketch that opened the Serial port wasn't running) I would get the data from the Android in the Arduino Serial Monitor (or garbage if the baud rate was wrong) ... so, I was definitely receiving!   But opening the serial port in the Sketch (with the Serial.begin() call) seemed to be causing me grief ... and the MeetAndroid library required that I did it ... so ... Catch 22 (if I called the Serial.begin() I couldn't receive data, but if I didn't I could, but I had to 'cause Amarino understandably requires it to be open) .

Anyhow ... then I found that if I wrote a little Arduino sketch that opened both the normal Serial Port and a Software Serial port, and moving the wires that ran between the TX/RX on the Arduino and Bluetooth to the pins specified in the Software Serial initialization that I could get the data coming from the Android no problem. 

So, I decided to play around and change the Amarino MeetAndroid library so that it used a Software Serial port rather than a Hardware Serial port ... make some minor changes to a couple Amarino sample sketches and voila ... it worked!

I have added a link where you can download a SoftwareSerial library-based version of the Amarino MeetAndroid library and I've also included the modified sample sketches.
So, for example ... for the Amarino Test application:

The first few lines look like this (past the comments):

 #include <MeetAndroid.h>  
   
 MeetAndroid meetAndroid;  

The SoftwareSerial version now looks like this:

 #include <SoftwareSerial.h> // absolutely required  
 #include <MeetAndroidSS.h>  
   
 MeetAndroidSS meetAndroid(9600, 1, 0);  // (baudrate, RXpin, TXpin)  

In addition, you need to remove the Serial.begin() call from the setup() function (the Software Serial port is intialized in the MeetAndroidSS class initialization and NOT with the Serial.begin() call ... in-fact if you leave in the Serial.begin() ... it probably won't work ... especially if you keep the RX and TX pin numbers at 1 and 0 respectively.

Oh ... and I did add a meetAndroid.send() call in the Test sketch testEvent() function so that I could see an 'Arduino Says' message in the Amarino Monitor.

I have changed the class / directory name so you can have both the SoftwareSerial-based and HardwareSerial-based libraries installed at the same time.

And remember ... the Baud Rate on your Bluetooth module has to still be the same as the Baud Rate specified in the class initialization call.  I've found the highest I can use without any problems is 57600 ... I'd recommend starting low at 9600 baud and working you way up to 115200 baud to see if/when it stops working.

Also, remember, if you are using a Mega or Mega 2560, there are limitations on which pins can be successfully used with the SoftwareSerial library ... 1 and 0 aren't included in those pins ... I personally just change the 1 and 0 to 51 and 50 (and connect wires appropriately).... that way all I have to do is remember that I need to add a 5 before both the RX and TX pin numbers if I'm using my Mega 2560 rather than my Uno (note: 11 and 10 are also available similarly as usable with the SoftwareSerial library for the Mega and Mega 2560, but the MultiColorLampTutorial sample uses both of these pins for LED output, so be careful) ... here's an example using 51 and 50:

 MeetAndroidSS meetAndroid(9600, 51, 50); // (baudrate, RXpin, TXpin)  

The MeetAndroidSS Library and all modified Amarino examples can be found here.


If you are working with the samples from the Arduino + Android Projects for the Evil Genius book (by Simon Monk).

The changes are as follows for the ch01_droid_droid sketch:

1.  Add an #include <SoftwareSerial.h> as the first line of the sketch.
2.  Change the #include <MeetAndroid.h> to #include <MeetAndroidSS.h>
3.  Change MeetAndroid phone; to MeetAndroidSS phone(baudRate, 1, 0);
     or whatever pins you use
4.  Delete the Serial.begin(baudRate); line in the setup() function.
5.  And don't forget that you may need to change the baudRate value to something other than 9600.


Full credit goes to the original authors.


Updates

1/16/2012 (or really late on 1/15)
  • Converted remainder of samples provided in the HardwareSerial version.  
  • Added getSerial() function allowing access to Software Serial port.  See SensorEvents sample for an example of its use.
1/17/2012
  • Added reminder regarding Mega and Mega 2560 compatibility issues with the SoftwareSerial library in the post above.
  • Added the changes necessary for the Evil Genius book sample in the post above.
2/14/2015
  • Moved Libraries and Samples to GitHub.

Thursday, January 12, 2012

Solderless (Stackable) Headers for Arduino Shields that Don't Have Any

If, like me, you have a shield that doesn't have any stackable headers soldered on it (and possibly no place to solder them on) and you'd like have access to the Arduino headers without a lot of hassle (or any soldering), try this...

Go find/buy two sets of Stackable Headers (yes two) like these and also go get 28 (2x8 + 2x6 = 28) micro hard drive jumpers like this pack of 24 ... unfortunately you'll need 2 packs to get to 28 ... but they aren't real expensive.   Now take the two sets of Headers and make a set of 4 pairs and put a micro jumper on each pin of the pair of headers.   Now, when you want to access the Arduino headers with a shield that doesn't have headers of it's own: first, place your new special headers into the Arduino header with one of each pair on the outside of the Arduino Header (so you will see the pins of the header that doesn't go into the Arduino on the outside of the Arduino Header, away from the board) and finally, place the shield so it is sitting on the special headers; again, so the extra header in the pairs is on the outside.

Now just run whatever connections you need to the outside pair, the micro hard drive jumpers will make the connection to the Arduino for you.   NO SOLDERING REQUIRED.

Here's a sample picture of an Adafruit Wave Shield sitting on a Mega 2560 with wires runnnig from pins 10, 11, 12 & 13 to 53, 51, 50 & 52 respectively (so the shield will work on the Mega) using the special headers:



A couple of things to remember:

1. You can't add another shield on top ... but, if you don't need to, this works well.
2. If the top shield requires connection to the ICSP pins you probably won't have to do this since, in reality, what we're doing here is connecting pins from the shield to the mega that are supported through the ICSP pins.   In-fact, I'd almost guess that if the shield has an ICSP connection and it doesn't work as-is on the Mega, the above won't help either.

Good Luck!

Sunday, January 1, 2012

Android ADK Terminal Emulator with a Honeycomb Tablet

If you have attempted to run the Android ADK Terminal Emulator that is referenced from the Circuits@Home article found here on a Honeycomb-based tablet (like the Motorola XOOM or similar) then you may find that it crashes before it will even start.   The problem is that the Terminal Emulator is using some functionality that isn't fully compatible with menus in the default theme when ran under the Honeycomb variation of the Android OS.

For a quick work-around ... just modify the AndroidManifest.xml file ... change the default application theme to something more 'compatible' ... for example:

change this
 <application android:icon="@drawable/icon" android:label="@string/app_name">  

to this (mine is all on a single line)
 <application android:icon="@drawable/icon" android:label="@string/app_name" android:theme="@android:style/Theme">  

Then after saving and rebuilding the Terminal Emulator, upload it to the Honeycomb tablet and it will, at least, start; and you will be able to do most of what the Terminal Emulator was designed to do, including communicating to an Arduino.  

Unfortunately, you won't have access to the preferences screen or the exit option that is available... you can't access it because the Honeycomb tablet doesn't have a hardware-based menu button, and the Terminal Emulator doesn't have the code in-place to handle a software-based menu.  So, there are still some changes that need to be made.  

What I found was the easiest is to just add a context menu that is identical to the options menu already coded in the Terminal Emulator and code it so that when the keyboard-toggle icon in the upper-left corner of the main Terminal Emulator window is pressed and held, the context menu is displayed and you can then access the preferences screen and exit option as-needed.  Plus, it doesn't interfere with the ability to show and hide the keyboard; you don't have to add any additional controls to pop-up the context menu; but you will have access to the menu's preferences and exit options.

If you are interested, I've put the updated Terminal Emulator project here.

Full credit goes to the original author and you can get the original project here.

If you have any problems, let me know, I'll try to help.

Updates

02-16-2015 - Downloads moved to Github.

Fun with the SolidDigi Color Image LCD Shield

If you have purchased the SolidDigi Color Image LCD Shield like the one found here then you have probably also found that even though it is very similar to the SparkFun Color LCD Shield like the one found here that there are some definite differences and incompatibilites when you try to use sketches that were created for use with the SparkFun Shield.

Well, I've taken a little time and gotten some of the libraries and sketches available for the SparkFun Shield to work with the SolidDigi Shield ... all are Arduino 1.0 compatible ... including:
  • The Color LCD Shield Library by Peter Davenport (the SparkFun version is found here).
  • The Arduino-O-scope (the SparkFun version is found here).
  • A SparkFun Sample (the Sparkfun version is found here).
  • Even some tweaks to the SolidDigi Sample to fix colors, etc.
Note: Full credit goes to the original authors of everything above ... I'm just providing some small tweaks so it works on a diffrent shield (or making some subtle changes to the original SolidDigi Sample).

If you are interested in any of this you can find the SolidDigi Shield compatible files here.

Again, I'm far from perfect doing this stuff ... but I'll try to help if you are having any problems.

Updates

02-16-2015 - Moved Libraries and Sketches to GitHub.