Hello everyone!
I am a complete newbie to Arduino coding, my current project needs to use the SDA/SCL signal for an OLED display and a DAC (MCP4725). I assume the TCA9548A would get the job done to multiply the SDA/SCL signals.
I am, for the time being just trying to get the U8glib- Hello World code to display on my OLED, through the multiplexer. If, someone could then give me some coding information to use the MCP4725 in the same multiplexer that would be awesome!
I have scoured over several tutorials for both chips, but nothing seems to be working inconjuction with each other.
I have to use U8glib, seems to be the only one I can get to work with the screen.
I am essentially creating a custom guitar pedal. Using a Arduino Mega 2560, an OLED display, and adding a DAC converter to create a true analog output.
When I run the i2c scanner, it recognizes the TCA9548A at 0X70
When I run a different i2c scanner it finds an ADDR at 112. I'm not sure how to interpret this lol.
Code is below.
/*
HelloWorld.pde
"Hello World!" example code.
>>> Before compiling: Please remove comment from the constructor of the
>>> connected graphics display (see below).
Universal 8bit Graphics Library, https://github.com/olikraus/u8glib/
Copyright (c) 2012, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <Wire.h>
#include "U8glib.h"
#define MUX_Address 0x70 // TCA9548A Encoders address
char tmp_string[8]; // Temp string to convert numeric values to string before print to OLED display
U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_NO_ACK); // Display which does not send ACK
// Initialize I2C buses using TCA9548A I2C Multiplexer
void tcaselect(uint8_t i2c_bus) {
if (i2c_bus > 7) return;
Wire.beginTransmission(MUX_Address);
Wire.write(1 << i2c_bus);
Wire.endTransmission();
}
void draw(void) {
// graphic commands to redraw the complete screen should be placed here
u8g.setFont(u8g_font_unifont);
//u8g.setFont(u8g_font_osb21);
u8g.drawStr( 0, 22, "Hello World!");
}
void setup(){
DisplayInit(); // Initialize the displays
Wire.begin();
}
// Initialize the displays
void DisplayInit(){
for (int i = 0; i < 7; i++) {
tcaselect(0); // Loop through each connected displays on the I2C buses
u8g.firstPage();
do {
u8g.begin(); // Initialize display
} while( u8g.nextPage() );
}
// assign default color value
if ( u8g.getMode() == U8G_MODE_R3G3B2 ) {
u8g.setColorIndex(255); // white
}
else if ( u8g.getMode() == U8G_MODE_GRAY2BIT ) {
u8g.setColorIndex(3); // max intensity
}
else if ( u8g.getMode() == U8G_MODE_BW ) {
u8g.setColorIndex(1); // pixel on
}
else if ( u8g.getMode() == U8G_MODE_HICOLOR ) {
u8g.setHiColorByRGB(255,255,255);
}
pinMode(8, OUTPUT);
}
void loop(void) {
for (int i = 0; i < 7; i++) {
tcaselect(0);
u8g.begin();
u8g.firstPage();
do {
draw();
} while( u8g.nextPage() );
// rebuild the picture after some delay
delay(50);
}
}