Arduino Forum

Products => Nano Boards (NEW types) => Nano Every => Topic started by: flyx on Jul 23, 2019, 11:21 pm

Title: Problem with arduino NANO EVERY and libraries
Post by: flyx on Jul 23, 2019, 11:21 pm
Hey what's up guys, I have bought my new arduino nano every like a month back now and still can't figure why are libs not working at all with it. I know that some of them are not updated yet for this new board, but there are problems with some basic ones too. I thought that some updates of the pack with this board in arduino ide might help, but still nothing and i would really like to get it running. I am little confused if it's just me, or other people too, cause I couldn't find any problems like this.
Compilation error is in attachment and btw, if it needs to solve some macro or files changes, I do not care and know how to do it - I am not a begginer

If you care, just quote me, thanks a lot for any reactions
Title: Re: Problem with arduino NANO EVERY and libraries
Post by: pert on Jul 24, 2019, 12:24 am
This is some strange looking output. What software are you using?
Title: Re: Problem with arduino NANO EVERY and libraries
Post by: david_2018 on Jul 24, 2019, 12:34 am
I managed to replicate the errors using the OLED_I2C library from Rinky-Dink Electronics.

http://www.rinkydinkelectronics.com/library.php?id=79 (http://www.rinkydinkelectronics.com/library.php?id=79)

Appears to be some direct register manipulation, so its not going to work with the atmega4809 processor used in the Nano Every.

To the original poster, you might want to look through the forum for the Uno WiFi rev 2 board, that board uses the same processor and you may find some suggestions there.  You can also try some of the other OLED libraries, you may find one that will work.
Title: Re: Problem with arduino NANO EVERY and libraries
Post by: flyx on Jul 24, 2019, 10:11 pm
This is some strange looking output. What software are you using?
It is an arduino extension for microsoft visual studio on win10. It works the same, but i prefer it more and it has more accurate error output. If you need error output from arduino IDE, i'll make one, but I have been testing it and it doesn't work too
Title: Re: Problem with arduino NANO EVERY and libraries
Post by: pert on Jul 24, 2019, 11:16 pm
I would prefer the output from the Arduino IDE because I'm familiar with it. I'm having trouble interpreting that output from Visual Studio because I have only used it for a very short period of time years ago. Others here may be experienced with VS and be able to work with that output easily.
Title: Re: Problem with arduino NANO EVERY and libraries
Post by: flyx on Jul 25, 2019, 01:28 pm
Okay here you have it
Title: Re: Problem with arduino NANO EVERY and libraries
Post by: oqibidipo on Jul 25, 2019, 02:30 pm
Rename the RTC variable, RTC is already defined in <avr/iom4809.h> (but not in <avr/iom328p.h>).

Code: [Select]
#define RTC                   (*(RTC_t *) 0x0140) /* Real-Time Counter */
Title: Re: Problem with arduino NANO EVERY and libraries
Post by: david_2018 on Jul 25, 2019, 04:08 pm
Rename the RTC variable, RTC is already defined in <avr/iom4809.h> (but not in <avr/iom328p.h>).

Code: [Select]
#define RTC                   (*(RTC_t *) 0x0140) /* Real-Time Counter */
That's probably because the atmega4809 has an internal RTC, although I'm not sure how accurate it is.
Title: Re: Problem with arduino NANO EVERY and libraries
Post by: flyx on Jul 29, 2019, 04:36 pm
Thank you guys, but it does not solve the problem with the oled library, which is still giving error outputs. There are some undefined macros and that is little strange, isn't it?
Title: Re: Problem with arduino NANO EVERY and libraries
Post by: 68tjs on Jul 29, 2019, 06:12 pm
Quote
That's probably because the atmega4809 has an internal RTC, although I'm not sure how accurate it is.
The accuracy of the RTC will be that of the main oscillator.
Arduino made the (very bad) choice not to use quartz or external resonators, unlike in  his other cards, probably to save money.
The accuracy of the internal oscillator is only ± 2% between 0 C and +70 C.

