OLED Display with 1306 on 328p

Go To Last Post
71 posts / 0 new

Pages

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

Read #34.   Look at the code in the projects that I posted in #19.

 

C projects have :

#include statements

#define statements

variables

optional function()s

main() function

 

I explained in #34 that I had to add some includes, defines and the mandatory main() function to Simonetta's code.

 

I expected you to take the example code in #40 and add it to the existing project :

add the include

add the displayBigNumber() function

edit the original main() to insert the displayBigNumber() call

 

All C programs end up being fairly long and complicated.

Whereas Arduino programs tend to have a few includes and a small setup() and loop().  Some complete examples only have 20 - 50 lines.

 

If you have a problem,  I can post the working AS7.0 solution.

But it is probably better to study the existing project(s) and read the replies.

If you don't understand something,  just ask.   It must be difficult for non-English speakers.

 

David.

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

Dear David
I did as you explained and I understand your english very well I rather have problems with the AS7 itself.
I will go all over again tomorow.
Thanks a lot for patient to help me.
I come back
regards
Juergen

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

JB57 wrote:
I only have the code for the display nothing else.
But is it called? If I write:

void foo(void) {
    // stuff
}

int main(void) {
}

then it will produce quite a different result to:

void foo(void) {
    // stuff
}

int main(void) {
    foo();
}

The default options in AS7 are -function-sections and -gc-sections. The first option says "build each function into a separate flash section". The second option says throw away (garbage collect, in fact) any sections that are not referred to. In my first example foo() is not called so the code will initially be generated but then it would be discarded during the final link once the linker spots that nothing ever refers to foo().

 

I'm guessing this is the effect you are seeing leading to only 134 bytes of code.

Last Edited: Tue. Jan 21, 2020 - 09:43 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Dear David

 

so I startet from scrap and now it works.

 

One problem is left, maybe its not too much effort for you to modify.

When I replace the number in displayBigNumber () by a variable I can only display 0-255 after that it starts again from 0.

 

regards

 

Juergen

 

 

 

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
int main(void)
{
    i2c_initialise();
    OLED_Init();
    OLED_SetCursor(0, 0);
    OLED_DisplayString("David Prentice");
    OLED_SetCursor(1, 0);
    OLED_DisplayString("Un-Dimensional array");
    for (int i = 0; i < 30000; i += 123) {
        displayBigNumber(i, 2, 20);
        _delay_ms(100);
    }
    displayBigDigit(5, 4, 0);
    displayBigDigit(9, 5, 20);
    while(1);
}

And I edited my includes and defines like this:

#include <avr/io.h>
#include <avr/pgmspace.h>   //.kbv for pgm_read_byte()
#include <stdlib.h>         //.kbv for itoa()
#define F_CPU 16000000      //.kbv for Uno hardware
#include <util/delay.h>     //.kbv for _delay_ms
#define FONT_SIZE 5         //.kbv
#define OLED_SLA7 0x3C      //.kbv

Incidentally,  my build for 16MHz ATmega328P reported

Program Memory Usage 	:	2526 bytes   7.7 % Full

This program would fit in a smaller AVR e.g. mega8, mega88.   Change Device in Properties.

It should also build for any AVR with regular TWI peripheral.

But would need changes for Xmega or AVR8X style chips like mega4809 or tiny817

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

Dear David

 

thanks a lot, this time it worked on the first attempt.

 

What I dont understand, why does it only work up to 32768 (2^15) after that it subtracts.

 

I tryed to figure it out but cant find it. First I tought my variable has a wrong declaration, but its uint32_t.

 

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%    David  Start  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
void displayBigNumber(int32_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;
		}
	}
}
			int main(void)
			{				
					i2c_initialise();
					OLED_Init();
					OLED_SetCursor(1, 0);
						displayBigNumber(step, 2, 20);
			}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  David End  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

"step" is my variable.

 

regards

 

Juergen

 

 

 

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

The function is written for an int16_t.    (the BigNumber font does not have a minus )

 

You could have an int32_t version

