OLED Display with 1306 on 328p

Go To Last Post
72 posts / 0 new

Pages

Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Dear Community

 

I would like to ad a oled display to my programm only for writing text.

 

What I did so far:
 

I downloaded this library:  https://github.com/adafruit/Adafruit_SSD1306

 

Using Atmel Studio 7

 

I installed it via Solution Explorer:
Adafruit_SSD1306.h
Adafruit_SSD1306.c++

splash.h

 

I did a build and I alway get an error:

Wire.h: No such direktiory

 

Can anybody help and tellme where I get this header file from, I did ask Google.

 

Very much apreciate your help

 

regards

Juergen

This topic has a solution.
Last Edited: Wed. Jan 15, 2020 - 05:27 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

A guess is Arduino.

https://github.com/arduino/ArduinoCore-avr/tree/master/libraries/Wire/src

 

P.S.

JB57 wrote:
I would like to ad a oled display to my programm only for writing text.

Re SSD1306, an alternate library is U8x8 in U8g2.

Home · olikraus/u8g2 Wiki · GitHub

 

"Dare to be naïve." - Buckminster Fuller

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

JB57 wrote:

I did a build and I alway get an error:

Wire.h: No such direktiory

Wire.h is from Arduino.

 

There are two real alternatives here:

 

1) just do everything in the Arduino IDE. It "knows" where things like Wire.h are so it will magically be found

 

2) if you can think of some strong reason why this must work in AS7 and not Arduino then write a minimal sketch that includes most things in Arduino first then go to AS7 and use the "create project from Arduino sketch" option and import it. That will bring in all the bits you need like Wire.h

 

There is an outside possibility:

 

3) identify all that is being relied upon that exists in the Wire class in Arduino then reimplement an equivalent in the AS7 project. This could be quite complex.

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

Thanks very much for the answers.

 

I would like to stick with AS7.

 

I am a very beginner so I dont want to open another bottle.

 

I will try the the link from texas :-)

Home · olikraus/u8g2 Wiki · GitHub

 

I will probably come back with more question.

 

Thanks and regards

Juergen

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

JB57 wrote:
I am a very beginner

There really are quite a few basics that you need to cover before you're ready to be interfacing OLED displays!

 

See Tip #6 (in my signature, below; may not be visible on mobile).

 

In particular:  https://www.avrfreaks.net/comment/1138166#comment-1138166

 

See also: https://www.avrfreaks.net/commen...

 

I will probably come back with more question.

If this thread is now resolved, see Tip #5.

 

For a new questions, start a new thread.

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. Jan 15, 2020 - 04:03 PM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I had  a look at the link, but as far as I understand its only for Arduino

 

regards

 

Juergen

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

JB57 wrote:
the link

Which link?

 

Tutorial on making replies in the forum: https://www.avrfreaks.net/forum/...

 

 

its only for Arduino

Arduino is just a microcontroller on a board, and the Arduino "language" is just C++ - there's nothing really special or magic about it.

 

It is specifically targetted at beginners - so might be a better place for you to start ... ?

 

EDIT

 

If you're referring to U8G2, it's not just for Arduino.

 

If you look in the Gallery, you'll see instructions for using it in AS7:

 

https://github.com/olikraus/u8g2...

 

which links to:  https://github.com/olikraus/u8g2/wiki/u8g2as7

 

But again, that's not a beginner project ...

 

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. Jan 15, 2020 - 04:51 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

olikraus comes from Germany.

 

U8g2lib is actually a C library with an Arduino "C++ wrapper".

 

He posted an AS7.0 version a few months ago.   From memory it was only for SPI interface.

Please post a link to the actual SSD1306 display that you bought.   e.g. Ebay page.

 

Life is much simpler with Arduino.   You will get results within minutes.

AS7.0 requires a lot of learning.

 

David.

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

Atmel AVR | Porting to new MCU platform · olikraus/u8g2 Wiki · GitHub

...

If you're using Atmel Studio:

...

edit : oops, redundant to post #7

"Dare to be naïve." - Buckminster Fuller

Last Edited: Wed. Jan 15, 2020 - 04:53 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

david.prentice wrote:
AS7.0 requires a lot of learning.

Indeed.

 

Atmel have a series of videos on getting started with AS7 - they're at the bottom of the AS7 web page:

 

https://www.microchip.com/mplab/avr-support/atmel-studio-7

 

 

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...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The wire.h library drives the Arduino's I2C interface.  There are two types of interface for the OLED SSD1306.   The SPI (serial peripheral interface) and the I2C (called TWI or two-wire interface in AVR datasheets).   SPI is faster.  It can rewrite the entire 1024 bytes of the OLED screen (128x64 pixels) in about 0.001 second (a millisecond).   I2C takes about 40 milliseconds.

 

As a beginner, I recommend using the Arduino IDE (integrated development environment)  if you have an Arduino UNO and the bootloader still works.  There are many examples of standard device interfacing and (nearly) all of the work well, even if you don't understand all of the software.  Atmel Studio is better used for AVR devices that aren't available in Arduino format.

 

   Try buying cheap Arduino Nanos from China on eBay.  They have a full working ATmega328p along with a USB-Serial interface IC for 3 to 4 Euros each.   About two weeks ago I published a long code attachment here for driving SSD1306 OLED displays using I2C without using Arduino libraries.  Scroll backwards through old messages.

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


Simonetta wrote:
Scroll backwards through old messages.

Or you can find all a user's posts via their profile - accessed by clicking their name.

 

Or click on the 'view posts' link ...

 

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...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Simonetta wrote:

The wire.h library drives the Arduino's I2C interface.  There are two types of interface for the OLED SSD1306.   The SPI (serial peripheral interface) and the I2C (called TWI or two-wire interface in AVR datasheets).   SPI is faster.  It can rewrite the entire 1024 bytes of the OLED screen (128x64 pixels) in about 0.001 second (a millisecond).   I2C takes about 40 milliseconds.

 

As a beginner, I recommend using the Arduino IDE (integrated development environment)  if you have an Arduino UNO and the bootloader still works.  There are many examples of standard device interfacing and (nearly) all of the work well, even if you don't understand all of the software.  Atmel Studio is better used for AVR devices that aren't available in Arduino format.

 

   Try buying cheap Arduino Nanos from China on eBay.  They have a full working ATmega328p along with a USB-Serial interface IC for 3 to 4 Euros each.   About two weeks ago I published a long code attachment here for driving SSD1306 OLED displays using I2C without using Arduino libraries.  Scroll backwards through old messages.

 

 

I will try tofind it, thanks very much SIMONETTA, also thank you AWNEIL

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

I have found the listing and pasted in test project.

 

I also included: #include <avr/pgmspace.h>

as AWNEIL recommended

 

I also added these to lines as I understood to do it from the other thread

#define FONT_SIZE 5                                //this value is in the comments above the font table

#define OLED_SLA7 0x3c                           //where nn is 7 bit address of the OLED I2C address

 

on my display it says: 0x78 for the I2C address, do I have to replace ox3C by ox78 ?

 

 

After building I get the following errores:

Error             recipe for target 'Oled_test.elf' failed   