Throughout the operating range it is only ± 4%.



I do not think this card is useful.
Title: Re: Problem with arduino NANO EVERY and libraries
Post by: david_prentice on Jul 29, 2019, 07:07 pm
Quote which library example.
Quote which library version.  e.g. from the IDE Library Manager

You will find that you get answers on this forum.
And a "fix" might get offered to the library author.   (for the benefit of the world)

Without this information we are on a wild goose chase.
Always test library examples before attempting to write your own sketch.

David.
Title: Re: Problem with arduino NANO EVERY and libraries
Post by: erikjanssen on Sep 22, 2019, 07:37 pm
Is there a way to verify a library for the new Nano boards without installing by trial and error?
Title: Re: Problem with arduino NANO EVERY and libraries
Post by: pert on Sep 22, 2019, 11:53 pm
Is there a way to verify a library for the new Nano boards without installing by trial and error?
By "installing by trial and error", do you mean the process of installing a potential library, uploading to the Nano, and seeing if it works?
Title: Re: Problem with arduino NANO EVERY and libraries
Post by: david_prentice on Sep 23, 2019, 09:43 am
I don't think you have much choice.   Most libraries are intended for "all targets" as default.
Very few libraries are restricted to specific targets.

You will only find out when you try to build for a NANO-EVERY target.

If you have a problem,   post on the Forum.
If you have a fix,  send a Pull-Request to the GitHub Repository

David.
Title: Re: Problem with arduino NANO EVERY and libraries
Post by: erikjanssen on Sep 23, 2019, 01:58 pm
By "installing by trial and error", do you mean the process of installing a potential library, uploading to the Nano, and seeing if it works?
Yes that is the case, my application has three NANO's at the limit of their capacity talking to a MEGA through RF24Network. When verified for and EVERY they fail on almost all libraries I use. So yes I accept the invitation to report about my findings, later in a different post.

Replacing the NANO with an EVERY is possible but requires a more work than moving to a MEGA where I had no issues.

Maybe I should abandon the idea of using an EVERY and move to a NANO IoT instead and a full re-design of my application.

Title: Re: Problem with arduino NANO EVERY and libraries
Post by: david_prentice on Sep 23, 2019, 10:47 pm
The NANO-EVERY is just a board with the same pinout as the popular NANO

The NANO-EVERY uses an ATmega4809 instead of the NANO's ATmega328P

You get 48kB vs 32kB Flash
You get 6kB vs 2kB SRAM
You get 256B vs 1024B EEPROM

The Arduino pinout may be identical but it maps to different MCU Port pins on the mega4809.
The regular Arduino functions and classes e.g. digitalWrite(), SPI.begin(), ... work the same.

If a library dives into the mega328P hardware it will not be the same on a mega4809.
Hence you need to report any problems.

The mega4809 peripherals are "better" than mega328P but don't expect them to work any faster.
The extra Flash and SRAM is handy.  The smaller EEPROM might be awkward.

It is generally easier to put everything on one big MCU than to use many small MCUs.
i.e. single-chip design if possible.

David.
Title: Re: Problem with arduino NANO EVERY and libraries
Post by: erikjanssen on Sep 26, 2019, 06:00 pm
I found a little help in the tool.

If I select Genuine UNO and go to files, examples and scroll down I can find the examples for keypad, LiquidCrystal I2C, RF24 and RF24Network.

When I select NANO EVERY and go to files, examples and scroll down I find a folder INCOMPATIBLE with, guess what, LiquidCrystal I2C, RF24 and RF24Network. So no wonder my application will not run on an Every.

They missed Keypad, the Hello Keypad does not verify.

This is a start and will help to determine whether I can use a library for a specific board. Still you can only see this after you installed a library.

I would love to see a filter on board in the software library manager.
Title: Re: Problem with arduino NANO EVERY and libraries
Post by: david_prentice on Sep 27, 2019, 01:11 am
Have you upgraded the libraries?
Have you raised an Issue with the relevant library authors?