void displayBigNumber(int32_t value, uint8_t row, uint8_t col)
{
	char buf[12], c;         //bigger buffer
	ltoa(value, buf, 10);    // Long to Ascii

Note that int32_t has more digits than will fit on your screen.

 

Seriously.   Using Adafruit_ssd1306 on an Arduino would make your life easier.

 

David.

Last Edited: Tue. Jan 21, 2020 - 06:07 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Dear David

 

I have tryed this before but it makes no differents.

 

Regarding Aruino

 

I did start with Arduino but I had problems with interrupt timing and changed to AS7 where it did work ok.

One reason is also to learn the standard C and not some proprietary Arduino C.

 

But if I cant get to a solution I will change.

 

I have found another lib  https://github.com/HarryLipphaus/DisplayKit

 

I installed the "lib" build it successfuly but it did not produce a hex file so I was not able to flash it. The AS7 is realy a pain in a..

 

Thanks for all your help David

 

regards

 

Juergen

 

 

 

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

Seriously.  Start with one project and stick with it.   If you provide the project code,  readers will help you.

 

If you have a problem take notes with pencil and paper.

Then you can type accurate information in your Forum message.

 

I followed your DisplayKit link.

copied the source files to an AS7.0 project.

added F_CPU to Symbols

added source directory to Directories (because <oled_config.h> was not a system header)

built and ran it on OLED.

Zipped up the project and attached it.

 

David.

 

Attachment(s): 

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

Dear David

 

thanks a lot, it works :-)

 

My problem is to get these libs in AS7 in the correct way.

 

You say:  added source directory to Directories (because <oled_config.h> was not a system header)

 

I tryed several ways, one of them was: properties/Toolchain/Directories
This seems to be wrong as I look at your project and I cant find config.h

 

Can you please explain how you get oled_config.h into AS7

 

I also dont understand how you got i2c_master.h into AS7 and also this oled_gfx.c, then there is a: ascii6x8.fnt, where do I have to put this file.

 

Lots of questions but maybe you take the time to explain, no hurry.

 

have a nice day

regards

Juergen

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


The only files you "add" in the Solution Explorer are source files (.c or .cpp). While you can add .h files there too it does not help in making the compiler/build "see" them. That is simply so they are listed for editing. The way you get the compiler to "see" .h files is by the compiler command -I which adds extra paths for where it should look for .h file. By default when compiling foo.c the compiler will look in the same directory for any .h files but if you are in the habit of keeping sources in one directory (often "src") and the .h files in another directory (often "include") then the .c/.cpp files in "src" will not immediately be able to find the .h. So if you had:

 

 

Then when foo.c and bar.c are being built the compiler needs either -I ..\include or -ID:\example\include to know where to look for the #include's of foo.h and bar.h (relative paths are "better" then absolute paths as they don't tie the code to a specific location on disk like D:\example)

 

In AS7 the way you set up -I's to be passed to the compiler is:

 

 

Note that C and C++ have separate entries for "Directories" - this can easily catch you out. If you have a mixed C and C++ project and have a header that is to be used in both you may need to enter the search location twice.

 

When you add a new path to "Directories" the location selector dialog that appears has a tick box for "relative path" so even if you locate the right place as an absolute path it will be turned into a relative path anyway.

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

I am guessing that you are using AS7.0 on a Win10 PC with Firefox as Browser.

 

1.   in Browser click on attached ZIP

2.   Dialog offers "Open with Windows Explorer" or "Save File"

3.   Choose Explorer.

4.   Right-click on File Folder.   Select Copy.

5.   Paste into your AS7.0 project folder.

6.   In AS7.0 you open the .cproj or .atsln

7.   This will give you the same AS7.0 project as me.

 

e.g. C:\Users\David Prentice\Documents\Atmel Studio\7.0\DisplayKit_ssd1306\DisplayKit_ssd1306.atsln

 

You can select the project node.   Right-click for Properties.    (or use Project from Menu Bar)

 

Properties->Toolchain->AVR/GNU C Compiler->Symbols

 

Properties->Toolchain->AVR/GNU C Compiler->Directories

 

You can examine the settings.   You can edit the settings.  

Note that I try to set these in Properties->Configuration=All Configurations

 

You can use the default Properties->Configuration=Debug

but this means the Release will not know your values.

 

Hey-ho.   This project would find "oled_config.h" with no problem.   But <oled_config.h> needs you to set the Directories.

 

The easiest way to fix it:   edit "lcd.h" to use "oled_config.h" instead of <oled_config.h>

 

