Arduino mega and the LOL shield

I purchased the LOL shield because I need it for a simple demonstration. I’m going to use the Arduino mega 1280 to display the numbers 0 to 9 on the LOL shield. That is not difficult to do, but I am also going to use a remote control to send a number to the Mega. That number should be left out of the sequence 0-9 that is displayed by the LOL shield. The fun part of the demonstration is an inspection camera that is used to ‘detect’ the missing number. It sounded easy but the problem started with the combination Arduino Mega and LOL shield. The LOL shield works perfectly on the Arduino UNO but it doesn’t work on the Mega. I’m not the only one running into this problem. The video below shows the problem. (No, it’s not me in the video below below, it’s another Arduino user.)

I started looking at the problem and started to eliminate problems. I started of using the simple example that doesn’t use the CharliePlexing library. I replaced the digitalWrite funtions with analogWrite(pin, 0) and analogWrite(pin, 255). This already got be a bit further. Then Gerard, one of my coworkers told me to disable the clock feeding timer 2. This resulted in rewriting the setup() function:


void setup()
{
alloff();
// Disable PWM on 0-13. Block the clock signal to timer2
TCCR2A = _BV(COM2A0) | _BV(COM2B1) | _BV(WGM20);
TCCR2B = _BV(WGM22) | _BV(CS22);
OCR2A = 0;
OCR2B = 0;
}

I Also updated allof() since the original function only implements the ‘UNO’ way, I needed a few changes because to do it the Mega way::

void alloff() {
// http://spreadsheets.google.com/pub?key=rtHw_R6eVL140KS9_G8GPkA&gid=0
// http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1266009870
// Arduino mega pin magging does not correspond with Arduino UNO
// Pin mapping.
DDRE = DDRE &~ B00111011;
DDRG = DDRG &~ B00100000;
DDRH = DDRH &~ B01111000;
DDRB = DDRB &~ B11110000;
}

These 2 changes allowed me to use digitalWrite() again. The result looks promissing. The next challange is to fix the CharliePlexing library. It doesn’t work with the Mega 1280. The fixes given above should be applied to the CharliePlexing library also. Also a few other fixes are needed since the ATMega1280 is treated as an ATMega328 in the CharliePlexing library and that is not correct. I’ll post my results here.

See ya.

Update 06-02-2011: I ran into a second issue. The LOL shield and the IR library are using the same timer. I need to assign another timer to the IR library 😦

Advertisements
This entry was posted in Post Arduino and tagged , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s