Hi all! I´m a chemistry teacher and I´m learning how to develop some educational projects using the stm32f103c8t6 using the online mbed compiler. I´m trying to connect an oled display using I2C communication protocol (SDA,SCL- PB_11,PB_10). Using an arduino UNO I´ve found that the address of the display is 0X3C and the display is working fine. I imported several “hello world” programs with respective libraries and nothing works. The display is off all the time. Has someone had success compiling the Adafruit_SSD1306_I2c library with the stm32f103 and the oled? It should´nt be so difficult…however…
Regards from Brasil
Hi all, I think the problem is with the reset pin. The library asks for a RST pin and I gave PC_13, that is just the on board led. At least the main() is working now. The display is still dead.
regards to alll
Hello,
You can try to check similar topics
- Displaying Text on a SSD1306 Oled display - Mbed OS / Hello world! - Arm Mbed OS support forum
- Mbed LPC1768 with OLED - Mbed OS - Arm Mbed OS support forum
- Trying to make sense of SSD1306 display behaviour - Mbed OS - Arm Mbed OS support forum
BR, Jan
Hello Alfredo,
Using an arduino UNO I´ve found that the address of the display is 0X3C and the display is working fine.
Also notice that Mbed (as opposed to Arduino) uses 8-bit I2C address:
const int addr7bit = 0x3C; // 7bit I2C address used with Arduino
const int addr8bit = 0x3C << 1; // 8bit I2C address, 0x78 used with Mbed
Hello Zoltan, I have a working knowlege of C++ but I have some difficulties with binary manipulations. Thanks again.
Alfredo
Hi Jan, thanks for your comment. I did figure out the need to attribut an unused pin to the RST pin as stated in * Displaying Text on a SSD1306 Oled display - Mbed OS / Hello world! - Arm Mbed OS support forum comment, however, the display is still black. no caracter showing up. I put a blink routine inside main() function and is working but I could not find why it is not displaying any character.
Regards, Alfredo
Hi Zoltan, I’d like to ask you a favor: Could you please revise the code below and see if you find some mistakes. I’m using the Mbed online compiler and Adafruit_GFX library from Neal Horman . The program is working since the led blinks in the while loop. The oled display display’s nothing. If I put the display on a arduino uno it works. The voltage on display pins is OK.
#include “mbed.h”
#include “Adafruit_SSD1306.h”
#define sda PB_11 //SDA on STM32F103C8T6
#define scl PB_10 //SCL
DigitalOut led1(PA_7);//only used to verify main()
// SPI sub-class that provides a constructed default
class I2CPreInit : public I2C
{
public:
I2CPreInit(PinName sda, PinName scl) : I2C(sda, scl)
{
frequency(400000);
// frequency(100000);
start();
};
};
I2CPreInit myI2C(PB_11,PB_10);
Adafruit_SSD1306_I2c myOled(myI2C,PC_13,0x78,32,128);
int main()
{ led1=1; //entering the main()
wait(1);
led1=0;
uint16_t x=0;
myOled.begin();
myOled.clearDisplay();
myOled.display();
myOled.clearDisplay();
myOled.setTextCursor(0,0);
myOled.printf("Hello Mbed OS");
myOled.display();
while(1)
{
led1 = !led1; //Verifying the while loop
myOled.clearDisplay();
myOled.printf("%u\r",x);
myOled.display();
x = x + 1;
if (x==10) {
x=0;
}
wait(1.0);
}
}
Regards, Alfredo
And did you tried to check the communication? The library not check for any response (ACK or NACK) from the slave device.
BR, Jan
Hello Alfredo,
The code seems OK so it’s most likely a HW problem.
- Make sure there are 4.7k (or similar) pull up resistors connected to the SDA and SCL lines and the +3.3V rail.
- On the STM32F103C8T6 module the
PC_13
pin is connected to the onboard LED. Try to select a different one. For example, connect thePB_1
pin to the display’s RST pin and change the code accordingly:
Adafruit_SSD1306_I2c myOled(myI2C, PB_1, 0x78, 32, 128);
NOTE: If you’d like the posted code to be displayed as formatted put a line of three backtick characters (```) before and after the related code. The backtick character is usually available on the same key as the “~
” one.
The display looks nice so I placed an order on the eBay. But I’m afraid it will take a couple of weeks to get them.
First of all sorry by the wrong way that I posted my code. All connections seems right. I did check the display again using an arduino UNO. I was already using the pull up resistors (4.7K) on SDA/SCL, connecting to the 3.3V rail. I changed the RST to PB_1 as you suggested and nothing happens. The code runs until the while loop, the led1 blinks, but nothing shows on the display. I even tested other I2C pins like the PC_9/PB_8 and the PB_11/PB_10. I found a code called I2C_address_scaner. If I run this code in any of above I2C pins it returns two address: 0x78 and 0x79. If I disconnect the display, the I2C_scanner foud nothing. I think may be is some compatibility problem amongthe stm32f103c8t6 and the adafruit_GFX library. I do not know how to solve this problem. If I find a way I’ll post the solution here…looks like I’m not the only one looking for this solution. Thanks for your attention,
Best regards
Alfredo
Hello! I found a code at the mbed import called Oled_test written by Team A.I.Mergen. The oled display is working and this shows that is a library problem. Their library does not allow to write text on the led. I only managed a way to draw a dot and a rectangule and some splash screens previously defined. Good weekendo to all
Alfredo
I have used Neils code some years before with mbed2 and fixed some things. The reset line is not always present at the china breakout boards, so it can be set to NC. The code needs to handle NC, this was changed in mbed2 long time ago.
Hi, I’ve tryed to use your library with the same results. It gives no compile erros but does not print anything on th oled display.
Regards, Alfredo
I tried the library, what Jojo posted, with Nucleo-F303RE and it is working well, with Mbed2.
Example based on JojoS's version of library
// based on https://os.mbed.com/users/JojoS/code/Test_OLED_Display/
#include "mbed.h" //Mbed2
#include "Adafruit_SSD1306.h"
class myI2C : public I2C
{
public:
myI2C(PinName sda, PinName scl) : I2C(sda, scl) {
frequency(400000);
start();
};
};
DigitalOut led(LED1);
myI2C gI2C(PB_9,PB_8); // Nucleo-F303RE
Adafruit_SSD1306_I2c gOled(gI2C, NC, 0x78, 32, 128);
int main()
{
int x = 0;
gOled.clearDisplay();
gOled.display();
gOled.printf("%ux%u OLED Display\r\n", gOled.width(), gOled.height());
while (1) {
led = !led;
gOled.setTextCursor(0, 10);
gOled.printf("%d\r", x);
gOled.display();
x++;
wait(1);
}
}
And also this one from Helmut is working well with MbedOS6+
Example based on Helmut's version of library
#include "mbed.h" / /MbedOS 6.7
#include "SSD1306I2C.h"
#define OLED_ADR 0x3C
SSD1306I2C lcd(OLED_ADR,I2C_SDA, I2C_SCL, GEOMETRY_128_32);
DigitalOut led(LED1);
int main()
{
lcd.init();
lcd.setFont(ArialMT_Plain_16);
lcd.drawString(0,0,"Hello world!");
lcd.setBrightness(64);
lcd.display();
while(1){
led = !led;
thread_sleep_for(800);
}
}
BR, Jan
Hi Jan, yesterday night I found a code ou_mbed_oled from Poushen Ou that is working for what I need. I just want display a temperature value of a calorimiter. Its variations are very slow. The Ou code does note use adafruit_gfx library, instead he re-wrote and it is working with mbed online compiler (by the way, I do not know what version it is). I wiil look at JojoS’s library to see if it is easer to use .
Thanks a lot for your efforts.
Alfredo