Page 1 of 1

Arduino Mega R3 and gLCD SH1106 SPI

Posted: Tue Jun 28, 2022 1:53 pm
by geomanfred
Hello,

I wanted to test Flowcode 9 (trial version) using Arduino Mega 23560 and a OLED Waveshare 1.3" with SH1106 in SPI mode.
It works fine with the Arduino IDE enviroment, but I wanted to test it also with Flowcode.
And it does not work. It has errors.
The compiler gives the the list of messages below.
Can you help to find the problem?

"
Target folder: C:\Users\geomanfred\Documents\Flowcode Projects
Source name: C:\Users\geomanfred\Documents\Flowcode Projects\Arduino Mega R3 SH1106H.fcfx
Title: App Developer Project
Description:
Device: ARD.ATMEGA.ATMEGA2560
Generated by: Flowcode v9.3.0.35
Date: Tuesday, June 28, 2022 14:39:06
Users: 1
Registered to: geomanfred (geomanfred)
Licence key: urSim
NOT FOR COMMERCIAL USE
https://www.flowcode.co.uk
Using FCD settings for compiler
Launching the compiler...
C:\ProgramData\MatrixTSL\FlowcodeV9\FCD\AVR\batchfiles\avra.bat "C:\Program Files (x86)\Flowcode\Common\Compilers\avrv5\" atmega2560 "C:\Users\geomanfred\Documents\Flowcode Projects\Arduino Mega R3 SH1106H.elf" "C:\Users\geomanfred\Documents\Flowcode Projects\Arduino Mega R3 SH1106H.c" "C:\Users\geomanfred\Documents\Flowcode Projects\Arduino Mega R3 SH1106H.lst"

C:\Users\geomanfred\Documents\Flowcode Projects>REM CRC: EA277D0C7EF9B4E537B79187D0BE7A25FA6080B4B01BE48BAF713429E4B690411241251B4A05C2B5828F4452C9F7348705C640EF477B79E0C7881D2E5EEC9BD6FE0D8D4660AC0314F98C28BCA92AF856EFD1DB5B777140BC4D00059D7958998291880A09BBE74CF7BA3F4E37F13004EE3637760F1F0B7DA0CC623CD30E3C7D6BAB4C3FE6151D92B8EC0ADD55E96639DAC02472BDE3806EF43AE3A028BD32A5DAE68BB191DA97CB6883A66D3C41849952BB2DD264AF32733E2C3050DA273BE4EEFF12703F3DAF67B119A5A5B069403B38249A6C4D8A1304B09A437E7E2D43FD26DF891DB3086C82D6

C:\Users\geomanfred\Documents\Flowcode Projects>REM REVISION: 1.0

C:\Users\geomanfred\Documents\Flowcode Projects>REM GUID: EA0828B2-5C70-41A5-8C54-F359DD5CC88B

C:\Users\geomanfred\Documents\Flowcode Projects>REM DATE: 29\03\2021

C:\Users\geomanfred\Documents\Flowcode Projects>REM DIR: FCD\AVR\batchfiles\avra.bat

