Solved: Thinary Nano Every ATmega4808 I2C TWI

Go To Last Post
21 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello,

 

Did anybody succeeded using Thinary Nano Every to work the LCD 20x4 on I2C interface?  

I connected as normal for Arduino Nano - SDA on A4 and SCL on A5. -GND +Vcc.

But the LCD does not work, it has backlight on. Changing the contrast with pot does not help.

 

I run on AS7 and Visual Micro plugin for Arduino.

The debugger shows that I am looping in twi.c library, lcd.init() function, line 326: 

 

        /* Arduino requires blocking function */
        while(master_result == TWIM_RESULT_UNKNOWN) {}
 

Any idea?

 

Thanks in advance. 

Best regards, Andrej

 

This topic has a solution.

Andrej M

Last Edited: Tue. Jan 26, 2021 - 10:38 AM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The Thinary board has PF2 and PF3 on A4, A5 pins.   These are the TWIS (Slave) pins.

If you want TWIM (Master) it is either on PA2, PA3 or on PC2, PC3 port pins.

 

If you want to use the Thinary Wire library (as Master) you should connect SDA to PA2 (D4) and SCL to PA3 (D5)

 

The regular Nano EVERY has PA2,PF2 hard-wired to A4 (SDA) and PA3,PF3 hard-wired to A5 (SCL)

This means that TWI is always on the same physical pins for the genuine EVERY.

 

Bill Perry's hd44780 library will work on Thinary if you:

1.  connect to SDA to D4 (PA2),  SCL to D5 (PA3)

2.  #define Serial Serial1

 

David.

 

p.s. Please could somebody explain why this "Thinary" thread has been split to some randomly named anonymous thread.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

david.prentice wrote:
p.s. Please could somebody explain why this "Thinary" thread has been split to some randomly named anonymous thread.

Well, it's not a "random" name - it's the standard way that split threads get named: "split from: <original-thread-name>"

 

It started as 'Thinary' her/himself trying to debug the design as a "sales pitch" in Marketplace:  https://www.avrfreaks.net/forum/nano-every-use-atmega4808

 

This was tacked-on as a hijack - unrelated to the original problem.

 

As  amla11  is now owner of this thread (s)he could now change the name to something more appropriate.  (s)he will also now be able to mark the solution once this problem is resolved ...

 

EDIT

 

Correct description of the original post.

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Wed. Jul 29, 2020 - 08:41 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sorry, I am a little late. I wired according to the David's explanation and the I2C  LCD works on Thinary Nano Every 4808 as expected. You should use the pins as described above D4 <-- SDA, D5 <-- SCL.  I used the Thinary Core, Wire & LCD libs on AS7 & VisualMicro. 

I also fount the definitions file in C:\Users\username\AppData\Local\Arduino15\packages\thinary\hardware\avr\1.0.0\variants\nona4808\pins_arduino.h , which helps for similar problems.

 

I would rename this chapter as "Thinary Nano Every ATmega4808 I2C TWI", if that's ok. 

 

Thanks again for help. 

Andrej

 

Andrej M

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

