Changes needed in code from Mega to Uno?

Hello all,

I have been running a pretty basic code on a Mega 2560 board to control two smart LED strips, also connected is a HC-06 bluetooth module to control the lights from a tablet.

I have always suspected that for my application the Mega isn't needed and Uno would be fine; cheaper and more compact.

I uploaded the code that works in Mega to a Uno board and the lights did not do anything. So I'm wondering if there are any precautions I should take both in terms of the connections and the code to switch from Mega to Uno.

Please let me know if you need any more detail, I am pretty illiterate with arduino and just know how to make my one application work :smiley:

Thanks in advance!

Marcos

Please post your sketch, using code tags when you do

A Mega is typically strongly required if many I/O pins are needed. Based on your description, it doesn't seem necessary to me, a UNO is enough, but maybe even a small Wemos D1 mini.

But if you post the code and possibly also a diagram of devices and connections, we can give you more specific answers and advice.

Thanks for the fast reply! Kind of nervous about posting the whole code, but I guess you can't make an omelette without breaking some eggs!

I use a high quality PSU to power both the addressable LEDs and the arduino board with 5V. The HC06 bluetooth module gets power from the board, RX->TXD and TX->RXD.

Each of the two smart LED strips are connected to pins 6 and 7 in the Mega board.

The code as posted works great in Mega (though if you spot any bugs or possible improvements I'm all ears) but didn't work when I uploaded to Uno. I noticed that PWM pins are 3, 5, 6, 9, 10, 11 in the Uno and in the Mega it's 2–13, 44–46. So I guess I was using PWM pins in the Mega and should use those in Uno too, though I have no idea why :smiley:

Thanks again,

Marcos

That is 4 x 1018 = 4072 bytes of RAM needed. How much RAM does your Uno have?

Note:
The Adafruit_NeoPixel library uses dynamic memory allocation so e.g. above memopry is not counted in the memory report.

It's a standard Uno R3, so I believe:

|Flash Memory|32 KB (ATmega328P) of which 0.5 KB used by bootloader|
|SRAM|2 KB (ATmega328P)|
|EEPROM|1 KB (ATmega328P)|

Whereas the Mega 2560 is supposed to have:

|Flash Memory|256 KB of which 8 KB used by bootloader|
|SRAM|8 KB|
|EEPROM|4 KB|

check each variable if you are using the correct variable size.
For example: You have a lot of "int" variables - which will be 2 bytes on an UNO/MEGA.

check each variable if an uint8_t or int8_t would be enough.

Further more, check your variables. Which of them don't need to be changed during program execution? If they hold constant values make them const or even constexpr

So how are you going to cram more that 4k in there?

I didn't realise that each pixel meant 4 b of RAM, nor that the specific RAM I was looking at was the SRAM :slight_smile: So if I'm understanding correctly, just on number of LEDs alone, I can't use a Uno and have to stick with the Mega, right? :-/

Yes.

Understood! Thank you and to all who commented :slight_smile:

Hmm, I'm just thinking that the R4 WiFi should have sufficient memory capabilities with the smaller footprint, right? Might get one to test!