C:\Users\geomanfred\Documents\Flowcode Projects>"C:\Program Files (x86)\Flowcode\Common\Compilers\avrv5\bin\avr-gcc.exe" -mmcu=atmega2560 -Os -ffunction-sections -fdata-sections -funsigned-char -o "C:\Users\geomanfred\Documents\Flowcode Projects\Arduino Mega R3 SH1106H.elf" "C:\Users\geomanfred\Documents\Flowcode Projects\Arduino Mega R3 SH1106H.c" -lm -Wl,-gc-sections
In file included from C:\Users\geomanfred\Documents\Flowcode Projects\Arduino Mega R3 SH1106H.c:44:0:
C:\ProgramData\MatrixTSL\FlowcodeV9\CAL\AVR\AVR_CAL_SPI.c: In function 'FC_CAL_SPI_Master_Init_1':
C:\Users\geomanfred\Documents\Flowcode Projects\Arduino Mega R3 SH1106H.c:73:28: error: 'tris' undeclared (first use in this function)
#define MX_SPI_MOSI_TRIS_1 tris
^
C:\ProgramData\MatrixTSL\FlowcodeV9\CAL\internals.c:413:38: note: in definition of macro 'set_bit'
#define set_bit( reg, bitNumb ) ((reg) |= (1 << (bitNumb)))
^
C:\ProgramData\MatrixTSL\FlowcodeV9\CAL\AVR\AVR_CAL_SPI.c:163:3: note: in expansion of macro 'FC_CAL_Bit_High_DDR'
FC_CAL_Bit_High_DDR (MX_SPI_MOSI_PORT_X, MX_SPI_MOSI_TRIS_X, MX_SPI_MOSI_PIN_X); // MOSI pin is default high
^
C:\ProgramData\MatrixTSL\FlowcodeV9\CAL\internals.c:75:26: note: in expansion of macro 'MX_SPI_MOSI_TRIS_1'
#define CAL_APD(a, b) a##b
^
C:\ProgramData\MatrixTSL\FlowcodeV9\CAL\internals.c:76:28: note: in expansion of macro 'CAL_APD'
#define CAL_APPEND(a, b) CAL_APD(a, b)
^
C:\ProgramData\MatrixTSL\FlowcodeV9\CAL\AVR\AVR_CAL_SPI.c:59:29: note: in expansion of macro 'CAL_APPEND'
#define MX_SPI_MOSI_TRIS_X CAL_APPEND(MX_SPI_MOSI_TRIS_, MX_SPI_NUM)
^
C:\ProgramData\MatrixTSL\FlowcodeV9\CAL\AVR\AVR_CAL_SPI.c:163:44: note: in expansion of macro 'MX_SPI_MOSI_TRIS_X'
FC_CAL_Bit_High_DDR (MX_SPI_MOSI_PORT_X, MX_SPI_MOSI_TRIS_X, MX_SPI_MOSI_PIN_X); // MOSI pin is default high
^
C:\Users\geomanfred\Documents\Flowcode Projects\Arduino Mega R3 SH1106H.c:73:28: note: each undeclared identifier is reported only once for each function it appears in
#define MX_SPI_MOSI_TRIS_1 tris
^
C:\ProgramData\MatrixTSL\FlowcodeV9\CAL\internals.c:413:38: note: in definition of macro 'set_bit'
#define set_bit( reg, bitNumb ) ((reg) |= (1 << (bitNumb)))
^
C:\ProgramData\MatrixTSL\FlowcodeV9\CAL\AVR\AVR_CAL_SPI.c:163:3: note: in expansion of macro 'FC_CAL_Bit_High_DDR'
FC_CAL_Bit_High_DDR (MX_SPI_MOSI_PORT_X, MX_SPI_MOSI_TRIS_X, MX_SPI_MOSI_PIN_X); // MOSI pin is default high
^
C:\ProgramData\MatrixTSL\FlowcodeV9\CAL\internals.c:75:26: note: in expansion of macro 'MX_SPI_MOSI_TRIS_1'
#define CAL_APD(a, b) a##b
^
C:\ProgramData\MatrixTSL\FlowcodeV9\CAL\internals.c:76:28: note: in expansion of macro 'CAL_APD'
#define CAL_APPEND(a, b) CAL_APD(a, b)
^
C:\ProgramData\MatrixTSL\FlowcodeV9\CAL\AVR\AVR_CAL_SPI.c:59:29: note: in expansion of macro 'CAL_APPEND'
#define MX_SPI_MOSI_TRIS_X CAL_APPEND(MX_SPI_MOSI_TRIS_, MX_SPI_NUM)
^
C:\ProgramData\MatrixTSL\FlowcodeV9\CAL\AVR\AVR_CAL_SPI.c:163:44: note: in expansion of macro 'MX_SPI_MOSI_TRIS_X'
FC_CAL_Bit_High_DDR (MX_SPI_MOSI_PORT_X, MX_SPI_MOSI_TRIS_X, MX_SPI_MOSI_PIN_X); // MOSI pin is default high
^
C:\Users\geomanfred\Documents\Flowcode Projects\Arduino Mega R3 SH1106H.c:83:28: error: 'port' undeclared (first use in this function)
#define MX_SPI_MOSI_PORT_1 port
^
C:\ProgramData\MatrixTSL\FlowcodeV9\CAL\internals.c:413:38: note: in definition of macro 'set_bit'
#define set_bit( reg, bitNumb ) ((reg) |= (1 << (bitNumb)))
^
C:\ProgramData\MatrixTSL\FlowcodeV9\CAL\AVR\AVR_CAL_SPI.c:163:3: note: in expansion of macro 'FC_CAL_Bit_High_DDR'
FC_CAL_Bit_High_DDR (MX_SPI_MOSI_PORT_X, MX_SPI_MOSI_TRIS_X, MX_SPI_MOSI_PIN_X); // MOSI pin is default high
^
C:\ProgramData\MatrixTSL\FlowcodeV9\CAL\internals.c:75:26: note: in expansion of macro 'MX_SPI_MOSI_PORT_1'
#define CAL_APD(a, b) a##b
^
C:\ProgramData\MatrixTSL\FlowcodeV9\CAL\internals.c:76:28: note: in expansion of macro 'CAL_APD'
#define CAL_APPEND(a, b) CAL_APD(a, b)
^
C:\ProgramData\MatrixTSL\FlowcodeV9\CAL\AVR\AVR_CAL_SPI.c:58:29: note: in expansion of macro 'CAL_APPEND'
#define MX_SPI_MOSI_PORT_X CAL_APPEND(MX_SPI_MOSI_PORT_, MX_SPI_NUM)
^
C:\ProgramData\MatrixTSL\FlowcodeV9\CAL\AVR\AVR_CAL_SPI.c:163:24: note: in expansion of macro 'MX_SPI_MOSI_PORT_X'
FC_CAL_Bit_High_DDR (MX_SPI_MOSI_PORT_X, MX_SPI_MOSI_TRIS_X, MX_SPI_MOSI_PIN_X); // MOSI pin is default high
^
C:\ProgramData\MatrixTSL\FlowcodeV9\CAL\AVR\AVR_CAL_SPI.c: In function 'FC_CAL_SPI_Master_Uninit_1':
C:\Users\geomanfred\Documents\Flowcode Projects\Arduino Mega R3 SH1106H.c:73:28: error: 'tris' undeclared (first use in this function)
#define MX_SPI_MOSI_TRIS_1 tris
^
C:\ProgramData\MatrixTSL\FlowcodeV9\CAL\internals.c:412:39: note: in definition of macro 'clear_bit'
#define clear_bit( reg, bitNumb ) ((reg) &= ~(1 << (bitNumb)))
^
C:\ProgramData\MatrixTSL\FlowcodeV9\CAL\AVR\AVR_CAL_SPI.c:315:3: note: in expansion of macro 'FC_CAL_Bit_In_DDR'
FC_CAL_Bit_In_DDR (MX_SPI_MOSI_PORT_X, MX_SPI_MOSI_TRIS_X, MX_SPI_MOSI_PIN_X);
^
C:\ProgramData\MatrixTSL\FlowcodeV9\CAL\internals.c:75:26: note: in expansion of macro 'MX_SPI_MOSI_TRIS_1'
#define CAL_APD(a, b) a##b
^
C:\ProgramData\MatrixTSL\FlowcodeV9\CAL\internals.c:76:28: note: in expansion of macro 'CAL_APD'
#define CAL_APPEND(a, b) CAL_APD(a, b)
^
C:\ProgramData\MatrixTSL\FlowcodeV9\CAL\AVR\AVR_CAL_SPI.c:59:29: note: in expansion of macro 'CAL_APPEND'
#define MX_SPI_MOSI_TRIS_X CAL_APPEND(MX_SPI_MOSI_TRIS_, MX_SPI_NUM)
^
C:\ProgramData\MatrixTSL\FlowcodeV9\CAL\AVR\AVR_CAL_SPI.c:315:42: note: in expansion of macro 'MX_SPI_MOSI_TRIS_X'
FC_CAL_Bit_In_DDR (MX_SPI_MOSI_PORT_X, MX_SPI_MOSI_TRIS_X, MX_SPI_MOSI_PIN_X);
^
C:\ProgramData\MatrixTSL\FlowcodeV9\CAL\AVR\AVR_CAL_SPI.c: In function 'FC_CAL_SPI_Master_Byte_1':
C:\Users\geomanfred\Documents\Flowcode Projects\Arduino Mega R3 SH1106H.c:83:28: error: 'port' undeclared (first use in this function)
#define MX_SPI_MOSI_PORT_1 port
^
C:\ProgramData\MatrixTSL\FlowcodeV9\CAL\internals.c:413:38: note: in definition of macro 'set_bit'
#define set_bit( reg, bitNumb ) ((reg) |= (1 << (bitNumb)))
^
C:\ProgramData\MatrixTSL\FlowcodeV9\CAL\AVR\AVR_CAL_SPI.c:343:6: note: in expansion of macro 'FC_CAL_Bit_High'
FC_CAL_Bit_High(MX_SPI_MOSI_PORT_X, MX_SPI_MOSI_PIN_X); //Set SDO bit
^
C:\ProgramData\MatrixTSL\FlowcodeV9\CAL\internals.c:75:26: note: in expansion of macro 'MX_SPI_MOSI_PORT_1'
#define CAL_APD(a, b) a##b
^
C:\ProgramData\MatrixTSL\FlowcodeV9\CAL\internals.c:76:28: note: in expansion of macro 'CAL_APD'
#define CAL_APPEND(a, b) CAL_APD(a, b)
^
C:\ProgramData\MatrixTSL\FlowcodeV9\CAL\AVR\AVR_CAL_SPI.c:58:29: note: in expansion of macro 'CAL_APPEND'
#define MX_SPI_MOSI_PORT_X CAL_APPEND(MX_SPI_MOSI_PORT_, MX_SPI_NUM)
^
C:\ProgramData\MatrixTSL\FlowcodeV9\CAL\AVR\AVR_CAL_SPI.c:343:22: note: in expansion of macro 'MX_SPI_MOSI_PORT_X'
FC_CAL_Bit_High(MX_SPI_MOSI_PORT_X, MX_SPI_MOSI_PIN_X); //Set SDO bit
^