I strongly advise that you just paste the project folder straight from the Explorer window.

 

David.

Last Edited: Wed. Jan 22, 2020 - 09:53 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Dear David, CLAWSON

 

I think I you got me wrong, sorry my english :-)

 

I got your project you have sent me working.

 

Now I wanted to try it on my own project and there I have the problem to get all the files on the right place.

 

I still dont know how you got the h-files on the right place.

 

When I open property/toolchain/directory I see a additional line where you put: .. (dot, dot)

 

I also see that all the files (lcd.h, ic2_master.h,etc.) are copied in the project directory. Did you just simply copy it there or is it somehow done by AS7.

 

At the moment I dont get my project working, I have to finde the fault and I will go over yours and CLAWSONs explanatins.

I tryed so many different thinks so I cant realy ask a quallified question at the moment, I start again and will consider all your explanations.

 

Thanks for all

regards

 

Juergen

 

 

 

 

 

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

The safest way to make an AS7.0 project from scratch is:

1.   New Project

2.   Select name, directory,  AVR chip.

3.   Right-click project.   Add files to project.   e.g. New or Existing item

4.   Right-click project.   Add F_CPU to project->Properties->Symbols   (All configurations)

 

If you take notes on paper you can type the steps in your message.   (numbered steps are a good idea)

Quote the step number that goes wrong.   Then you will get an answer swiftly.    Many readers know AS7.0

 

I copied all the DisplayKit files from the GitHub ZIP to the project directory in one go.

The "Add files to project" finds them easily.   The Browse starts in the project directory.   You still have to "Add" to project.

 

I suggest that you experiment with creating a new Project.    And simply "Add" the files from one of the projects that I have posted.

It will give you AS7.0 experience.

 

David.

Last Edited: Wed. Jan 22, 2020 - 05:21 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks David

 

I try again tomorow

 

regards

 

Juergen

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

Dear David

 

I now I did the whole thing again and now it works.

 

What have I done?

 

I compared the main() from the AVR-sample direktory and your main().

What you appearently did is: you deleted:
"#include "ic2_master"

"#include oled_gfx"

 

I guess these are typos because of the missing .h and .c

 

Next I added #include "i2c_master.h" and it still worked.

 

Next I added #include "oled_gfx.c" and it stoped Build Failed

 

 

As far as I can see it works with and without    i2c_master.h    and    oled_gfx    is not needed.

 

I will now start to integrate it in my little project.

 

Thanks very much for all David

regards

 

Juergen

 

 

 

 

 

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

You need all the C and H source files in the project directory (on disk).

You only need the C files in the AS7.0 project node.

 

It is convenient to "Add" the H files to the project node because it lets you click on them.

AS7.0 looks at the file types.   It only compiles C, CPP, S files.   It ignores any H or TXT files that you may have "Add"ed to the project.

 

Yes,  oled_gfx.c can be omitted if GRAPHICMODE  not defined in oled_config.h or led.h

Use ctl-shift-F to search for "define GRAPHICMODE" in all Solution.

 

You #include an H file.

You should NEVER #include a C file.    You "Add" the C file to the project node.

 

There are several conventions used by C programmers:

1.  variables are in lowercase or camelCase

2.  #define macros are in UPPERCASE

3.  #include H files

4.  do not put executable code in H files

5.  indent blocks neatly

6. "Add" C files to a project

7.  Global symbols like F_CPU should be in Properties.   All C files get compiled with the same F_CPU

 

 

These are only "conventions".   The C compiler does not enforce them.   But it upsets readers if you do not follow the convention.

 

Note that a New project in AS7.0 always gives you a "main.c".   I find life is easier if you rename it to "project.c"

If you are copying files from another project,  you might get a "project.c" and a "main.c" (which gives you two main() functions)

 

David.

Last Edited: Thu. Jan 23, 2020 - 12:27 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

David what is the project node?
Is the file in project node when I use „ADD new or existing“ ?

I think my major problem is the AS7 itself. I tryed to whatch these videos but I have problems to understand because of the sound quality and also the content.

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


JB57 wrote:
David what is the project node?

He is referring to the "tree" representation of the project structure in the 'Solution Explorer' view:

 

 

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

Ah, then its clear. Thanks Awneil

Pages