Uno vs Uno WiFi Rev2

Could not upload a DCC++ sketch to an Uno WiFi Rev2 that will load easily to an Uno.

Are the two fundamentally that different that the Uno WiFi will not accept the sketch without errors?

(deleted)

I did select the correct board before trying to upload the sketch.

Please do this:

  • When you encounter an error, you’ll see a button on the right side of the orange bar “Copy error messages” in the Arduino IDE (or the icon that looks like two pieces of paper at the top right corner of the black console window in the Arduino Web Editor). Click that button…
  • In a forum reply here, click on the reply field.
  • Click the </> button on the forum toolbar. This will add the forum’s code tags markup to your reply.
  • Press “Ctrl + V”. This will paste the error between the code tags.
  • Move the cursor outside of the code tags before you add any additional text to your reply.

If the text exceeds the forum’s 9000 character limit, save it to a .txt file and podst it as an attachment. If you click the “Reply” button here, you will see an “Attachments and other settings” link.

Error Message:

Arduino: 1.8.9 (Windows 10), Board: "Arduino Uno WiFi Rev2, None (ATMEGA4809)"

In file included from C:\DCC++2\BaseStation-master\BaseStation-master\DCCpp_Uno\DCCpp_Uno.ino:171:0:

DCCpp_Uno_Wifi_Rev2.h:12:0: error: unterminated #ifndef

 #ifndef DCCpp_Uno_Wifi_Rev2_h

 

exit status 1
unterminated #ifndef

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Please post a link (using the chain links icon on the forum toolbar to make it clickable) to where you downloaded that sketch from.

You need an "#endif" to close the "#ifndef", usually as the last line in the file.

The verbose version:

Arduino Uno WiFi Error.txt (14.1 KB)

You have already gotten a sollution, further (attached) error messages are useless.

I still would be interested in a link to where the sketch was downloaded from so that I could submit a pull request to fix the bug in order to save others from the same confusion.

Want to reboot this thread to start from the beginning.
To test my sketch upload again without trying to tweak the original DCC++ sketch, located here:

I want clarify that the sketch was based on and works with the Arduino Uno or Arduino Mega.
This sketch is 3-years old and there is no technical support for it from the original author, only from other users.

I do understand from some of the available DCC++ support forums on Facebook and Trainboard that the sketch will need to be amended to include the Arduino Uno WiFi Rev2.
I don’t write code so my attempts to edit the sketch were a failure.

No one, to my knowledge, in the DCC++ community has tried using the Arduino Uno WiFi Rev2 yet so no knowledge base there yet.

I, as of today, got a new Arduino Uno and uploaded the DCC++ sketch, again, successfully.
I then connected the Arduino Uno Wifi Rev2 and got the predictable error message below:

Arduino: 1.8.9 (Windows 10), Board: “Arduino Uno WiFi Rev2, ATMEGA328”

Build options changed, rebuilding all
In file included from C:\DCC++\BaseStation-master\DCCpp_Uno\DCCpp_Uno.ino:171:0:

DCCpp_Uno.h:51:4: error: #error CANNOT COMPILE - DCC++ ONLY WORKS WITH AN ARDUINO UNO OR AN ARDUINO MEGA 1280/2560

#error CANNOT COMPILE - DCC++ ONLY WORKS WITH AN ARDUINO UNO OR AN ARDUINO MEGA 1280/2560

^~~~~

exit status 1
#error CANNOT COMPILE - DCC++ ONLY WORKS WITH AN ARDUINO UNO OR AN ARDUINO MEGA 1280/2560

This report would have more information with
“Show verbose output during compilation”
option enabled in File → Preferences.

You cannot expect ppl in this forum to fix a library for you. You could try to force the library to compile for a regular Uno Rev3 by putting "#define ARDUINO_AVR_UNO" into the library's "Config.h". It may work or it may not - probably the latter.

Sounds like that error gives you the answer! DCC++ only works on Uno or Mega. The Uno WiFi Rev. 2 is a dramatically different board from the original Uno. They absolutely should not have named it "Uno" because it uses a different chip with different peripherals (Uno is based on the atmega328p, which is AVR, Uno WiFi Rev. 2 is based on atmega4809, which is megaAVR).

