program modification

Post here first, or if you can't find a relevant section!
stan
Posts: 70
Joined: Wed Nov 11, 2020 7:40 pm

program modification

Post by stan »

I modify this program to have on OLED "Hello World "
viewtopic.php?f=7&t=402

On serial monitor I have it but OLED is black = what to do ?

Code: Select all

 
//https://www.stm32duino.com/viewtopic.php?t=402
 
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
 
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels
 

TwoWire Wire2(PB11, PB10);// OLED
Adafruit_SSD1306 *display;
 
void setup() {
  Serial.begin(115200);
  Wire2.begin();
  Wire2.setClock(400000);
 
  display = new Adafruit_SSD1306(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire2); // OLED
 
  while (!display->begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
    delay(500);
  }
  display->clearDisplay();
  display->dim(0);
  display->setTextSize(1);
  display->setTextColor(WHITE);
}
 
void loop()
{
  Serial.println("Hello World");
  display->setCursor(0, 0);
  display->println("Hello World");
  display->display();
}
mrburnette
Posts: 633
Joined: Thu Dec 19, 2019 1:23 am
Answers: 7

Re: program modification

Post by mrburnette »

Maple Mini I2C (5 year old Adafruit libs)

Code: Select all

#include <SPI.h>
#include <Wire.h>
#include <Streaming.h>
#include "./Adafruit_GFX.h"
#include "./Adafruit_SSD1306.h"
#include "./BMP085.h" // #include "I2CDEV.h" is pulled in also

// These pin #'s are for Maple Mini
//     __Signal__Maple_//__OLED 128x64___
#define OLED_CS   14   //   ---   x Not Connected
#define OLED_DC   22   //   D/C   pin# 6
#define OLED_RST  21   //   RST   pin# 5
#define OLED_MOSI 20   //   SDA   pin# 4
#define OLED_CLK  19   //   SCL   pin# 3

Adafruit_SSD1306 OLED(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RST, OLED_CS);  // OLED object

Full ZIP compiles on current IDE (unknown if OLED works, I cannot find my OLED parts box at the moment.)
Sketch uses 28036 bytes (22%) of program storage space. Maximum is 122880 bytes.
Global variables use 4472 bytes (21%) of dynamic memory, leaving 16008 bytes for local variables. Maximum is 20480 bytes.
Attachments
SPI_OLED_BPM180.zip
(25.31 KiB) Downloaded 251 times
stan
Posts: 70
Joined: Wed Nov 11, 2020 7:40 pm

Re: program modification

Post by stan »

The idea is to use I2C2 = PB10, PB11.
STM342F103.
mrburnette
Posts: 633
Joined: Thu Dec 19, 2019 1:23 am
Answers: 7

Re: program modification

Post by mrburnette »