I have a I2C LCD (https://www.amazon.it/gp/product...) that works well with Arduino nano and LiquidCrystal_I2C library.

I tryied it with Thinary nano every. I wired D4 <-- SDA, D5 <-- SCL, but it no works, damn. It fails on init()

Can someone help me, please?
Thanks

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Please compare the item that arrived on your desk with the photos in the Amazon link.

i.e. does the backpack have the same components as the pictures in the link?  e.g. PCF8574T

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

amla11 wrote:
Any idea?

The first thing I would do is use the Arduino IDE and load an I2C scanner sketch and see if it reports what I2C address it finds if it finds anything?

Once you know (for sure) what the address is for your board, then run an Arduino sketch that displays some test text to the display.

 

Once those two work, then make any mods needed so the program your using, uses the same address.

I2C will tell  you what is wrong by looking at the returned status of your I2C functions, you should always be looking at and responding to this returned status on every function call.

 

Jim

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Or just look at Bill Perry's hd44780 Arduino library. It has a test sketch that will automatically identify any attached displays, their pinout, backlight operation, etc. He is also very helpful on the Arduino forums.

 

(It's also a masterclass in code design, modularity, implementation and documentation. You'll learn more about the idiosyncrasies of this 30-yr old interface from his copious comments than probably any other source).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you for your reply. Yes, on the back there is a LCM1602 with PCF8574T chip.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you for your reply.

 

I load the following I2C scanner sketch on Thinary Every but it freezes on error = Wire.endTransmission();  (led 13 turns on but does not turn off). The same code on Arduino nano reports

Scanning...
I2C device found at address 0x27  !
done

#include <Wire.h>
 
#if defined(__AVR_ATmega4808__)
#define Serial Serial1
#endif
 
void setup()
{
#if defined(__AVR_ATmega4808__)
delay(1000);
#endif

  Wire.begin();
 
  Serial.begin(9600);
  while (!Serial);
  Serial.println("\nI2C Scanner");
  pinMode(13, OUTPUT);
}
 
 
void loop()
{
  byte error, address;
  int nDevices;
 
  Serial.println("Scanning...");
 
  nDevices = 0;
  for(address = 1; address < 127; address++ )
  {
    // The i2c_scanner uses the return value of
    // the Write.endTransmisstion to see if
    // a device did acknowledge to the address.
    Serial.println("Scanning...");
    Wire.beginTransmission(address);
    digitalWrite(13, HIGH);
    error = Wire.endTransmission();
    digitalWrite(13, LOW);
    if (error == 0)
    {
      Serial.print("I2C device found at address 0x");
      if (address<16)
        Serial.print("0");
      Serial.print(address,HEX);
      Serial.println("  !");
 
      nDevices++;
    }
    else if (error==4)
    {
      Serial.print("Unknown error at address 0x");
      if (address<16)
        Serial.print("0");
      Serial.println(address,HEX);
    }    
  }
  if (nDevices == 0)
    Serial.println("No I2C devices found\n");
  else
    Serial.println("done\n");
 
  delay(5000);           // wait 5 seconds for next scan
}

 

I make another test: 

Thinary Every as master  <->  Arduino nano as slave

D4 <-> A4

D5 <-> A5

 

and it works properly. Therefore the ports on Thinary aren't broken.

Last Edited: Tue. Jan 26, 2021 - 09:26 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I reported in #2 how to use the LCD backpack.

 

I presume that I must have verified this in real life.

I suggest that you do the same.   Take notes on paper.

 

If you still have a problem,  I will dig out the Thinary and try it again.

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you, David. I followed your instruction:

1.  connect to SDA to D4 (PA2),  SCL to D5 (PA3)

2.  #define Serial Serial1

 

but it seems that there is a trouble on i2c between my thinary and my display. If I try to scan i2c address of LCD backpack, thinary freezes. I have already test that the D4 and D5 ports work (I made a simple master slave with thinary every and an arduino nano and everything works). I am discouraged.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

1.  connect to SDA to D4 (PA2),  SCL to D5 (PA3)

2.  #define Serial Serial1 i.e. add line at beginning of example sketch

 

Using library Wire at version 1.0 in folder: C:\Users\David Prentice\AppData\Local\Arduino15\packages\thinary\hardware\avr\1.0.0\libraries\Wire 
Using library hd44780 at version 1.3.2 in folder: C:\Users\David Prentice\Documents\Arduino\libraries\hd44780 
"C:\\Users\\David Prentice\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino5/bin/avr-size" -A "C:\\Users\\DAVIDP~1\\AppData\\Local\\Temp\\arduino_build_948608/I2CexpDiag.ino.elf"
Sketch uses 15278 bytes (31%) of program storage space. Maximum is 49152 bytes.
Global variables use 671 bytes (10%) of dynamic memory, leaving 5473 bytes for local variables. Maximum is 6144 bytes.

The I2CexpDiag sketch not only passes but prints the results on the Serial Terminal

********************************
Serial Initialized
--------------------------------------------------------------------
I2CexpDiag - i2c LCD i/o expander backpack diagnostic tool
--------------------------------------------------------------------
hd44780 lib version: 1.3.2
--------------------------------------------------------------------
Reported Arduino Revision: 1.8.13
CPU ARCH: AVR - F_CPU: 16000000
--------------------------------------------------------------------
SDA digital pin: 22
SCL digital pin: 23
--------------------------------------------------------------------
Checking for required external I2C pull-up on SDA - YES
Checking for required external I2C pull-up on SCL - YES
Checking for I2C pins shorted together - Not Shorted
--------------------------------------------------------------------
Scanning i2c bus for devices..
 i2c device found at address 0x27
Total I2C devices found: 1
--------------------------------------------------------------------
Scanning i2c bus for all lcd displays (4 max)
 LCD at address: 0x27 | config: P01245673H | R/W control: Yes
Total LCD devices found: 1
--------------------------------------------------------------------
LCD Display Memory Test
Display: 0
 Walking 1s data test:	PASSED
 Address line test:	PASSED
--------------------------------------------------------------------
Each working display should have its backlight on
and be displaying its #, address, and config information
If all pixels are on, or no pixels are showing, but backlight is on, try adjusting contrast pot
If backlight is off, wait for next test
--------------------------------------------------------------------
Blinking backlight test: to verify BL level autodetection
If backlight is mostly off but
you briefly see "BL Off" on display with backlight on,
then the library autodetected incorrect BL level
and the library cannot autoconfigure the device
--------------------------------------------------------------------
Displaying 'uptime' on all displays
--------------------------------------------------------------------


Note that I upload the programs with ATMEL-ICE on the Thinary UPDI pin.

My Thinary bootloader does not work but the genuine Nano-Every works just fine.

 

David.

 

Edit.  I upgraded the hd44780 library to v1.3.2 and replaced my build and app reports.

 

Last Edited: Tue. Jan 26, 2021 - 11:41 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I report my log:

**************************************************************-----------------------------------------------------------
I2CexpDiag - i2c LCD i/o expander backpack diagnostic tool
--------------------------------------------------------------------
hd44780 lib version: 1.3.2
--------------------------------------------------------------------
Reported Arduino Revision: 1.8.13
CPU ARCH: AVR - F_CPU: 16000000
--------------------------------------------------------------------
SDA digital pin: 22
SCL digital pin: 23
--------------------------------------------------------------------
Checking for required external I2C pull-up on SDA - YES
Checking for required external I2C pull-up on SCL - YES
Checking for I2C pins shorted together - Not Shorted
--------------------------------------------------------------------
Scanning i2c bus for devices..

I waited a few minutes and I reseted several times, but the log stops on scan.

 

I'll try another Thinary board, maybe this one is bad.

Last Edited: Tue. Jan 26, 2021 - 03:04 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I did ask whether your backpack pcb matched the pictures in the Amazon link.

i.e. are all the resistors mounted?

i.e. same numbers printed on the resistors?

i.e. are the capacitors mounted?

 

You don't have to understand what components do.   Just compare the pcb with the pictures.

David.

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I don't understand why my Thinary does not upload via the Serial-USB chip.

 

The regular Nano-Every uploads fine.

 

I checked my 4808 Fuse values versus the 4809 Fuses with this sketch:

#if defined(__AVR_ATmega4808__)
#define Serial Serial1
#endif

void print_hexval(const char *msg, uint8_t val, bool newline = true)
{
    Serial.print(msg);
    if (val < 0x10) Serial.print('0');
    Serial.print(val, HEX);
    if (newline) Serial.print("\n");
}

void dump_hex(const char *msg, const uint8_t *row, int n, bool ascii = false)
{
    Serial.print(msg);
    for (int i = 0; i < n; i++) print_hexval(" ", row[i], false);
    if (ascii) {
        char buf[n + 1];
        memcpy(buf, row, n);
        buf[n] = '\0';
        Serial.print(" ");
        Serial.print(buf);
    }
    Serial.println();
}

void setup(void)
{
    Serial.begin(9600);
    delay(1000);
    while (!Serial) ;
    delay(100);
    print_hexval("lockb = 0x", LOCKBIT_LOCKBIT);
    print_hexval("WDTCFG fuse = 0x", FUSE_WDTCFG);
    print_hexval("BODCFG fuse = 0x", FUSE_BODCFG);
    print_hexval("OSCCFG fuse = 0x", FUSE_OSCCFG);
    print_hexval("SYSCFG0 fuse = 0x", FUSE_SYSCFG0);
    print_hexval("SYSCFG1 fuse = 0x", FUSE_SYSCFG1);
    print_hexval("APPEND fuse = 0x", FUSE_APPEND);
    print_hexval("BOOTEND fuse = 0x", FUSE_BOOTEND);
    dump_hex("Signature:", &SIGROW.DEVICEID0, 3);
    dump_hex("User Row:", &USERROW.USERROW0, 16);
    dump_hex("Serial:", &SIGROW.SERNUM0, 10, true);
    dump_hex("Tempsense:", &SIGROW.TEMPSENSE0, 2);
    dump_hex("Osccal16:", &SIGROW.OSCCAL16M0, 2);
}

void loop(void)
{
}

I get:

lockb = 0xC5
WDTCFG fuse = 0x00
BODCFG fuse = 0x00
OSCCFG fuse = 0x01
SYSCFG0 fuse = 0xC9
SYSCFG1 fuse = 0x07
APPEND fuse = 0x00
BOOTEND fuse = 0x00
Signature: 1E 96 50
User Row: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
Serial: 51 50 4B 39 30 20 2E 12 08 1E QPK90 .
Tempsense: 91 F7
Osccal16: BB 04

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sorry, I didn't understand well. The backpack is not identical. I take a picture of that

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

First off.   Ebay, Amazon, AliExpress, ... are often mendacious.    A Red backpack is fairly obvious when the pictures show a Blue backpack with lots more components.

 

Looking at your Red backpack:

There are NO pullups on SCL and SDA.

There are no pullups on the Address-select lines.

 

I suggest that you add 4k7 pullups to your circuit.  

 

I have the same cheapo red backpack (that I bought to test)

It does not work on Thinary without the SDA, SCL pullups.

 

However I would expect the Diagnostic sketch to report missing pullups.

And I get exactly the same as your report.

 

David.

 

Ah-ha.   I have not looked to see how Bill is testing for external pullups.   I did post a method to test the pullup speed on a Uno some years ago.   (that Bill Perry did not approve of)

Last Edited: Tue. Jan 26, 2021 - 06:55 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

When you get your LCD working,  please can you run my Fuse Diagnostic sketch from #16 on your Thinary.

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you, David,

I put pullup resistors and all works!

 

Is it possible solder the pullup resistors directly on red backpack? If yes, where?

 

Follows the diagnostic info:

lockb = 0xC5
WDTCFG fuse = 0x00
BODCFG fuse = 0x00
OSCCFG fuse = 0x01
SYSCFG0 fuse = 0xC9
SYSCFG1 fuse = 0x07
APPEND fuse = 0x00
BOOTEND fuse = 0x00
Signature: 1E 96 50
User Row: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
Serial: 51 51 53 31 4E 20 14 29 10 17 QQS1N )
Tempsense: 8E E8
Osccal16: B9 05

 

Last Edited: Thu. Jan 28, 2021 - 03:32 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for your Fuses etc.  You have same fuses as me.   Empty UserRow.   Similar Calibration values.

Similar Serial Number (I suspect that your Thinary was made from the same batch as mine i.e. only one batch ever made)

 

Look at the Red backpack pcb.  Remove the backlight jumper link on the left hand side of the pcb.

 

You will see empty pads labelled GND, VCC, SDA, SCL.

Solder 4k7 between VCC and SDA.

Solder 4k7 between VCC and SCL.

Replace the jumper.

 

If you intend to have multiple I2C devices on the bus,   you only need one pair of pullups.    If your other device has pullups,  your LCD does not need any extra ones.

 

If you want a different address to 0x27,   you can solder resistors across the holes at the bottom right of the pcb.

 

David.