The MegaAVR boards are still pretty new, are not in very widespread use yet, and many libraries designed for the classic AVR architecture won't work on the megaAVR boards without extensive modification. All the registers to control all the on-chip peripherals are completely different.

TexasRailroader:
I don't write code so my attempts to edit the sketch were a failure.

So are you saying that you created the file DCCpp_Uno_Wifi_Rev2.h that contains the code that caused the compilation error?

I used the unmodified sketch in addition to attempts of editing the sketch. Both failed.

DrAzzy:
Sounds like that error gives you the answer! DCC++ only works on Uno or Mega. The Uno WiFi Rev. 2 is a dramatically different board from the original Uno. They absolutely should not have named it "Uno" because it uses a different chip with different peripherals (Uno is based on the atmega328p, which is AVR, Uno WiFi Rev. 2 is based on atmega4809, which is megaAVR).

The MegaAVR boards are still pretty new, are not in very widespread use yet, and many libraries designed for the classic AVR architecture won't work on the megaAVR boards without extensive modification. All the registers to control all the on-chip peripherals are completely different.

So why would Arduino market a new board called an Uno but you cannot upload sketches to it as you would to an Uno? This is somewhat misleading on Arduino's part.

I think it’s a valid criticism about the naming. The Uno WiFi Rev2 is certainly not just an Uno with WiFi. Arduino did make some extra efforts to provide compatibility between the Uno WiFi Rev2’s ATmega4809 microcontroller and the ATmega328P microcontroller of the Uno, but there will always be some inevitable differences.

The first issue you hit is that the Arduino IDE defines a unique macro for each Arduino board so that your code can automatically adapt to the board that is being compiled for. When you have Tools > Board > Arduino/Genuino Uno selected then the ARDUINO_AVR_UNO macro is defined. When you have Tools > Board > Arduino Uno WiFi Rev2 selected then the ARDUINO_AVR_UNO_WIFI_REV2 macro is defined. Unfortunately that is not the only difference. If you adjust the code to accept the ARDUINO_AVR_UNO_WIFI_REV2 macro then you get a bunch of new errors:

In file included from C:\Users\per\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.1\cores\arduino/api/ArduinoAPI.h:52:0,

                 from C:\Users\per\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.1\cores\arduino/Arduino.h:23,

                 from C:\Users\per\AppData\Local\Temp\arduino_build_741987\sketch\DCCpp_Uno.ino.cpp:1:

C:\Users\per\AppData\Local\Temp\arduino_modified_sketch_108556\DCCpp_Uno.ino: In function 'void setup()':

DCCpp_Uno:289:10: error: 'TCCR1A' was not declared in this scope

   bitSet(TCCR1A,WGM10);     // set Timer 1 to FAST PWM, with TOP=OCR1A

          ^

C:\Users\per\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.1\cores\arduino/api/Common.h:77:30: note: in definition of macro 'bitSet'

 #define bitSet(value, bit) ((value) |= (1UL << (bit)))

                              ^~~~~

In file included from C:\Users\per\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.1\cores\arduino/api/ArduinoAPI.h:52:0,

                 from C:\Users\per\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.1\cores\arduino/Arduino.h:23,

                 from C:\Users\per\AppData\Local\Temp\arduino_build_741987\sketch\PacketRegister.h:13,

                 from C:\Users\per\AppData\Local\Temp\arduino_build_741987\sketch\SerialCommand.h:13,

                 from C:\Users\per\AppData\Local\Temp\arduino_build_741987\sketch\SerialCommand.cpp:17:

C:\Users\per\AppData\Local\Temp\arduino_build_741987\sketch\SerialCommand.cpp: In static member function 'static void SerialCommand::parse(char*)':

SerialCommand.cpp:457:14: error: 'TCCR1B' was not declared in this scope

     bitClear(TCCR1B,CS12);    // set Timer 1 prescale=8 - SLOWS NORMAL SPEED BY FACTOR OF 8

              ^

C:\Users\per\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.1\cores\arduino/api/Common.h:78:32: note: in definition of macro 'bitClear'

 #define bitClear(value, bit) ((value) &= ~(1UL << (bit)))

                                ^~~~~