stan wrote: Tue Jan 26, 2021 12:36 am The idea is to use I2C2 = PB10, PB11.
STM342F103.
IF you are using the Libmaple (Roger's) core:
https://www.google.com/search?&q=I2C2+s ... oforum.com


If you are using the Official core, maybe check out the WiKi.
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: program modification

Post by ag123 »

i've not worked with SSD1306 but the Adafruit tutorial may be useful
https://learn.adafruit.com/monochrome-o ... s/overview
there is a datasheet in the downloads page, keep it handy

but u'd need to find out if the lcd is responding over the i2c bus
i2c has an ack response, one of those ways is to find out in the i2c code if there is a way to print (or insert your own print statement) some debug output when the oled is connected.

among the things you need to be sure that your oled is at the correct address
https://learn.adafruit.com/i2c-addresses
try the different address like 0x3C and 0x3D
Last edited by ag123 on Tue Jan 26, 2021 7:51 am, edited 1 time in total.
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: program modification

Post by fpiSTM »

You van use i2c scanner example from the wire library example.
stan
Posts: 70
Joined: Wed Nov 11, 2020 7:40 pm

Re: program modification

Post by stan »

When I connect OLED to PB6 and PB7 I have address 0x3C,
When I connect it to PB10 and BP11 I have this;

scan 10.png
scan 10.png (14.9 KiB) Viewed 5083 times
Can someone do similar scanning and show the results, does not have to be OLED, can be LCD16x2 with I2C .
Franke39
Posts: 30
Joined: Sat Mar 28, 2020 6:39 pm

Re: program modification

Post by Franke39 »

The number of connections/wires needed is determined by the OLED display. The Adafruit ones have a dedicated connection for reset, (and may also have optional SPI) BUT the cheaper ones don't. I am using one of the cheaper ones and it has 4 connections: ground, Vcc, SCL and SDA.

When you asked for a "scan" I assume you are asking for the results of a I2C scanner. Most I2C scanners I see, are for the Uno/Nano type boards and only look for one I2C bus. If you use that type of I2C scanner, it doesn't know to look on the second I2C bus (SCL2 @ PB10, SDA2 @ PB11)... It will only show the first I2C bus (SCL1 @ PB6, SDA1 @ PB7)

If you want to use the second I2C bus you need to add these lines before setup()

Code: Select all

 #define OLED_RESET -1 // use -1 if no reset pin on OLED board

// use second I2C bus on STM32F103
// TwoWire Wire2(SDA2, SCL2);
TwoWire Wire2(PB11, PB10);

Adafruit_SSD1306 Display
// below is for a 128x64 OLED. Other option is 128x32 for smaller OLED
(128, 64, &Wire2, OLED_RESET); 
Then after setup():

Code: Select all

   Display1.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // if nothing is displayed using 0x3C, try 0x3D
  
  //  Display1
  Display1.clearDisplay();
  Display1.setTextSize(2);
  Display1.setTextColor(WHITE, BLACK);
  Display1.setCursor(0, 0 );
  Display1.println("Display");
  Display1.println("I2C #2 @ 3C");
  Display1.display(); 
I hope this helps :)
stan
Posts: 70
Joined: Wed Nov 11, 2020 7:40 pm

Re: program modification

Post by stan »

I did this way and have an error

Code: Select all

// --------------------------------------
// i2c_scanner
//
// Version 1
//    This program (or code that looks like it)
//    can be found in many places.
//    For example on the Arduino.cc forum.
//    The original author is not know.
// Version 2, Juni 2012, Using Arduino 1.0.1
//     Adapted to be as simple as possible by Arduino.cc user Krodal
// Version 3, Feb 26  2013
//    V3 by louarnold
// Version 4, March 3, 2013, Using Arduino 1.0.3
//    by Arduino.cc user Krodal.
//    Changes by louarnold removed.
//    Scanning addresses changed from 0...127 to 1...119,
//    according to the i2c scanner by Nick Gammon
//    http://www.gammon.com.au/forum/?id=10896
// Version 5, March 28, 2013
//    As version 4, but address scans now to 127.
//    A sensor seems to use address 120.
//
// This sketch tests the standard 7-bit addresses
// Devices with higher bit address might not be seen properly.
//

#include <Wire_slave.h>

//use IIC2
//TwoWire WIRE2 (2,I2C_FAST_MODE);
//#define Wire WIRE2

//////////////////
 #define OLED_RESET -1 // use -1 if no reset pin on OLED board

// use second I2C bus on STM32F103
// TwoWire Wire2(SDA2, SCL2);
TwoWire Wire2(PB11, PB10);

Adafruit_SSD1306 Display
// below is for a 128x64 OLED. Other option is 128x32 for smaller OLED
(128, 64, &Wire2, OLED_RESET);
//////////////////
void setup() {

  Serial.begin(115200);
  Wire.begin();
  Serial.println("\nI2C Scanner");
}