Error returned from [avr-gcc.exe]

C:\ProgramData\MatrixTSL\FlowcodeV9\FCD\AVR\batchfiles\avra.bat reported error code 0x1

Autoclose turned off


FINISHED

"

Re: Arduino Mega R3 and gLCD SH1106 SPI

Posted: Tue Jun 28, 2022 5:24 pm
by jgu1
Hello geomanfred!

These tiny display doesn`t work in FC9 But fine in FC8 ?Have a look here:

viewtopic.php?f=3&t=790


Br Jorgen

Re: Arduino Mega R3 and gLCD SH1106 SPI

Posted: Wed Jun 29, 2022 10:02 am
by BenR
Hello,
error: 'port' undeclared (first use in this function)
It sounds like your display component may have unconnected pins. Check the properties of the component on the panel.

Re: Arduino Mega R3 and gLCD SH1106 SPI

Posted: Wed Jun 29, 2022 1:07 pm
by geomanfred
I have tried various settings and in the end it worked for me.
I do not know what have I done to make it work. It could be pin remapping or Font setting, but it works now in SPI mode. One error that I remember was not setting the programming port on the project settings.
I have tried 2 different OLEDs with SH1106: one is Waveshare, which has SPI and I2C option and another one, no name, only I2C. Both worked, Waveshare in SPI and the other one on I2C.
The Waveshare worked in the past with I2C too, but now it does not work anymore with I2C, it works only with SPI. I do not know why. I have tried also with Arduino IDE, checked the pin mapping, the right address, I2C resistors pull-up and cannot be seen by the I2C scanner of Arduino, but in the past it worked. I do not why it does not work now anymore on I2C, but that is another story. FC9 works now in my case with these SH1106 OLEDs.

Re: Arduino Mega R3 and gLCD SH1106 SPI

Posted: Tue Jul 05, 2022 10:15 am
by geomanfred
I have 2 more questions related with these OLEDs:
- Why I cannot print negative numbers on OLED display? Why I cannot see the “-” symbol?
- If I print a 2 digit or 3 digit number on the same X, Y location, then when it goes down. Lets’s say from 999 to 99 or to 9, then it remains on digit on display printed if I do not clear somehow that location. So I tried printing 3-4 empty spaces or tried ClearDisplay command.
In both cases, that digit blinks somehow, it is noticeable with the eyes that before is an empty space printed. It is disturbing.
I increased I2C to 1MHz and seems a bit better, but still observable.
With Arduino IDE I do not see anything, the text or numbers just appear on OLED on the same X,Y location even if print “ ” empty spaces before on the same X,Y location.
Attached is the test code.
How can we solve that problem?

Re: Arduino Mega R3 and gLCD SH1106 SPI

Posted: Tue Jul 05, 2022 10:48 am
by geomanfred
Looking at this topic: viewtopic.php?f=3&t=1300
I tried to implement it usigíng TextField.
But I have the same problems: signed numbers, negative numbers are not printed and the location where is printed is blinking-like during the print moment.

Re: Arduino Mega R3 and gLCD SH1106 SPI

Posted: Tue Jul 05, 2022 12:25 pm
by medelec35
Hello.
Within your loop, you are using Count using a variable.
That will always reset the variable to 0, so the count will override your variable value (-20 in your case) and start at 0.
Try the attached file, and see if that is what you are after.

Re: Arduino Mega R3 and gLCD SH1106 SPI

Posted: Tue Jul 05, 2022 3:12 pm
by geomanfred
Thank you Martin!
That solved indeed the negative numbers print problem.
How do we solve the 2nd problem?

Re: Arduino Mega R3 and gLCD SH1106 SPI

Posted: Tue Jul 05, 2022 9:37 pm
by medelec35
Hello.
If not using the TextField component, you can ensure the unrequired digits are erased by printing a string instead of a print number.
Then use something like

Code: Select all

CountString = CountString + "    "
The spaces will overwrite the unwanted chars.
To convert a number to string you could either use

Code: Select all

CountString = STRING count
or

Code: Select all

CountString = ToString$ (count)
I have included both methods in the attached project.

Re: Arduino Mega R3 and gLCD SH1106 SPI

Posted: Wed Jul 06, 2022 8:35 am
by geomanfred
Thank you very much Martin!
That solved indeed the "flickering" problem too and the OLED displays smooth the numbers.