I suggest that you use hd44780 library instead of the randomly named LiquidCrystal I2C

David.
Title: Re: Problem with arduino NANO EVERY and libraries
Post by: erikjanssen on Sep 27, 2019, 01:22 pm
Yes, I keep my development environment upgraded.

Keypad can be replaced with Adafruit Keypad
LiquidCrystal_I2C can be replaced with hd44780

RF24 and RF24Network are classified as INCOMPATIBLE by Arduino, I assumed raising an issue would be useless.

So on my project, 4 libraries need work to get things going again. For me that is not worth the trouble. In order to move forward I decided to go for the Arduino NANO IoT and start from skratch to rebuild my application together with the possibility to publish the results on the web.

Title: Re: Problem with arduino NANO EVERY and libraries
Post by: david_prentice on Sep 27, 2019, 06:55 pm
Anything that can be done on Uno or Nano should be possible on NANO-EVERY board.

The authors just need to be told.   After all,   the RF24 libraries were written before the ATmega4809 was invented.
The GitHub site seems to have some activity.   So it is simply a question of raising an Issue or offering a Pull Request.

The author might want you to do some testing.    That is how the world benefits from OPen Source.

David.
Title: Re: Problem with arduino NANO EVERY and libraries
Post by: david_prentice on Sep 28, 2019, 01:54 am
I built the pingpair_ack example for Uno and Teensy3.2 without problem.
It failed for NANO-EVERY because two digitalWrite() statements were not correct.

RF24.cpp
Code: [Select]

...
#if !defined (RF24_LINUX)
digitalWrite(csn_pin,mode ? HIGH : LOW);  //.kbv
delayMicroseconds(csDelay);
#endif

}

/****************************************************************************/

void RF24::ce(bool level)
{
  //Allow for 3-pin use on ATTiny
  if (ce_pin != csn_pin) digitalWrite(ce_pin,level ? HIGH : LOW);   //.kbv
}
...


Compilers are fussy.   digitalWrite() expects an enum and not a bool for the second argument.
TRUE and HIGH happen to have the same value but are obviously completely different type.

I have not tested on real hardware.   A correct build does not mean the library is going to work.

David.
Title: Re: Problem with arduino NANO EVERY and libraries
Post by: david_2018 on Sep 28, 2019, 06:07 am
I built the pingpair_ack example for Uno and Teensy3.2 without problem.
It failed for NANO-EVERY because two digitalWrite() statements were not correct.

RF24.cpp
Code: [Select]

...
#if !defined (RF24_LINUX)
 digitalWrite(csn_pin,mode ? HIGH : LOW);  //.kbv
 delayMicroseconds(csDelay);
#endif

}

/****************************************************************************/

void RF24::ce(bool level)
{
  //Allow for 3-pin use on ATTiny
  if (ce_pin != csn_pin) digitalWrite(ce_pin,level ? HIGH : LOW);   //.kbv
}
...


Compilers are fussy.   digitalWrite() expects an enum and not a bool for the second argument.
TRUE and HIGH happen to have the same value but are obviously completely different type.

I have not tested on real hardware.   A correct build does not mean the library is going to work.

David.

I tried your code with the scanner example and it compiles and runs, but gives no output on the serial monitor.  The printf.h file included with the library needs to be modified to allow for the megaavr architecture.

Code: [Select]

#if defined (ARDUINO_ARCH_AVR) || defined (ARDUINO_ARCH_MEGAAVR) || defined(__ARDUINO_X86__) //added ARDUINO_ARCH_MEGAAVR

int serial_putc( char c, FILE * )

/***********************************************************************************************/