Warning        missing braces around initializer [-Wmissing-braces]                       const uint8_t FontTable[][FONT_SIZE] PROGMEM = {

Message        (near initialization for 'FontTable')                                                 const uint8_t FontTable[][FONT_SIZE] PROGMEM = {

Warning        missing braces around initializer [-Wmissing-braces]                       const uint8_t BigDigitFont[][36] PROGMEM = { // each SSD1306 data byte is 8 vertical pixels.
 
Message        (near initialization for 'BigDigitFont')                                              const uint8_t BigDigitFont[][36] PROGMEM = { // each SSD1306 data byte is 8 vertical pixels.

Error        ld returned 1 exit status 

 

 

For reference, this is the code:
 

I hope you can help

regards

Jürgen

/*
 * Oled_test.c
 *
 * Created: 15.01.2020 20:03:07
 * Author : jb
 */ 
#include <avr/pgmspace.h>

#define SSD1306_CHAR_SIZE        6
#define SSD1306_OLED_SLA7              0x3C     //  SSD1306 controller,  I2C slave address
#define SSD1306_LASTLINE                0x07
#define SSD1306_COMMAND                 0x00
#define SSD1306_DATA                    0xC0
#define SSD1306_DATA_CONTINUE           0x40
#define SSD1306_SET_CONTRAST_CONTROL    0x81
#define SSD1306_DISPLAY_ALL_ON_RESUME   0xA4
#define SSD1306_DISPLAY_ALL_ON          0xA5
#define SSD1306_NORMAL_DISPLAY          0xA6
#define SSD1306_INVERT_DISPLAY          0xA7
#define SSD1306_DISPLAY_OFF             0xAE
#define SSD1306_DISPLAY_ON              0xAF
#define SSD1306_NOP                     0xE3
#define SSD1306_HORIZONTAL_SCROLL_RIGHT 0x26
#define SSD1306_HORIZONTAL_SCROLL_LEFT  0x27
#define SSD1306_SCROLL_VERT_AND_RIGHT   0x29
#define SSD1306_SCROLL_VERT_AND_LEFT    0x2A
#define SSD1306_DEACTIVATE_SCROLL       0x2E
#define SSD1306_ACTIVATE_SCROLL         0x2F
#define SSD1306_SET_VERT_SCROLL_AREA    0xA3
#define SSD1306_SET_LOWER_COLUMN        0x00
#define SSD1306_SET_HIGHER_COLUMN       0x10
#define SSD1306_MEMORY_ADDR_MODE        0x20
#define SSD1306_SET_COLUMN_ADDR         0x21
#define SSD1306_SET_PAGE_ADDR           0x22
#define SSD1306_SET_START_LINE          0x40
#define SSD1306_SET_SEGMENT_REMAP       0xA0
#define SSD1306_SET_MULTIPLEX_RATIO     0xA8
#define SSD1306_COM_SCAN_DIR_INC        0xC0
#define SSD1306_COM_SCAN_DIR_DEC        0xC8
#define SSD1306_SET_DISPLAY_OFFSET      0xD3
#define SSD1306_SET_COM_PINS            0xDA
#define SSD1306_CHARGE_PUMP             0x8D
#define SSD1306_SET_CLOCK_DIV_RATIO     0xD5
#define SSD1306_SET_PRECHARGE_PERIOD    0xD9
#define SSD1306_SET_VCOM_DESELECT       0xDB

#define FONT_SIZE 5								//this value is in the comments above the font table

#define OLED_SLA7 0x3c								//where nn is 7 bit address of the OLED I2C address

/*##############################################################*/

//  global variables that need to be unchanged between each call to OLED_SetCursor() and OLED_DisplayChar().
uint8_t         OLEDlineNumber = 0, OLEDcursorPos = 0;

// Next comes two font tables that go into 1K of flash. The first table is for 7x5 chars and
//  it is the same table found in most libraries of graphics-based display controllers.
//   After the 7x5 table is a second table for making big digit
//  chars that are three rows high.  {0..9, plus colon : and space chars)
//  Least-sig-bit on upper top side of char column.  Bytes go left to right.
 // Vertical pixel alignment: 475 bytes in flash.
const uint8_t FontTable[][FONT_SIZE] PROGMEM = {
        0x00, 0x00, 0x00, 0x00, 0x00,   // space 00   20 hexASCII
        0x00, 0x00, 0x2f, 0x00, 0x00,   // !     01   21
        0x00, 0x07, 0x00, 0x07, 0x00,   // "     02   22
        0x14, 0x7f, 0x14, 0x7f, 0x14,   // #     03   23
        0x24, 0x2a, 0x7f, 0x2a, 0x12,   // $     04   24
        0x23, 0x13, 0x08, 0x64, 0x62,   // %     05   25
        0x36, 0x49, 0x55, 0x22, 0x50,   // &     06   26
        0x00, 0x05, 0x03, 0x00, 0x00,   // '     07   27
        0x00, 0x1c, 0x22, 0x41, 0x00,   // (     08   28
        0x00, 0x41, 0x22, 0x1c, 0x00,   // )     09   29
        0x14, 0x08, 0x3E, 0x08, 0x14,   // *     10   2a
        0x08, 0x08, 0x3E, 0x08, 0x08,   // +     11   2b
        0x00, 0x00, 0xA0, 0x60, 0x00,   // ,     12   2c
        0x08, 0x08, 0x08, 0x08, 0x08,   // -     13   2d
        0x00, 0x60, 0x60, 0x00, 0x00,   // .     14   2e
        0x20, 0x10, 0x08, 0x04, 0x02,   // /     15   2f
        0x3E, 0x51, 0x49, 0x45, 0x3E,   // 0     16   30
        0x00, 0x42, 0x7F, 0x40, 0x00,   // 1     17   31
        0x42, 0x61, 0x51, 0x49, 0x46,   // 2     18   32
        0x21, 0x41, 0x45, 0x4B, 0x31,   // 3     19   33
        0x18, 0x14, 0x12, 0x7F, 0x10,   // 4     20   34
        0x27, 0x45, 0x45, 0x45, 0x39,   // 5     21   35
        0x3C, 0x4A, 0x49, 0x49, 0x30,   // 6     22   36
        0x01, 0x71, 0x09, 0x05, 0x03,   // 7     23   37
        0x36, 0x49, 0x49, 0x49, 0x36,   // 8     24   38
        0x06, 0x49, 0x49, 0x29, 0x1E,   // 9     25   39
        0x00, 0x36, 0x36, 0x00, 0x00,   // :     26   3a
        0x00, 0x56, 0x36, 0x00, 0x00,   // ;     27   3b
        0x08, 0x14, 0x22, 0x41, 0x00,   // <     28   3c
        0x14, 0x14, 0x14, 0x14, 0x14,   // =     29   3d
        0x00, 0x41, 0x22, 0x14, 0x08,   // >     30   3e
        0x02, 0x01, 0x51, 0x09, 0x06,   // ?     31   3f
        0x32, 0x49, 0x59, 0x51, 0x3E,   // @     32   40
        0x7C, 0x12, 0x11, 0x12, 0x7C,   // A     33   41
        0x7F, 0x49, 0x49, 0x49, 0x36,   // B     34   42
        0x3E, 0x41, 0x41, 0x41, 0x22,   // C     35   43
        0x7F, 0x41, 0x41, 0x22, 0x1C,   // D     36   44
        0x7F, 0x49, 0x49, 0x49, 0x41,   // E     37   45
        0x7F, 0x09, 0x09, 0x09, 0x01,   // F     38   46
        0x3E, 0x41, 0x49, 0x49, 0x7A,   // G     39   47
        0x7F, 0x08, 0x08, 0x08, 0x7F,   // H     40   48
        0x00, 0x41, 0x7F, 0x41, 0x00,   // I     41   49
        0x20, 0x40, 0x41, 0x3F, 0x01,   // J     42   4a
        0x7F, 0x08, 0x14, 0x22, 0x41,   // K     43   4b
        0x7F, 0x40, 0x40, 0x40, 0x40,   // L     44   4c
        0x7F, 0x02, 0x0C, 0x02, 0x7F,   // M     45   4d
        0x7F, 0x04, 0x08, 0x10, 0x7F,   // N     46   4e
        0x3E, 0x41, 0x41, 0x41, 0x3E,   // O     47   4f
        0x7F, 0x09, 0x09, 0x09, 0x06,   // P     48   50
        0x3E, 0x41, 0x51, 0x21, 0x5E,   // Q     49   51
        0x7F, 0x09, 0x19, 0x29, 0x46,   // R     50   52
        0x46, 0x49, 0x49, 0x49, 0x31,   // S     51   53
        0x01, 0x01, 0x7F, 0x01, 0x01,   // T     52   54
        0x3F, 0x40, 0x40, 0x40, 0x3F,   // U     53   55
        0x1F, 0x20, 0x40, 0x20, 0x1F,   // V     54   56
        0x3F, 0x40, 0x38, 0x40, 0x3F,   // W     55   57
        0x63, 0x14, 0x08, 0x14, 0x63,   // X     56   58
        0x07, 0x08, 0x70, 0x08, 0x07,   // Y     57   59
        0x61, 0x51, 0x49, 0x45, 0x43,   // Z     58   5a
        0x00, 0x7F, 0x41, 0x41, 0x00,   // [     59   5b
        0x55, 0xAA, 0x55, 0xAA, 0x55,   //       60   5c Backslash (Checker pattern)
        0x00, 0x41, 0x41, 0x7F, 0x00,   // ]     61   5d
        0x04, 0x02, 0x01, 0x02, 0x04,   // ^     62   5e
        0x40, 0x40, 0x40, 0x40, 0x40,   // _     63   5f underscore
        0x00, 0x03, 0x05, 0x00, 0x00,   // `     64   60 apostrophe
        0x20, 0x54, 0x54, 0x54, 0x78,   // a     65   61
        0x7F, 0x48, 0x44, 0x44, 0x38,   // b     66   62
        0x38, 0x44, 0x44, 0x44, 0x20,   // c     67   63
        0x38, 0x44, 0x44, 0x48, 0x7F,   // d     68   64
        0x38, 0x54, 0x54, 0x54, 0x18,   // e     69   65
        0x08, 0x7E, 0x09, 0x01, 0x02,   // f     70   66
        0x18, 0xA4, 0xA4, 0xA4, 0x7C,   // g     71   67
        0x7F, 0x08, 0x04, 0x04, 0x78,   // h     72   68
        0x00, 0x44, 0x7D, 0x40, 0x00,   // i     73   69
        0x40, 0x80, 0x84, 0x7D, 0x00,   // j     74   6a
        0x7F, 0x10, 0x28, 0x44, 0x00,   // k     75   6b
        0x00, 0x41, 0x7F, 0x40, 0x00,   // l     76   6c
        0x7C, 0x04, 0x18, 0x04, 0x78,   // m     77   6d
        0x7C, 0x08, 0x04, 0x04, 0x78,   // n     78   6e
        0x38, 0x44, 0x44, 0x44, 0x38,   // o     79   6f
        0xFC, 0x24, 0x24, 0x24, 0x18,   // p     80   70
        0x18, 0x24, 0x24, 0x18, 0xFC,   // q     81   71
        0x7C, 0x08, 0x04, 0x04, 0x08,   // r     82   72
        0x48, 0x54, 0x54, 0x54, 0x20,   // s     83   73
        0x04, 0x3F, 0x44, 0x40, 0x20,   // t     84   74
        0x3C, 0x40, 0x40, 0x20, 0x7C,   // u     85   75
        0x1C, 0x20, 0x40, 0x20, 0x1C,   // v     86   76
        0x3C, 0x40, 0x30, 0x40, 0x3C,   // w     87   77
        0x44, 0x28, 0x10, 0x28, 0x44,   // x     88   78
        0x1C, 0xA0, 0xA0, 0xA0, 0x7C,   // y     89   79
        0x44, 0x64, 0x54, 0x4C, 0x44,   // z     90   7a
        0x00, 0x10, 0x7C, 0x82, 0x00,   // {     91   7b
        0x00, 0x00, 0xFF, 0x00, 0x00,   // |     92   7c
        0x00, 0x82, 0x7C, 0x10, 0x00,   // }     93   7d
        0x00, 0x06, 0x09, 0x09, 0x06};  // ~     94   7e

const uint8_t BigDigitFont[][36] PROGMEM = { // each SSD1306 data byte is 8 vertical pixels.
// 12 columns * 3 rows = 36 bytes per digit [ * 12 digit characters__432 bytes total ]
//         0    1    2    3    4    5    6    7    8    9   10   11
    0xfc,0xfe,0xfe,0x0f,0x07,0x07,0x07,0x07,0xcf,0xfe,0xfc,0xf8,  // character '0'
    0xff,0xff,0xff,0xf0,0x78,0x3c,0x1e,0x0f,0x07,0xff,0xff,0xff,  //
    0x3f,0x7f,0x7f,0xf8,0xf0,0xf0,0xf0,0xf0,0xf8,0x7f,0x7f,0x1f,  //

    0x00,0x00,0x40,0x60,0x70,0x78,0xfc,0xfe,0xff,0xff,0x00,0x00,  // character '1'
    0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,  //
    0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,  //

    0x38,0x3c,0x3e,0x0f,0x07,0x07,0x07,0x0f,0x1f,0xff,0xfe,0xfc,  // character '2'
    0xc0,0xe0,0xe0,0xf0,0x78,0x78,0x3c,0x1e,0x0f,0x0f,0x07,0x03,  //
    0xff,0xff,0xff,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,  //

    0x38,0x3c,0x1e,0x0f,0x0f,0x0f,0x0f,0x0f,0x1e,0xfc,0xf8,0xf0,  // character '3'
    0x00,0x00,0x00,0x1e,0x1e,0x1e,0x1e,0x3e,0xff,0xff,0xe7,0x80,  //
    0x78,0xf8,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf8,0xff,0x7f,0x1f,  //

    0x00,0x00,0x00,0x00,0x00,0xc0,0xf0,0xf8,0x7e,0xff,0xff,0xff,  // character '4'
    0xe0,0xf0,0xf8,0xbe,0x9f,0x8f,0x83,0x81,0x80,0xff,0xff,0xff,  //
    0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0xff,0xff,0xff,  //

    0xff,0xff,0xff,0x87,0x87,0x87,0x87,0x87,0x87,0x07,0x07,0x07,  // character '5'
    0x07,0x07,0x03,0x03,0x03,0x03,0x03,0x03,0x07,0xff,0xff,0xfc,  //
    0x3c,0x7c,0x78,0xf0,0xf0,0xf0,0xf0,0xf0,0x78,0x7f,0x3f,0x1f,  //

    0xf8,0xfc,0xfe,0x0f,0x07,0x07,0x07,0x07,0x07,0x0f,0x1e,0x1c,  // character '6'
    0xff,0xff,0xff,0x1e,0x0e,0x0e,0x0e,0x0e,0x1e,0xfe,0xfc,0xf8,  //
    0x3f,0x7f,0x7f,0xf0,0xe0,0xe0,0xe0,0xe0,0xf8,0x7f,0x3f,0x1f,  //

    0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0xff,0xff,0xff,0xff,  // character '7'
    0x00,0x00,0x00,0x00,0x80,0xe0,0xf8,0xfe,0x7f,0x1f,0x0f,0x03,  //
    0x00,0xc0,0xf0,0xfe,0xff,0x1f,0x07,0x01,0x00,0x00,0x00,0x00,  //

    0xf8,0xfe,0xff,0x07,0x07,0x07,0x07,0x07,0x8f,0xff,0xfe,0x78,  // character '8'
    0xe0,0xff,0xff,0x1f,0x0e,0x0e,0x0e,0x1f,0x3f,0xff,0xf9,0xe0,  //
    0x1f,0x7f,0x7f,0xf0,0xe0,0xe0,0xe0,0xf0,0x78,0x7f,0x3f,0x1f,  //

    0xfc,0xfe,0xff,0x0f,0x07,0x07,0x07,0x07,0x0f,0xff,0xfc,0xf8,  // character '9'
    0x1f,0x3f,0x3f,0x7c,0x78,0x78,0x78,0x78,0x3c,0xff,0xff,0xff,  //
    0x00,0x70,0xf0,0xf0,0xf0,0xf0,0x70,0x78,0x7c,0x3f,0x3f,0x0f,  //

    0x00,0x00,0x00,0x60,0xf0,0xf8,0xf8,0xf0,0x60,0x00,0x00,0x00,  // character ':'
    0x00,0x00,0x00,0x00,0x80,0xc1,0xc1,0x80,0x00,0x00,0x00,0x00,  //
    0x00,0x00,0x00,0x03,0x07,0x0f,0x0f,0x07,0x03,0x00,0x00,0x00,  //

    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,  // character ' '
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,  //
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 };
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */

//  here are the functions for using the SSD1306, followed by documentation.

//~~~~~~~~~~~~~~~~~~~~~~~LOW-level OLED_I2C  @ 180 lines of code ~~~~
void i2c_initialise()  {   //  should called at the beginning of main() {Arduino:  by setup() when not using Wire.h}
        TWBR = 12;         //  400KHz   use 0x62 = @80KHz
        TWSR = 0x01;
        TWCR = (1<<TWEN);
}//~~~~~~~~~~~~~~~~~~~~~ LOW-level OLED_I2C ~~~~~~~~~~~~~~~~~~~~~~~~
void OLED_sendCommand(uint8_t myCmd)   {
        TWCR=((1<<TWINT)|(1<<TWSTA)|(1<<TWEN)); // send START
        while(!(TWCR & (1 << TWINT)));  // delay until TWINT set
        TWDR = OLED_SLA7 << 1;   // send SLA    8-bit SLAw = 0x78
        TWCR = ((1<<TWINT)|(1<<TWEN)); while(!(TWCR & (1<<TWINT)));

        TWDR = SSD1306_COMMAND; // send D/C_sentinel byte for command:0x00
        TWCR = ((1<<TWINT)|(1<<TWEN)); while(!(TWCR & (1<<TWINT)));

        TWDR = myCmd;   // I2C write, wait until completed
        TWCR = ((1<<TWINT)|(1<<TWEN)); while(!(TWCR & (1<<TWINT)));

        TWCR = ( (1<<TWINT)|(1<<TWEN)|(1<<TWSTO) ); // I2C STOP
}//~~~~~~~~~~~~~~~~~~~~~ LOW-level OLED_I2C ~~~~~~~~~~~~~~~~~~~~~~~~
void OLED_clear() {
        OLED_sendCommand(SSD1306_SET_COLUMN_ADDR);   // opcode:0x21
        OLED_sendCommand(0);     // start at left edge of screen
        OLED_sendCommand(127);   // end at right edge of screen

        OLED_sendCommand(SSD1306_SET_PAGE_ADDR);     // opcode:0x22
        OLED_sendCommand(0);     // start at the top row
        OLED_sendCommand(7);     // end at the bottom row

        TWCR=((1<<TWINT)|(1<<TWSTA)|(1<<TWEN)); // send START
        while(!(TWCR & (1 << TWINT)));  // delay until TWINT set
        TWDR = OLED_SLA7 << 1;   // send SLA  8-bit SLAw = 0x78
        TWCR = ((1<<TWINT)|(1<<TWEN)); while(!(TWCR & (1<<TWINT)));

        TWDR = SSD1306_DATA_CONTINUE;   // send D/C sentinal byte 0x40
        TWCR = ((1<<TWINT)|(1<<TWEN)); while(!(TWCR & (1<<TWINT)));

        // TWI NOT using Wire.h   128 bytes (8 bits vertical) per row * 8 char rows = 1024
        // Send 64 TWI messages { START:SLAw:0x40:16 bytes of 0x00:STOP }  1024 data bytes total
        for (uint16_t scrClearIndex=0; scrClearIndex<1024; scrClearIndex++) {  // (SSD1306_LCDWIDTH*SSD1306_LCDHEIGHT/8)
            TWCR=((1<<TWINT)|(1<<TWSTA)|(1<<TWEN)); // send START
            while(!(TWCR & (1 << TWINT)));  // delay until TWINT set
            TWDR = OLED_SLA7 << 1;   // 8-bit SLAw = 0x78
            TWCR = ((1<<TWINT)|(1<<TWEN)); while(!(TWCR & (1<<TWINT))); // TX?done delay

            TWDR = 0x40;  // send D/C_sentinal byte for data stream
            TWCR = ((1<<TWINT)|(1<<TWEN)); while(!(TWCR & (1<<TWINT)));

            for (uint8_t x=0; x<16; x++) {
                TWDR = 0x00;  // all eight pixels in the column are off.
                TWCR = ((1<<TWINT)|(1<<TWEN)); while(!(TWCR & (1<<TWINT)));
                scrClearIndex++;  // 16 bytes per I2C transmission__64 transmissions per screen
            }
            scrClearIndex--;
            TWCR = ( (1<<TWINT)|(1<<TWEN)|(1<<TWSTO) ); // I2C STOP
        }
}//~~~~~~~~~~~~~~~~~~~~~ LOW-level OLED_I2C ~~~~~~~~~~~~~~~~~~~~
void OLED_Init(void) {  // cmd: send START, 8bitSLA, D/C sentinal=0x00, command_value, STOP
        OLED_sendCommand(SSD1306_DISPLAY_OFF);          //   0xAE
        OLED_sendCommand(SSD1306_SET_CLOCK_DIV_RATIO);  //   0xD5
        OLED_sendCommand(0x80);                         //   0x80
        OLED_sendCommand(SSD1306_SET_MULTIPLEX_RATIO);  //   0xA8
        OLED_sendCommand(0x3F);                         //   0x3F
        OLED_sendCommand(SSD1306_SET_DISPLAY_OFFSET);   //   0xD3
        OLED_sendCommand(0x0);                          //   0x00
        OLED_sendCommand(SSD1306_SET_START_LINE | 0x00); //   0x40
        OLED_sendCommand(SSD1306_CHARGE_PUMP);          //   0x8D
        OLED_sendCommand(0x14);                         //   0x14
        OLED_sendCommand(SSD1306_MEMORY_ADDR_MODE);     //   0x20
        OLED_sendCommand(0x00);                         //   0x00
        OLED_sendCommand(SSD1306_SET_SEGMENT_REMAP | 0x01);// 0xA1
        OLED_sendCommand(SSD1306_COM_SCAN_DIR_DEC);     //   0xC8
        OLED_sendCommand(SSD1306_SET_COM_PINS);         //   0xDA
        OLED_sendCommand(0x12);                         //   0x12
        OLED_sendCommand(SSD1306_SET_CONTRAST_CONTROL); //   0x81
        OLED_sendCommand(0xCF);                         //   0xCF
        OLED_sendCommand(SSD1306_SET_PRECHARGE_PERIOD); //   0xD9
        OLED_sendCommand(0xF1);                         //   0xF1
        OLED_sendCommand(SSD1306_SET_VCOM_DESELECT);    //   0xDB
        OLED_sendCommand(0x40);                         //   0x40
        OLED_sendCommand(SSD1306_DISPLAY_ALL_ON_RESUME);//   0xA4
        OLED_sendCommand(SSD1306_NORMAL_DISPLAY);       //   0xA6
        OLED_sendCommand(SSD1306_DISPLAY_ON);           //   0xAF
        OLED_clear();
}//~~~~~~~~~~~~~~~~~~~~~~ LOW-level OLED_I2C ~~~~~~~~~~~~~~~~~~~~~
void OLED_SetCursor(uint8_t myLineNumber,uint8_t myColumnPosition) {
        if( (myLineNumber <= SSD1306_LASTLINE) && (myColumnPosition <= 127) ) {
            OLEDlineNumber = myLineNumber;     // global var: current line number
            OLEDcursorPos =  myColumnPosition; // global var: current cursor position

            OLED_sendCommand(SSD1306_SET_COLUMN_ADDR);
            OLED_sendCommand(myColumnPosition);
            OLED_sendCommand(127);

            OLED_sendCommand(SSD1306_SET_PAGE_ADDR);
            OLED_sendCommand(myLineNumber);
            OLED_sendCommand(7);

            TWCR=((1<<TWINT)|(1<<TWSTA)|(1<<TWEN)); // send START
            while(!(TWCR & (1 << TWINT)));  // delay until TWINT set
            TWDR = OLED_SLA7 << 1;   // 8-bit SLAw = 0x78  7-bitSLA=0x3C  SSD1306 controller
            TWCR = ((1<<TWINT)|(1<<TWEN)); while(!(TWCR & (1<<TWINT)));

            TWDR = SSD1306_DATA_CONTINUE;   // 0x40
            TWCR = ((1<<TWINT)|(1<<TWEN)); while(!(TWCR & (1<<TWINT)));  // TWINT?set delay
        }
}//~~~~~~~~~~~~~~~~~~~~~~ LOW-level OLED_I2C ~~~~~~~~~~~~~~~~~~~~~~~
void OLED_GoToLine(uint8_t myLine) {
        if( myLine < 8) {
            OLEDlineNumber = myLine;
            OLED_SetCursor(OLEDlineNumber, 0);
        }
}//~~~~~~~~~~~~~~~~~~~~~~ LOW-level OLED_I2C ~~~~~~~~~~~~~~~~~~~~~~~
void OLED_GoToNextLine() {      // Increment and roll-over the current line number.
        OLEDlineNumber++;       // global var for current line number
        OLEDlineNumber = OLEDlineNumber & 0x07; // roll-over back to top after 8 lines
        OLED_SetCursor(OLEDlineNumber, 0);
}//~~~~~~~~~~~~~~~~~~~~~~ LOW-level OLED_I2C ~~~~~~~~~~~~~~~~~~~~~~~~~~
void OLED_DisplayChar(uint8_t myDisplayChar) {
        uint8_t charColumnBitMap, charBitMapIndex = 0;

        if(((OLEDcursorPos + FONT_SIZE) >= 128) || (myDisplayChar=='\n')) { // font size=5
//      If the line has no more room for complete chars OR NewLine command,
//      then move the cursor to next line
            OLED_GoToNextLine();
        }
        if(myDisplayChar != '\n') {
            myDisplayChar = myDisplayChar - 0x20; // As the lookup table starts from Space(0x20)
            while(1) {
               charColumnBitMap = pgm_read_byte(&FontTable[myDisplayChar][charBitMapIndex]);
               TWDR = charColumnBitMap;
               TWCR = ((1<<TWINT)|(1<<TWEN)); while(!(TWCR & (1<<TWINT))); // TX?done delay
               OLEDcursorPos++;
               charBitMapIndex++;
               if( charBitMapIndex == FONT_SIZE) {   // Exit the loop after sending five bytes
                  TWDR = 0x00;  // last column of char is one column of space between chars.
                  TWCR = ((1<<TWINT)|(1<<TWEN)); while(!(TWCR & (1<<TWINT))); // TX?done delay
                  OLEDcursorPos++;
                  break;
               }    }    }
}//~~~~~~~~~~~~~~~~~~~~~ LOW-level OLED_I2C ~~~~~~~~~~~~~~~~~~~~~~~~~~
void OLED_DisplayString(uint8_t *ptr) {
        while(*ptr) OLED_DisplayChar(*ptr++);
}//~~~~~~~~~~~~~~~~~~~~~ LOW-level OLED_I2C ~~~~~~~~~~~~~~~~~~~~~~~~~

void displayBigDigit(uint8_t myDigit, uint8_t myDigitRow, uint8_t myDigitColumn) {
        uint8_t charColumnBitMap, columnIndex = 0, rowIndex = 0, fullDigitIndex=0;
        
        if ( (myDigitRow <= 5) && (myDigitColumn <= 116) ) { // full digit gets displayed
            if (myDigit >= 0 && myDigit <= 9 ) {
              for (rowIndex=0; rowIndex<3; rowIndex++) {
                 OLED_SetCursor(myDigitRow + rowIndex, myDigitColumn);
                 for (columnIndex = 0; columnIndex < 12; columnIndex++) {
                    charColumnBitMap = pgm_read_byte(&BigDigitFont[myDigit][fullDigitIndex]);
                    TWDR = charColumnBitMap;
                    TWCR = ((1<<TWINT)|(1<<TWEN)); while(!(TWCR & (1<<TWINT))); // TX?done delay
                    fullDigitIndex++;
                 }
              }
            }
            
            if (myDigit == 10 ) {
               for (rowIndex=0; rowIndex<3; rowIndex++) {
                  OLED_SetCursor(myDigitRow + rowIndex, myDigitColumn);
                  for (columnIndex = 0; columnIndex < 12; columnIndex++) {
                      charColumnBitMap = pgm_read_byte(&BigDigitFont[10][fullDigitIndex]);
                      TWDR = charColumnBitMap;
                      TWCR = ((1<<TWINT)|(1<<TWEN)); while(!(TWCR & (1<<TWINT))); // TX?done delay
                      fullDigitIndex++;
                  }
               }
            }    // myDigit 10
              
            if (myDigit == 11 ) {
               for (rowIndex=0; rowIndex<3; rowIndex++) {
                  OLED_SetCursor(myDigitRow + rowIndex, myDigitColumn);
                  for (columnIndex = 0; columnIndex < 12; columnIndex++) {
                      charColumnBitMap = pgm_read_byte(&BigDigitFont[11][fullDigitIndex]);
                      TWDR = charColumnBitMap;
                      TWCR = ((1<<TWINT)|(1<<TWEN)); while(!(TWCR & (1<<TWINT))); // TX?done delay
                      fullDigitIndex++;
                  }
               }
            }   // myDigit 11
        }   // myDigitRow  5..116
}/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */


/* OLED display techniques:  numbers; flash strings, bitmaps;
-----------
Numbers:  Values that change and need to be updated:
-----------
            uint8_t myBuffer[22];

            OLED_SetCursor(0, 11 * CHAR_SIZE); //=6   top line 0, mid-screen char (0-20)
            itoa(integer_Variable_Name, myBuffer, 10);   // use dtostrf() for floats
            OLED_DisplayString(myBuffer);
-----------
Individual Characters
-----------OLED_DisplayChar(uint8_t myDisplayChar);

-----------
SRAM strings
-----------OLED_DisplayString(uint8_t *ptr);
 
Constant Number values in program memory:
----------- uint16_t workFMfreq, myFMpresetFreq;
            float displayFMfrequency ;
            byte highFMreg3, lowFMreg3, myBuffer[8];

            OLED_SetCursor(7, 16 * CHAR_SIZE); //=6   bottom line 7, right screen char (0-20)
            myFMpresetFreq = pgm_read_word(&FMstationPreset[currentFMstationIndex]);
            displayFMfrequency  =  (float) myFMpresetFreq / 100;
            dtostrf(displayFMfrequency,4,1,myBuffer); // 4 chars, 1 digit after dec point
            OLED_DisplayString(myBuffer); // dtostrf(value,strSize,decPtCnt,buffer);
-----------
Flash strings:  constant strings that are stored in program memory:
-----------
const char String00[] PROGMEM = "KFBW";   //  FM _The Buzz
const char String01[] PROGMEM = "KLTH";   //  The Eagle
const char String02[] PROGMEM = "KXRY";   //  progressive independent
const char String03[] PROGMEM = "KXJM";   //  Jam'n 1075
const char * const  StringArray[ 4 ] PROGMEM = {String00, String01, String02, String03};

            uint8_t myBuffer[22], *myPtrToFlashString;

            OLED_SetCursor(2,0 * SSD1306_CHAR_SIZE);  // = 6    starting row:char column pixel
            myPtrToFlashString = (char *) pgm_read_word (& StringArray


);
            strcpy_P ((char *) myBuffer, myPtrToFlashString);
            OLED_DisplayString(myBuffer);
-----------
BitMaps:  used for real-time clock's hours:minutes display:
//offset 0-11; row 0-5; BIGDIGITSPACING=15
----------- displayBigDigit(digit_offset, 5, 1 * BIGDIGITSPACING);        */
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~ LOW-level OLED_I2C ~~~~~~~~~~~~~~~~~~~~~~~~~

 

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

You have 1D initialisers for a 2D array?

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

{You have 1D initialisers for a 2D array?}    I don't know what this means.

 

Each I2C device type has a seven-bit address that has a value between 1 and 127 [0x01-0x7f in hexidecimal] (value 0 is a special case).  This value gets shifted once to the left (same as being multiplied by 2) which leaves bit 0 undefined.  If you are writing data to the I2C device, bit 0 is cleared to 0.  If you are reading data from the I2C device, bit 0 is set to 1.

  The seven-bit address of the OLED is 0x3C  or b00111100.  When this is shifted left by one bit, and bit:0 is left clear to indicate a write operation, then the value sent to the I2C device after START is b01111000 or 0x78.

 

"    recipe for target 'Oled_test.elf' failed    "   I have no idea what this means.  What is a "recipe"?

 

"  missing braces around initializer [-Wmissing-braces]    "   Again, no idea!  Why do compilers in 2020 give the same stupid, worthless error messages that they did in 1972?

 

"  (near initialization for 'BigDigitFont')   "     I ...think... that this ...might... have something do with some AVR devices having more than 64K of Flash memory.

 

How to fix it so that it works:    Use the Arduino IDE instead of Atmel Studio.   Things that crash-and-burn in Studio just work OK in Arduino when you use tested and documented Arduino example code and standardized libraries.    Life is too short to pretend that Atmel Studio is more advanced than the Arduino IDE.

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

Thanks for your answers

 

I dont know what this means either " You have 1D initialisers for a 2D array? " I just copied the code.

 

Thanks for the address explanation.

 

I have writen all my code in AS7 and the reason was to learn the standard C and not a derivate like Arduino.

 

I just wanted a sort of text display and this Oled is very smal and also cheap.

 

I am wondering, that there is no working application for this display in such a big community.

 

I have found another lib here and I will try this

https://github.com/Sylaina/oled-display

 

 

Thanks a lot for your responses

regards

Juergen

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

Simonetta wrote:
{You have 1D initialisers for a 2D array?}    I don't know what this means.

Seriously?

 

surprise

 A 1D array has just 1 Dimension -  array[x] - and is initialised with a 1-dimensional list of values:

uint8_t array[5] = { 0, 1, 2, 3, 4 };

 

 A 2D  array has 2 Dimensions -  array[x,y] - and is usually initialised with a 2-dimensional list of values:

uint8_t array[3][3] = { {0x00, 0x01, 0x02}, {0x10, 0x11, 0x12}, {0x20, 0x21, 0x22} };

Which makes clear the row-column structure of the array in the list of initial values.

 

When you do that, the compiler can check that you have the right number of row values, and the right number of column values in each row

 

However, the 'C' language allows you to just specify one long, unstructured list:

uint8_t array[3][3] = { 0x00, 0x01, 0x02, 0x10, 0x11, 0x12, 0x20, 0x21, 0x22 };

 

So the warning is just telling you that you've missed an opportunity to make your code clearer - and have the compiler check it more thoroughly.

 

EDIT: More detail on multidimension arrays & initialisation here:  https://www.avrfreaks.net/forum/multidimensional-array-0

 

"    recipe for target 'Oled_test.elf' failed    "   I have no idea what this means.  What is a "recipe"?

surprise

 

A makefile is a "recipe" for building the code.

 

 

"  missing braces around initializer [-Wmissing-braces]    "   Again, no idea! 

See above

 

 

Why do compilers in 2020 give the same stupid, worthless error messages that they did in 1972?

Not worthless at all - see above

 

 

"  (near initialization for 'BigDigitFont')   "     I ...think... that this ...might... have something do with some AVR devices having more than 64K of Flash memory.

No - it's just telling you where the issue was detected.

 

EDIT

 

typo

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: Sat. Feb 15, 2020 - 12:28 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

1D means one-dimensional e.g. BigDigitFont[]

2D means two-dimensional e.g. BigDigitFont[][36]

3D means three-dimensional  e.g. array[3][4][5]

 

Simonetta's code did not compile.

I have attached an AS7.0 solution with 3 projects:

ssd1306_1D.cproj

ssd1306_2D.cproj

ssd1306_simonetta.cproj the non-working code that Simonetta posted.  (main.c)

 

The ssd1306_1D.cproj and ssd1306_2D.cproj should both compile and run.

ssd1306_2D.c required a lot of editing to declare the tables with legal C syntax.

 

David.

 

Edit.  Updated ssd1306_simonetta.zip.   Added ssd1306_UD.cproj which makes Simonetta's code work.

AS7.0 builds the project but Warns about the poor Font declarations.

Attachment(s): 

Last Edited: Fri. Jan 17, 2020 - 11:55 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

JB57 wrote:
After building I get the following errores:

Error             recipe for target 'Oled_test.elf' failed   

Warning        missing braces around initializer [-Wmissing-braces]                       const uint8_t FontTable[][FONT_SIZE] PROGMEM = {

Message        (near initialization for 'FontTable')                                                 const uint8_t FontTable[][FONT_SIZE] PROGMEM = {

Warning        missing braces around initializer [-Wmissing-braces]                       const uint8_t BigDigitFont[][36] PROGMEM = { // each SSD1306 data byte is 8 vertical pixels.
 
Message        (near initialization for 'BigDigitFont')                                              const uint8_t BigDigitFont[][36] PROGMEM = { // each SSD1306 data byte is 8 vertical pixels.

Error        ld returned 1 exit status 

There must be more than that! Those Warnings alone shouldn't stop the project from building.

 

Did you take that from the "Error List"?  Sadly, that's a really unhelpful presentation of the messages; eg,

 

 

 

It's usually far better to look at the actual build output:

 

 

See:  https://www.avrfreaks.net/forum/where-find-actual-compiler-output

 

EDIT

 

remove repetition

 

#AS7OutputWindow #AS7ErrorList

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: Fri. Jan 17, 2020 - 09:44 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

JB57 wrote:
After building I get the following errores:
Do not bother with "Error List" - it strips out too much of the detail from errors and puts them in the wrong (random!) order. The key thing in any build is the build output and when you have errors the most important thing in all that is the first one encountered.

 

But anyway my previous 1D/2D post was simply referring to

Warning        missing braces around initializer [-Wmissing-braces]                       const uint8_t FontTable[][FONT_SIZE] PROGMEM = {

Warning        missing braces around initializer [-Wmissing-braces]                       const uint8_t BigDigitFont[][36] PROGMEM = { // each SSD1306 data byte is 8 vertical pixels.

which refer to:

const uint8_t FontTable[][FONT_SIZE] PROGMEM = {
        0x00, 0x00, 0x00, 0x00, 0x00,   // space 00   20 hexASCII
        0x00, 0x00, 0x2f, 0x00, 0x00,   // !     01   21
        0x00, 0x07, 0x00, 0x07, 0x00,   // "     02   22
        0x14, 0x7f, 0x14, 0x7f, 0x14,   // #     03   23

and

const uint8_t BigDigitFont[][36] PROGMEM = { // each SSD1306 data byte is 8 vertical pixels.
// 12 columns * 3 rows = 36 bytes per digit [ * 12 digit characters__432 bytes total ]
//         0    1    2    3    4    5    6    7    8    9   10   11
    0xfc,0xfe,0xfe,0x0f,0x07,0x07,0x07,0x07,0xcf,0xfe,0xfc,0xf8,  // character '0'
    0xff,0xff,0xff,0xf0,0x78,0x3c,0x1e,0x0f,0x07,0xff,0xff,0xff,  //
    0x3f,0x7f,0x7f,0xf8,0xf0,0xf0,0xf0,0xf0,0xf8,0x7f,0x7f,0x1f,  //

which would not show the warning if structured as:

const uint8_t FontTable[][FONT_SIZE] PROGMEM = {
        { 0x00, 0x00, 0x00, 0x00, 0x00 },   // space 00   20 hexASCII
        { 0x00, 0x00, 0x2f, 0x00, 0x00 },   // !     01   21
        { 0x00, 0x07, 0x00, 0x07, 0x00 },   // "     02   22
        { 0x14, 0x7f, 0x14, 0x7f, 0x14 },   // #     03   23

and

const uint8_t BigDigitFont[][36] PROGMEM = { // each SSD1306 data byte is 8 vertical pixels.
// 12 columns * 3 rows = 36 bytes per digit [ * 12 digit characters__432 bytes total ]
//         0    1    2    3    4    5    6    7    8    9   10   11
    { 0xfc,0xfe,0xfe,0x0f,0x07,0x07,0x07,0x07,0xcf,0xfe,0xfc,0xf8,  // character '0'
      0xff,0xff,0xff,0xf0,0x78,0x3c,0x1e,0x0f,0x07,0xff,0xff,0xff,  //
      0x3f,0x7f,0x7f,0xf8,0xf0,0xf0,0xf0,0xf0,0xf8,0x7f,0x7f,0x1f },  //

(as others have explained above)

 

In effect you are initialising individual "mini arrays" that go together to initialize the large (2D) array.

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

awneil wrote:

However, the 'C' language allows you to just specify one long, unstructured list:

uint8_t array[3][3] = { 0x00, 0x01, 0x02, 0x10, 0x11, 0x12, 0x20, 0x21, 0x22 };

 

So the warning is just telling you that you've missed an opportunity to make your code clearer - and have the compiler check it more thoroughly.

 

The current C compiler does not like that syntax.   I could not understand how anyone could write a 2D array with 1D initialiser.    What flag do you need to set for GCC ?

 

I guess that you can declare a 1D array.   And then cast the base address to a 2D array.   But that seems really nasty.

 

David.

 

Edit.   Just tried again with the un-dimensional declaration.   And it worked !!

Last Edited: Fri. Jan 17, 2020 - 09:51 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

david.prentice wrote:
The current C compiler does not like that syntax

In Atmel Studio 7.0.1652 it just gives a warning - code builds successfully.

 

What flag do you need to set for GCC ?

I haven't adjusted anything

 

EDIT: oh - just seen your edit!

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...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

JB57 wrote:
I have found the listing

For reference, it's here:

 

https://www.avrfreaks.net/commen... - and see following posts there for steps necessary to make it build.

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...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Simonetta wrote:
Why do compilers in 2020 give the same stupid, worthless error messages

Actually, if they had been posted properly, they would have been a lot clearer:

 

C:\************************\atmel\AVR\Tiny45\GccApplication1\GccApplication1\main.c(14,23): warning: missing braces around initializer [-Wmissing-braces]
		 uint8_t array[3][3] = { 0x00, 0x01, 0x02, 0x10, 0x11, 0x12, 0x20, 0x21, 0x22 };
		                       ^
C:\************************\atmel\AVR\Tiny45\GccApplication1\GccApplication1\main.c(14,23): info: (near initialization for 'array')

See how it shows you the line in question, and even gives a little pointer to where the problem is!

 

 

Also note that the "[-Wmissing-braces]" is telling you which option enables/disables this warning

 

You can look it up in the docs:

 

The GCC docs wrote:

-Wmissing-braces

Warn if an aggregate or union initializer is not fully bracketed. In the following example, the initializer for a is not fully bracketed, but that for b is fully bracketed. This warning is enabled by -Wall in C.

int a[2][2] = { 0, 1, 2, 3 };
int b[2][2] = { { 0, 1 }, { 2, 3 } };

This warning is enabled by -Wall.

 

https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html

 

Use the Arduino IDE instead of Atmel Studio

Surely, the Arduino IDE uses exactly the same GCC compiler - so you will get exactly the same error messages ?

 

 

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...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Simonetta wrote:
Again, no idea!  Why do compilers in 2020 give the same stupid, worthless error messages that they did in 1972?
This is utter nonsense. How could the compiler have been more explicit? It said EXACTLY what it was warning about. Indeed how could I have made the post about 1D/2D if I did understand exactly what it was saying. Any, even vaguely competent, programmer would understand both the message and the required action.

 

I personally LOVE the errors and warnings in GCC. They are clear, concise and to the point. The additional behaviour of printing the failing line with the caret to show the actual point at which the issue occurred that is now shown these days is just icing on the cake. About the only way in which GCC error/warnings are deficient is that they aren't each given a unique ID number (as is done by MSVC). If I wrote this is MSVC:

char * p;

int main(void) {
    p = 12345;
}

then the error is:

    d:\c\testfp\testfp\testfp.cpp(6): error C2440: '=': cannot convert from 'int' to 'char *'
    d:\c\testfp\testfp\testfp.cpp(6): note: Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast

The "cannot convert" message already tells me exactly what is wrong but if I'm in any doubt I can just google "C2440" which leads me to:

 

https://docs.microsoft.com/en-us/cpp/error-messages/compiler-errors-1/compiler-error-c2440?view=vs-2019

 

But this is about the only way GCC could be "better" in reporting warnings/errors - but to do this requires a large documentation database which Microsoft can provide as you pay a lot of money for their compiler but that would have to be done by volunteers for GCC.

 

At present GCC (in Linux) reports the above as:

foo.cpp: In function ‘int main()’:
foo.cpp:4:4: error: invalid conversion from ‘int’ to ‘char*’ [-fpermissive]
  p =12345;
    ^

 

Last Edited: Fri. Jan 17, 2020 - 12:49 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for all the replies

 

My answers:

 

To David
Thanks very much, I will try it and will let you know, would be great if it works

 

To CLawson
Thanks also for your response, I have to go trough as I dont understand on the first glance

 

 

 

To AWNEIL:

1. Sorry I do know basicly what is a 2D array, I just wanted to say I dont know why the author did code it like that.

2. There must be more than that! Those Warnings alone shouldn't stop the project from building.
 NO I sent you the output as you described.
I would send you a pic, but I deleted the whole project to start all over again.

 

 

Thank you all very much

I will carry on

regards

 

Juergen

 

 

 

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

JB57 wrote:
I do know basicly what is a 2D array

It was  Simonetta  that didn't understand.

I dont know why the author did code it like that.

From the replies, because (s)he didn't know better!

 

 

2. There must be more than that! Those Warnings alone shouldn't stop the project from building.
 NO I sent you the output as you described.

See #20: it looks like you took them from the   "Error List" - don't do that, because if does give you a confused & incomplete view.

 

Always look the the 'Output' window for the complete build output.

 

I would send you a pic

Generally better to copy & paste as text - as shown in #25.

 

Post as for source code - see Tip #1.

 

 

 

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...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok, I am quite sure it was from the output, but I will be more careful, thanks very much

 

regards

Juergen

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

#25 shows what the messages in the full output would look like.

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...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

JB57 wrote:
2. There must be more than that! Those Warnings alone shouldn't stop the project from building.
Indeed the actual error that stopped the build is nothing to do with these array initialisers, they are just warnings. The real reason the build failed is:

Error             recipe for target 'Oled_test.elf' failed   

Error        ld returned 1 exit status 

but as you say there must be more to it than that. This just proves how totally useless and misleading the "Error List" in Studio 7 actually is (it's the same in the Visual Studio on which Studio 7 is based). It tries to summarise all the errors/warnings but  it reorders things (so you don't know which is the first and most serious issue) and often it omits things that are the real reason for the problems. That's why the ONLY thing you can trust is the build output. Switch to the "Output" tab, scroll all the way back to the top then read through to the first thing that shows any sign of "error" (wording may be "failed" or something else even) and that is the thing that needs to be fixed.

Last Edited: Fri. Jan 17, 2020 - 02:02 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
it's the same in the Visual Studio on which Studio 7 is based

and Eclipse does much the same.

 

angry

 

Out of interest, how does the Arduino IDE handle this ?

 

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...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


awneil wrote:
Out of interest, how does the Arduino IDE handle this ?
Curiously. I put a couple of deliberate warnable offences and one definite error into a sketch:

 

 

So it caught the real error (unresolved foo()) and it warned about the int/char* thing but nothing about the array initialiser at all.

 

I do not find their error display easy to read either - it's peppered with lots of pointless vertical white space which forced me to expand the window even to see the wood from the trees in the first place. I'm guessing what it has actually done is simply filtered the build output to remove "non warn/error" lines but if it is doing that I wonder why it thinks I'm interested in seeing their '\n's ?

 

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

Life is much easier if you post a complete AS7.0 project.    Other IDEs are available but AS7.0 is the most common one for AVR.

 

The original Simonetta code omits important includes and defines:

#include <avr/io.h>
#include <avr/pgmspace.h>
#define FONT_SIZE 5         //.kbv
#define OLED_SLA7 0x3C      //.kbv

And it omits any main() function e.g.

int main(void)
{
    i2c_initialise();
    OLED_Init();
    OLED_SetCursor(0, 0);
    OLED_DisplayString("David Prentice");
    OLED_SetCursor(1, 0);
    OLED_DisplayString("Un-Dimensional array");
    displayBigDigit(5, 4, 0);
    displayBigDigit(9, 5, 20);
    while(1);
}

Yes,   AS7.0 is crap when you omit the main() function.

Likewise Arduino IDE when you omit setup() or loop().   But the verbose build does give you some clues e.g.

C:\Program Files (x86)\Arduino-1.8.9\hardware\arduino\avr\cores\arduino/main.cpp:43: undefined reference to `setup'

As others have suggested.   View the Output window when it comes to Errors or Warnings.   Some are obvious from the Error list.    Others do not even appear in the Error list.

 

David.

Last Edited: Fri. Jan 17, 2020 - 02:28 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
 nothing about the array initialiser at all

Could that be because Arduino is C++ ... ?

 

EDIT

 

Just tried it as C++ in AS - and got no warnings on

 

/*
 * GccppApplication5.cpp
 *
 * Created: 17/01/2020 14:44:33
 * Author : awn
 */ 

#include <avr/io.h>

uint8_t array[3][3] = { 0x00, 0x01, 0x02, 0x10, 0x11, 0x12, 0x20, 0x21, 0x22 };

uint8_t array1[3][3] = { {0x00, 0x01, 0x02}, {0x10, 0x11, 0x12}, {0x20, 0x21, 0x22} };

uint8_t array2[3][3] = { {0x00, 0x01, 0x02},  0x10, 0x11, 0x12, {0x20, 0x21, 0x22} };

int main(void)
{
    /* Replace with your application code */
    while (1)
    {
    }
}

 

EDIT 2

 

Looking again at the GCC documentation (see #25):

The GCC docs wrote:

Warn if an aggregate or union initializer is not fully bracketed. In the following example, the initializer for a is not fully bracketed, but that for b is fully bracketed. This warning is enabled by -Wall in C.

So evidently not in C++

 

If I manually add the -Wmissing-braces in 'Other flags', then  I do get the warning.

 

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: Fri. Jan 17, 2020 - 02:53 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi David

 

thanks for your code.
 

As a beginner I was able to compile and I got your sample text on the display, my very first succsess with the display.

 

Maybe you can help me a step further:

 

1. I dont understand 1D, 2D, UD, all the files do the same. If you have time maybe you can explain this to a novice.

 

2. The size of the numbers in your samples is exactly what I need. But what I figured out is that I need some sort of matrix for all the letters. Is there a source for these tables or do I have to make it myself and if yes how is the structure I was not able to find it out.

 

Maybe you are so kind and help me.

 

regards

 

Juergen

 

 

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

Read Cliff's explanation in #21 about syntax for multi-dimensional arrays.

 

UD is project with "wrong" syntax for Font declarations.   But it builds with a warning.

1D is project with declaration for one-dimensional array.    But I had to amend the Font display functions.

2D is project with "legal" declaration for two-dimensional array.   The display functions are unchanged.

 

You can see that editing the original code to add extra braces in the 2D Font declarations needed a lot of effort.

 

The regular 7x5 Font is used by almost every code that I have seen.   All this other code uses the "unstructured" one-dimensional array declaration.   And display functions like my 1D versions.

 

The Big Number font is unusual.   But it works.

 

Note that you can only print text on 8-scanline boundaries.   The "row" argument 0, 1, 2, 3, ... refers to scanlines 0, 8, 16, 24, ...

 

This makes text printing easier.    But sophisticated libraries allow you to draw text at any pixel scanline.   And mix graphics with text.

 

I strongly advise you to use Arduino code with the Adafruit_ssd1306 library.

If your project is very big you need to be careful with SRAM.   e.g. storing text messages in PROGMEM

 

You can print strings with the regular Font.   e.g. OLED_DisplayString("David Prentice");

But you can only display Big Digits one at a time.  e.g.  to print "1234" on row 4 (scanline=32).

    displayBigDigit(1, 4, 0);
    displayBigDigit(2, 4, 18);
    displayBigDigit(3, 4, 36);
    displayBigDigit(4, 4, 54);

 

David.

Last Edited: Sat. Jan 18, 2020 - 01:37 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

JB57 wrote:
. I dont understand 1D, 2D

 

These are standard programming terms; not specific to AVR, nor even to 'C' - so a 'C' textbook should cover this.

 

In fact, the terms are used with exactly the same meaning as in general life:

  1. A one-dimensional object - "1D" - has length only
     
  2. A two-dimensional object - "2D" - has length & width; eg, a drawing on paper.
    This can also be seen as "rows" and "columns" - as here
     
  3. A three-dimensional object - "3D" - has length,  width, & height
     
  4. etc, etc, ...

 

 

 

all the files do the same

As explained in #18, the "1D" and "2D" are both legal - but the "2D" gives you extra benefits.

 

 

. If you have time maybe you can explain this to a novice.

See #18

 

And a 'C' textbook

 

Here are some 'C' learning & reference materials - including a free online textbook:

 

http://blog.antronics.co.uk/2011...

 

 

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: Sat. Jan 18, 2020 - 03:10 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for the reply

 

@David
I understand that the text is limited to the 8-scanline boundaries, which is too small.

 

I just realised that the bigDigit is ok in size but does not help me either because of the structure, a dynamic output of a variable larger than 9 is  not possible.

 

I dont want to switch to Arduino IDE, I have to search for a lib which works with AS7.

 

@AWNEIL
I understand the dimension staff, but I have sometimes problems to express myself in english. I did not look in detail at the code so I was wondering why to use different methodes and I also have problems to understand the code in detail.

 

Thanks you all and have a nice weekend

 

regards

 

Juergen
 

 

 

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

Yes,   I wondered how a German speaker might understand our English.

 

It is simple enough to convert a number into digits.  e.g.

void displayBigNumber(int16_t value, uint8_t row, uint8_t col)
{
    char buf[7], c;
    itoa(value, buf, 10);
    for (uint8_t i = 0; buf[i] != 0; i++) {
        c = buf[i];
        if (c >= '0' && c <= '9') {
            displayBigDigit(c - '0', row, col);
            col += 18;
        }
    }
}

you need to tell AS7.0 about itoa() by:

#include <stdlib.h>

and call like this:

    displayBigNumber(12345, 2, 20);
    displayBigDigit(5, 4, 0);
    displayBigDigit(9, 5, 20);

Note that there is no line spacing between the "12345" and the "9".

 

David.

 

Edit.  Corrected my typo.  i.e. from itoa(val, buf, 10) to itoa(value, buf, 10)

Last Edited: Mon. Jan 20, 2020 - 02:37 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Oh, thanks David this should be ok for my little project, great.

 

I will try it tomorow

 

regards

 

Juergen

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

Have you tried  https://www.mikrocontroller.net/  ?

 

 it's in German, and they have an AVR section:

 

https://www.mikrocontroller.net/articles/AVR

 

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...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, I know it but did not have closer look at. Thank I look into it.
thanks very much for your efforts to help me.

regards
Juergen

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

I just wanted to implement the code from David. I get an error:

 

(512,7): error: 'val' undeclared (first use in this function) itoa(val, buf, 10);

 

 

I have installed the std.lib.h and it appears in the Solution explorer under Libraries.

And it also in the Dependencies.

 

I think I have done everything correct due to the describtion in the manual.

 

Maybe one of you knows about Studio 7 and libs. 

 

regards

 

Juergen

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

There is a typographical error in:

void displayBigNumber(int16_t value, uint8_t row, uint8_t col)
{
    char buf[7], c;
    itoa(val, buf, 10);

The variable comes into the function as "value" but David inadvertently used "val" rather than "value" in the call to itoa().

JB57 wrote:
I have installed the std.lib.h
No idea what you mean by this. stdlib.h like all the C standard headers (stdio.h, string.h, math.h, etc) is just part of what comes with any C compiler. The only thing you actually have to "do" is to add the #include at the top of any .c/.cpp file that then goes on to use a function documented in the header. There is no "installation" necessary and this has nothing to do with "Libraries" or anything like that.

 

A simple example. If I build:

#include <avr/io.h>

char buffer[12];

int main(void)
{
	itoa(1234, buffer, 10);
}

I get the warning:

		.././main.c: In function 'main':
D:\test\test\main.c(7,2): warning: implicit declaration of function 'itoa' [-Wimplicit-function-declaration]
		  itoa(1234, buffer, 10);
		  ^

The compiler is pointing out that I have called a function called itoa() which it has never heard of. If I simply use:

#include <avr/io.h>
#include <stdlib.h>

char buffer[12];

int main(void)
{
	itoa(1234, buffer, 10);
}

the warning goes away because now the compiler knows what itoa() is (because stdlib.h told it).

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

Thanks Clawson

 

I tryed to implement because David posted:

 

"you need to tell AS7.0 about itoa() by:"#include <Stdlib.h>

 

 

 

I did the correction on value and it build with no error

 

but I was unable to programm eventhough the ATMEL ICE did not tell an error either.

 

What I observed, the compiler did not produce a hex file but a .elf wich I tryed to programm.

 

But there was no change on the display.

 

Any idea

 

regards

 

Juergen

 

 

 

 

 

 

 

 

 

 


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

JB57 wrote:
What I observed, the compiler did not produce a hex file but a .elf wich I tryed to programm.
Well it should be doing both. In AS7 when it compiles .c files it creates .o files (object files) which are really just ELF but in a state before it has been "linked". Then a final step invokes the build tools again which joins all the .o files (with linking) to create a final projectwide .elf file. Then avr-objcopy is run on that (three times I think it is) to extract three different forms of data from it. The code itself is read out as .hex, the EEPROM contents as .eep and a second version of the code as .srec. You can see that happening here:

		Invoking: AVR8/GNU Linker : 5.4.0
		"C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-g++.exe" -o test.elf  main.o second.o   -Wl,-Map="test.map" -Wl,--start-group -Wl,-lm -Wl,-lprintf_flt  -Wl,--end-group -Wl,--gc-sections -mrelax -Wl,-section-start=.myportc=0x800640  -mmcu=attiny1614 -B "C:\Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATtiny_DFP\1.3.229\gcc\dev\attiny1614" -Wl,-print-gc-sections -Wl,-section-start=.fram=0x10000000  
		Finished building target: test.elf
		"C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-objcopy.exe" -O ihex -R .eeprom -R .fuse -R .lock -R .signature -R .user_signatures  "test.elf" "test.hex"
		"C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-objcopy.exe" -j .eeprom  --set-section-flags=.eeprom=alloc,load --change-section-lma .eeprom=0  --no-change-warnings -O ihex "test.elf" "test.eep" || exit 0
		"C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-objcopy.exe" -O srec -R .eeprom -R .fuse -R .lock -R .signature -R .user_signatures "test.elf" "test.srec"

There were two source files (main.c, second.c). Each had individually been compiled to create main.o and second.o then the first line you see here creates test.elf by combining those two. The next line extracts test.hex. The following creates test.eep and the last creates test.srec

 

Usually you would pass test.hex to your programmer to program it into the AVR (and maybe test.eep too if you use EEPROM). It's unusual to ever need test.srec

 

Some programming systems may be happy to use test.elf (and internally they will do the same extraction process that created test.hex above) but if you do pass a test.hex to something that only accepts .hex normally it will be very confused by what it finds in the file.

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

I have edited my typo in #40

 

The Compiler will build and run the project  but with some Warnings:

 

warning: missing braces around initializer [-Wmissing-braces]

warning: missing braces around initializer [-Wmissing-braces]

warning: implicit declaration of function 'itoa' [-Wimplicit-function-declaration]

warning: pointer targets in passing argument 1 of 'OLED_DisplayString' differ in signedness [-Wpointer-sign]

warning: pointer targets in passing argument 1 of 'OLED_DisplayString' differ in signedness [-Wpointer-sign]

 

You fix the braces warning by using the correct brace syntax

You fix the implicit warning by #include <stdlib.h>

You fix the pointer warning by changing uint8_t to char in void OLED_DisplayString(uint8_t *ptr)

 

David.

Last Edited: Mon. Jan 20, 2020 - 02:53 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I did the modificaten.

Thats what I get after build

 

But when programmed nothing happens.

 

Its probably the lack of my AS7 knowledge

 

------ Build started: Project: David, Configuration: Debug AVR ------
Build started.
Project "David.cproj" (default targets):
Target "PreBuildEvent" skipped, due to false condition; ('$(PreBuildEvent)'!='') was evaluated as (''!='').
Target "CoreBuild" in file "C:\Program Files (x86)\Atmel\Studio\7.0\Vs\Compiler.targets" from project "C:\Bearbeiten\Amtel\Projecte\David\David\David.cproj" (target "Build" depends on it):
	Task "RunCompilerTask"
		Shell Utils Path C:\Program Files (x86)\Atmel\Studio\7.0\shellUtils
		C:\Program Files (x86)\Atmel\Studio\7.0\shellUtils\make.exe all --jobs 16 --output-sync 
		make: Nothing to be done for 'all'.
	Done executing task "RunCompilerTask".
	Task "RunOutputFileVerifyTask"
				Program Memory Usage 	:	134 bytes   0,4 % Full
				Data Memory Usage 		:	0 bytes   0,0 % Full
				Warning: Memory Usage estimation may not be accurate if there are sections other than .text sections in ELF file
	Done executing task "RunOutputFileVerifyTask".
Done building target "CoreBuild" in project "David.cproj".
Target "PostBuildEvent" skipped, due to false condition; ('$(PostBuildEvent)' != '') was evaluated as ('' != '').
Target "Build" in file "C:\Program Files (x86)\Atmel\Studio\7.0\Vs\Avr.common.targets" from project "C:\Bearbeiten\Amtel\Projecte\David\David\David.cproj" (entry point):
Done building target "Build" in project "David.cproj".
Done building project "David.cproj".

Build succeeded.
========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==========

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
				Program Memory Usage 	:	134 bytes   0,4 % Full
				Data Memory Usage 		:	0 bytes   0,0 % Full

That looks awfully like the size of a completely "empty" C program for a mega328P!

 

If I build just:

#include <avr/io.h>

int main(void)
{
}

for a mega328P in AS7 I get:

		Invoking: AVR8/GNU Linker : 5.4.0
		"C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-g++.exe" -o test.elf  main.o   -Wl,-Map="test.map" -Wl,--start-group -Wl,-lm -Wl,-lprintf_flt  -Wl,--end-group -Wl,--gc-sections -mrelax -Wl,-section-start=.myportc=0x800640  -mmcu=atmega328p -B "C:\Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.3.300\gcc\dev\atmega328p" -Wl,-print-gc-sections -Wl,-section-start=.fram=0x10000000  
		Finished building target: test.elf
		"C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-objcopy.exe" -O ihex -R .eeprom -R .fuse -R .lock -R .signature -R .user_signatures  "test.elf" "test.hex"
		"C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-objcopy.exe" -j .eeprom  --set-section-flags=.eeprom=alloc,load --change-section-lma .eeprom=0  --no-change-warnings -O ihex "test.elf" "test.eep" || exit 0
		"C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-objdump.exe" -h -S "test.elf" > "test.lss"
		"C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-objcopy.exe" -O srec -R .eeprom -R .fuse -R .lock -R .signature -R .user_signatures "test.elf" "test.srec"
		"C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-size.exe" "test.elf"
		   text	   data	    bss	    dec	    hex	filename
		    132	      0	      0	    132	     84	test.elf
	Done executing task "RunCompilerTask".
	Using "RunOutputFileVerifyTask" task from assembly "C:\Program Files (x86)\Atmel\Studio\7.0\Extensions\Application\AvrGCC.dll".
	Task "RunOutputFileVerifyTask"
				Program Memory Usage 	:	132 bytes   0.4 % Full
				Data Memory Usage 		:	0 bytes   0.0 % Full
				Warning: Memory Usage estimation may not be accurate if there are sections other than .text sections in ELF file
	Done executing task "RunOutputFileVerifyTask".

So my "completely empty" program is 132 bytes. Your program builds to 134 bytes. I wonder what the exciting 2 bytes you have managed to add actually contain??

 

The majority of these 132/134 bytes are actually a complete (but unassigned) interrupt vector table together with a very small amount of code that comes from the C compiler (the so called "C Run Time" = CRT) that just gets the AVR ready to be able to run C (like setting the stack pointer and so on). In my case the entire listing (.lss file from the build) is:

00000000 <__vectors>:
   0:	33 c0       	rjmp	.+102    	; 0x68 <__ctors_end>
   2:	00 00       	nop
   4:	39 c0       	rjmp	.+114    	; 0x78 <__bad_interrupt>
   6:	00 00       	nop
   8:	37 c0       	rjmp	.+110    	; 0x78 <__bad_interrupt>
   a:	00 00       	nop
   c:	35 c0       	rjmp	.+106    	; 0x78 <__bad_interrupt>
   e:	00 00       	nop
  10:	33 c0       	rjmp	.+102    	; 0x78 <__bad_interrupt>
  12:	00 00       	nop
  14:	31 c0       	rjmp	.+98     	; 0x78 <__bad_interrupt>
  16:	00 00       	nop
  18:	2f c0       	rjmp	.+94     	; 0x78 <__bad_interrupt>
  1a:	00 00       	nop
  1c:	2d c0       	rjmp	.+90     	; 0x78 <__bad_interrupt>
  1e:	00 00       	nop
  20:	2b c0       	rjmp	.+86     	; 0x78 <__bad_interrupt>
  22:	00 00       	nop
  24:	29 c0       	rjmp	.+82     	; 0x78 <__bad_interrupt>
  26:	00 00       	nop
  28:	27 c0       	rjmp	.+78     	; 0x78 <__bad_interrupt>
  2a:	00 00       	nop
  2c:	25 c0       	rjmp	.+74     	; 0x78 <__bad_interrupt>
  2e:	00 00       	nop
  30:	23 c0       	rjmp	.+70     	; 0x78 <__bad_interrupt>
  32:	00 00       	nop
  34:	21 c0       	rjmp	.+66     	; 0x78 <__bad_interrupt>
  36:	00 00       	nop
  38:	1f c0       	rjmp	.+62     	; 0x78 <__bad_interrupt>
  3a:	00 00       	nop
  3c:	1d c0       	rjmp	.+58     	; 0x78 <__bad_interrupt>
  3e:	00 00       	nop
  40:	1b c0       	rjmp	.+54     	; 0x78 <__bad_interrupt>
  42:	00 00       	nop
  44:	19 c0       	rjmp	.+50     	; 0x78 <__bad_interrupt>
  46:	00 00       	nop
  48:	17 c0       	rjmp	.+46     	; 0x78 <__bad_interrupt>
  4a:	00 00       	nop
  4c:	15 c0       	rjmp	.+42     	; 0x78 <__bad_interrupt>
  4e:	00 00       	nop
  50:	13 c0       	rjmp	.+38     	; 0x78 <__bad_interrupt>
  52:	00 00       	nop
  54:	11 c0       	rjmp	.+34     	; 0x78 <__bad_interrupt>
  56:	00 00       	nop
  58:	0f c0       	rjmp	.+30     	; 0x78 <__bad_interrupt>
  5a:	00 00       	nop
  5c:	0d c0       	rjmp	.+26     	; 0x78 <__bad_interrupt>
  5e:	00 00       	nop
  60:	0b c0       	rjmp	.+22     	; 0x78 <__bad_interrupt>
  62:	00 00       	nop
  64:	09 c0       	rjmp	.+18     	; 0x78 <__bad_interrupt>
	...

00000068 <__ctors_end>:
  68:	11 24       	eor	r1, r1
  6a:	1f be       	out	0x3f, r1	; 63
  6c:	cf ef       	ldi	r28, 0xFF	; 255
  6e:	d8 e0       	ldi	r29, 0x08	; 8
  70:	de bf       	out	0x3e, r29	; 62
  72:	cd bf       	out	0x3d, r28	; 61
  74:	02 d0       	rcall	.+4      	; 0x7a <main>
  76:	04 c0       	rjmp	.+8      	; 0x80 <_exit>

00000078 <__bad_interrupt>:
  78:	c3 cf       	rjmp	.-122    	; 0x0 <__vectors>

0000007a <main>:
#include <avr/io.h>

int main(void)
{
  7a:	80 e0       	ldi	r24, 0x00	; 0
  7c:	90 e0       	ldi	r25, 0x00	; 0
  7e:	08 95       	ret

00000080 <_exit>:
  80:	f8 94       	cli

00000082 <__stop_program>:
  82:	ff cf       	rjmp	.-2      	; 0x82 <__stop_program>

The only bytes of that which come from main() are those from 7a: to 7e:

 

Like I say it seems you are building a project with almost nothing in it.

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

Thanks Clawson

 

I only have the code for the display nothing else.

 

I will have a closer look and try to investigate.

 

Thanks very much for now, I will come back.

 

regards

 

Juergen

 

Pages