C:\Users\per\AppData\Local\Temp\arduino_modified_sketch_108556\DCCpp_Uno.ino:289:10: note: suggested alternative: 'TCB1'

   bitSet(TCCR1A,WGM10);     // set Timer 1 to FAST PWM, with TOP=OCR1A

          ^

C:\Users\per\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.1\cores\arduino/api/Common.h:77:30: note: in definition of macro 'bitSet'

 #define bitSet(value, bit) ((value) |= (1UL << (bit)))

                              ^~~~~

DCCpp_Uno:289:17: error: 'WGM10' was not declared in this scope

   bitSet(TCCR1A,WGM10);     // set Timer 1 to FAST PWM, with TOP=OCR1A

                 ^

C:\Users\per\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.1\cores\arduino/api/Common.h:77:49: note: in definition of macro 'bitSet'

 #define bitSet(value, bit) ((value) |= (1UL << (bit)))

                                                 ^~~

DCCpp_Uno:290:17: error: 'WGM11' was not declared in this scope

   bitSet(TCCR1A,WGM11);

                 ^

C:\Users\per\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.1\cores\arduino/api/Common.h:77:49: note: in definition of macro 'bitSet'

 #define bitSet(value, bit) ((value) |= (1UL << (bit)))

                                                 ^~~

DCCpp_Uno:291:10: error: 'TCCR1B' was not declared in this scope

   bitSet(TCCR1B,WGM12);

          ^

C:\Users\per\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.1\cores\arduino/api/Common.h:77:30: note: in definition of macro 'bitSet'

 #define bitSet(value, bit) ((value) |= (1UL << (bit)))

                              ^~~~~

C:\Users\per\AppData\Local\Temp\arduino_build_741987\sketch\SerialCommand.cpp:457:14: note: suggested alternative: 'TCB1'

     bitClear(TCCR1B,CS12);    // set Timer 1 prescale=8 - SLOWS NORMAL SPEED BY FACTOR OF 8

              ^

C:\Users\per\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.1\cores\arduino/api/Common.h:78:32: note: in definition of macro 'bitClear'

 #define bitClear(value, bit) ((value) &= ~(1UL << (bit)))

                                ^~~~~

SerialCommand.cpp:457:21: error: 'CS12' was not declared in this scope

     bitClear(TCCR1B,CS12);    // set Timer 1 prescale=8 - SLOWS NORMAL SPEED BY FACTOR OF 8

                     ^

C:\Users\per\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.1\cores\arduino/api/Common.h:78:52: note: in definition of macro 'bitClear'

 #define bitClear(value, bit) ((value) &= ~(1UL << (bit)))

                                                    ^~~

C:\Users\per\AppData\Local\Temp\arduino_modified_sketch_108556\DCCpp_Uno.ino:291:10: note: suggested alternative: 'TCB1'

   bitSet(TCCR1B,WGM12);

          ^

Arduino did make some efforts to prevent this sort of error when compiling low level ATmega328P-specific code for the Uno WiFi Rev2, but it didn’t help much in this particular case. You would need to go through the datasheet for the ATmega4809 and figure out what register names to use to replace the ones that are not defined. That can be pretty difficult for a beginner.

The reality is that you will always have some troubles like this when you use a new or uncommon microcontroller. The ATmega328P boards have been around for something like 15 years so they have had time to get super excellent support from all the 3rd party libraries and sketches written by the Arduino community. It’s hard for anything else to compare to the level of support we have for the ATmega328P.

TexasRailroader:
you cannot upload sketches to it as you would to an Uno?

This isn't a problem with uploading. It's a problem with compiling.

It uses direct manipulation of the timer peripherals to set up ISRs on the Output Capture events that generate (bit-bang) the DCC bitstream. That would have to be changed for any chip with a different timer structure (Uno WiFi2 included.) The rest of the program looks pretty chip-independent.

That doesn't seem like it would be really difficult to change, but you'd need to find someone who was intimately familiar with the timers on the new target chip. It looks to be pretty well documented in DCCpp, and confined mostly to the main .ino file (at startup.)