void loop() {
  byte error, address;
  int nDevices;

  Serial.println("Scanning...");

  nDevices = 0;
  for(address = 1; address < 127; address++) {
    // The i2c_scanner uses the return value of
    // the Write.endTransmisstion to see if
    // a device did acknowledge to the address.

    Wire.beginTransmission(address);
    error = Wire.endTransmission();
    
    if (error == 0) {
      Serial.print("I2C device found at address 0x");
      if (address < 16) 
        Serial.print("0");
      Serial.println(address, HEX);

      nDevices++;
    }
    else if (error == 4) {
      Serial.print("Unknown error at address 0x");
      if (address < 16) 
        Serial.print("0");
      Serial.println(address, HEX);
    }    
  }
  if (nDevices == 0)
    Serial.println("No I2C devices found");
  else
    Serial.println("done");

  delay(5000);           // wait 5 seconds for next scan
}
////////////////////
   Display1.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // if nothing is displayed using 0x3C, try 0x3D
  
  //  Display1
  Display1.clearDisplay();
  Display1.setTextSize(2);
  Display1.setTextColor(WHITE, BLACK);
  Display1.setCursor(0, 0 );
  Display1.println("Display");
  Display1.println("I2C #2 @ 3C");
  Display1.display(); 
////////////////////
error

Arduino: 1.8.12 (Mac OS X), Board: "Generic STM32F103C series, STM32F103C8 (20k RAM. 64k Flash), Serial, 72Mhz (Normal), Smallest (default)"

i2c_scanner_wire:38:25: error: no matching function for call to 'TwoWire::TwoWire(<anonymous enum>, <anonymous enum>)'
TwoWire Wire2(PB11, PB10);
^
In file included from /var/folders/yj/fygyw1t57zggv9lf50h08zr80000gn/T/arduino_modified_sketch_609513/i2c_scanner_wire.ino:27:0:
/Users/Documents/Arduino/hardware/Arduino_STM32-master-3/STM32F1/libraries/WireSlave/src/Wire_slave.h:91:3: note: candidate: TwoWire::TwoWire(i2c_dev*)
TwoWire(i2c_dev* i2cDevice);
^~~~~~~
/Users/Documents/Arduino/hardware/Arduino_STM32-master-3/STM32F1/libraries/WireSlave/src/Wire_slave.h:91:3: note: candidate expects 1 argument, 2 provided
i2c_scanner_wire:40:1: error: 'Adafruit_SSD1306' does not name a type
Adafruit_SSD1306 Display
^~~~~~~~~~~~~~~~
i2c_scanner_wire:90:4: error: 'Display1' does not name a type
Display1.begin(SSD1306_SWITCHCAPVCC, 0x3C); // if nothing is displayed using 0x3C, try 0x3D
^~~~~~~~
i2c_scanner_wire:93:3: error: 'Display1' does not name a type
Display1.clearDisplay();
^~~~~~~~
i2c_scanner_wire:94:3: error: 'Display1' does not name a type
Display1.setTextSize(2);
^~~~~~~~
i2c_scanner_wire:95:3: error: 'Display1' does not name a type
Display1.setTextColor(WHITE, BLACK);
^~~~~~~~
i2c_scanner_wire:96:3: error: 'Display1' does not name a type
Display1.setCursor(0, 0 );
^~~~~~~~
i2c_scanner_wire:97:3: error: 'Display1' does not name a type
Display1.println("Display");
^~~~~~~~
i2c_scanner_wire:98:3: error: 'Display1' does not name a type
Display1.println("I2C #2 @ 3C");
^~~~~~~~
i2c_scanner_wire:99:3: error: 'Display1' does not name a type
Display1.display();
^~~~~~~~

exit status 1
no matching function for call to 'TwoWire::TwoWire(<anonymous enum>, <anonymous enum>)'
Franke39
Posts: 30
Joined: Sat Mar 28, 2020 6:39 pm

Re: program modification

Post by Franke39 »

What do you want to do?
Scan the second I2C bus, or use the second I2C bus?

The code above is a jumble of setting up the second I2C bus and scanning the first I2C bus.
Post Reply

Return to “General discussion”