Go Down

Topic: Code that was working with Duemilanove, not working with Mega2560 (Read 325 times) previous topic - next topic

no_way


Hi all,

First time posting here and wondering if you could help. I'm quite new to Arduino and I'm not great with code.

I've been working on a project with a Duemilanove (given to me by a friend) that involves 64 analogue inputs (from pots and LDRs) from eight 4051 multiplexers and sending the values to Max/MSP. I had six 4051s running fine exactly how I wanted, from the 6 analogue pins on the Duemilanove using this code I found online (sorry but I can't find where I found it. I will track you down and thank you soon). All running and reading in Max with no problems. Good times.

I just bought a Mega2560, I bought it to avoid the extra multiplexing multiplexers and extra hassle, and assumed it would work in the same way but with the extra analogue pins i needed (for the full 64 inputs). But it's not and I don't know why. Bad times.

I've ran the basic sketches on the Mega2560 to make sure it's working ok and it is, and I've downloaded the latest software.

If anyone could help out that would be amazing.

Thanks.

Here's the code:

Code: [Select]
byte data;

void setup() {

Serial.begin(57600);
DDRD = B00011110;

}

void loop() {
for(int i = 0; i < 24; i++) {

PORTD = (i % 8) << 2;

data = (analogRead(i / 8)) / 4;

Serial.print(data);
}
delay(5);

}

PaulS

Quote
But it's not and I don't know why. Bad times.

That's the peril of doing direct port manipulation - it is not portable.


retrolefty

And if you are ever interested in converting direct port commands to and from 328 and 1280/2560 chips then you might find this doc helpful.

https://spreadsheets.google.com/pub?key=rtHw_R6eVL140KS9_G8GPkA&gid=0

Lefty

no_way


Thanks for the quick reply and info, guys.

So I need to translate/convert the ports from the 328 to 2560. Looking over the spreadsheet... I don't understand how to convert PORTD to PORTE (PE 4 & 5) for digital pins 2 & 3 and PORTG (PG 5) for digital pin 4, in the code.

I might be talking completely rubbish, as I don't really know what I talking about, but is this the way to do it? If so do you have a solution?

Thanks again.

retrolefty



Thanks for the quick reply and info, guys.

So I need to translate/convert the ports from the 328 to 2560. Looking over the spreadsheet... I don't understand how to convert PORTD to PORTE (PE 4 & 5) for digital pins 2 & 3 and PORTG (PG 5) for digital pin 4, in the code.

I might be talking completely rubbish, as I don't really know what I talking about, but is this the way to do it? If so do you have a solution?

Thanks again.


Why don't you experiment on your mega board. Rewrite the the basic IDE example blink sketch, but only using direct port commands and see if you can get pin 13 on the mega blinking. When you have accomplished that I think you will have learned what you need to convert 328 direct port commands to 2560 direct port commands.

Teach one to fish, etc....

Lefty

no_way


Cheers. I appreciate the help.

I'll have a play around.

Thanks again.

Go Up