Converting a Mega 2560 Sketch Over to a Due

Hi, I've been working on a project for some time now and have really hit the limits on the mega 2560. The sketch has grown to 243kb using 6kb of SRAM and that's after skrinking libraries. The reason its so large is because it has a 22 page GUI for a 800*480 display.

A while ago I changed the project to include two mega2560's, not because of the limitations, I wanted all my connectors to be hidden away from the display not coming out of it, I have 9 so far and hopefully more to come. Currently I have the two mega2560's communicating through the serial and that has to work exactly the same.

One arduino is responsible for the sensors and equipment and the other is responsible for the GUI and RTC. The mega 2560 is perfect for the equipment as it has more than enough resources because it has no GUI or UTFT or anything like that.

Now I want to add more features but I'm at a point where I can't have many more images, etc... So I want to replace the mega controlling the display with a Due and leave the other mega doing the rest.

Will the mega2560 and Due communicate via Serial the same as two mega will? As in Serial2.println(F("304"));?

The libraries on the display mega 2560 are as follows.

Wire.h
UTFT.h
UTouch.h
UTFT_tinyFAT.h
SdFat.h
EEPROM.h
RTClib.h
Time.h
TimeAlarms.h

I'm not worried about the first 5 libraries as they are compatible with minimal code changes.

I know the Due doesn't have an eeprom and was going to add one. I found this tutorial and was wondering if it will work? It looks pretty close to the eeprom library and straightforward. I'm worried about the code not hooking it up.

What really scares me about the conversion is the RTC and times. I'm using the RTClib with a DS1307 and was hoping the following library will work without much changes to the sketch? Has anyone used this updated version?
http://forum.arduino.cc/index.php?topic=143515.0

For the time and timeAlarm library I found a link on the arduino website to updated libraries for the Due, will these work without changes to the sketch?

http://playground.arduino.cc/Code/Time

I don't have a Due but was going to order one and some eeproms but wanted to make sure this was possible without rewriting the sketch. If the serial communication between the mega and due are exactly the same then I shouldn't need to touch the other sketch?

Will the mega2560 and Due communicate via Serial the same as two mega will?

Yes, of course.

I'm worried about the code not hooking it up.

Is there a comma missing from that statement? Since the project was posted on instructables, of course it will work. About as well as any of the rest of the crap posted there. YMMV.

What really scares me about the conversion is the RTC and times.

Why? I2C is I2C.

will these work without changes to the sketch?

You have an RTC. Why can't you do things at the defined time, without a library? Why can't you just try the code and see if it works?

I'm worried about the RTC libraries because there are a lot of date conversions throughout the sketch. If I had to change libraries I would need to re-write that. The problem with that is I'm not really sure how. I started this project with another sketch that had a lot of that worked out so I don't really know how it works and don't want to find out right now. I'm not a very good programmer, so that's why I was wondering if the linked libraries I posted would work with minimal changes.

I was worried about the serial communications because I don't want to touch the other sketch, I spent a lot of time getting that working and don't want to redo it. :slight_smile:

I would try it but I don't have a due or eeprom and don't really want to order one if these libraries weren't going to work.

robsworld78:
Will the mega2560 and Due communicate via Serial the same as two mega will?

Not without a 5V <-> 3.3V level shifter, the Due is 3.3V only and is absolutely intolerant
of 5V signals.
But at the software level you'll be OK.

MarkT:
Not without a 5V <-> 3.3V level shifter, the Due is 3.3V only and is absolutely intolerant
of 5V signals.
But at the software level you'll be OK.

I was reading that a couple resistors would do the job? Do I have to get a level shifter, if so what would work?

So how would I physically connect TX1 and RX2 between the mega 2560 and Due?

I've been searching but can only find a thread on this site saying some resistors would work. I've been searching digikey for a level shifter but can't find any. The thread mentioning resistors wasn't to clear either.

robsworld78:
I was reading that a couple resistors would do the job? Do I have to get a level shifter, if so what would work?

Series resistors work just fine. I have dozens of 5V devices connected to my Dues, using 300 ohm resistors. Never had a single problem. They just need to be large enough to limit current into the Due pins to less than the current limit of the ESD diodes, which are good for something like 6mA.

Regards,
Ray L.

74HC4050 powered from 3.3V. 5V in, 3.3V out.
Hex converter, so it's good for several signals.

RayLivingston:
Series resistors work just fine. I have dozens of 5V devices connected to my Dues, using 300 ohm resistors. Never had a single problem. They just need to be large enough to limit current into the Due pins to less than the current limit of the ESD diodes, which are good for something like 6mA.

Regards,
Ray L.

What is a series resistor? I googled it but only get resistors in series. Which lines do the resistors go? I have all kinds of 1/4w metal film resistors, will these work? Sorry I'm just learn about resistors, etc...

CrossRoads:
74HC4050 powered from 3.3V. 5V in, 3.3V out.
Hex converter, so it's good for several signals.

I looked that part up on digikey and they have all kinds, which one would it be? Is there a schematic around showing how this gets wired to the TX & Rx wires?
The resistors sound a lot easier.

robsworld78:
What is a series resistor? I googled it but only get resistors in series. Which lines do the resistors go. I have all kinds of 1/4w metal film resistors, will these work? Sorry I'm just learn about resistors, etc...I looked that part up on digikey and they have all kinds, which one would it be? Is there a schematic around showing how this gets wired to the TX & Rx wires?
The resistors sound a lot easier.

ANY pin you want to connect to a 5V signal needs to have a 300 ohm resistor connected with one end on the 5V signal, the other end on the Due pin. NEVER connect a 5V signal to any Due pin directly, even briefly, or you WILL damage the pin, and possibly other things in the chip. For simple, low-speed I/Os, there is no advantage whatsoever to using a level-shifter chip. It's just adding unnecessary complication.

Regards,
Ray L.

Would I hook it up exactly like the mega's are except with a resistor inline on both wires?

Is a 300ohm 1/4w metal film resistor good?

I have the serial baud rate at 9600 and send strings back and forth.

CrossRoads:
74HC4050 powered from 3.3V. 5V in, 3.3V out.
Hex converter, so it's good for several signals.

Would this be the part you're talking about?

Would I put that inline on the Tx & Rx wires?

I drew up a schematic using that 74HC4050, does this look right? Do I need any resistors or is it direct connections?

CrossRoads:
74HC4050 powered from 3.3V. 5V in, 3.3V out.
Hex converter, so it's good for several signals.

Hi CrossRoads, could you please comment if I have the wiring correct above? Now I'm thinking the Tx from the Due should be going into an input on the 74HC4050 not an output? Or maybe the Tx from the Due doesn't even need to go through the IC as the Mega can handle the 3.3v? Will 3.3v be enough for the mega, someone was telling me I needed a bi-directional level shifter? I've already ordered the 74HC4050's which arrived today. I want to try this out but worried I have it wired wrong. Any help is appreciated.

Can't open your link. Use the "Attachment and other options" link below, Browse to your locally stored file, and Attach it.

Oh that's odd, I see it. How's this.

Also can I add a DS1307 RTC board to this?

I use 5V powered 74HC125 to convert 3.3V signals back to 5V. Generally for SPI (MISO) so that 5V applied by a programmer doesn't make it back to the 3.3V device.
If you have the Due's TX going to an Rx that will not have a way to be driven to 5V by anything, then you can connect direct.

Not so odd - just an ISP blocked website.

You can do that, it won't hurt anything and protects the Due if you should accidentally drive the Rx line high.

Thanks, even though the Tx from the Due is on an output the signal will still make it to the mega?

Any thought on the DS1307?

How does this updated schematic look with the RTC?