void printf_begin(void)
{
  #if defined (ARDUINO_ARCH_AVR) || defined (ARDUINO_ARCH_MEGAAVR) //added ARDUINO_ARCH_MEGAAVR
    fdevopen( &serial_putc, 0 );


It is also necessary to wait long enough in setup() for the Serial interface to initialize before using it. The usual while (!Serial) doesn't seem to work properly for the Nano Every, so I use a delay().

(edit)
Made slight modification to code for readability, does not affection function.
Title: Re: Problem with arduino NANO EVERY and libraries
Post by: david_prentice on Sep 28, 2019, 09:22 am
There you are.   10 minutes to identify the digitalWrite() syntax problem.
10 minutes to identify any  conditional blocks that need extending for MEGAAVR

You have the hardware.    You can do real life testing of the library on your hardware.

And then make an Issue or Pull Request.
The library author can make a new Release.   The Library Manager will prompt for update.

We can help you with the procedure.
If you want help with targets,  I can probably dig out two NRF24L01 and a variety of targets e.g. Uno, Zero, Due, ESP32, ...
You will have to suggest suitable examples.

David.
Title: Re: Problem with arduino NANO EVERY and libraries
Post by: david_2018 on Sep 29, 2019, 01:31 am
I found a little help in the tool.

If I select Genuine UNO and go to files, examples and scroll down I can find the examples for keypad, LiquidCrystal I2C, RF24 and RF24Network.

When I select NANO EVERY and go to files, examples and scroll down I find a folder INCOMPATIBLE with, guess what, LiquidCrystal I2C, RF24 and RF24Network. So no wonder my application will not run on an Every.

They missed Keypad, the Hello Keypad does not verify.

This is a start and will help to determine whether I can use a library for a specific board. Still you can only see this after you installed a library.

I would love to see a filter on board in the software library manager.
The INCOMPATIBLE listing is generated from the library.properties file in each library, and is not really a reliable way to tell if a library is compatible or not, since the megaavr architecture used by the Nano Every and WiFi Rev 2 board did not exist on any Arduino board before the beginning of the year.

As for the Keypad library, the errors are related to the change from using defines to an enum for the arguments of the digitalWrite() and pinMode() functions, which wreaks havoc with a lot of code.  I don't have a keypad to test with, but the following modifications to the Keypad.h file at least allow the library to compile without error:

Code: [Select]

.......
// bperrybap - Thanks for a well reasoned argument and the following macro(s).
// See http://arduino.cc/forum/index.php/topic,142041.msg1069480.html#msg1069480
#if not defined (INPUT_PULLUP) && not defined (ARDUINO_ARCH_MEGAAVR) // add test for megaavr architecture
#warning "Using  pinMode() INPUT_PULLUP AVR emulation"
.........


Code: [Select]

class Keypad : public Key {
public:

 Keypad(char *userKeymap, byte *row, byte *col, byte numRows, byte numCols);

#if defined(ARDUINO_ARCH_MEGAAVR) //change type of arguments to pinMode and digitialWrite functions
 virtual void pin_mode(byte pinNum, PinMode mode) { pinMode(pinNum, mode); }
 virtual void pin_write(byte pinNum, PinStatus level) { digitalWrite(pinNum, level); }
#else
 virtual void pin_mode(byte pinNum, byte mode) { pinMode(pinNum, mode); } //original line from code
 virtual void pin_write(byte pinNum, boolean level) { digitalWrite(pinNum, level); } //original line from code
#endif
 virtual int  pin_read(byte pinNum) { return digitalRead(pinNum); }
Title: Re: Problem with arduino NANO EVERY and libraries
Post by: pert on Sep 29, 2019, 04:55 am
Just to elaborate on what david_2018 said, the Arduino IDE determines whether a library is compatible or not with a given architecture based on the comma-separator "architectures" field in the library.properties file found in the library's root folder. If the library has no library.properties file, then the IDE assumes it's compatible with all architectures. The IDE will also display an incompatible library warning in the console when you compile a library that doesn't have a match for the currently selected board's architecture in its architectures field.

This is not always reliable because:
Title: Re: Problem with arduino NANO EVERY and libraries
Post by: erikjanssen on Sep 30, 2019, 03:57 pm
Thank you for your comments. With all the new boards available now it is indeed a good idea to validate a library before starting developments.

I have chosen not to proceed with the EVERY for my next upgrade but move directly to the NANO 33 IoT.